类的对象属性 [英] object property for a class

查看:25
本文介绍了类的对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定 Jena 中某个类的对象属性.我可以获取所有对象的属性,但我想获取特定类的对象属性.

获取所有对象属性的代码:

 ExtendedIterator objects = m.listObjectProperties();而 (objects.hasNext()){属性 essaProperty = (Property) objects.next();System.out.println("Propiedad:" + essaProperty.getLocalName());}

另外,如何获取对象属性的相关类,我的意思是,知道 A 如何获取对象属性---->"以及如何获取B"

 有(A---------->B)

谢谢

解决方案

您可能会在这个答案中找到足够的信息来使用 Jena 解析 schema.org ttl/owl 文件 以解决您的问题,但如果没有,则需要进行一些讨论.

首先,请注意 OWL 中的属性与面向对象编程语言中的属性"不同.我们说一个属性 P 有一个域 D 的意思是,当我们看到一个属性为 P 的陈述时,我们可以推断出主语是类型 D.通常,这是:

x P y Prdfs:domain D--------------------------x rdf:类型 D

但是考虑一下这意味着什么.如果 D 是 C 的子类,那么我们可以从 x rdf:type D 推断 x rdf:type C.这意味着 C 也是 P 的域.(这是 OWL 中的情况,但纯 RDF 的语义略有不同.)因此,如果您要问哪些属性将类 C 作为域",除了将 C 作为域的属性之外,您还将获得将 C 的子类作为域的属性.

如果您确实想要类和属性的某种面向对象"视图,您可以使用 Jena 方法 OntClass#listDeclaredProperties.

<块引用>

listDeclaredProperties

com.hp.hpl.jena.util.iterator.ExtendedIteratorlistDeclaredProperties(布尔直接)

返回一个迭代器,遍历与框架相关的属性这门课的看法.这捕获了一个直观的概念类的属性.这在呈现本体时很有用用户界面中的类,例如通过自动构造一个表单来实例化类的实例.中的属性类的框架式视图是通过比较域来确定的此类的 OntModel 中的属性与类本身.看:[将 RDF 呈现为框架][2] 了解更多详情.

注意判断一个属性是否关联的很多情况类取决于 RDFS 或 OWL 推理.这种方法可能因此仅在具有附加的模型中返回完整结果推理机.

参数:

  • direct - 如果为 true,则将返回的属性限制为与此类直接关联的属性.如果为false,超类的属性此类的将不会列在此的声明属性中类.

返回:

按域与此类关联的属性的迭代.

How can I determine object properties for a class in Jena . I can get the all objects properties, but I want to get the object properties for a particular class.

Code for getting all the objectProperties:

 ExtendedIterator objects = m.listObjectProperties();

  while (objects.hasNext()) 
       {
            Property essaProperty = (Property) objects.next();            
            System.out.println("Propiedad: " + essaProperty.getLocalName());

       }

Also, how I can get the related class to the object property, I mean, knowing A how I can get the object property "---->" and how I can get "B"

                                  has  
                             (A---------->B)

Thanks

解决方案

You might find enough information in this answer to Parsing schema.org ttl/owl file using Jena to solve your problem, but if not, some discussion is in order.

First, note that properties in OWL are not the same kind of thing as "properties" in an object-oriented programming languages. What it means we we say that a property P has a domain D is that when we see a statement whose property is P, we can infer that the subject is of type D. As a rule, this is:

x P y      P rdfs:domain D
--------------------------
    x rdf:type D

But consider what this means. If D is a subclass of C, then we can infer from x rdf:type D that x rdf:type C. This means that C is also a domain of P. (This is the case in OWL, but pure RDF has a slightly different semantics.) Thus, if you're asking "what properties have class C as a domain", you'll get the properties that have subclasses of C as domains, in addition to properties that have C as a domain.

If you do want a sort of "object-oriented" view of the classes and properties, you can use the Jena method OntClass#listDeclaredProperties.

listDeclaredProperties

com.hp.hpl.jena.util.iterator.ExtendedIterator<OntProperty> listDeclaredProperties(boolean direct)

Return an iterator over the properties associated with a frame-like view of this class. This captures an intuitive notion of the properties of a class. This can be useful in presenting an ontology class in a user interface, for example by automatically constructing a form to instantiate instances of the class. The properties in the frame-like view of the class are determined by comparing the domain of properties in this class's OntModel with the class itself. See: [Presenting RDF as frames][2] for more details.

Note that many cases of determining whether a property is associated with a class depends on RDFS or OWL reasoning. This method may therefore return complete results only in models that have an attached reasoner.

Parameters:

  • direct - If true, restrict the properties returned to those directly associated with this class. If false, the properties of super-classes of this class will not be listed among the declared properties of this class.

Returns:

An iteration of the properties that are associated with this class by their domain.

这篇关于类的对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆