c# - 使用 dotNetRDF 的 SPARQL 查询返回正确数量的结果但值为空,为什么?
问题描述
我已经在 protege 中的披萨本体上测试了我的 SPARQL 查询,并且查询工作正常。问题是当我尝试使用 dotNetRDF 对同一个本体文件运行相同的查询时。查询返回正确数量的结果,但它们似乎都是空的。
谁能指出这里可能存在什么问题?
使用 Protege 查询结果:
使用 dotNetRDF 查询结果:
这是我在 C# 中的代码:
OntologyGraph ontGraph = new OntologyGraph();
FileLoader.Load(ontGraph, "PizzaOntology.owl");
ontGraph.BaseUri = null;
#region SPARQL query
SparqlParameterizedString queryString = new SparqlParameterizedString();
queryString.Namespaces.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
queryString.Namespaces.AddNamespace("owl", new Uri("http://www.w3.org/2002/07/owl#"));
queryString.Namespaces.AddNamespace("rdfs", new Uri("http://www.w3.org/2000/01/rdf-schema#"));
queryString.Namespaces.AddNamespace("xsd", new Uri("http://www.w3.org/2001/XMLSchema#"));
queryString.Namespaces.AddNamespace("ont", new Uri("http://www.semanticweb.org/ontologies/pizza.owl#"));
queryString.CommandText = "SELECT ?subject";
queryString.CommandText += "WHERE { ?subject rdfs:subClassOf ont:PizzaBase }";
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery query = parser.ParseFromString(queryString);
#endregion
#region Query Processor
TripleStore store = new TripleStore();
store.Add(ontGraph);
InMemoryDataset ds = new InMemoryDataset(store, true);
ISparqlQueryProcessor processor = new LeviathanQueryProcessor(ds);
object results = processor.ProcessQuery(query);
if (results is SparqlResultSet)
{
//Print out the Results
SparqlResultSet rset = (SparqlResultSet)results;
foreach (SparqlResult result in rset)
{
Console.WriteLine(result.ToString());
}
}
#endregion
解决方案
推荐阅读
- algorithm - CRS格式的稀疏矩阵乘法
- python - 用列表列表屏蔽两列(Pandas df)
- r - 使用 R 中 k 的奇数值介于 1 和 21(含)之间的类包执行 KNN
- javascript - 如何使用带有 json 的 javascript 从站点中提取信息?
- jndi - JNDI,使用没有用户/密码的 Persistence.xml,仅从独立的 RMI 获得 DataSource
- asp.net - 为什么我的 Web Api(完整框架)项目不会生成 Xml 文档文件
- django - 无法通过虚拟机内的 Nginx 代理到 Websocket
- ssh - 如何使用 SSH 使用密码连接到 GCP VM 实例?
- spring-boot - 如何在保留旧参数的同时添加参数 URL?
- css - 如何改变纯css动画的前景色?