Java 我无法从本体文件中获取属性
我无法从本体文件中获取属性。我不熟悉本体论和ApacheJena。而且我不能以正确的方式使用“getProperty”命令。 在编写这些代码之前,我能够获取类,但我不知道如何使用“getProperty”、“listObjectsOfProperty”命令获取属性Java 我无法从本体文件中获取属性,java,eclipse,jena,owl,ontology,Java,Eclipse,Jena,Owl,Ontology,我无法从本体文件中获取属性。我不熟悉本体论和ApacheJena。而且我不能以正确的方式使用“getProperty”命令。 在编写这些代码之前,我能够获取类,但我不知道如何使用“getProperty”、“listObjectsOfProperty”命令获取属性 package onto1; import java.io.InputStream; import org.semarglproject.vocab.OWL; import com.hp.hpl.jena.ontology.Ont
package onto1;
import java.io.InputStream;
import org.semarglproject.vocab.OWL;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
public class ontolo {
public static void main(String[] args) {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
String inputFileName = "file:///F:/apache-jena-2.12.1/travel.owl";
InputStream in = FileManager.get().open( inputFileName );
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
//Property hasTime = model.createProperty( "file:///F:/apache-jena-2.12.1/shopping.owl#" );
//Property getProperty ( inputFileName, hastime) ;
model.read(in, null);
com.hp.hpl.jena.rdf.model.Property irrr = model.getProperty(OWL.ON_PROPERTIES);
com.hp.hpl.jena.rdf.model.NodeIterator iter1 = model.listObjectsOfProperty(irrr);
com.hp.hpl.jena.rdf.model.ResIterator i = model.listSubjectsWithProperty (irrr);
//com.hp.hpl.jena.rdf.model.Statement iir = model.getRequiredProperty(inputFileName, irrr);
//com.hp.hpl.jena.rdf.model.NodeIterator iter2 = model.listObjectsOfProperty(inputFileName.subClassOf);
ExtendedIterator<OntClass> iter = ((OntModel) model).listClasses();
while ( iter.hasNext()){
System.out.println(iter.next().toString());
}
// write it to standard out
model.write(System.out);
}
}
getProperty不会出现在代码中的任何位置。什么不起作用?请给出一个最小的工作示例,说明您期望或不希望工作的内容,以及您期望它产生的内容和实际产生的内容。我没有发布完整的代码,因为我无法理解如何使用GetProperties和其他命令。提前谢谢。你想用哪个getProperty?或者?在上面的代码中,我试图使用“Model.getProperty”,但我不知道应该使用哪个“getProperty”。我的主要目标是从本体文件中查找属性。您只需要模型中使用的属性列表吗?例如,如果模型是三元组{apbbaaqcbrd}的集合,您想要列表[p,q,r]?