Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

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

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
                 }
                 '''
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"))
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...