[QUESTION] Using RDFQuery with DbPedia Wiktionary
dgerding opened this issue · 2 comments
Hi,
(Thanks for this library and the great PDF docs.)
I am trying to return dbpedia entries for Wiktionary terms by searching for the term using the RDFSharp library. (Once I have the term, I'll get additional properties, but for now I just need to know if I'm approaching this the right way.)
My question: Can someone tell me how to modify my RDFQuery, and dependent object instances, to return get the dbpedia entry for a specific wiktionary term by matching part of speech and the term string.
I used a related example SPARQL query from SO (https://stackoverflow.com/questions/30895925/how-to-get-all-nouns-in-a-certain-language-from-wiktionary-using-sparql) and the RDFSharp query docs as a starting point.
The SPARQL query generated by my implementation looks good to me, but I'm a Sparql newb. So far I only get empty result sets.
Any ideas or suggestions appreciated.
...
`
PREFIX terms: http://wiktionary.dbpedia.org/terms/
PREFIX dc: http://purl.org/dc/elements/1.1/
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
SELECT *
WHERE {
{
?TERM terms:hasPoS terms: Noun .
FILTER ( ?TERMLABEL = "dog" )
}
}
LIMIT 5
RDFSPARQLEndpoint dbPedidaWiktionaryEndpoint = new RDFSPARQLEndpoint(new Uri(@"https://dbpedia.org/sparql"));
RDFNamespace terms = new RDFNamespace("terms", "http://wiktionary.dbpedia.org/terms/");
RDFNamespace dc = new RDFNamespace("dc", "http://purl.org/dc/elements/1.1/");
RDFNamespace rdfs = new RDFNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
RDFResource termsHasPos = new RDFResource(terms + "hasPoS");
RDFResource termsNoun = new RDFResource(terms + "Noun");
RDFResource termsEnglish = new RDFResource(terms + "English");
// Create variables
RDFVariable searchTerm = new RDFVariable("term"); //passed in
RDFVariable termLabel = new RDFVariable("termLabel");
RDFPatternGroup PG1 = new RDFPatternGroup();
RDFPattern termIsANoun = new RDFPattern(searchTerm, termsHasPos, termsNoun);
RDFModifier limitReturnCount = new RDFLimitModifier(5);
PG1.AddPattern(termIsANoun)
.AddFilter(new RDFComparisonFilter( RDFQueryEnums.RDFComparisonFlavors.EqualTo, termLabel, new RDFPlainLiteral(term)));
RDFSPARQLEndpointQueryOptions endpointQueryOptions = new RDFSPARQLEndpointQueryOptions();
endpointQueryOptions.TimeoutMilliseconds = 30000;
RDFGraph graph = new RDFGraph();
// Compose query
RDFSelectQuery query = new RDFSelectQuery()
.AddPrefix(terms)
.AddPrefix(dc)
.AddPrefix(rdfs)
.AddPatternGroup(PG1)
.AddModifier(limitReturnCount);
//have tried these "flavors" of query invocations, jic, alway empty result :/
//RDFSelectQueryResult selectResult = await query.ApplyToSPARQLEndpointAsync(dbPedidaWiktionaryEndpoint, endpointQueryOptions);
//RDFSelectQueryResult selectResult = query.ApplyToGraph(graph);
RDFSelectQueryResult selectResult = await query.ApplyToGraphAsync(graph);
string queryText = query.ToString();
`
Hi David,
I am trying an even simpler smoke-test query directly on https://dbpedia.org/sparql web page and found that there is something wrong with the predicate "terms:hasPoS" because I never get data for it:
PREFIX terms: <http://wiktionary.dbpedia.org/terms/>
SELECT *
WHERE {
{
?S terms:hasPoS ?O .
}
}
LIMIT 1
I also get a lot of "Connection TImeout" errors from the DBPedia SPARQL endpoint, so I assume the status of their infrastructure is not stable at the moment.
About your query: be aware that in case you had results from the "?TERM terms:hasPoS terms:Noun" pattern you ask to filter rows having the "?TERMLABEL" column equal to "dog", but you don't have that variable in your bindings so you'll have always 0 results.
I found this page which documents ontology properties you may use in your queries: wiktionary-rdf-extraction
Let me know if things get better from DBPedia side.
Regards,
Marco