- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经通过曼彻斯特 OWL 语法转换器将众所周知的 pizza.owl
本体转换为 RDF 文件 pizza.rdf
。我已经写了这段代码,但我没有得到任何结果,但也没有错误,也没有。如何使用谓词 MushroomTopping
获取三元组?
TripleStore store = new TripleStore();
store.LoadFromFile(@"C:\pizza.rdf");
Object results = store.ExecuteQuery("PREFIX pizza:<http://example.org/> SELECT * WHERE { ?X ?Y pizza:MushroomTopping . }
if (results is SparqlResultSet)
{
//Print out the Results
//Console.WriteLine("working up to this ");
SparqlResultSet rset = (SparqlResultSet)results;
foreach (SparqlResult result in rset.Results)
{
Console.WriteLine(result.ToString());
}
}
最佳答案
参见 Querying with SPARQL文档特别是关于 Common Errors 的部分其中说:
A common error with making queries is that queries by default typically operate only over the unnamed default graph in the store (depending on your query processor). Therefore executing queries may yield no results depending on what graphs your data is in and whether you configured your dataset correctly. Please see the SPARQL Datasets page for discussions of configuring different kinds of dataset. You can also look at Debugging SPARQL Queries for a method to debug what is happening with your query when using the in-memory SPARQL engine.
The typical cause of this is that when you call LoadFromFile() or LoadFromUri() the library automatically assigns the graph a name based on the data source so when you add it a store instance it is a named graph rather than the default graph. The easiest way to resolve this is to simply set the BaseUri property of your graph instance to null after loading it and before you execute queries with it.
添加的重点是我的,因为这准确描述了您的情况。加载的图表根据其来源的文件命名,命名图表也是如此,您商店的默认图表保持为空。
另请注意,由于这个问题,您使用的 ExecuteQuery()
方法已被特别弃用,并且您会收到有关使用过时方法的编译器警告。此方法可能会在未来的版本中删除,因此应避免使用。
有两种方法可以解决这个问题,首先,如上面引用的文档中所述,我们可以从图中删除名称,以便将其视为默认图:
Graph g = new Graph();
g.LoadFromFile(@"C:\pizza.rdf");
g.BaseUri = null;
store.Add(g);
或者您可以通过创建 query processor 来完全避免使用已弃用的方法。和一个数据集,让您可以直接控制将哪个图用作默认值:
Graph g = new Graph();
g.LoadFromFile(@"C:\pizza.rdf");
ISparqlDataset ds = new InMemoryDataset(g);
LeviathanQueryProcessor processor = new LeviathanQueryProcessor(ds);
Object results = processor.ProcessQuery("# Your query");
关于c# - dotNetRDF 中的 sparql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30497174/
我正在比较两个图表,一个来自具有简单文字对象的 Turtle 文件,另一个来自具有显式数据类型 IRI 的文件。这些图在其他方面是相等的。 图 A: "o" 图 B: "o"^^xsd:str
我已经通过曼彻斯特 OWL 语法转换器将众所周知的 pizza.owl 本体转换为 RDF 文件 pizza.rdf。我已经写了这段代码,但我没有得到任何结果,但也没有错误,也没有。如何使用谓词 Mu
我想做的是在我使用 Protege 5 创建的猫头鹰文件中使用以下查询列出所有类,并将“foaf”作为导入的本体。 PREFIX rdf: PREFIX owl: PREFIX rdfs: PR
我正在使用 dotnetRDF 框架和 C# 为患者导出海龟格式的图形,为每个患者创建一个海龟文件。在大约 400 名患者之后,程序由于内存问题而停止。每个海龟文件在 2 - 150 MB 之间。如任
我喜欢使用 dotNetRDF 从 RDF 文件中删除 RDF 元组。这是我正在使用的代码 public void deleteDest(string destID) {
当我使用 (dotnetRDF) VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultSet() 在 http://dbpedia.org/sparql
我使用 dotNetRDF 库编写 sparql 查询。我使用“http://dbpedia.org/sparql”作为 DBPedia SPARQL 端点,使用“http://dbpedia.org
用于读写 RDF 和使用具有不同端点的 Sparql 进行查询的最常用工具是什么。 到目前为止我发现 Jena (jena.net) :它是为 Java 开发的,但有些人设法将其转换为程序集 Dotn
我是一名优秀的程序员,十分优秀!