當前位置: 首頁>>代碼示例>>Java>>正文


Java OntModel.getOntClass方法代碼示例

本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.getOntClass方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.getOntClass方法的具體用法?Java OntModel.getOntClass怎麽用?Java OntModel.getOntClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.hp.hpl.jena.ontology.OntModel的用法示例。


在下文中一共展示了OntModel.getOntClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUriInModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private static synchronized String getUriInModel(OntModel model, String ns, String name) {
	Resource r = model.getAnnotationProperty(ns + name);
       if (r != null) {
           return r.getURI();
       }
       r = model.getDatatypeProperty(ns + name);
       if (r != null) {
           return r.getURI();
       }
       r = model.getObjectProperty(ns + name);
       if (r != null) {
           return r.getURI();
       }
       r = model.getOntClass(ns + name);
       if (r != null) {
           return r.getURI();
       }
       r = model.getIndividual(ns + name);
       if (r != null) {
           return r.getURI();
       }
       if (RDF.type.getURI().equals(ns + name)) {
       	return RDF.type.getURI();
       }
       return null;
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:27,代碼來源:JenaTranslatorPlugin.java

示例2: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String[] args) {
    OntoManager om = OntoManager.getInstance();
    om.load();
    OntModel model = om.getModel();
    final String NS = om.getOntologyIRI() + "#";
    logger.info(NS);

    Scanner s = new Scanner(System.in);

    while (true) {

        System.out.println("enter:");
        String clsName = s.nextLine();
        System.out.println("enhancing for: |"+clsName+"|");
        if(clsName.equalsIgnoreCase("exit"))break;
        OntClass pCls = model.getOntClass(NS + clsName);
        if(pCls==null){
            System.err.println("class does not exist");
            continue;
        }

        LinguisticEnhancer le = new LinguisticEnhancer();
        List<SynSuggestion> suggestions = le.suggestLinguisticData(pCls);


        // exclude name + labels , syn includes etc when adding syn includes

        //for suspects
        for (SynSuggestion sug : suggestions) {
            logger.debug(sug.toString());
            if (true) {
                List<String> excludeList = le.getAllExcludes(pCls, le.getClassLabels(pCls).toArray(new String[0]));
                le.addSuggestion(pCls, sug, excludeList);
            }
        }

        om.save();
    }
}
 
開發者ID:sasinda,項目名稱:OntologyBasedInormationExtractor,代碼行數:40,代碼來源:Main.java

示例3: readOwlFile

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
static void readOwlFile (String pathToOwlFile) {
        OntModel ontologyModel =
                ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
        ontologyModel.read(pathToOwlFile, "RDF/XML-ABBREV");
       // OntClass myClass = ontologyModel.getOntClass("namespace+className");

        OntClass myClass = ontologyModel.getOntClass(ResourcesUri.nwr+"domain-ontology#Motion");
        System.out.println("myClass.toString() = " + myClass.toString());
        System.out.println("myClass.getSuperClass().toString() = " + myClass.getSuperClass().toString());

        //List list =
              //  namedHierarchyRoots(ontologyModel);


       Iterator i = ontologyModel.listHierarchyRootClasses()
                .filterDrop( new Filter() {
                    public boolean accept( Object o ) {
                        return ((Resource) o).isAnon();
                    }} ); ///get all top nodes and excludes anonymous classes

       // Iterator i = ontologyModel.listHierarchyRootClasses();
        while (i.hasNext()) {
            System.out.println(i.next().toString());
/*            OntClass ontClass = ontologyModel.getOntClass(i.next().toString());
            if (ontClass.hasSubClass()) {

            }*/
        }

        String q = createSparql("event", "<http://www.newsreader-project.eu/domain-ontology#Motion>");
        System.out.println("q = " + q);
        QueryExecution qe = QueryExecutionFactory.create(q,
                ontologyModel);
        for (ResultSet rs = qe.execSelect() ; rs.hasNext() ; ) {
            QuerySolution binding = rs.nextSolution();
            System.out.println("binding = " + binding.toString());
            System.out.println("Event: " + binding.get("event"));
        }

        ontologyModel.close();
    }
 
開發者ID:newsreader,項目名稱:StreamEventCoreference,代碼行數:42,代碼來源:OwlReader.java

示例4: calcSim

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private void calcSim() {
	OntologyIndex.get().load(OntologyIndex.class.getResource(Config.getAppProperty(Config.Key.ONTOLOGY_FILE)));
	
	OntologyIndex oi = OntologyIndex.get();
	OntModel model = oi.getModel();
	
	persistenceStore.beginTransaction();
	Query query = persistenceStore.createHQLQuery("from Concept");
	List<Concept> concepts1 = (List<Concept>)query.list();

	Query query1 = persistenceStore.createHQLQuery("from Concept");
	List<Concept> concepts2 = (List<Concept>)query1.list();
	persistenceStore.endTransaction();

	for (Concept co1 : concepts1) {
		OntClass c1 = model.getOntClass(co1.getUri());
		for (Concept co2 : concepts2) {
				OntClass c2 = model.getOntClass(co2.getUri());
		}
	}
}
 
開發者ID:ag-csw,項目名稱:ExpertFinder,代碼行數:22,代碼來源:ExpertiseModel.java

示例5: findAllLabels

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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

示例6: testGetAnnotationPropertyValueInAxiom

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Test
public void testGetAnnotationPropertyValueInAxiom() throws Exception {
    OntModel model=om.getModel();
    OntClass tvCls=model.getOntClass(NS+"TV");
    OntClass featureCls=model.getOntClass(NS+"PowerConsumption");
    Literal isNeg=OntoUtil.getAnnotationPropertyValueInAxiom(tvCls,featureCls, PO.AP_IS_NEGATIVE);
    assertTrue( isNeg.getBoolean() );
}
 
開發者ID:sasinda,項目名稱:OntologyBasedInormationExtractor,代碼行數:9,代碼來源:OntoUtilTest.java

示例7: testGetSuperClassesWithDistance

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@org.junit.Test
public void testGetSuperClassesWithDistance() throws Exception {
    OntModel model=om.getModel();

    OntClass tvCls=model.getOntClass(NS+"Fridge");
    Map<Integer,List<OntClass>> map = om.getSuperClassesWithDistance(tvCls);
    System.out.println(map);
}
 
開發者ID:sasinda,項目名稱:OntologyBasedInormationExtractor,代碼行數:9,代碼來源:OntoManagerTest.java

示例8: createJenaModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void createJenaModel(RegisterContextRequest rcr) {

        OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
        Model entityOnt = FileManager.get().loadModel(ONT_FILE);
        ontModel.addSubModel(entityOnt);
        ontModel.setNsPrefixes(entityOnt.getNsPrefixMap());

//         OntClass regClass = ontModel.getOntClass(ONT_URL + "iotReg");
//         OntClass entClass = ontModel.createOntClass(ONT_URL + "entity");
//        OntClass regClass = (OntClass) ontModel.createOntResource(OntClass.class, null,ONT_URL+"Registration" );
//        OntClass regClass = (OntClass) ontModel.createClass(ONT_URL + "Registration");
//        OntClass entityClass = (OntClass) ontModel.createClass(ONT_URL + "Entity");
        OntClass entityClass = (OntClass) ontModel.getOntClass(ONT_URL + "Entity");

//         System.out.println("Class type is: " + regClass.getLocalName());
//         System.out.println(rcr.getRegistrationId());
        Individual regIndividual = ontModel.createIndividual(ONT_URL + "roomSensor13CII01", entityClass);
        
        System.out.println("has propertry \"expiry\":"+regIndividual.hasProperty(ontModel.getProperty(ONT_URL, "expiry")));
//        Property p = ontModel.createProperty(ONT_URL, "hasRegistrationId");
//        regIndividual.addProperty(p, "");
        regIndividual.setPropertyValue(ontModel.getProperty(ONT_URL, "registrationId"), ontModel.createLiteral(rcr.getRegistrationId()));
//        p = ontModel.createProperty(ONT_URL, "hasDuration");
//        regIndividual.addProperty(p, "");
        regIndividual.setPropertyValue(ontModel.getProperty(ONT_URL, "expiry"), ontModel.createLiteral(rcr.getDuration()));
        System.out.println("has propertry \"expiry\":"+regIndividual.hasProperty(ontModel.getProperty(ONT_URL, "expiry")));

        ExtendedIterator<OntProperty> iter = ontModel.listAllOntProperties();
        while (iter.hasNext()) {
            OntProperty ontProp = iter.next();
            System.out.println(ontProp.getLocalName());
//            if (formParams.containsKey(ontProp.getLocalName())) {
//                regIndividual.addProperty(ontProp, ontModel.getcreateTypedLiteral(formParams.get(ontProp.getLocalName())[0]));
//            }
        }
        ontModel.write(System.out, "TURTLE");
//        ontModel.write(System.out, "RDF/XML");
//          ontModel.write(System.out, "JSON-LD");

    }
 
開發者ID:UniSurreyIoT,項目名稱:fiware-iot-discovery-ngsi9,代碼行數:41,代碼來源:SemanticConverter.java

示例9: getSuperClasses

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * Returns 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.
 * 
 * @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> getSuperClasses(String uri) {
	OntModel model = OntologyIndex.get().getModel();
	OntClass clazz = model.getOntClass(uri);
	if (clazz != null) {
		return clazz.listSuperClasses(true);
	}
	
	return EmptyIterator.INSTANCE;
}
 
開發者ID:ag-csw,項目名稱:ExpertFinder,代碼行數:21,代碼來源:ExpertFinder.java

示例10: getSubClasses

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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

示例11: isOfKind

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
static boolean isOfKind(Resource rrule, String uri) {
    if (rrule == null || uri == null || uri.isEmpty() || rrule.getURI() == null) {
        return false;
    }
    OntModel ontModel = ModelFactory.createOntologyModel();
    ontModel.add(coreModel);
    Individual res = ontModel.getIndividual(rrule.getURI());
    OntClass clase = ontModel.getOntClass(uri);
    if (res == null || clase == null) {
        return false;
    }
    return res.hasOntClass(clase);

}
 
開發者ID:oeg-upm,項目名稱:odrlapi,代碼行數:15,代碼來源:RDFUtils.java

示例12: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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

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

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

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

}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:38,代碼來源:Task07_Ivan_Diez.java


注:本文中的com.hp.hpl.jena.ontology.OntModel.getOntClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。