我正在使用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 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);
}
执行查询时出错
[第1行第10列到第1行第52列的UriToken]预期在查询中跟随PREFIX谓词的前缀令牌
答案 0 :(得分:0)
您使用的是哪个版本的库?
旧版本有一个错误,在你的情况u:
中,前缀之间必须有空格(在你的情况下是<http://localhost:49682/Semantic/test.rdf>
- 和名称空间URI}
如果您使用最新版本的库(0.5.1),则不会再出现此问题
修改强>
这是修复版本0.5.0(请参阅问题CORE-88),因此如果您看到此错误,则至少有两个版本落后,因为我已经回答了升级应解决问题。