我想得到我的本体的所有类。这是 Protege 创建的 RDF/XML 格式的本体文件的一部分:
<!-- http://www.w3.org/2002/07/owl#aqua -->
<Class rdf:about="&owl;aqua"/>
<!-- http://www.w3.org/2002/07/owl#varioPerfect -->
<Class rdf:about="&owl;varioPerfect"/>
我编写了这个查询,它在 Protege 中可以正常工作,但是当我在 dotNetRDF 中使用它时,它会返回类的完整 URI 而不仅仅是它的名称。
public string[] ontologysearch()
{
List<string> list = new List<string>();
TripleStore store = new TripleStore();
Graph mygraph = new Graph();
mygraph.LoadFromFile("D:/msc/search-engine/project/catalogXML.owl");
store.Add(mygraph);
string sparqlQuery1 = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ "SELECT distinct ?cls1"
+ " WHERE{"
+ " ?cls1 a owl:Class .}";
SparqlQueryParser sparqlParser = new SparqlQueryParser();
SparqlQuery query = sparqlParser.ParseFromString(sparqlQuery1);
InMemoryDataset ds = new InMemoryDataset(mygraph);
//Get the Query processor
ISparqlQueryProcessor processor = new LeviathanQueryProcessor(ds);
Object results = processor.ProcessQuery(query);
if (results is SparqlResultSet)
{
SparqlResultSet r = results as SparqlResultSet;
foreach (SparqlResult res in r)
{
list.Add(res["cls1"].ToString());
}
}
return list.ToArray();
}
我期望的结果只是“aqua”,但实际上是“ http://www.w3.org/2002/07/owl#aqua ”。为什么会发生这种情况,我该如何取而代之取回名称?