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


Java OntModel.read方法代碼示例

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


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

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

示例2: loadOntModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Override
public OntModel loadOntModel(String owlFilename) {
	try {
		FileInputStream is = new FileInputStream(new File(owlFilename));
		return initOntModel(is, getOwlFormatFromFile(owlFilename));
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	boolean savePI = ontModel.getDocumentManager().getProcessImports();
	ontModel.getDocumentManager().setProcessImports(false);
	try {
		ontModel.read(owlFilename, getOwlFormatFromFile(owlFilename));
	}
	finally {
		ontModel.getDocumentManager().setProcessImports(savePI);
	}
	return ontModel;
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:21,代碼來源:ConfigurationManagerForIDE.java

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

示例4: readModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
protected OntModel readModel() {
  Reasoner reasoner = PelletReasonerFactory.theInstance().create();
  Model infModel = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
  OntModel ontModel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, infModel);
  ontModel.read(getClass().getResourceAsStream("/" + modelBase), null, TTL);
  return ontModel;
}
 
開發者ID:mehmandarov,項目名稱:zebra-puzzle-workshop,代碼行數:8,代碼來源:Exercise4.java

示例5: readModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
protected OntModel readModel(String modelInput) {
    Reasoner reasoner = PelletReasonerFactory.theInstance().create();
    Model infModel = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
    OntModel ontModel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, infModel);
    ontModel.read(getClass().getResourceAsStream("/" + modelInput), null, TTL);
    return ontModel;
}
 
開發者ID:mehmandarov,項目名稱:zebra-puzzle-workshop,代碼行數:8,代碼來源:Exercise32.java

示例6: run

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Override
public void run() {
	final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
	for (final URL u : ontologyURLs)
		try {
			final String uri = u.toExternalForm();
			out.println("Loading " + uri);
			if (uri.endsWith(".ttl")){
				out.println("recognized turtle");
				model.read(uri, "http://example.org", "TURTLE");
			} else
				model.read(u.toExternalForm());
			out.println("Loaded " + uri);
		} catch (Exception e) {
			model.close();
			handler.error(new OntologyDownloadError(u, e));
			return;
		}
	out.println("Consistency check started");
	final ValidityReport report = model.validate();
	if (report.isValid()){
		out.println("Consistency check succesful complete");
		handler.complete(new JenaQueryEngine(model));
	}
	else {
		out.println("Consistency check complete with errors");
		model.close();
		handler.error(new InconsistenOntologyException());
	}
}
 
開發者ID:opendatahacklab,項目名稱:semanticoctopus,代碼行數:31,代碼來源:JenaPelletSeqDownloadTask.java

示例7: testTranslateRule

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Test
public void testTranslateRule() throws TranslationException {
	ITranslator trans = new SWIPrologTranslatorPlugin();
	OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	String altUrl = kbroot + "/Shapes/OwlModels/Shapes.owl";
	String format = "RDF/XML";
	om.read(altUrl, format);
	Rule rule = new Rule("TestRule");
	
	String stat = trans.translateRule(om, rule);
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:12,代碼來源:TestTranslator.java

示例8: InputFactoryTest

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * @param name
 */
public InputFactoryTest(String name) {
	super(name);
	QueryEngine qe = RippleQueryEngineSingleton.getInstance();
	Vector<DataSource> source1 = new Vector<>();
	Vector<DataSource> source2 = new Vector<>();
	source1.add(new RippleSource("test",qe));
	//OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
       OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
	m.read(TEST_PARAMETER_URI);
	source2.add(new JenaPelletSource("test",m));
	_linkedInputFactory = new InputFactory(source1, false);
	_cachedLinkedInputFactory = new InputFactory(source1, true);
	_jenaInputFactory = new InputFactory(source2, false);
}
 
開發者ID:tetherless-world,項目名稱:s2s,代碼行數:18,代碼來源:InputFactoryTest.java

示例9: FacetCollectionFactoryTest

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * @param name
 */
public FacetCollectionFactoryTest(String name) {
	super(name);
	
	Vector<DataSource> source = new Vector<>();
	OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
	source.add(new JenaPelletSource("test",m));
	m.read(TEST_FACETCOLLECTION_URI);
	_jenaFactory = new FacetCollectionFactory(source, false);
	_cachedFactory = new FacetCollectionFactory(source, true);
}
 
開發者ID:tetherless-world,項目名稱:s2s,代碼行數:14,代碼來源:FacetCollectionFactoryTest.java

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

示例11: setUp

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
protected void setUp() throws Exception {
	super.setUp();
	OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
	m.read(TEST_URI);
	_facet = new ConnectedFacetImpl(TEST_URI, new JenaPelletSource("test",m));
	_linkedFacet = new ConnectedFacetImpl(TEST_URI, new RippleSource("test",RippleQueryEngineSingleton.getInstance()));
	//TODO: linked data facet test
}
 
開發者ID:tetherless-world,項目名稱:s2s,代碼行數:9,代碼來源:ConnectedFacetImplTest.java

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

示例13: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example5.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 6.1: Create a new class named "University" **
	model.createClass(ns+"University");
	
	// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
	model.getOntClass(ns+"Person").addSubClass(model.createClass(ns+"Researcher"));
	
	// ** TASK 6.3: Create a new property named "worksIn" **
	model.createProperty(ns+"worksIn");
	
	// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
	model.getOntClass(ns+"Researcher").createIndividual(ns+"JaneSmith");
	
	// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
	model.getIndividual(ns+"JaneSmith").addProperty(VCARD.FN, "Jane Smith");
	model.getIndividual(ns+"JaneSmith").addProperty(VCARD.Given, "Jane");
	model.getIndividual(ns+"JaneSmith").addProperty(VCARD.Family, "Smith");
	
	// ** TASK 6.6: Add UPM as the university where John works **
	model.getIndividual(ns+"JohnSmith").addProperty(model.getProperty(ns+"worksIn"), model.getOntClass(ns+"University").createIndividual(ns+"UPM"));
	
	model.write(System.out, "RDF/XML-ABBREV");
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:39,代碼來源:Task06_Tubilok.java

示例14: getOntModelForEditing

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private OntModel getOntModelForEditing(String thisModelName) throws IOException, ConfigurationException, InvalidNameException, URISyntaxException {
	if (editedTboxModels != null && editedTboxModels.containsKey(thisModelName)) {
		return editedTboxModels.get(thisModelName);
	}
	try {
		if (modelName != null && !modelName.equals(thisModelName)) {
			if (instanceDataModels != null && instanceDataModels.containsKey(thisModelName)) {
				return instanceDataModels.get(thisModelName);
			}
			else if (getInstanceDataName() == null || thisModelName.equals(getInstanceDataName())) {
				if (getInstanceDataName() == null) {
					setInstanceDataNamespace(thisModelName + "#");
				}
				return createInstanceModel(thisModelName);
			}
		}
	} catch (ConfigurationException e) {
		// it's ok for instance names space to fail
	}
	String altUrl = canModifyModel(thisModelName);
	if (altUrl != null) {
		OntModel ontModel = ModelFactory.createOntologyModel(getConfigurationMgr().getOntModelSpec(null));
		altUrl = getConfigurationMgr().fileNameToFileUrl(altUrl);
		ontModel.getSpecification().setImportModelGetter((ModelGetter) configurationMgr.getModelGetter());
		ontModel.read(altUrl);
		ontModel.getDocumentManager().setProcessImports(true);
		ontModel.loadImports();
		ontModel.getDocumentManager().setProcessImports(false);
		if (editedTboxModels == null) {
			editedTboxModels = new HashMap<String, OntModel>();
		}
		editedTboxModels.put(thisModelName, ontModel);
		return ontModel;
	}
	return null;
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:37,代碼來源:SadlServerPEImpl.java

示例15: readModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private OntModel readModel() {
    OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
    ontModel.read(getClass().getResourceAsStream("/" + MODEL_INPUT_EX31_EX32), null, TTL);
    return ontModel;
}
 
開發者ID:mehmandarov,項目名稱:zebra-puzzle-workshop,代碼行數:6,代碼來源:Exercise31.java


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