org.semanticweb.owlapi.model.OWLOntologyID Java Examples
The following examples show how to use
org.semanticweb.owlapi.model.OWLOntologyID.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestOWLManager.java From elk-reasoner with Apache License 2.0 | 6 votes |
public static OWLOntologyManager createOWLOntologyManager() { OWLOntologyManager man = new OWLOntologyManagerImpl(df, new NoOpReadWriteLock()); man.getOntologyFactories() .set(new OWLOntologyFactoryImpl(new OWLOntologyBuilder() { private static final long serialVersionUID = -7962454739789851685L; @Override public OWLOntology createOWLOntology(OWLOntologyManager om, OWLOntologyID id) { return new OWLOntologyImpl(om, id); } })); man.getOntologyParsers().set(MASTER_MANAGER_.getOntologyParsers()); man.getOntologyStorers().set(MASTER_MANAGER_.getOntologyStorers()); man.getIRIMappers().set(MASTER_MANAGER_.getIRIMappers()); return man; }
Example #2
Source File: GraphOwlVisitor.java From SciGraph with Apache License 2.0 | 6 votes |
@Override public Void visit(OWLOntology ontology) { this.ontology = Optional.of(ontology); this.definingOntology = OwlApiUtils.getIri(ontology); Long versionNodeID = null; Long ontologyNodeID = null; OWLOntologyID id = ontology.getOntologyID(); if (null == id.getOntologyIRI()) { logger.fine("Ignoring null ontology ID for " + ontology.toString()); } else { ontologyNodeID = getOrCreateNode(id.getOntologyIRI().toString(), OwlLabels.OWL_ONTOLOGY); } if (null != id.getVersionIRI()){ versionNodeID = getOrCreateNode(id.getVersionIRI().toString(), OwlLabels.OWL_ONTOLOGY); } if (null != ontologyNodeID && null != versionNodeID) { graph.createRelationship(ontologyNodeID, versionNodeID, OwlRelationships.OWL_VERSION_IRI); } return null; }
Example #3
Source File: OboOntologyReleaseRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
private String handleVersion(String ontologyId) { // TODO add an option to set/overwrite the version manually via command-line // TODO re-use/create a method in obo2owl for creating an version IRI String version; OWLOntology ontology = mooncat.getOntology(); OWLOntologyID owlOntologyId = ontology.getOntologyID(); Optional<IRI> versionIRI = owlOntologyId.getVersionIRI(); if (versionIRI.isPresent() == false) { // set a new version IRI using the current date version = OntologyVersionTools.format(new Date()); versionIRI = Optional.of(IRI.create(Obo2OWLConstants.DEFAULT_IRI_PREFIX+ontologyId+"/"+oortConfig.getVersionSubdirectory()+"/"+version+"/"+ontologyId+".owl")); OWLOntologyManager m = mooncat.getManager(); m.applyChange(new SetOntologyID(ontology, new OWLOntologyID(owlOntologyId.getOntologyIRI(), versionIRI))); } else { String versionIRIString = versionIRI.get().toString(); version = OntologyVersionTools.parseVersion(versionIRIString); if (version == null) { // use the whole IRI? escape? logError("Could not parse a version from ontolgy version IRI: "+versionIRIString); version = versionIRIString; } } return version; }
Example #4
Source File: OntologyMetadata.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public OntologyMetadata(OWLOntology ont) { super(); OWLOntologyID id = ont.getOntologyID(); if (id.getOntologyIRI().isPresent()) ontologyIRI = id.getOntologyIRI().get().toString(); if (id.getVersionIRI().isPresent()) versionIRI = id.getVersionIRI().get().toString(); importDirectives = new HashSet<String>(); for (OWLImportsDeclaration oid : ont.getImportsDeclarations()) { importDirectives.add(oid.getIRI().toString()); } classCount = ont.getClassesInSignature().size(); namedIndividualCount = ont.getIndividualsInSignature().size(); axiomCount = ont.getAxiomCount(); annotations = new HashSet<OntologyAnnotation>(); for (OWLAnnotation ann : ont.getAnnotations()) { annotations.add(new OntologyAnnotation(ann)); } }
Example #5
Source File: SimpleOntologyValuesTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testOwlapiOntologyId() throws Exception { org.semanticweb.owlapi.model.IRI oIRI = org.semanticweb.owlapi.model.IRI.create("http://www.test.com/ontology"); org.semanticweb.owlapi.model.IRI vIRI = org.semanticweb.owlapi.model.IRI.create("http://www.test.com/ontology/1.0.0"); OWLOntologyID owlId = new OWLOntologyID(oIRI, vIRI); SimpleOntologyId simpleId1 = mock(SimpleOntologyId.class); expect(simpleId1.getOwlapiOntologyId()).andReturn(owlId); OntologyId simpleId2 = mock(OntologyId.class); expect(simpleId2.getOntologyIRI()).andReturn(Optional.of(ontologyIRI)).anyTimes(); expect(simpleId2.getVersionIRI()).andReturn(Optional.of(versionIRI)).anyTimes(); mockStaticPartial(SimpleOntologyValues.class, "owlapiIRI"); expect(SimpleOntologyValues.owlapiIRI(ontologyIRI)).andReturn(oIRI).anyTimes(); expect(SimpleOntologyValues.owlapiIRI(versionIRI)).andReturn(vIRI).anyTimes(); replay(simpleId1, simpleId2, SimpleOntologyValues.class); OWLOntologyID owlId1 = SimpleOntologyValues.owlapiOntologyId(simpleId1); OWLOntologyID owlId2 = SimpleOntologyValues.owlapiOntologyId(simpleId2); assertEquals(owlId, owlId1); assertEquals(oIRI, owlId2.getOntologyIRI().get()); assertEquals(vIRI, owlId2.getVersionIRI().get()); }
Example #6
Source File: SimpleOntologyValuesTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testMobiOntologyId() throws Exception { org.semanticweb.owlapi.model.IRI oIRI = org.semanticweb.owlapi.model.IRI.create("http://www.test.com/ontology"); org.semanticweb.owlapi.model.IRI vIRI = org.semanticweb.owlapi.model.IRI.create("http://www.test.com/ontology/1.0.0"); OWLOntologyID owlId2 = new OWLOntologyID(oIRI, vIRI); IRI moIRI = mock(IRI.class); IRI mvIRI = mock(IRI.class); expect(moIRI.stringValue()).andReturn("http://www.test.com/ontology").anyTimes(); expect(mvIRI.stringValue()).andReturn("http://www.test.com/ontology/1.0.0").anyTimes(); mockStaticPartial(SimpleOntologyValues.class, "mobiIRI"); expect(SimpleOntologyValues.mobiIRI(oIRI)).andReturn(moIRI).anyTimes(); expect(SimpleOntologyValues.mobiIRI(vIRI)).andReturn(mvIRI).anyTimes(); replay(moIRI, mvIRI, SimpleOntologyValues.class); OntologyId ontologyId = SimpleOntologyValues.mobiOntologyId(owlId2); assertEquals("http://www.test.com/ontology", ontologyId.getOntologyIRI().get().stringValue()); assertEquals("http://www.test.com/ontology/1.0.0", ontologyId.getVersionIRI().get().stringValue()); }
Example #7
Source File: SimpleOntologyValues.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
/** * . */ public static OWLOntologyID owlapiOntologyId(OntologyId simpleId) { if (simpleId == null) { return null; } if (simpleId instanceof SimpleOntologyId) { return ((SimpleOntologyId) simpleId).getOwlapiOntologyId(); } else { Optional<IRI> ontologyIRI = simpleId.getOntologyIRI(); Optional<IRI> versionIRI = simpleId.getVersionIRI(); if (versionIRI.isPresent()) { return new OWLOntologyID(Optional.of(owlapiIRI(ontologyIRI.get())), Optional.of(owlapiIRI(versionIRI.get()))); } else if (ontologyIRI.isPresent()) { return new OWLOntologyID(Optional.of(owlapiIRI(ontologyIRI.get())), Optional.empty()); } else { return new OWLOntologyID(); } } }
Example #8
Source File: SimpleOntologyValues.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
/** * . */ public static OntologyId mobiOntologyId(OWLOntologyID owlId) { if (owlId == null) { return null; } Optional<org.semanticweb.owlapi.model.IRI> ontologyIRI = owlId.getOntologyIRI(); Optional<org.semanticweb.owlapi.model.IRI> versionIRI = owlId.getVersionIRI(); if (versionIRI.isPresent()) { return new SimpleOntologyId.Builder(factory).ontologyIRI(mobiIRI(ontologyIRI.get())) .versionIRI(mobiIRI(versionIRI.get())).build(); } else if (ontologyIRI.isPresent()) { return new SimpleOntologyId.Builder(factory).ontologyIRI(mobiIRI(ontologyIRI.get())).build(); } else { return new SimpleOntologyId.Builder(factory).build(); } }
Example #9
Source File: MobiOntologyFactoryTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void loadOWLOntologyTest() throws Exception { assertEquals(owlOntology, factory.loadOWLOntology(owlOntologyManager, protocolSource, handler, configuration)); verify(ontologyManager).getOntologyModel(matIRI); verify(handler).setOntologyFormat(any(OWLOntology.class), any(OWLDocumentFormat.class)); verify(owlOntologyManager).removeOntology(any(OWLOntology.class)); verify(ontologyFactory, times(2)).createOWLOntology(eq(owlOntologyManager), any(OWLOntologyID.class), eq(owlProtocolIRI), eq(handler)); }
Example #10
Source File: MobiOntologyFactoryTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); PowerMockito.mockStatic(SimpleOntologyValues.class); when(SimpleOntologyValues.owlapiOntology(any(Ontology.class))).thenReturn(owlOntology); when(SimpleOntologyValues.mobiIRI(any(IRI.class))).thenReturn(matIRI); when(ontologyFactory.createOWLOntology(any(OWLOntologyManager.class), any(OWLOntologyID.class), any(IRI.class), any(OWLOntologyFactory.OWLOntologyCreationHandler.class))).thenReturn(owlOntology); when(ontologyManager.retrieveOntology(any(Resource.class))).thenReturn(Optional.of(ontology)); when(ontologyManager.getOntologyModel(any(Resource.class))).thenReturn(mf.createModel()); when(owlOntologyManager.getOntology(any(IRI.class))).thenReturn(owlOntology); when(owlOntologyManager.getOntologyConfigurator()).thenReturn(ontologyConfigurator); when(ontologyConfigurator.buildWriterConfiguration()).thenReturn(owlOntologyWriterConfiguration); when(owlOntologyWriterConfiguration.shouldRemapAllAnonymousIndividualsIds()).thenReturn(false); when(owlOntology.importsDeclarations()).thenReturn(Stream.of(importsDeclaration)); when(owlOntology.getOWLOntologyManager()).thenReturn(owlOntologyManager); when(owlOntology.annotationPropertiesInSignature(any(Imports.class))).thenReturn(Stream.empty()); when(owlOntology.dataPropertiesInSignature(any(Imports.class))).thenReturn(Stream.empty()); when(owlOntology.objectPropertiesInSignature(any(Imports.class))).thenReturn(Stream.empty()); when(owlOntology.classesInSignature(any(Imports.class))).thenReturn(Stream.empty()); when(owlOntology.datatypesInSignature(any(Imports.class))).thenReturn(Stream.empty()); when(owlOntology.individualsInSignature(any(Imports.class))).thenReturn(Stream.empty()); when(owlOntology.getOntologyID()).thenReturn(owlOntologyID); when(owlOntologyID.getOntologyIRI()).thenReturn(Optional.empty()); when(owlOntologyID.isAnonymous()).thenReturn(true); when(ontology.getOntologyId()).thenReturn(ontologyId); when(ontology.asModel(any(ModelFactory.class))).thenReturn(mf.createModel()); when(ontologyId.getOntologyIdentifier()).thenReturn(vf.createIRI("https://inovexcorp.com/mobi/test-ontology")); when(sesameTransformer.sesameModel(any(Model.class))).thenAnswer(i -> Values.sesameModel(i.getArgumentAt(0, Model.class))); factory = new MobiOntologyFactory(ontologyManager, ontologyFactory, sesameTransformer); }
Example #11
Source File: MobiOntologyFactory.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public OWLOntology createOWLOntology(OWLOntologyManager manager, OWLOntologyID ontologyID, IRI documentIRI, OWLOntologyCreationHandler handler) throws OWLOntologyCreationException { LOG.trace("Enter createOWLOntology()"); long start = System.currentTimeMillis(); if (!ontologyID.isAnonymous()) { LOG.debug("createOWLOntology: {}", ontologyID.toString()); } OWLOntology owlOntology = ontologyFactory.createOWLOntology(manager, ontologyID, documentIRI, handler); LOG.trace("Exit createOWLOntology() {} ms", System.currentTimeMillis() - start); return owlOntology; }
Example #12
Source File: BioChebiGenerator.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void appendOntologyId(OWLOntologyID ontologyID, StringBuilder sb) { Optional<IRI> ontologyIRI = ontologyID.getOntologyIRI(); if (ontologyIRI.isPresent()) { sb.append("Ontology(id=").append(ontologyIRI.get()); Optional<IRI> versionIRI = ontologyID.getVersionIRI(); if (versionIRI .isPresent()) { sb.append(", version=").append(versionIRI.get()); } sb.append(")"); } else { sb.append("Ontology with no ID"); } }
Example #13
Source File: EcoTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create an instance for the given graph and reasoner. * * @param graph * @param reasoner * @param disposeReasoner set to true, if the reasoner should also be disposed * @throws UnknownOWLOntologyException * @throws OWLOntologyCreationException * * @see #dispose() */ public EcoTools (OWLGraphWrapper graph, OWLReasoner reasoner, boolean disposeReasoner) throws UnknownOWLOntologyException, OWLOntologyCreationException { // This has bitten me, so let's try and bew specific... if( reasoner == null ){ throw new Error("No reasoner was specified for use with the EcoTools. Add a reasoner for the command line"); } // assume the graph wrapper is more than eco // try to find ECO by its purl Set<OWLOntology> allOntologies = graph.getAllOntologies(); OWLOntology eco = null; for (OWLOntology owlOntology : allOntologies) { OWLOntologyID id = owlOntology.getOntologyID(); Optional<IRI> ontologyIRI = id.getOntologyIRI(); if (ontologyIRI.isPresent()) { if (ECO_PURL.equals(ontologyIRI.get().toString())) { eco = owlOntology; } } } if (eco != null) { // found eco create new wrapper this.eco = new OWLGraphWrapper(eco); } else { // did not find eco, use whole wrapper this.eco = graph; } this.reasoner = reasoner; this.disposeReasonerP = disposeReasoner; }
Example #14
Source File: EcoMapperFactory.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a {@link TraversingEcoMapper} instance using the given * {@link OWLGraphWrapper}. It is assumed that ECO can be retrieved from the * graph using its default IRI. The mappings are retrieved using the PURL. * <p> * Uses the given reasoner in the traversal methods. If disposeReasoner is * set to true, dispose also the reasoner, while calling * {@link TraversingEcoMapper#dispose()}. * * @param all * graph containing all ontologies, including ECO * @param reasoner * reasoner capable of traversing ECO * @param disposeReasoner * set to true if the reasoner should be disposed, when calling * {@link TraversingEcoMapper#dispose()} * @return mapper * @throws IOException * @throws OWLException * @throws IllegalArgumentException * throw when the reasoner is null, or the * {@link OWLGraphWrapper} does not contain ECO. * * @see EcoMapper#ECO_PURL_IRI * @see EcoMapper#ECO_MAPPING_PURL */ public static TraversingEcoMapper createTraversingEcoMapper(OWLGraphWrapper all, OWLReasoner reasoner, boolean disposeReasoner) throws IOException, OWLException { // This has bitten me, so let's try and be specific... if( reasoner == null ) { throw new IllegalArgumentException("No reasoner was specified for use with the EcoTools. Add a reasoner for the command line"); } OWLOntology eco = null; // assume the graph wrapper is more than eco // try to find ECO by its purl Set<OWLOntology> allOntologies = all.getAllOntologies(); for (OWLOntology owlOntology : allOntologies) { OWLOntologyID id = owlOntology.getOntologyID(); Optional<IRI> ontologyIRI = id.getOntologyIRI(); if (ontologyIRI.isPresent()) { if (EcoMapper.ECO_PURL_IRI.equals(ontologyIRI.get())) { eco = owlOntology; } } } if (eco == null) { throw new IllegalArgumentException("The specified graph did not contain ECO with the IRI: "+EcoMapper.ECO_PURL_IRI); } OWLGraphWrapper ecoGraph = new OWLGraphWrapper(eco); Reader reader = null; try { reader = createReader(EcoMapper.ECO_MAPPING_PURL); EcoMappings<OWLClass> mappings = loadEcoMappings(reader, ecoGraph); return new TraversingEcoMapperImpl(mappings, reasoner, disposeReasoner); } finally { IOUtils.closeQuietly(reader); } }
Example #15
Source File: QuerySubsetGeneratorTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private OWLGraphWrapper getTargetGraph() throws Exception { OWLOntologyManager targetManager = OWLManager.createOWLOntologyManager(); OWLOntologyID ontologyID = new OWLOntologyID(Optional.of(IRI.create("http://test.owltools.org/dynamic")), Optional.absent()); OWLOntology targetOntology = targetManager.createOntology(ontologyID); OWLGraphWrapper targetGraph = new OWLGraphWrapper(targetOntology); return targetGraph; }
Example #16
Source File: MobiOntologyFactory.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public OWLOntology loadOWLOntology(OWLOntologyManager manager, OWLOntologyDocumentSource source, OWLOntologyCreationHandler handler, OWLOntologyLoaderConfiguration config) throws OWLOntologyCreationException { LOG.trace("Enter loadOWLOntology()"); long start = System.currentTimeMillis(); OWLOntology existingOntology = null; IRI documentIRI = source.getDocumentIRI(); if (manager.contains(documentIRI)) { existingOntology = manager.getOntology(documentIRI); } OWLOntologyID ontologyID = new OWLOntologyID(); OWLOntology ont = createOWLOntology(manager, ontologyID, documentIRI, handler); if (existingOntology == null && !ont.isEmpty()) { // Junk from a previous parse. We should clear the ont LOG.trace("Clearing extraneous ontology"); manager.removeOntology(ont); ont = createOWLOntology(manager, ontologyID, documentIRI, handler); } IRI recordId = IRI.create(documentIRI.getIRIString().replace(MobiOntologyIRIMapper.protocol, MobiOntologyIRIMapper.standardProtocol)); Model ontologyModel = ontologyManager.getOntologyModel(SimpleOntologyValues.mobiIRI(recordId)); RioParserImpl parser = new RioParserImpl(new RioRDFXMLDocumentFormatFactory()); org.eclipse.rdf4j.model.Model sesameModel = sesameTransformer.sesameModel(ontologyModel); OWLDocumentFormat format = parser.parse(new RioMemoryTripleSource(sesameModel), ont, config); handler.setOntologyFormat(ont, format); LOG.debug("Loaded imported Ontology: {}", ont.getOntologyID().toString()); LOG.trace("Exit loadOWLOntology() {} ms", System.currentTimeMillis() - start); return ont; }
Example #17
Source File: MobiOntologyFactoryTest.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Test public void createOWLOntologyTest() throws Exception { OWLOntologyID id = new OWLOntologyID(); assertEquals(owlOntology, factory.createOWLOntology(owlOntologyManager, id, owlProtocolIRI, handler)); verify(ontologyFactory).createOWLOntology(owlOntologyManager, id, owlProtocolIRI, handler); }
Example #18
Source File: SimpleOntologyId.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
protected OWLOntologyID getOwlapiOntologyId() { return ontologyId; }
Example #19
Source File: MirrorOperation.java From robot with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Mirrors ontologies on local filesystem. * * @param rootOntology The ontology to mirror. * @param baseFolder The folder. * @param catalogFile The catalog file to write to. * @throws IOException on most problems. * @throws OWLOntologyStorageException if the ontology cannot be saved. */ public static void mirror(OWLOntology rootOntology, File baseFolder, File catalogFile) throws IOException, OWLOntologyStorageException { logger.info("Mirroring ontologies: " + rootOntology); Map<IRI, String> iriMap = new HashMap<>(); for (OWLOntology ont : rootOntology.getImportsClosure()) { logger.info("Mirroring: " + ont); validateImports(ont); OWLOntologyID ontologyID = ont.getOntologyID(); IRI ontologyIRI = ontologyID.getOntologyIRI().orNull(); // Not really sure why this is here, but apparently we can get // an ontology without an IRI, in which case we'll generate one // that is 'sort of' unique (only fails if two different machines // run this tool at the exact same time). // if (ontologyIRI == null) { ontologyIRI = IRI.generateDocumentIRI(); } // Always write the actualIRI String localFilePath = getMirrorPathOfOntologyIRI(ontologyIRI); IRI outputStream = IRI.create(new File(baseFolder, localFilePath)); ont.getOWLOntologyManager().saveOntology(ont, outputStream); iriMap.put(ontologyIRI, localFilePath); // // In case there is a difference between the source document IRI // and the IRI of the resolved target (e.g., there is an HTTP // redirect from a legacy IRI to a newer IRI), then write an entry // in the catalog that points the legacy IRI to the newer, canonical // one. // Examples of this include: // http://purl.obolibrary.org/obo/so.owl // which redirects to: // http://purl.obolibrary.org/obo/so-xp.obo.owl // IRI documentIRI = ont.getOWLOntologyManager().getOntologyDocumentIRI(ont); if (!documentIRI.toString().startsWith("file:") && documentIRI != ontologyIRI) { String sourceLocalFile = getMirrorPathOfOntologyIRI(ontologyIRI); logger.info("Mirroring " + documentIRI + " in " + sourceLocalFile); iriMap.put(documentIRI, sourceLocalFile); } } writeCatalog(catalogFile, iriMap); }
Example #20
Source File: BioChebiGenerator.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Create the GCIs for BioChEBI. Add the axioms into the given ontology. * * @param ontology * @param ignoredClasses */ public void expand(OWLOntology ontology, Set<OWLClass> ignoredClasses) { final OWLOntologyManager manager = ontology.getOWLOntologyManager(); final OWLDataFactory factory = manager.getOWLDataFactory(); // scan axioms Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED); for (OWLSubClassOfAxiom axiom : axioms) { OWLClassExpression superCE = axiom.getSuperClass(); OWLClassExpression subCE = axiom.getSubClass(); if (subCE.isAnonymous()) { // sub class needs to be an named OWLClass continue; } if (superCE instanceof OWLObjectSomeValuesFrom == false) { continue; } OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) superCE; OWLObjectPropertyExpression expression = some.getProperty(); if (expression.isAnonymous()) { // object property expression needs to be a named OWLObjectProperty continue; } OWLObjectProperty p = (OWLObjectProperty) expression; Set<OWLObjectProperty> expansions = expansionMap.get(p); if (expansions == null) { continue; } // get content for GCI OWLClassExpression y = some.getFiller(); OWLClass x = subCE.asOWLClass(); if (ignoredClasses.contains(x)) { continue; } for (OWLObjectProperty createProperty : expansions) { OWLClassExpression ce1 = factory.getOWLObjectSomeValuesFrom(createProperty, x); OWLClassExpression ce2 = factory.getOWLObjectSomeValuesFrom(createProperty, y); OWLEquivalentClassesAxiom eq = factory.getOWLEquivalentClassesAxiom(ce1, ce2); manager.addAxiom(ontology, eq); } } Set<OWLOntology> imports = ontology.getImports(); StringBuilder sb = new StringBuilder(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); sb.append("Generated on ").append(dateFormat.format(new Date())).append(" using the following import chain:"); for (OWLOntology owlOntology : imports) { OWLOntologyID ontologyID = owlOntology.getOntologyID(); sb.append(" "); appendOntologyId(ontologyID, sb); } addComment(sb.toString(), ontology); }
Example #21
Source File: ImportClosureSlurper.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void save(File baseFolder, BufferedWriter w) throws IOException, OWLOntologyStorageException { w.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); w.write("<catalog prefer=\"public\" xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\n"); for (OWLOntology ont : ontology.getImportsClosure()) { validateImports(ont); OWLOntologyID ontologyID = ont.getOntologyID(); IRI actualIRI = null; Optional<IRI> optional = ontologyID.getOntologyIRI(); if (optional.isPresent()) { actualIRI = optional.get(); } // Not really sure why this is here, but apparently we can get // an ontology without an IRI, in which case we'll generate one // that is 'sort of' unique (only fails if two different machines run // this tool at the exact same time). // if (actualIRI == null) { IRI generatedIRI = IRI.generateDocumentIRI(); actualIRI = generatedIRI; } // Always write the actualIRI String actualLocalFile = createLocalFileName(actualIRI); IRI outputStream = IRI.create(new File(baseFolder, actualLocalFile)); ont.getOWLOntologyManager().saveOntology(ont, outputStream); if (LOGGER.isInfoEnabled()) { LOGGER.info("name: "+ actualIRI +" local: "+actualLocalFile); } w.write(" <uri name=\""+ actualIRI +"\" uri=\""+ actualLocalFile +"\"/>\n"); // // In case there is a difference between the source document IRI // and the IRI of the resolved target (e.g., there is an HTTP // redirect from a legacy IRI to a newer IRI), then write an entry // in the catalog that points the legacy IRI to the newer, canonical one. // Examples of this include: // http://purl.obolibrary.org/obo/so.owl // which redirects to: // http://purl.obolibrary.org/obo/so-xp.obo.owl // IRI documentIRI = ont.getOWLOntologyManager().getOntologyDocumentIRI(ont); if (documentIRI != actualIRI) { String sourceLocalFile = createLocalFileName(actualIRI); if (LOGGER.isInfoEnabled()) { LOGGER.info("alias: "+ documentIRI + " ==> " + actualIRI + " local: "+ sourceLocalFile); } w.write(" <uri name=\""+ documentIRI +"\" uri=\""+ sourceLocalFile +"\"/>\n"); } } w.write("</catalog>\n"); w.flush(); }