简体   繁体   English

如何从Java中owl类的“Equivalent To”部分中定义的类表达式中检索对象属性?

[英]How to retrieve object properties from a class expression defined in the “Equivalent To” section of an owl class in Java?

I have defined (in Protege) a class Missing which is equivalent to ((not (atHome value 30)) and (not (atWork value 30)))and (not (onleave value 30)). 我已经定义了(在Protege中)一个类Missing,它等同于((not(atHome值30))和(not(atWork value 30)))和(not(onleave value 30))。 By using OWL-API, I would like to obtain the single object properties (in this case, the negated object properties) from the class expression , in order to further get their domains and ranges and perform further reasoning. 通过使用OWL-API,我想从类表达式获取单个对象属性 (在本例中为否定的对象属性),以便进一步获取其域和范围并执行进一步的推理。 However, I am not sure how to parse the whole equivalent class expression in Java. 但是,我不确定如何解析Java中的整个等效类表达式。

For now I am able to retrieve the equivalent class expression of a class (in this case Missing) in functional form with the following code. 现在,我能够使用以下代码以函数形式检索类的等效类表达式(在本例中为Missing)。

localOntology.getEquivalentClassesAxioms(missingClass);

The provided code returns the functional representation of the equivalence class expression I have provided in Protege, however I am not able to parse it and retrive not (atWork value 30), not (atHome value 30), not (onleave value 30), which is what I would like. 提供的代码返回我在Protege中提供的等价类表达式的函数表示,但是我无法解析它并且不能(不是atWork值30),而不是(atHome值30),而不是(onleave值30),是我想要的。

  • First. 第一。 In the described above ontology IRIs atHome , atWork and onleave are not object properties, but rather data properties, since atHome value 30 is a Literal Value Restriction , that has datatype property, not object property. 在上面描述的本体IRI中, atHomeatWorkonleave不是对象属性,而是数据属性,因为atHome value 30文字值限制 ,它具有数据类型属性,而不是对象属性。 If, of course, it is not Punning . 当然,如果它不是Punning

  • In OWL-API v5, the method OWLOntology#getEquivalentClassesAxioms(OWLClass) is deprecated. 在OWL-API v5中,不推荐使用方法OWLOntology#getEquivalentClassesAxioms(OWLClass) Instead it is recommended to use its Java-Stream-API companion: OWLOntology#equivalentClassesAxioms(OWLClass) 相反,建议使用其Java-Stream-API伴侣: OWLOntology#equivalentClassesAxioms(OWLClass)

  • Using this method the solution (getting all data properties for the specified OWL Class) might look like this: 使用此方法,解决方案(获取指定OWL类的所有数据属性)可能如下所示:

    o.equivalentClassesAxioms(c) .flatMap(OWLNaryClassAxiom::operands) .filter(x -> x instanceof OWLObjectComplementOf) .map(x -> ((OWLObjectComplementOf) x).getOperand()) .filter(x -> x instanceof OWLDataHasValue) .flatMap(x -> ((OWLDataHasValue) x).components()) .filter(x -> x instanceof OWLDataProperty) .forEach(System.out::println);

  • the same can be rewritten using the standard Java Collections API, but more cumbersome. 可以使用标准Java Collections API重写相同的内容,但更麻烦。

  • Also, it is possible to use org.semanticweb.owlapi.util.OWLObjectComponentCollector or org.semanticweb.owlapi.util.OWLEntityCollector utility tools, but theses particular impls collect all components in a single Set , so it is still need to filter the result: 此外,可以使用org.semanticweb.owlapi.util.OWLObjectComponentCollectororg.semanticweb.owlapi.util.OWLEntityCollector实用工具,但这些特定的impls会收集单个Set所有组件,因此仍需要过滤结果:

    o.equivalentClassesAxioms(c) .flatMap(a -> new OWLObjectComponentCollector().getComponents(a) .stream().filter(x -> x instanceof OWLDataProperty)) .forEach(System.out::println) ; o.equivalentClassesAxioms(c) .flatMap(a -> new OWLObjectComponentCollector().getComponents(a) .stream().filter(x -> x instanceof OWLDataProperty)) .forEach(System.out::println) ;

  • create your own org.semanticweb.owlapi.util.AbstractCollectorEx impl to collect only data properties. 创建自己的org.semanticweb.owlapi.util.AbstractCollectorEx impl以仅收集数据属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM