在我的.owl文件中有五个个体与我的sparql查询匹配,我在protege的“sparql query”中尝试了相同的查询,它返回5个个体。但是当我在eclipse中使用jena库尝试这个查询时,它只返回3个个体!
我的代码:
String file="....\\Ontology.owl";
File f=new File(file);
FileReader r=new FileReader(f);
OntModel m=ModelFactory.createOntologyModel();
m.read(r,null);
String req ="" +
"PREFIX m: <http://www.NewOnto1.org/Ontology#>"+
"PREFIX aut:<http://www.NewOnto1.org/Citations#AuthorCite>"+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
"SELECT ?AuthorName ?AuthorField"+
"WHERE{"+
"?x rdf:type m:AuthorCite."+
"?x m:AuthorName ?AuthorName."+
"?x m:AuthorBelongsToField ?AuthorField."+
"FILTER regex(str(?AuthorField),\""+field+"\")."+
"}";
com.hp.hpl.jena.query.Query query = QueryFactory.create(req);
QueryExecution qe = QueryExecutionFactory.create(query, m);
com.hp.hpl.jena.query.ResultSet res = qe.execSelect();
//ResultSetFormatter.out(System.out, res, query);
int leng=0;
while(res.hasNext()){
leng++;
res.next();
}
System.out.println("Length : "+leng);
有关更多信息,我想获取属于特定研究领域(field)的个人(作者)。
暂无答案!
目前还没有任何答案,快来回答吧!