- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在用 Java 编写一个利用 OWL API 版本 3.1.0 的程序。我有一个 String
表示使用曼彻斯特 OWL 语法的公理,我想将此字符串转换为 OWLAxiom
对象,因为我需要将生成的公理添加到一个使用方法 addAxiom(OWLOntology owl, OWLAxiom axiom)
的本体(这是 OWLOntologyManager
的一个方法)。我该怎么做?
最佳答案
像下面的 Java 代码怎么样?请注意,我正在解析一个完整但很小的本体。如果您实际上只期望一些曼彻斯特文本不能作为完整的本体进行解析,您可能需要为所有内容添加一些标准前缀。不过,对于特定应用程序而言,这更值得关注。您还需要确保获得您感兴趣的公理类型。必然会有声明公理(例如,Person 是一个类),但是您可能对 TBox 和 ABox 公理更感兴趣,因此我添加了一些关于如何获得这些公理的注释。
要注意的一点是,如果您只是想添加公理到现有的本体中,这就是 OWLParser 方法所做的,尽管 Javadoc 并没有特别清楚地说明这一点(在我的想法)。 documentation about OWLParser说
An
OWLParser
parses an ontology document into an OWL API object representation of an ontology.
但事实并非如此。如果 parse() 的本体参数已经有内容,并且 parse() 没有删除它,那么本体参数最终成为本体文档超集的对象表示(它是本体文档加上先前的内容)。不过幸运的是,这正是您想要的情况:您想要阅读一段文本并将其添加到现有本体中。
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxParserFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLParser;
import org.semanticweb.owlapi.io.StreamDocumentSource;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class ReadManchesterString {
public static void main(String[] args) throws OWLOntologyCreationException, IOException {
// Get a manager and create an empty ontology, and a parser that
// can read Manchester syntax.
final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
final OWLOntology ontology = manager.createOntology();
final OWLParser parser = new ManchesterOWLSyntaxParserFactory().createParser( manager );
// A small OWL ontology in the Manchester syntax.
final String content = "" +
"Prefix: so: <http://stackoverflow.com/q/21005908/1281433/>\n" +
"Class: so:Person\n" +
"Class: so:Young\n" +
"\n" +
"Class: so:Teenager\n" +
" SubClassOf: (so:Person and so:Young)\n" +
"";
// Create an input stream from the ontology, and use the parser to read its
// contents into the ontology.
try ( final InputStream in = new ByteArrayInputStream( content.getBytes() ) ) {
parser.parse( new StreamDocumentSource( in ), ontology );
}
// Iterate over the axioms of the ontology. There are more than just the subclass
// axiom, because the class declarations are also axioms. All in all, there are
// four: the subclass axiom and three declarations of named classes.
System.out.println( "== All Axioms: ==" );
for ( final OWLAxiom axiom : ontology.getAxioms() ) {
System.out.println( axiom );
}
// You can iterate over more specific axiom types, though. For instance,
// you could just iterate over the TBox axioms, in which case you'll just
// get the one subclass axiom. You could also iterate over
// ontology.getABoxAxioms() to get ABox axioms.
System.out.println( "== ABox Axioms: ==" );
for ( final OWLAxiom axiom : ontology.getTBoxAxioms( false ) ) {
System.out.println( axiom );
}
}
}
输出是:
== All Axioms: ==
SubClassOf(<http://stackoverflow.com/q/21005908/1281433/Teenager> ObjectIntersectionOf(<http://stackoverflow.com/q/21005908/1281433/Person> <http://stackoverflow.com/q/21005908/1281433/Young>))
Declaration(Class(<http://stackoverflow.com/q/21005908/1281433/Person>))
Declaration(Class(<http://stackoverflow.com/q/21005908/1281433/Young>))
Declaration(Class(<http://stackoverflow.com/q/21005908/1281433/Teenager>))
== ABox Axioms: ==
SubClassOf(<http://stackoverflow.com/q/21005908/1281433/Teenager> ObjectIntersectionOf(<http://stackoverflow.com/q/21005908/1281433/Person> <http://stackoverflow.com/q/21005908/1281433/Young>))
关于java - 在 Java 中使用 owlapi 3 将曼彻斯特语法中的字符串转换为 OWLAxiom 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21005908/
我正在为一个项目使用 OWLAPI,我需要比较两个本体以了解它们之间的差异。这将忽略空白节点,例如,我可以确定两个本体中是否存在相同的 OWL 限制。我不仅需要知道是否存在差异,还需要找出这些差异是什
我正在尝试使用 OWL-API 3.5.0 以编程方式从数据模型构建 OWL 文件。 一般来说,该模型遵循 A -> B 的形式,其中关系(“->”)可以是子类或属性。 我认为我的子类正在工作,但我不
整体引用代码:https://github.com/jottinger/ontology 我正在创建一个本体并填充它(我认为正确)。结构已经存在,但我还没有验证它。 但是,我仍然期待声明出现,但我不知
有一种方法可以找到类的所有命名子类,而无需使用推理器 for (OWLClass child : reasoner.getSubClasses(clazz, true).getFlattened()
我的目标是捕获 OWLAPI 分别断言和推断的公理,换句话说,区别在于本体中已经存在的公理和那些不存在但只是由推理器推断的公理。 例如: public void printHierarchy(OWLR
我正在尝试使用 OWLAPI 版本 4.0.2(来自 Maven)从本体中删除一些文字注释 为此,我使用RemoveOntologyAnnotation 类和管理器applyChange() 方法。这
我尝试使用 owl-osgi-distribution 4.0.2 在 eclipse 中使用 owlapi 创建本体,并收到 Noclassfound 错误,该错误与链接中的错误类似 Getting
我得到了一个关于个体的小本体。其中一些个体应该通过对称 ObjectProperty 相互连接。 我需要使用 Pellet Reasoner,以便它可以同步并将对称 ObjectProperty 附加
我使用 OWL-API 创建了本体。我使用数组添加了实例。但是本体按字母顺序表示它,而不是按照我在数组中包含的顺序。因此,其他实例不匹配。 String Item1_List[]={"P
如何使用 owlapi 从加载的本体中获取所有类?这里我有一个关于如何获取一个类的示例,但我对访问本体中定义的所有类感兴趣。 OWLOntologyManager manager = WLMa
拜托,我想使用 OWLAPI 通过 java 程序解析以下本体。
如何在 Java 中使用 owlapi 找到所有已定义的类?我知道已弃用的 getClassesInSignature 方法,但文档 (JavaDocs) 缺少一些相关信息,应该使用什么来代替? 最佳
这是我的 OWL 文件的一部分: # Class: :Book (:Book) SubClassOf(:Book ObjectSomeValuesFrom(:writtenBy owl:Thing))
我正在尝试编写一个加载输入类的子类的方法。此代码在 OWL API 3.1.x(Pizza.owl) 编写的 RDF 文件中运行良好,但现在不适用于 OWL API 3.4.x 版本生成的文件。 下面
本文整理了Java中org.semanticweb.owlapi.util.ZipIRIMapper类的一些代码示例,展示了ZipIRIMapper类的具体用法。这些代码示例主要来源于Github/S
我尝试从 Reasoner (hermit 1.3.8.4) 和 OWLApi (3.4.10) 检索属性断言。在这张图片中,我想检索“isGrandfather Sandro,isGrandfath
有没有办法通过 Java API 使用 OWL API 访问 Jena TDB? Jena 似乎不支持 OWL-API。除了 RDF API 之外,它还具有一些便利函数 (OntAPI),用于在被视为
如何使用 HERMIT Reasoner 1.3.8 在 Java 中执行 SPARQL 查询?我正在使用 owlapi 4.2,并且我已经使用以下方式加载了 HERMIT 推理机: OWLReaso
我正在使用 OWL 2.0 的 OWL API,但有一件事我似乎无法弄清楚。我有一个 OWL/XML 文件,我想检索我的对象属性断言的注释。以下是我的 OWL/XML 和 Java 代码的片段: 猫头
我正在开发一个 Maven 插件来使用 OWL-API v3.4.3 和 HermiT 1.3.8.4 验证 OWL 本体。一些 OWL 本体是专有的,因此无法在 Web 上获得。 查看文档,我使用
我是一名优秀的程序员,十分优秀!