Free text search in sparql when you have multiword and scaping character

♀尐吖头ヾ 提交于 2020-01-16 19:47:09

问题


I am wondering how I can use in sparql query when I have a word like : Robert J. O'Neill I am looking for the resource that have the multiword unit with quota or unicode character in the Label property.

                 SELECT DISTINCT ?resource ?abstract 
                 WHERE {?resource rdfs:label ?s.
                 ?s <bif:contains> "'Robert J. O'Neill'"
                 ?resource dbo:abstract ?abstract
                 }
                 '''

回答1:


Here is the query that will return all the elements that have "Robert J. O'Neill" as label.

SELECT DISTINCT ?s WHERE 
{
    ?s rdfs:label ?label .
    FILTER(regex(?label, "Robert J. O'Neill", "i"))
}

If you are sure that you need a specific string matching. This is faster :

SELECT DISTINCT ?s WHERE 
{
    ?s rdfs:label ?label .
    ?label bif:contains "Robert J. O'Neill"
}

But be aware that, Virtuoso for example doesnt support such a query because of the spaces in the string. So an alternative is to avoid it as :

SELECT DISTINCT * WHERE 
{
    ?s rdfs:label ?label .
    ?label bif:contains "Robert" .
    FILTER (CONTAINS(?label, " J. O'Neill"))
}



回答2:


I found following code faster that the regex:

SELECT ?s  WHERE { ?s  rdfs:label ?o FILTER ( bif:contains ( ?o, '"Robert" AND "J." AND "Neill"' ) ) }


来源:https://stackoverflow.com/questions/50801621/free-text-search-in-sparql-when-you-have-multiword-and-scaping-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!