本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.listIndividuals方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.listIndividuals方法的具體用法?Java OntModel.listIndividuals怎麽用?Java OntModel.listIndividuals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.listIndividuals方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOntResourcesOfType
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
* Gets a list of resources of the given type
*
* @param model Jena model
* @param resource Given resource
* @return List of resources
*/
public static List<Resource> getOntResourcesOfType(Model model, Resource resource) {
List<Resource> res = new ArrayList();
OntModel ontModel = ModelFactory.createOntologyModel();
ontModel.add(model);
ontModel.add(coreModel);
// RDFUtils.print(ontModel);
Resource r2 = ontModel.createResource(resource.getURI());
ExtendedIterator it = ontModel.listIndividuals(r2);
while (it.hasNext()) {
Individual ind = (Individual) it.next();
if (ind.isResource()) {
res.add(ind);
}
}
return res;
}
示例2: getIndividuals
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
protected List<Individual> getIndividuals(OntModel model) {
List<Individual> individuals = new ArrayList<Individual>();
ExtendedIterator<Individual> iterator = model.listIndividuals();
while (iterator.hasNext()) {
individuals.add(iterator.next());
}
return individuals;
}
示例3: test1
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void test1() {
logger.info("Test builder");
Specification.getInstance().setPrettyOutput(true);
// iterate over models, testing heach individual in model data
int md_num = 1;
for (OntModel testModel : testModels) {
logger.debug(" TESTING MODEL:"+md_num++);
for (Iterator i = testModel.listIndividuals(); i.hasNext(); ) {
Individual in = (Individual) i.next();
try {
SemanticObject so = builder.createSemanticObject(in);
assertNotNull("Can create SO",so);
logger.debug("Created Individual from model SO w/ uri:"+so.getNamespaceURI());
logger.debug("Created Individual from model SO :\n"+so.toXMLString());
// Check the class of the output object. For one object, we
// had a special handler build it, otherwise, its SemanticObjectImpl
// class
} catch (SemanticObjectBuilderException e) {
logger.error(e.getMessage());
fail(e.getLocalizedMessage());
}
}
}
}
示例4: test2
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void test2() {
logger.info("Test Extended builder");
Specification.getInstance().setPrettyOutput(true);
// iterate over models, testing heach individual in model data
for (OntModel testModel : testModels) {
for (Iterator i = testModel.listIndividuals(); i.hasNext(); ) {
Individual in = (Individual) i.next();
try {
SemanticObject so = extended_builder.createSemanticObject(in);
assertNotNull("Can create SO",so);
logger.debug("Created SO :\n"+so.toXMLString());
// Check the class of the output object. For one object, we
// had a special handler build it, otherwise, its SemanticObjectImpl
// class
if (in.getURI().equals(SpecialInstanceURI)) {
assertEquals("Class for special object is correct", TestSemanticObject.class, so.getClass());
} else {
assertEquals("Class for special object is correct", SemanticObjectImpl.class, so.getClass());
}
} catch (SemanticObjectBuilderException e) {
logger.error(e.getMessage());
fail(e.getLocalizedMessage());
}
}
}
}
示例5: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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" **
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<Individual> personIter = model.listIndividuals(person);
while (personIter.hasNext()) {
Individual indiv = personIter.next();
System.out.println("Individual uri = " + indiv.getURI());
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> personsubclasses = person.listSubClasses();
while (personsubclasses.hasNext()) {
OntClass subclass = personsubclasses.next();
System.out.println("Subclass uri = " + subclass.getURI());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
示例6: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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" **
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<Individual> listaInd = model.listIndividuals(person);
while (listaInd.hasNext())
{
System.out.println("Individual: " + listaInd.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> listaSub = person.listSubClasses();
while (listaSub.hasNext())
{
System.out.println("Individual: " + listaSub.next());
}
// ** 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.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
String filename = "src/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" **
ExtendedIterator<Individual> personIterator = model.listIndividuals(model.getOntClass(ns+"Person"));
while(personIterator.hasNext()){
Individual individual = personIterator.next();
System.out.println("Individual: "+individual);
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> subclassIterator = model.getOntClass(ns+"Person").listSubClasses();
while(subclassIterator.hasNext()){
OntClass subclass = subclassIterator.next();
System.out.println("Subclass: "+subclass);
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
示例8: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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());
}
}
}
示例9: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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... **
}
示例10: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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
示例11: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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" **
OntClass person = model.getOntClass(ns+"Person");
ExtendedIterator<Individual> it=model.listIndividuals(person);
if(it.hasNext())
{
Individual auxind = it.next();
System.out.println("Person: "+auxind.getLocalName());
}
// ** TASK 7.2: List all subclasses of "Person" ** //
System.out.println("TASK 7.2: List all subclasses of ");
ExtendedIterator<OntClass> it2 =person.listSubClasses();
if(it2.hasNext())
{
OntClass auxclass = it2.next();
System.out.println("Lista de Subclasses "+auxclass.getSubClass().getLocalName());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
//model.write(System.out, "TURTLE");
}
示例12: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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());
}
}
示例13: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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" **
OntClass person = model.getOntClass(ns+"Person");
ExtendedIterator<Individual> personIter = model.listIndividuals(person);
while (personIter.hasNext()) {
System.out.println(personIter.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> personIt = person.listSubClasses();
while (personIt.hasNext()) {
System.out.println(personIt.next());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
示例14: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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: List all individuals of Person");
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<Individual> itInd = model.listIndividuals();
while (itInd.hasNext()) {
Individual ind = itInd.next();
System.out.println(ind.getLocalName());
}
System.out.println("");
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("7.2: List all subclasses of Person");
ExtendedIterator<OntClass> itSub = person.listSubClasses();
while (itSub.hasNext()) {
OntClass c = itSub.next();
System.out.println(c.getLocalName());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:48,代碼來源:Task07_JoseRodriguezBueno.java