如何列出与Jena中的实例关联的所有对象属性?
例如: 人有一个名为“ hasVehicle ”的对象属性,该属性与类车辆
相关联答案 0 :(得分:5)
适当的Jena方法是OntClass.listDeclaredProperties
。有一些细微差别需要注意;耶拿RDF frames how-to详细解释。
<强>更新强>
好的,我查看了你的代码示例,并阅读了你的描述,我担心我不明白你想做什么。我所做的就是重新编写你的代码示例,以便它根据你在评论中的描述做出你可能想要的猜测:
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() );
}
}
}
}
}
}
这会提供以下输出,首先列出rdf:type
#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
一些一般性建议,特别是如果您有任何后续问题: