在RDFDOTNET中查询RDF文件
我正在使用rdfdotnet库查询rdf文件 这是我的密码在RDFDOTNET中查询RDF文件,rdf,Rdf,我正在使用rdfdotnet库查询rdf文件 这是我的密码 //Define your Graph here - it may be better to use a QueryableGraph if you plan //on making lots of Queries against this Graph as that is marginally more performant IGraph g = new Graph(); //Load some data into your Gra
//Define your Graph here - it may be better to use a QueryableGraph if you plan
//on making lots of Queries against this Graph as that is marginally more performant
IGraph g = new Graph();
//Load some data into your Graph using the LoadFromFile() extension method
g.LoadFromFile("C:/Users/admin/Desktop/current/Semantic/test.rdf");
//Use the extension method ExecuteQuery() to make the query against the Graph
try
{
String q = " Prefix u:<http://localhost:49682/Semantic/test.rdf> SELECT * WHERE {?x1 u:age ?x2}";
Object results = g.ExecuteQuery(q);
if (results is SparqlResultSet)
{
//SELECT/ASK queries give a SparqlResultSet
SparqlResultSet rset = (SparqlResultSet)results;
foreach (SparqlResult r in rset)
{
//Do whatever you want with each Result
}
}
else if (results is IGraph)
{
//CONSTRUCT/DESCRIBE queries give a IGraph
IGraph resGraph = (IGraph)results;
foreach (Triple t in resGraph.Triples)
{
//Do whatever you want with each Triple
}
}
else
{
//If you don't get a SparqlResutlSet or IGraph something went wrong
//but didn't throw an exception so you should handle it here
Console.WriteLine("ERROR");
}
}
catch (VDS.RDF.Query.RdfQueryException queryEx)
{
//There was an error executing the query so handle it here
Console.WriteLine(queryEx.Message);
}
它在我执行查询时给出一个错误
[UriToken位于第1行第10列至第1行第52列]在查询中,应在前缀动词后加前缀标记您使用的是哪个版本的库 旧版本有一个bug,在你的例子中前缀u:-和命名空间URI之间必须有一个空格 如果使用库0.5.1的最新版本,则不再存在此问题 编辑 这是在版本0.5.0中修复的,请参阅问题,因此,如果您看到此错误,您在撰写本文时至少落后两个版本,因为我已经回答了升级应该解决此问题