列出Jena中实例的对象属性

Lea*_*dro 2 list jena object-properties object-property

如何列出与Jena中的实例关联的所有对象属性?

例如:Person有一个名为" hasVehicle " 的Object属性,它与类Vehicle相关联

Ian*_*son 5

适当的耶拿方法是OntClass.listDeclaredProperties.有一些细微差别需要注意; Jena RDF的框架详细解释了如何解释.

更新

好的,我看了你的代码示例,并阅读了你的描述,我担心我不明白你想做什么.我所做的就是重新编写你的代码示例,以便它根据你在评论中的描述做一些我你可能想要的东西:

package test;

import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class LeandroTest
{
    public static String NS = "http://www.owl-ontologies.com/TestProject.owl#";

    public static void main( String[] args ) {
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
        FileManager.get().readModel( m, "./src/main/resources/project-test.owl" );

        OntClass equipe = m.getOntClass( NS + "Equipe" );
        OntProperty nome = m.getOntProperty( NS + "nome" );

        for (ExtendedIterator<? extends OntResource> instances = equipe.listInstances(); instances.hasNext(); ) {
            OntResource equipeInstance = instances.next();
            System.out.println( "Equipe instance: " + equipeInstance.getProperty( nome ).getString() );

            // find out the resources that link to the instance
            for (StmtIterator stmts = m.listStatements( null, null, equipeInstance ); stmts.hasNext(); ) {
                Individual ind = stmts.next().getSubject().as( Individual.class );

                // show the properties of this individual
                System.out.println( "  " + ind.getURI() );
                for (StmtIterator j = ind.listProperties(); j.hasNext(); ) {
                    Statement s = j.next();
                    System.out.print( "    " + s.getPredicate().getLocalName() + " -> " );

                    if (s.getObject().isLiteral()) {
                        System.out.println( s.getLiteral().getLexicalForm() );
                    }
                    else {
                        System.out.println( s.getObject() );
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这给出了以下输出,首先列出了所有资源rdf:type #Equipe,然后为每个资源列出了链接该Equipe 的模型中的资源,然后对于那些链接资源,它列出了所有RDF属性.我认为这不是一件特别有用的事情,但希望它会向你展示一些在耶拿遍历RDF图的模式.

Equipe instance: Erica
Equipe instance: Etiene
  http://www.owl-ontologies.com/TestProject.owl#EtapaExecucao_01
    EtapaExecucao_DataModificao -> 2010-03-29T10:54:05
    caso_de_teste -> http://www.owl-ontologies.com/TestProject.owl#CasoDeTeste_01
    EtapaExecucao_StatusTeste -> Passou
    EtapaExecucao_Reprodutibilidade -> Sempre
    type -> http://www.owl-ontologies.com/TestProject.owl#EtapaExecucao
    EtapaExecucao_VersaoDefeitoSurgiu -> Release ICAMMH_01.00
    EtapaExecucao_Severidade -> Minimo
    EtapaExecucao_VersaoDefeitoCorrigiu -> Release ICAMMH_02.00
    DataExecucao -> 2009-07-10T09:42:02
    EtapaExecucao_StatusDoDefeito -> Nao sera corrigido
    EtapaExecucao_DataSubmissao -> 2009-06-30T09:43:01
    Tipos_Fases -> http://www.owl-ontologies.com/TestProject.owl#FaseTesteExecucao
    EtapaExecucao_Resolucao -> Fechado
    executor_do_teste -> http://www.owl-ontologies.com/TestProject.owl#Etiene
    EtapaExecucao_PrioridadeCorrecao -> Normal
Equipe instance: Fabio
Equipe instance: Melis
Run Code Online (Sandbox Code Playgroud)

一些一般性建议,特别是如果您有任何后续问题:

  • 提出具体问题,很难回答一个含糊不清的问题;
  • 如果可能的话,提供可运行的代码:你可以把我的代码放在下面,把它放到像Eclipse这样的代码环境中并试一试
  • 提供的代码和数据的问题,而不是引擎收录链接关闭
  • 花一些时间将代码和数据减少到显示问题所需的最小形式:您的Protégé文件长度超过600行