简体   繁体   中英

Dbpedia sparql gives empty result to my query, what is wrong?

I'm doing sparql query in this site . It gives me an empty result, what is wrong with my query?

prefix foaf:    <http://xmlns.com/foaf/0.1/>
select * where {
?s rdf:type foaf:Person.

} LIMIT 100

This query is ok, but when I add the second pattern, I got empty result.

?s foaf:name 'Abraham_Robinson'.

prefix foaf:    <http://xmlns.com/foaf/0.1/>
select * where {
?s rdf:type foaf:Person.
?s foaf:name 'Abraham_Robinson'.
} LIMIT 100

How to correct my query so the result includes this record:

http://dbpedia.org/resource/Abraham_Robinson

The following query should work. Right now it isn't working due to a need to refresh the text index associated with this instance (currently in progress):

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
SELECT * where {
?s rdf:type foaf:Person.
?s foaf:name "'Abraham Robinson'".
} 
LIMIT 100

Note how the phrase is placed within single-quotes that are within double-quotes.

If the literal content is language-tagged, as is the case in DBpedia the exact-match query would take the form (already clarified in @TallTed's response):

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
SELECT * where {
?s rdf:type foaf:Person.
?s foaf:name 'Abraham Robinson'@en.
} 
LIMIT 100

This SPARQL Results Page Link should produce a solution when the index update completes.

I guess Kingsley misread this as a freetext search, rather than a simple string comparison.

The query Kingsley posted and linked earlier delivers no solution , for the same reasons as the original query failed, as identified in the comment by AKSW, ie --

  • foaf:name values don't generally replaces spaces with underscores as in the original value; ie, 'Abraham_Robinson' should have been 'Abraham Robinson'
  • foaf:name strings are typically langtagged, and it is in this case, so that actually needs to be 'Abraham Robinson'@en

Incorporating AKSW's fixes with this line ?s foaf:name 'Abraham Robinson'@en. , the query works .

All that said -- you may prefer an alternative query, which will deliver results whether or not the foaf:name value is langtagged and whether or not the spaces are replaced by underscores. This one is Virtuoso-specific, and produces results faster because the bif:contains function uses its free-text indexes, would be --

PREFIX  foaf:  <http://xmlns.com/foaf/0.1/>
SELECT * 
WHERE
  {
    ?s     rdf:type      foaf:Person ;
           foaf:name     ?name .
    ?name  bif:contains  "'Abraham Robinson'" . 
  } 
LIMIT 100

Generic SPARQL using a REGEX FILTER works against both Virtuoso and other RDF stores, but produces results more slowly because REGEX does not leverage the free-text indexes, as in --

PREFIX  foaf:  <http://xmlns.com/foaf/0.1/>
SELECT * 
WHERE
  {
    ?s     rdf:type      foaf:Person ;
           foaf:name     ?name .
    FILTER ( REGEX ( ?name, 'Abraham Robinson' ) ) . 
  } 
LIMIT 100

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM