如何使用 Jena 将远程 vocabulary/namespace 包含到 OntModel?
How to include a remote vocabulary/namespace to OntModel using Jena?
我是语义网和 Jena 的新手。
我想从耶拿的 OntModel 生成一个 ontology,我需要使用预定义的词汇表和本体来表征我的 classes 和属性。
在 Jena 中,有默认的本体,如 RDF、FOAF...因此我们可以指定 class 并将 属性 添加到资源中,例如:
ontClass.setSameAs(FOAF.Person);
ontClass.addProperty(FOAF.name, "name");
或
ontProperty.setRange(XSD.xstring);
但是我如何将我的 ontClass 引用到耶拿中不存在的另一个 vocabulary/ontology(GeoSparql、Geofla、我自己定义的词汇等)?知道我可以获得这些词汇表的 URI 吗?
此主题中已提出此问题:How to add vocabulary in Jena? 建议使用 Jena Schemagen,但我看不出如何去做。
非常感谢您的帮助!
我想其中一个选择是导入(或阅读)论文 vocabularies/ontologies 以便您可以使用 Jena Ontology API.
例如(如果我们假设您的 ontModel 名为 m
),您可以像这样将 OWL-Time ontology 读入您的模型:
m.read("http://www.w3.org/2006/time")
然后您可以使用它通过 Jena 的程序化定义的元素 API :
OntClass instant = dataModel.getOntClass("http://www.w3.org/2006/time#Instant");
如果您不想阅读模型中的整个 ontology,您也可以使用其 URI 来“创建”必要的资源/属性:
Property inXSDDateTime = m.createDatatypeProperty(
"http://www.w3.org/2006/time#inXSDDateTime");
Resource resource = m.createResource("someURIForThisRessource");
Statement s = m.createStatement(
resource, inXSDDateTime, m.createTypedLiteral(someValue));
m.add(s);
它应该按预期写入结果(但是,通过这样做,您不会加载您正在引用的 ontology 的公理,因此您将无法对其进行推理 - 但根据对于您的评论,我想也许这就是您想要的)
我是语义网和 Jena 的新手。
我想从耶拿的 OntModel 生成一个 ontology,我需要使用预定义的词汇表和本体来表征我的 classes 和属性。
在 Jena 中,有默认的本体,如 RDF、FOAF...因此我们可以指定 class 并将 属性 添加到资源中,例如:
ontClass.setSameAs(FOAF.Person);
ontClass.addProperty(FOAF.name, "name");
或
ontProperty.setRange(XSD.xstring);
但是我如何将我的 ontClass 引用到耶拿中不存在的另一个 vocabulary/ontology(GeoSparql、Geofla、我自己定义的词汇等)?知道我可以获得这些词汇表的 URI 吗?
此主题中已提出此问题:How to add vocabulary in Jena? 建议使用 Jena Schemagen,但我看不出如何去做。
非常感谢您的帮助!
我想其中一个选择是导入(或阅读)论文 vocabularies/ontologies 以便您可以使用 Jena Ontology API.
例如(如果我们假设您的 ontModel 名为 m
),您可以像这样将 OWL-Time ontology 读入您的模型:
m.read("http://www.w3.org/2006/time")
然后您可以使用它通过 Jena 的程序化定义的元素 API :
OntClass instant = dataModel.getOntClass("http://www.w3.org/2006/time#Instant");
如果您不想阅读模型中的整个 ontology,您也可以使用其 URI 来“创建”必要的资源/属性:
Property inXSDDateTime = m.createDatatypeProperty(
"http://www.w3.org/2006/time#inXSDDateTime");
Resource resource = m.createResource("someURIForThisRessource");
Statement s = m.createStatement(
resource, inXSDDateTime, m.createTypedLiteral(someValue));
m.add(s);
它应该按预期写入结果(但是,通过这样做,您不会加载您正在引用的 ontology 的公理,因此您将无法对其进行推理 - 但根据对于您的评论,我想也许这就是您想要的)