Reputation: 42957
I am trying to integrate SPARQL queries into Prolog program (I am using SWI-Prolog)
To test it I am doing the following operations:
Into SWI-Prolog shell I execute this command: use_module(library(semweb/sparql_client)). that load the sparql client library
Then, in the SWI-Prolog shell, I execute the following SPARQL query:
?- sparql_query('select count(*) where { ?person a http://dbpedia.org/ontology/Person .?person http://it.dbpedia.org/property/nome ?name.filter regex(?name,"Leonardo"). }', Row, [ host('dbpedia.org'), path('/sparql/')]). Row = row(literal(type('http://www.w3.org/2001/XMLSchema#integer', '0'))).
I don't know well SPARQL but I think that this is pretty simple and that work in this way:
This query ask about the instances number of objects that are considered personal names on a RDF ontology called dbpedia, passing the input parameter "Leonardo".
As you can see the problem seems that don't find any instance of this type (I have tried also with others personal name)
Why? What are am I missing?
Upvotes: 1
Views: 781
Reputation: 85813
Your query does not return what you want it to return. You can use SPARQL interactively with the DBpedia SPARQL endpoint. I suggest that you use that to debug your query and make sure it returns what you would like first, and then copy it into your Prolog program. You can build it up in pieces to make sure it's giving suitable results. For instance, start with something like the following:
select * where {
?person a <http://dbpedia.org/ontology/Person> .
}
LIMIT 10
Then expand it piece by piece:
select * where {
?person a <http://dbpedia.org/ontology/Person> .
?person <http://it.dbpedia.org/property/nome> ?name .
}
LIMIT 10
This query doesn't return anything, so it would be best to debug it before continuing on the the FILTER or COUNT.
After playing with the endpoint for a while, it seems that using REGEX is going to be kind of expensive, as are other string operations. If you can query for the strings you want directly, you might be better off. Unfortunately, you'll need to start working with language tags, too. For instance, here is a query that counts people with the given name or surname "Leonardo"
.
select COUNT(?person) where {
?person a dbpedia-owl:Person .
{ ?person foaf:givenName "Leonardo" }
UNION
{ ?person foaf:surname "Leonardo" }
}
It returns 0
. However, if we add (English) language tags to those strings, we get different results (133
):
select COUNT(?person) where {
?person a dbpedia-owl:Person .
{ ?person foaf:givenName "Leonardo"@en }
UNION
{ ?person foaf:surname "Leonardo"@en }
}
Upvotes: 6