@Test(expected = OWLOntologyDocumentAlreadyExistsException.class) public void testCreateDuplicatedDocumentIRI() throws Exception { OWLOntologyManager manager = Factory.getManager(); IRI ontologyIRI = IRI("http://www.semanticweb.org/ontologies/ontology"); IRI ontologyIRI2 = IRI("http://www.semanticweb.org/ontologies/ontology2"); IRI documentIRI = IRI("file:documentIRI"); manager.addIRIMapper(new SimpleIRIMapper(ontologyIRI, documentIRI)); manager.addIRIMapper(new SimpleIRIMapper(ontologyIRI2, documentIRI)); manager.createOntology(new OWLOntologyID(ontologyIRI)); manager.createOntology(new OWLOntologyID(ontologyIRI2)); }
/** * Initialise les composants du conteneur sémantique une fois les URI des ontologies dispatchées * par OwlDistributionInitializer. */ public void semInit() throws ExceptionInInitializerError { if (isInitialized()) { /** Initialisation de l'ontologie locale. Cette ontologie n'est plus modifiée ensuite. */ // Initialisation du manager de l'ontologie locale. N'est utilisé qu'ici. OWLOntologyManager localOntoManager = OWLManager.createOWLOntologyManager(); OWLOntologyIRIMapper localOntoMapper = new SimpleIRIMapper(getOntologyIri(), getPhysicalIri()); localOntoManager.addIRIMapper(localOntoMapper); // Initialisation de l'ontologie try { // On crée l'ontologie locale. this.localOntology = localOntoManager.loadOntology(getPhysicalIri()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } // System.out.println("localOntology : " + localOntology + " ; pyhsicalIri : " + // getPhysicalIri().toString()); /** * Initialisation de l'ontologie du reasoner, qui contiendra l'ontologie locale plus d'autres * axiomes éventuels. On crée l'instance, qu'on rattache à un manager et un reasoner * accessibles par des getters. L'instance reste la même, mais le contenu change. */ // Initialisation du manager de l'ontologie du reasoner this.manager = OWLManager.createOWLOntologyManager(); // On crée une deuxième ontologie. try { IRI ontoName = IRI.create(this.nameSpace); OWLOntologyID ontoId = new OWLOntologyID(ontoName); this.reasoningOntology = this.manager.createOntology(ontoId); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } // Initialisation du reasoner PelletReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance(); PelletOptions.USE_INCREMENTAL_CONSISTENCY = true; PelletOptions.USE_COMPLETION_QUEUE = true; // PelletReasoner reasoner = reasonerFactory.createReasoner(reasoningOntology); PelletReasoner reasoner = reasonerFactory.createNonBufferingReasoner(reasoningOntology); // add the reasoner as an ontology change listener this.manager.addOntologyChangeListener(reasoner); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); /* reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS); reasoner.precomputeInferences(InferenceType.DATA_PROPERTY_HIERARCHY); reasoner.precomputeInferences(InferenceType.DISJOINT_CLASSES); reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_HIERARCHY); reasoner.precomputeInferences(InferenceType.SAME_INDIVIDUAL); */ this.reasoner = reasoner; } else throw new ExceptionInInitializerError( "Paramètres de l'ontologie non initialisés ; ontoParamsInit = " + Reflection.getCallerClass(2)); // initOntoReasoner(); }
private void addTripsBaseOntologies(OWLOntologyManager manager) throws Exception { SimpleIRIMapper iriMapperTime = new SimpleIRIMapper( IRI.create("http://www.w3.org/2006/time"), IRI.create(new File("Time.owl"))); manager.addIRIMapper(iriMapperTime); SimpleIRIMapper iriMapperCore = new SimpleIRIMapper( IRI.create( "http://www.ibm.com/SCTC/ontology/" + "CoreSpatioTemporalDataSensorOntology.owl"), IRI.create(new File("CoreSpatioTemporalDataSensorOntology.owl"))); manager.addIRIMapper(iriMapperCore); SimpleIRIMapper iriMapperTravelTime = new SimpleIRIMapper( IRI.create("http://www.ibm.com/SCTC/ontology/TravelTimeOntology.owl"), IRI.create(new File("TravelTimeOntology.owl"))); manager.addIRIMapper(iriMapperTravelTime); }
@Test public void testCreateOntologyWithIRIWithMapper() throws Exception { OWLOntologyManager manager = Factory.getManager(); IRI ontologyIRI = IRI("http://www.semanticweb.org/ontologies/ontology"); IRI documentIRI = IRI("file:documentIRI"); SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI); manager.addIRIMapper(mapper); OWLOntology ontology = manager.createOntology(ontologyIRI); assertNotNull("ontology should not be null", ontology); assertNotNull("ontology id should not be null", ontology.getOntologyID()); assertEquals(ontologyIRI, ontology.getOntologyID().getDefaultDocumentIRI()); assertEquals(ontologyIRI, ontology.getOntologyID().getOntologyIRI()); assertNull(ontology.getOntologyID().getVersionIRI()); assertEquals(documentIRI, manager.getOntologyDocumentIRI(ontology)); }
public void loadOntology() { try { /* * --apaitoymena vimata gia th dhmioyrgia mapped ontologias: * 1.dhmioyrgoyme ena toBeMappedIRI me skopo toy thn antistoixish me * to local File. 2.dhmioyrgoyme ena File me th dieythynsh ths * ontologias sto topiko apothikeytiko meso. 3.dhmioyrgoyme enan * SimpleIRIMapper kai ton prosthetoyme mesw toy manager. o * SimpleIRIMapper syndeei to toBeMappedIRI poy dwsame arxika, me * thn fysikh topothesia ths ontologias sto topiko apothikeytiko * meso. 4.dhmioyrgoyme ena ontologyIRI me akrivws thn idia arxiki * timh me to toBeMappedIRI to opoio tha einai to IRI ths ontologias * mas 5.dhmioyrgoyme thn ontologia mas xrhsimopoiwntas to * manager.loadOntology(ontologyIRI); */ String sep = File.separator; manager = OWLManager.createOWLOntologyManager(); toBeMappedIRI = IRI.create( "http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl"); // ontFile = new File("../src/ontologyresources/ptyxiaki_v0.8.owl"); ontFile = new File("src/ontologyresources/ptyxiaki_v0.8.owl"); // in case of alternative location on load time when the application is jar'ed! if (!ontFile.canRead()) { ontFile = new File("ontologyresources/ptyxiaki_v0.8.owl"); } manager.addIRIMapper(new SimpleIRIMapper(toBeMappedIRI, IRI.create(ontFile))); ontologyIRI = IRI.create( "http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl"); topIxOnt = manager.loadOntology(ontologyIRI); OWLFactory = manager.getOWLDataFactory(); topIxFormat = manager.getOntologyFormat(topIxOnt); topIxPrefixManager = new DefaultPrefixManager(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#'); System.out.println("loaded ontology: " + this.topIxOnt); System.out.println("from: " + this.manager.getOntologyDocumentIRI(this.topIxOnt)); } catch (OWLException oex) { logger.info(oex.getMessage()); } }
@Before public void setup() throws Exception { String uri = Resources.getResource("ontologies/unsat_parent.owl").toURI().toString(); IRI iri = IRI.create(uri); manager = OWLManager.createOWLOntologyManager(); manager.addIRIMapper( new OWLOntologyIRIMapper() { @Override public IRI getDocumentIRI(IRI origIri) { String uri = null; try { uri = Resources.getResource("ontologies/unsat.owl").toURI().toString(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } return IRI.create(uri); } }); ont = manager.loadOntologyFromOntologyDocument(iri); ReasonerConfiguration config = new ReasonerConfiguration(); config.setFactory(ElkReasonerFactory.class.getCanonicalName()); util = new ReasonerUtil(config, manager, ont); }
/** @param args */ public static void main(String[] args) { String external = "http://purl.obolibrary.org/obo/iao/dev/external.owl"; String externalDerived = "http://purl.obolibrary.org/obo/iao/dev/externalDerived.owl"; String externalByHand = "http://purl.obolibrary.org/obo/iao/dev/externalByHand.owl"; String metaData = "http://purl.obolibrary.org/obo/iao/dev/ontology-metadata.owl"; String reasonerName = "hermit"; String path = "C:/Documents and Settings/Jie/My Documents/Ontology/iao/releases/2012-01-05/"; String saveIaoFilename = path + "merged/iao-main-infer.owl"; String inferOntURIStr = "http://purl.obolibrary.org/obo/iao/dev/iao_inferredSuperClasses.owl"; String saveInferFilename = path + "merged/iao-inferredSuperClasses.owl"; // Get hold of an ontology manager OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); AutoIRIMapper mapper = new AutoIRIMapper(new File(path + "ontology/"), false); manager.addIRIMapper(mapper); OWLOntology iaoOnt = OntologyManipulator.load(path + "ontology/iao-main.owl", manager); // OntologyManipulator.printPrefixNSs(manager, iaoOnt); OWLDataFactory df = manager.getOWLDataFactory(); // get all imported ontologies Set<OWLOntology> importOnts = iaoOnt.getImports(); // remove imports statements from the loaded ontology for (OWLOntology importOnt : importOnts) { IRI importOntIRI = importOnt.getOntologyID().getOntologyIRI(); if (importOntIRI.equals(IRI.create(metaData)) || importOntIRI.equals(IRI.create(external)) || importOntIRI.equals(IRI.create(externalByHand)) || importOntIRI.equals(IRI.create(externalDerived))) { RemoveImport ri = new RemoveImport(iaoOnt, df.getOWLImportsDeclaration(importOntIRI)); manager.applyChange(ri); } } // merge the removed imported ontologies to the loaded one for (OWLOntology importOnt : importOnts) { IRI importOntIRI = importOnt.getOntologyID().getOntologyIRI(); if (importOntIRI.equals(IRI.create(metaData)) || importOntIRI.equals(IRI.create(external)) || importOntIRI.equals(IRI.create(externalByHand)) || importOntIRI.equals(IRI.create(externalDerived))) { // OntologyManipulator.printPrefixNSs(manager, importOnt); iaoOnt = OntologyManipulator.mergeToTargetOnt(manager, iaoOnt, importOnt); } } // generate the inferred hierarchy and clean the super classes OWLReasoner reasoner = OWLReasonerRunner.runReasoner(manager, iaoOnt, reasonerName); iaoOnt = OWLReasonerRunner.getCleanedOntologyWithInferredSuperClasses( manager, iaoOnt, inferOntURIStr, reasoner); OntologyManipulator.saveToFile(manager, iaoOnt, saveIaoFilename); if (manager.contains(IRI.create(inferOntURIStr))) { OWLOntology inferOnt = manager.getOntology(IRI.create(inferOntURIStr)); OntologyManipulator.saveToFile(manager, inferOnt, saveInferFilename); } }