- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个由 Protege 4.2.0 生成的本体文件。它包括如下定义的 DatatypeProperty。
<owl:DatatypeProperty rdf:about="http://example.com/NLPSchema.owl#race">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<rdfs:domain rdf:resource="http://example.com/NLPSchema.owl#Person"/>
<rdfs:subPropertyOf rdf:resource="http://example.com/NLPSchema.owl#semanticProperty"/>
<rdfs:range>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>african_american</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>asian</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>caucasian</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>hispanic</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>other</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</rdfs:range>
</owl:DatatypeProperty>
DatatypeProperty p = ontModel.getDatatypeProperty("http://example.com/NLPSchema.owl#race");
OntClass range = p.getRange().asClass();
最佳答案
考虑这个简单地声明一个 DatatypeProperty 的小本体,hasFlavor
(首先,在 RDF/XML 中,因为那是您使用的):
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://example.org/icecream#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://example.org/icecream"/>
<owl:DatatypeProperty rdf:about="http://example.org/icecream#hasFlavor">
<rdfs:range>
<rdfs:Datatype>
<owl:oneOf>
<rdf:List>
<rdf:first>chocolate</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>strawberry</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>vanilla</rdf:first>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</rdf:List>
</rdf:rest>
</rdf:List>
</rdf:rest>
</rdf:List>
</owl:oneOf>
</rdfs:Datatype>
</rdfs:range>
</owl:DatatypeProperty>
</rdf:RDF>
@prefix : <http://example.org/icecream#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
:hasFlavor a owl:DatatypeProperty ;
rdfs:range [ a rdfs:Datatype ;
owl:oneOf [ a rdf:List ;
rdf:first "chocolate" ;
rdf:rest [ a rdf:List ;
rdf:first "strawberry" ;
rdf:rest [ a rdf:List ;
rdf:first "vanilla" ;
rdf:rest ()
]
]
]
] .
<http://example.org/icecream>
a owl:Ontology .
rdf:List
资源即枚举。
hasFlavor
有一个
rdfs:range
这是一个
owl:Datatype
,以及
owl:Datatype
与
owl:oneOf
的枚举有关.
import java.util.List;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFList;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDFS;
public class ExtractEnumeratedDatatypeElements {
public static void main(String[] args) {
// Load the ontology.
final OntModel iceCream = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM );
iceCream.read( "file:///home/taylorj/tmp/ontologies/icecream/icecream.owl" );
// Get to the property and the datatype that is its range.
final DatatypeProperty hasFlavor = iceCream.createDatatypeProperty( "http://example.org/icecream#hasFlavor" );
final Resource datatype = hasFlavor.getPropertyResourceValue( RDFS.range );
// The datatype is related to a list of values by owl:oneOf.
final RDFList enumeration = datatype.getPropertyResourceValue( OWL.oneOf ).as( RDFList.class );
// The RDFList can be converted to a Java List.
final List<RDFNode> list = enumeration.asJavaList();
System.out.println( list );
}
}
[chocolate, strawberry, vanilla]
关于rdf - 使用 Jena 解析 Protege 生成的枚举数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15018784/
我想用前缀来表示这个nt文件: . "a" . "b" . "c" . 我写入一个新的nt文件是: @prefix sp: . . "a" . "b" . "c"
我有一个名为 Modelling.owl 的 OWL 文件,它是使用 Protege 4.2 创建的。但是后来我必须通过使用 Jena 注册一些新的 Individual 和它的属性来修改它。例如我有
我正在尝试使用 Jena 写入本地免费的独立 GraphDB(版本 8.5.0)存储库。 我尝试过的 (1) 耶拿直接使用 我使用了这个 Jena 3.7.0 代码片段: String strInse
我无法在我的 Ontology 中表达以下情况: 假设我有四个人投票,投了四票(所以 vote 和 voter 之间存在一对一的映射)。人们可以投票赞成或反对。如果我知道三个人的投票结果,我应该能够推
我在我的项目中使用 Dbpedia,我想创建一个本地 sparql 端点,因为在线端点不可靠。我下载了数据转储(大型 NT 文件)并决定使用 Jena TDB。使用 NetBeans IDE,我使用输
我用这个java代码在jena中创建了一个模型 Model m = ModelFactory.createDefaultModel(); Resource a1 = m.createR
我有一个猫头鹰本体,我将它读入 Jena OntModel。然后我在运行时更新它。现在我想把它写回一个OWL 本体。我正在使用下面的代码: RDFWriter writer = model.getWr
我将 Jena 和 Fuseki 安装为服务使用 一个可靠的角色 gremid.fuseki . 而且我想自定义监听主机和监听端口。但是,我不知道。 也许我应该编辑$FUSEKI_BASE/confi
我正在对基于本体的上下文管理和基于流程的上下文管理进行性能分析。然而,为了创建与 PCM 案例研究类似的场景,我需要在推理过程中直接从 Jena SWRL 规则触发 Java 方法。我做了很多研究,但
我正在使用 SPARQL 查询查询整数结果: String qString = "SELECT (COUNT(?S) AS ?C) "+ "WHERE
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 8年前关闭。 Improve t
我无法找到一些使用 SWRL 和 Jena 的简单代码示例佩莱,或者至少使用 SWRL?我研究了 Pellet 文档中的一些示例,但没有关于使用 SWRL 的示例。网络上的大多数示例都不完整且令人困惑
我对 RDF 和 Jena 很陌生。我想将一个 .nt (N-TRIPLE) 文件加载到模型中。我试过 read(inputStream, "N-TRIPLE") 但没有帮助。 它抛出 org.apa
我成功地使用 Jena API 和 Eclipse 创建、修改、合并本体。我还在 Eclipse 中成功启动了 OWL 推理器和 Pellet 推理器。 现在我想了解如何使用 Jena API 在 E
我正在尝试使用 Jena 框架来编辑使用 Protoge 4.2 构建的现有本体。即更改属性值或添加个人或类别,然后进行推理。假设在本体中我们有这样的规则:hasAge(?p,?age)^swrlb:
我了解到您可以使用以下代码提取 rdf 文件并初始化为 jena 中的模型: DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(
我目前正在开发一个项目,初始值为 .owl包含我们本体的基本模式的文件。我们使用 Jena API 加载此文件并对其执行不同的操作,例如添加本体类和个体。 我们寻求将系统迁移到三重存储,这意味着,而不
这是我的代码: public class FunctionalityCheckTest1 { InfModel infModel; Model model = ModelFactory
我使用Jena和TDB来存储RDF,我想对其进行一些推断。但是RDF数据很大,Jena的owl reasoner必须将所有数据加载到内存中。 所以我想找到一个可以推理而不将所有数据加载到内存中的推理器
我建立了一个使用SWRL规则进行推理的本体。当我在Protege中执行SQWRL查询时,它工作正常。问题是,当我想将Pellet与Jena一起使用时,Pellet似乎在查询中不包括SWRL规则。我像这
我是一名优秀的程序员,十分优秀!