当前位置: 首页>>代码示例>>Java>>正文


Java OntClass.listSubClasses方法代码示例

本文整理汇总了Java中com.hp.hpl.jena.ontology.OntClass.listSubClasses方法的典型用法代码示例。如果您正苦于以下问题:Java OntClass.listSubClasses方法的具体用法?Java OntClass.listSubClasses怎么用?Java OntClass.listSubClasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.hp.hpl.jena.ontology.OntClass的用法示例。


在下文中一共展示了OntClass.listSubClasses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findAllLabels

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public LinkedList<SemanticConcept> findAllLabels(String ontologyUri,String rootClass){
    
    LinkedList<SemanticConcept> list = new LinkedList<>();
    
    try{
    
        //Create a reasoner
        OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);

        //Create new URL of ontology
        URL url = new URL(ontologyUri);
    
        //Create model for the ontology
        model.read(url.openStream(),null);
    
        //Load model to the reasoner
        model.prepare();
    
        //Compute the classification tree
        ((PelletInfGraph) model.getGraph()).getKB().classify();
        
        //Set OWL root element (e.g., it could be thing: model.getOntClass(OWL.Thing.getURI()))
        OntClass owlRoot = model.getOntClass(rootClass);
        
        SemanticConcept sc = new SemanticConcept();
        sc.setUrl(owlRoot.getURI());
        sc.setName("");
        sc.setSemanticSimilarity("");
        list.add(sc);
    
        //For each subclass (direct or indirect)
        for (Iterator it = owlRoot.listSubClasses(false); it.hasNext();) {

            OntClass subclass = (OntClass) it.next();

            //If subclass is not anonymous
            if (!subclass.isAnon()) {

                //If subclass is not nothing
                if(!subclass.getURI().equals(com.hp.hpl.jena.vocabulary.OWL.Nothing.getURI())){
                    
                    sc = new SemanticConcept();
                    sc.setUrl(subclass.getURI());
                    sc.setName("");
                    sc.setSemanticSimilarity("");
                
                    list.add(sc);
                }
            }
        }
        
    }catch(IOException ex){}
    
    return list;
    
}
 
开发者ID:usplssb,项目名称:SemanticSCo,代码行数:57,代码来源:SemanticReasoner.java

示例2: getSubClasses

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
/**
 * Returns an iterator over all subclasses of the class specified by the
 * given uri or an empty iterator if no such class exists or if it has no
 * subclasses.
 * 
 * @param uri
 * @return an iterator over all super classes of the class specified by the
 *         given uri or an empty iterator if no such class exists or if it
 *         has no super classes.
 */
@SuppressWarnings("unchecked")
public Iterator<OntClass> getSubClasses(String uri) {
	OntModel model = OntologyIndex.get().getModel();
	OntClass clazz = model.getOntClass(uri);
	if (clazz != null) {
		return clazz.listSubClasses(true);
	}
	
	return EmptyIterator.INSTANCE;
}
 
开发者ID:ag-csw,项目名称:ExpertFinder,代码行数:21,代码来源:ExpertFinder.java

示例3: main

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[]) {
	TEOJENACalendarAnalyzer analyzer = new TEOJENACalendarAnalyzer();
	String fileName = "src/test/resources/TEO/TEO_1.1.0.owl";
	analyzer.load(fileName);
	
	// test case - all defined Federal Holidays
	String classStr = CalendarConstants.getWithNS("TEO_0000017"); // federal holidays
	OntClass rootClass = analyzer.getModel().getOntClass(classStr);
	ExtendedIterator<OntClass> subClsItor = rootClass.listSubClasses(true);
	
	int testYear = 2019;
	DateConstraint yearConstraint = new DateConstraint();
	yearConstraint.setMaxYear(testYear);
	yearConstraint.setMinYear(testYear);
	
	ArrayList<String> dates = null;
	OntClass subCls = null;
	
	while (subClsItor.hasNext()) {
		try {
			subCls = subClsItor.next();
			dates = analyzer.getSpecialDateInstances(subCls.toString(), yearConstraint);
			for (String date : dates) {
				System.out.println("Possible dates of \"" + subCls.getLabel(null) + "\" in year = " + testYear + " are: " + date);
				System.out.println();
			}
		} catch (TEOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
开发者ID:iluoyi,项目名称:teo-library,代码行数:33,代码来源:TEOJENACalendarAnalyzer.java

示例4: checkForSubClassCardinalityExistence

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private boolean checkForSubClassCardinalityExistence(com.hp.hpl.jena.rdf.model.Resource sr, OntClass subjClass,
		Property prop, SadlResource propResource) throws InvalidTypeException {
	ExtendedIterator<OntClass> ei = subjClass.listSubClasses();
	while (ei.hasNext()) {
		OntClass subClass = ei.next();
		if (checkForCardinalityExistence(sr, subClass, prop, propResource)) {
			return true;
		}
		if (checkForSubClassCardinalityExistence(sr, subClass, prop, propResource)) {
			return true;
		}
	}

	return false;
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:16,代码来源:JenaBasedSadlModelProcessor.java

示例5: loadViaOntology

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private Set<String> loadViaOntology(String ontString) {
  Set<String> toLoadInto = new HashSet<>();
  OntClass oc = this.model.getOntClass(this.toURI(ontString));
  if (oc == null)
    return toLoadInto;
  ExtendedIterator<OntClass> ei = oc.listSubClasses(false);
  while (ei.hasNext()) {
    OntClass occ = ei.next();
    toLoadInto.add(occ.getLocalName());
  }

  return toLoadInto;
}
 
开发者ID:hltcoe,项目名称:concrete-java,代码行数:14,代码来源:ConcreteOntology.java

示例6: 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

}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:38,代码来源:Task07_JorgeGonzalez.java

示例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" **
	
	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... **
	

}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:38,代码来源:Task07aydee.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" **
	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... **
	

}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:38,代码来源:Task07_Ivan_Diez.java

示例9: 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());
	}
}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:60,代码来源:Task07_pdoro.java

示例10: loadViaOntology

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private Set<String> loadViaOntology(String ontString) {
  Set<String> toLoadInto = new HashSet<>();  
  OntClass oc = this.model.getOntClass(this.toURI(ontString));
    ExtendedIterator<OntClass> ei = oc.listSubClasses(false);
    while (ei.hasNext()) {
      OntClass occ = ei.next();
      toLoadInto.add(occ.getLocalName());
    }
  
  return toLoadInto;
}
 
开发者ID:hltcoe,项目名称:concrete-ontology,代码行数:12,代码来源:ConcreteOntology.java

示例11: createTree

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private Node createTree(OntClass owlClass) {
    
    //If is a class Nothing, return null
    if(owlClass.getURI().equals(com.hp.hpl.jena.vocabulary.OWL.Nothing.getURI()))
        return null;

    //Create new node, and set name and url
    Node node = new Node();
    node.setName(owlClass.getLabel(null));
    node.setUrl(owlClass.getURI());
    
    //Create list of processed subclasses
    HashMap<String,String> processedSubclasses = new HashMap<>();
    
    //For each direct subclass
    for(Iterator it=owlClass.listSubClasses(true);it.hasNext();){
        
        OntClass subclass = (OntClass) it.next();
        
        //If subclass is not anonymous
        if(!subclass.isAnon()){
            
            //If subclass was not already processed
            if(!processedSubclasses.containsKey(subclass.getURI())){
                
                //Recursively call method "createTree" to process subclass
                Node subNode = createTree(subclass);
                
                //If subclass is not owl:Nothing, create add subclass to parent node. Otherwise, the returned node is null
                if(subNode != null) {
                    
                    //Add subclass node to parent node
                    node.getChildrenNode().add(subNode);
                    
                    //Add subclass to list of processed subclasses
                    processedSubclasses.put(subNode.getUrl(),subNode.getName());
        
                }
            }
        }
    }
    
    return node;   
    
}
 
开发者ID:usplssb,项目名称:SemanticSCo,代码行数:46,代码来源:SemanticReasoner.java

示例12: 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());
   		}

		
	}
}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:51,代码来源:Task07_Marco_Lopez.java

示例13: 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... **
	

}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:43,代码来源:Task07_Tarasyuk.java

示例14: 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

示例15: 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" **
	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");
}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:44,代码来源:Task7_AlexPilicita.java


注:本文中的com.hp.hpl.jena.ontology.OntClass.listSubClasses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。