- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试通过 Jena 界面使用 PelletReasoner 仅列出知识(新三元组)。我只想要应用 后生成的推断数据托盘推理机 和 信息模型 来自本体( OWL )。目前,我列出了所有个人 - 其中包含断言和推断的知识。
那么我怎样才能得到只有从猫头鹰推断知识。提前谢谢..
//Inference Logic//
com.hp.hpl.jena.reasoner.Reasoner reasoner = org.mindswap.pellet.jena.PelletReasonerFactory.theInstance().create();
Model infModel = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, infModel);
try
{
inputStream = new FileInputStream(OWL_File);
}
catch (FileNotFoundException p)
{
p.printStackTrace();
}
model.read(inputStream, null, "RDF/XML");
最佳答案
下面的代码创建了一个简单的 OntModel 类 B 和 A,其中 B ⊑ A,而 i 是 B 类型的个体。我们可以推断,例如,i 是 A 的一个实例,我们将看到在结果中。
import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.Filter;
public class JustTheDeductionsPlease {
public static void main(String[] args) {
// Create the base model. B is a subclass of A, and i is an instance of B.
String NS = "http://example.org/";
final OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM );
OntClass a = model.createClass( NS+"A" );
OntClass b = model.createClass( NS+"B" );
a.addSubClass( b );
model.createIndividual( NS+"i", b );
// Create the inference model.
InfModel pModel = ModelFactory.createInfModel( PelletReasonerFactory.theInstance().create(), model);
// An iterator over the statements of pModel that *aren't* in the base model.
ExtendedIterator<Statement> stmts = pModel.listStatements().filterDrop( new Filter<Statement>() {
@Override
public boolean accept(Statement o) {
return model.contains( o );
}
});
// For convenient printing, we create a model for the deductions.
// (If stmts were a StmtIterator, we could add it directly. It's not,
// so we end up creating a new StmtIteratorImpl, which is kludgey, but
// it's more efficient than converting the thing to a list.)
Model deductions = ModelFactory.createDefaultModel().add( new StmtIteratorImpl( stmts ));
deductions.write( System.out, "TTL" );
}
}
<http://example.org/A>
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://www.w3.org/2002/07/owl#Thing> , <http://example.org/A> ;
<http://www.w3.org/2002/07/owl#disjointWith>
<http://www.w3.org/2002/07/owl#Nothing> ;
<http://www.w3.org/2002/07/owl#equivalentClass>
<http://example.org/A> .
<http://example.org/B>
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://www.w3.org/2002/07/owl#Thing> , <http://example.org/B> ;
<http://www.w3.org/2002/07/owl#disjointWith>
<http://www.w3.org/2002/07/owl#Nothing> ;
<http://www.w3.org/2002/07/owl#equivalentClass>
<http://example.org/B> .
<http://example.org/i>
a <http://www.w3.org/2002/07/owl#Thing> , <http://example.org/A> ;
<http://www.w3.org/2002/07/owl#sameAs>
<http://example.org/i> .
关于rdf - 如何仅从 Jena Ontology 模型中获取推断数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25055263/
我想用前缀来表示这个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规则。我像这
我是一名优秀的程序员,十分优秀!