Getting Wiktionary Term from DBPedia Sparql Endpoint with RDFSharp

98 Views Asked by At

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 current implementation (below) only returns empty result sets.

How can I modify my RDFQuery and the 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 (How to get all nouns in a certain language from Wiktionary using SPARQL) and the RDFSharp query docs as a starting point.

...

//spaql generated by rdfsharp
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
//end sparql fragment


//C# 
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();

0

There are 0 best solutions below