【发布时间】:2013-09-16 11:28:12
【问题描述】:
我有一个可以使用的 RDF 文件
Model model = ModelFactory.createDefaultModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(args[0]);
if (in == null) {
throw new IllegalArgumentException(
"File: " + args[0] + " not found");
}
// read the RDF/XML file
model.read(in, null);
我还有一个 OWL 文件,其中包含用于创建我的模型的本体描述。我的问题是:我是否需要阅读此文件(以及如何阅读?)才能正确使用我的 RDF 模型?
为了说明清楚,我举个例子:
我需要知道一个资源是否与其他资源有某种关系(例如Station1 has predicate "isResponsibleFor" Workorder1)。我怎样才能用 Jena 做到这一点?
如果我尝试使用 resource.hasProperty(ResourceFactory.createProperty("isResponsibleFor")) 之类的东西,它会返回 false(但属性在那里!)。
您能否指导我阅读有关此主题的一些高级教程?我在 Papache 网站等上找到了许多教程,但它们没有为我提供我正在寻找的信息。对不起,如果问题不清楚,我对耶拿很陌生
编辑:目前,我正在搜索我的模型是否包含给定的语句:
public static boolean containsStatement(Model model, String sub,
String pred, String obj) {
// list the statements in the Model
StmtIterator iter = model.listStatements();
// print out the predicate, subject and object of each statement
while (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
Resource subject = stmt.getSubject(); // get the subject
Property predicate = stmt.getPredicate(); // get the predicate
RDFNode object = stmt.getObject(); // get the object
if (subject.toString().contains(sub)
&& predicate.toString().contains(pred)
&& object.toString().contains(obj)) {
return true;
}
}
return false;
}
但我很确定这是一种非常无效的方法。你能给我推荐一些更优雅、更快速的方法吗?谢谢!
【问题讨论】: