本文整理汇总了Java中com.hp.hpl.jena.ontology.OntClass.listInstances方法的典型用法代码示例。如果您正苦于以下问题:Java OntClass.listInstances方法的具体用法?Java OntClass.listInstances怎么用?Java OntClass.listInstances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.ontology.OntClass
的用法示例。
在下文中一共展示了OntClass.listInstances方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: classInstances
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private List<GraphSegment> classInstances(OntClass cls, List<GraphSegment> instData) {
ExtendedIterator<? extends OntResource> itr = cls.listInstances(true);
while (itr.hasNext()) {
OntResource or = itr.next();
if (or.canAs(Individual.class)){
GraphSegment gs = new GraphSegment(getModelUri(), or.as(Individual.class), "is a", cls, configMgr);
if (!instData.contains(gs)) {
annotateHeadAsIndividual(gs);
annotateTailAsClass(gs);
instData.add(gs);
}
}
}
return instData;
}
示例2: getCoreODRLActions
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
/**
* Gets the ODRL core actions
*/
public static List<String> getCoreODRLActions() {
List<String> actions = new ArrayList();
OntClass action = coreModel.getOntClass("http://www.w3.org/ns/odrl/2/Action");
ExtendedIterator it = action.listInstances();
while (it.hasNext()) {
Individual saction = (Individual) it.next();
String comment = RDFUtils.getFirstPropertyValue(saction, RDFUtils.COMMENT);
String label = RDFUtils.getFirstPropertyValue(saction, RDFUtils.LABEL);
actions.add(label);
}
return actions;
}
示例3: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "rdf examples/example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
OntClass person = model.getOntClass(ns+"Person");
ExtendedIterator<? extends OntResource> it = person.listInstances();
System.out.println("List of all the individuals of Person");
while (it.hasNext()){
System.out.println(it.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
it = person.listSubClasses();
System.out.println("List of all the subclasses of Person");
while (it.hasNext()){
System.out.println(it.next());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
// not yet
}
示例4: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
String filename = "example7.rdf";
String namespace = "www.example.org/resources#";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: " + filename + " not found");
// Read the RDF/XML file
model.read(in, null);
// Task 7.1: List all individuals of "Person"
OntClass personClass = model.getOntClass(namespace + "Person");
ExtendedIterator<? extends OntResource> personInstances = personClass.listInstances();
OntResource person;
while(personInstances.hasNext()) {
person = personInstances.next();
System.out.println("Person Instance: " + person.getURI());
}
// Task 7.1: List all subclasses of "Person"
ExtendedIterator<? extends OntResource> subclassesOfPerson = personClass.listSubClasses();
OntResource personSubclass;
while(subclassesOfPerson.hasNext()) {
personSubclass = subclassesOfPerson.next();
System.out.println("Person Subclasse: " + personSubclass.getURI());
}
// Task 7.2: Make the necessary changes to get as well indirect instances and subclasses
ExtendedIterator<? extends OntResource> indirectPersons = personClass.listInstances(false);
OntResource indirectPerson;
while(indirectPersons.hasNext()) {
indirectPerson = indirectPersons.next();
if( !indirectPerson.hasRDFType(personClass, true) )
System.out.println("Person Indirect Intance: " + indirectPerson.getURI());
}
/* ------------------------------------------------ */
ExtendedIterator<? extends OntResource> indirectSubclassesOfPerson = personClass.listSubClasses(false);
OntResource indirectPersonSubclass;
while(indirectSubclassesOfPerson.hasNext()) {
indirectPersonSubclass = indirectSubclassesOfPerson.next();
if( !indirectPersonSubclass.asClass().isSameAs(personClass) )
System.out.println("Person Indirect Subclass: " + indirectPersonSubclass.getURI());
}
}
示例5: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "rdf examples/example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
OntClass person = model.createClass(ns+"Person");
ExtendedIterator<Individual> individuals = model.listIndividuals();
while (individuals.hasNext()) {
Individual individual = individuals.next();
System.out.println("Person: " + individual.getLocalName());
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> subClases = person.listSubClasses();
while (subClases.hasNext()) {
OntClass essaClasse = (OntClass) subClases.next();
System.out.println("Subclass: "+essaClasse.getURI());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
ExtendedIterator<OntClass> listaSubclases = person.listSubClasses();
//Imprimiremos las subclases y las instancias de cada subclase
while (listaSubclases.hasNext()){
OntClass clase = (OntClass) listaSubclases.next();
ExtendedIterator<Individual> listaInstancias = (ExtendedIterator<Individual>) clase.listInstances();
while(listaInstancias.hasNext()){
System.out.println("Clase: "+clase.getURI()+" Nombre Instancia: "+ listaInstancias.next().getURI());
}
}
}
示例6: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
Resource individ = model.getResource(ns + "Person");
ExtendedIterator<Individual> iter = model.listIndividuals(individ);
while(iter.hasNext())
{
System.out.println("Persons: " + iter.next().getURI());
}
// ** TASK 7.2: List all subclasses of "Person" **
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<? extends OntResource> iter2 = person.listInstances();
iter2 = person.listSubClasses();
while(iter2.hasNext())
{
OntClass subclass = (OntClass)iter2.next();
System.out.println("subclasses of Person: " + subclass);
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
示例7: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[]) {
String filename = "example6.rdf";
// Create an empty model
OntModel model = ModelFactory
.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: " + filename
+ " not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
System.out.println("TASK 7.1");
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<Individual> iterator = model.listIndividuals(person);
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("TASK 7.2");
ExtendedIterator<OntClass> listSubClass = person.listSubClasses();
while (listSubClass.hasNext()) {
System.out.println(listSubClass.next());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect
// instances and sutbclasses. TIP: you need some inference... **
System.out.println("TASK 7.3");
listSubClass = person.listSubClasses();
while (listSubClass.hasNext()) {
OntClass ont = listSubClass.next();
ExtendedIterator<? extends OntResource> iter = ont
.listInstances();
while (iter.hasNext()) {
System.out.println(ont.toString()+ " Tiene como instancia: "+iter.next());
}
}
}
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:52,代码来源:MiguelOrtegaMoreno_Task07.java
示例8: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
System.out.println("\nTASK 7.1 - List all individuals of Person\n");
OntClass person = model.getOntClass(ns+"Person");
ExtendedIterator<? extends OntResource> itr = person.listInstances();
while(itr.hasNext()){
Individual persons = (Individual) itr.next();
System.out.println("Person : " + persons);
}
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("\nTASK 7.2 - List all subclasses of Person\n");
itr = person.listSubClasses(false);
while (itr.hasNext()) {
OntClass ontClass = (OntClass) itr.next();
System.out.println("Subclass : " + ontClass);
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. **
// ** TIP: you need some inference... **
System.out.println("\nTASK 7.3 - Make the necessary changes to get as well indirect instances and subclasses\n");
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
reasoner = reasoner.bindSchema(model);
reasoner.setDerivationLogging(true);
InfModel inf = ModelFactory.createInfModel(reasoner, model);
StmtIterator i = inf.listStatements(person, null, (RDFNode) null);
while(i.hasNext()){
Statement s = i.nextStatement();
System.out.println("Statement: \n" + s.asTriple()); //turtle format
}
}
示例9: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[]) {
String filename = "rdf examples" + File.separator + "example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null) {
throw new IllegalArgumentException("File: " + filename + " not found");
}
// Read the RDF/XML file
model.read(in, null);
ExtendedIterator<? extends OntResource> it; // "? extends OntResource" Java go home you are drunk.
OntClass person = model.getOntClass(ns + "Person");
// ** TASK 7.1: List all individuals of "Person" **
System.out.println("Person instances: ");
it = person.listInstances();
while (it.hasNext()) {
System.out.println(it.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("Person subclasses: ");
it = person.listSubClasses();
while (it.hasNext()) {
System.out.println(it.next());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
Reasoner reasoner = ReasonerRegistry.getRDFSReasoner();
reasoner = reasoner.bindSchema(model);
OntModelSpec ontModelSpec = OntModelSpec.RDFS_MEM;
ontModelSpec.setReasoner(reasoner);
OntModel ontModel = ModelFactory.createOntologyModel(ontModelSpec, model);
OntClass infPerson = ontModel.getOntClass(ns + "Person");
System.out.println("Person instances: ");
it = infPerson.listInstances();
while (it.hasNext()) {
System.out.println(it.next());
}
System.out.println("Person subclasses: ");
it = infPerson.listSubClasses();
while (it.hasNext()) {
System.out.println(it.next());
}
}
示例10: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "C:\\Users\\MerY\\201409\\WebLinked_SematicData\\src\\Assigment3\\example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
System.out.println("7.1");
OntClass IndvPerson = model.getOntClass(ns + "Person");
ExtendedIterator<Individual> personIter = model.listIndividuals(IndvPerson);
while (personIter.hasNext()) {
Individual indiv = personIter.next();
System.out.println(indiv.getURI()+"\n");
}
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("7.2");
ExtendedIterator<OntClass> subcPerson = IndvPerson.listSubClasses();
while (subcPerson.hasNext()) {
OntClass subclass = subcPerson.next();
System.out.println(subclass.getURI()+"\n");
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
System.out.println("7.3");
Reasoner reasoner = ReasonerRegistry.getRDFSReasoner();
reasoner = reasoner.bindSchema(model);
OntModelSpec ontol = OntModelSpec.RDFS_MEM;
ontol.setReasoner(reasoner);
OntModel ontModel = ModelFactory.createOntologyModel(ontol, model);
OntClass infer = ontModel.getOntClass(ns + "Person");
ExtendedIterator<? extends OntResource> iterator = infer.listInstances();
ExtendedIterator<OntClass> iterPerson = infer.listSubClasses();
System.out.println("Indirect instances: ");
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
System.out.println("Subclasses: ");
while (iterPerson.hasNext()) {
System.out.println(iterPerson.next());
}
}
示例11: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
System.out.println("******Task 7.1*******");
OntClass person = model.getOntClass(ns+"Person");
ExtendedIterator< ? extends OntResource> it=person.listInstances();
while(it.hasNext()){
Individual aux=(Individual)it.next();
System.out.println("Individuo: "+aux.getLocalName());
}
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("******Task 7.2*******");
ExtendedIterator< ? extends OntResource> it2= person.listSubClasses();
while(it2.hasNext()){
OntClass subclass= (OntClass)it2.next();
System.out.println("Subclass: "+ subclass+" => "+subclass.getLocalName() );
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
System.out.println("****Task 7.3********");
}
示例12: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example6.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 7.1: List all individuals of "Person" **
System.out.println("TASK 7.1");
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<? extends OntResource> eIter = person.listInstances();
while (eIter.hasNext())
{
Individual i = (Individual) eIter.next();
System.out.println("Individual: " +i);
}
System.out.println("");
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("TASK 7.2");
OntClass person2 = model.getOntClass(ns + "Person");
ExtendedIterator<OntClass> eIter2=person.listSubClasses();
while (eIter2.hasNext())
{
Resource s = eIter2.next();
System.out.println("Subclass: " +s);
}
System.out.println("");
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
System.out.println("TASK 7.3");
//no yet
}