org.semanticweb.owlapi.model.OWLOntologyStorageException Java Examples
The following examples show how to use
org.semanticweb.owlapi.model.OWLOntologyStorageException.
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: NCBI2OWL.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Read a data file, create an OWL representation, and save an OWL file. * Create alternate identifiers from the merge.dmp file information * * @param inputPath the path to the input data file (e.g. taxonomy.dat) * @param outputPath the path to the output OWL file * (e.g. ncbi_taxonomy.owl). * @param mergeInfo the input stream of the merged information * @param citationInfo the input stream of the citation information * @param uniqueNames * @return OWL ontology * @throws IOException if the paths do not resolve * @throws OWLOntologyCreationException if OWLAPI fails to create an * empty ontology * @throws OWLOntologyStorageException if OWLAPI can't save the file */ public static OWLOntology convertToOWL(String inputPath, String outputPath, InputStream mergeInfo, InputStream citationInfo, Map<String, String> uniqueNames) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException { File outputFile = new File(outputPath); IRI outputIRI = IRI.create(outputFile); OWLOntology ontology = convertToOWL(inputPath, uniqueNames); if (mergeInfo != null) { addAltIds(ontology, mergeInfo); } if (citationInfo != null) { addCitationInfo(ontology, citationInfo); } logger.debug("Saving ontology..."); ontology.getOWLOntologyManager().saveOntology( ontology, outputIRI); return ontology; }
Example #2
Source File: QueryOperationTest.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Tests a verify with no violations. * * @throws IOException on IO error * @throws OWLOntologyStorageException on ontology error */ @Test public void testExecVerifyNoViolations() throws IOException, OWLOntologyStorageException { OWLOntology ontology = loadOntology("/simple.owl"); Dataset dataset = QueryOperation.loadOntologyAsDataset(ontology); String allViolations = "SELECT ?s ?p ?o\n" + "WHERE {\n" + " \n" + "}\n" + "LIMIT 0"; ResultSet resultSet = QueryOperation.execQuery(dataset, allViolations); ResultSetRewindable copy = ResultSetFactory.copyResults(resultSet); int resultSize = copy.size(); copy.reset(); ByteArrayOutputStream testOut = new ByteArrayOutputStream(); QueryOperation.writeResult(copy, Lang.CSV, testOut); boolean violations = false; if (resultSize > 0) { violations = true; } assertFalse(violations); assertEquals(1, Lists.newArrayList(testOut.toString().split("\n")).size()); }
Example #3
Source File: QueryOperationTest.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Tests a verify with violations. * * @throws IOException on IO error * @throws OWLOntologyStorageException on ontology error */ @Test public void testExecVerifyWithViolations() throws IOException, OWLOntologyStorageException { OWLOntology ontology = loadOntology("/simple.owl"); Dataset dataset = QueryOperation.loadOntologyAsDataset(ontology); String allViolations = "SELECT ?s ?p ?o\n" + "WHERE {\n" + " ?s ?p ?o .\n" + "}\n" + "LIMIT 10"; ResultSet resultSet = QueryOperation.execQuery(dataset, allViolations); ResultSetRewindable copy = ResultSetFactory.copyResults(resultSet); int resultSize = copy.size(); copy.reset(); ByteArrayOutputStream testOut = new ByteArrayOutputStream(); QueryOperation.writeResult(copy, Lang.CSV, testOut); boolean violations = false; if (resultSize > 0) { violations = true; } assertTrue(violations); assertEquals(7, Lists.newArrayList(testOut.toString().split("\n")).size()); }
Example #4
Source File: QueryOperationTest.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Tests an update statement that adds a label. * * @throws IOException on IO error * @throws OWLOntologyStorageException on ontology error * @throws OWLOntologyCreationException on ontology error */ @Test public void testExecUpdate() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException { OWLOntology inputOntology = loadOntology("/simple.owl"); Model model = QueryOperation.loadOntologyAsModel(inputOntology); String updateString = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" + "PREFIX s: <https://github.com/ontodev/robot/robot-core/src/test/resources/simple.owl#>" + "INSERT { " + "s:test2 rdfs:label \"test 2\" ." + " } WHERE {}"; QueryOperation.execUpdate(model, updateString); OWLOntology outputOntology = QueryOperation.convertModel(model); assertIdentical("/simple_update.owl", outputOntology); }
Example #5
Source File: QueryOperationTest.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Tests a construct query. * * @throws IOException on IO error * @throws OWLOntologyStorageException on ontology error */ @Test public void testConstruct() throws IOException, OWLOntologyStorageException { OWLOntology ontology = loadOntology("/bot.owl"); Dataset dataset = QueryOperation.loadOntologyAsDataset(ontology); String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" + "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX part_of: <http://purl.obolibrary.org/obo/BFO_0000050>\n" + "CONSTRUCT {\n" + " ?part part_of: ?whole\n" + "}\n" + "WHERE {\n" + " ?part rdfs:subClassOf [\trdf:type owl:Restriction ;\n" + "\t\t\t\t\t\towl:onProperty part_of: ;\n" + "\t\t\t\t\t\towl:someValuesFrom ?whole ]\n" + "}"; Model model = QueryOperation.execConstruct(dataset, query); Resource s = ResourceFactory.createResource("http://purl.obolibrary.org/obo/UBERON_0000062"); Property p = ResourceFactory.createProperty("http://purl.obolibrary.org/obo/BFO_0000050"); RDFNode o = ResourceFactory.createResource("http://purl.obolibrary.org/obo/UBERON_0000467"); assertTrue(model.contains(s, p, o)); }
Example #6
Source File: SnomedFunctionalSyntaxStorer.java From snomed-owl-toolkit with Apache License 2.0 | 6 votes |
@Override protected void storeOntology(@Nonnull OWLOntology ontology, @Nonnull Writer writer, OWLDocumentFormat format) throws OWLOntologyStorageException { try { FunctionalSyntaxObjectRenderer renderer = new FunctionalSyntaxObjectRenderer(ontology, writer); // Force ontology prefix manager into renderer if (format instanceof PrefixManager) { renderer.setPrefixManager((PrefixManager) format); } ontology.accept(renderer); writer.flush(); } catch (IOException e) { throw new OWLOntologyStorageException(e); } }
Example #7
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void topCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, UnknownOWLClassException { if (isHelp()) { info("Basic metadata about current ontology"); // TODO - json return; } OntologySetMetadata osmd = new OntologySetMetadata(this.getOWLOntology()); String manifestVersion = VersionInfo.getManifestVersion("owltools-build-timestamp"); osmd.serverManifestVersion = manifestVersion == null ? "unknown" : manifestVersion; ServerMetadata smd = new ServerMetadata(); smd.ontologySetMetadata = osmd; smd.setMemoryUsage(); smd.serverManifest = osmd.serverManifestVersion; // if (this.getOWLSim() != null) { // smd.owlSimMetadata = this.getOWLSim().getMetadata(); // } returnJSON(smd); }
Example #8
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Params: id * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws IOException * @throws OWLParserException */ public void getAxiomsCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, OWLParserException { headerOWL(); boolean direct = getParamAsBoolean(Param.direct, false); OWLObject obj = this.resolveEntity(); LOG.info("finding axioms about: "+obj); Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(); if (obj instanceof OWLClass) { axioms.addAll(graph.getSourceOntology().getAxioms((OWLClass)obj, Imports.EXCLUDED)); } if (obj instanceof OWLIndividual) { axioms.addAll(graph.getSourceOntology().getAxioms((OWLIndividual)obj, Imports.EXCLUDED)); } if (obj instanceof OWLObjectProperty) { axioms.addAll(graph.getSourceOntology().getAxioms((OWLObjectProperty)obj, Imports.EXCLUDED)); } for (OWLAxiom ax : axioms) { output(ax); } }
Example #9
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * generates a sub-ontology consisting only of classes specified using the id param. * If the include_ancestors param is true, then the transitive closure of the input classes is * included. otherwise, intermediate classes are excluded and paths are filled. * * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws IOException * @see Mooncat#makeMinimalSubsetOntology(Set, IRI) */ public void makeSubsetOntologyCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException { headerOWL(); Set<OWLClass> objs = resolveClassList(); Set<OWLClass> tObjs = new HashSet<OWLClass>(); if (getParamAsBoolean("include_ancestors")) { // TODO - more more efficient for (OWLClass obj : objs) { for (OWLObject t : graph.getAncestorsReflexive(obj)) { tObjs.add((OWLClass)t); } } } else { tObjs = objs; } Mooncat mooncat; mooncat = new Mooncat(graph); OWLOntology subOnt = mooncat.makeMinimalSubsetOntology(tObjs, IRI.create("http://purl.obolibrary.org/obo/temporary")); for (OWLAxiom axiom : subOnt.getAxioms()) { output(axiom); // TODO } graph.getManager().removeOntology(subOnt); }
Example #10
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * tests which of a set of input classes (specified using id) is applicable for a set of taxa * (specified using taxid) * * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws IOException */ public void isClassApplicableForTaxonCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException { headerOWL(); TaxonConstraintsEngine tce = new TaxonConstraintsEngine(graph); Set<OWLClass> testClsSet = resolveClassList(); Set<OWLClass> testTaxSet = resolveClassList(Param.taxid); for (OWLClass testTax : testTaxSet) { Set<OWLObject> taxAncs = graph.getAncestorsReflexive(testTax); LOG.info("Tax ancs: "+taxAncs); for (OWLClass testCls : testClsSet) { Set<OWLGraphEdge> edges = graph.getOutgoingEdgesClosure(testCls); boolean isOk = tce.isClassApplicable(testCls, testTax, edges, taxAncs); // TODO - other formats output(testCls); print("\t"); output(testTax); outputLine("\t"+isOk); } } }
Example #11
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void getLowestCommonSubsumersCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException { if (isHelp()) { info("Returns LCSs using sim2"); return; } headerOWL(); OwlSim sos = getOWLSim(); Set<OWLObject> objs = this.resolveEntityList(); if (objs.size() == 2) { Iterator<OWLObject> oit = objs.iterator(); OWLClass a = (OWLClass) oit.next(); OWLClass b = (OWLClass) oit.next(); Set<Node<OWLClass>> lcsNodes = sos.getNamedCommonSubsumers(a, b); for (Node<OWLClass> n : lcsNodes) { for (OWLClass c : n.getEntities()) { output(c); } } } else { // TODO - throw } }
Example #12
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Deprecated public void deleteFactCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException { if (isHelp()) { info("generates ClassAssertion"); return; } OWLOntology ont = resolveOntology(Param.ontology); OWLIndividual i = resolveIndividual(Param.individualId); OWLIndividual j = resolveIndividual(Param.fillerId); OWLObjectProperty p = resolveObjectProperty(Param.propertyId); for (OWLObjectPropertyAssertionAxiom ax : ont.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) { if (ax.getSubject().equals(i)) { if (p == null || ax.getProperty().equals(p)) { if (j == null || ax.getObject().equals(j)) { removeAxiom(ont, graph.getDataFactory().getOWLObjectPropertyAssertionAxiom(p, i, j)); } } } } String jsonStr = ""; response.getWriter().write(jsonStr); }
Example #13
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void printCachedObjects() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException { if (getFormat().equals("json")) { OWLGsonRenderer jsonp = new OWLGsonRenderer(response.getWriter()); if (cachedObjects.size() > 0) { jsonp.render(cachedObjects); } else { jsonp.render(cachedAxioms); } } else { // ontology format if (cachedAxioms.size() == 0) return; OWLOntology tmpOnt = getTemporaryOntology(); graph.getManager().addAxioms(tmpOnt, cachedAxioms); OWLDocumentFormat ofmt = getOWLOntologyFormat(); LOG.info("Format:"+ofmt); ParserWrapper pw = new ParserWrapper(); //graph.getManager().saveOntology(tmpOnt, ofmt, response.getOutputStream()); pw.saveOWL(tmpOnt, ofmt, response.getOutputStream()); graph.getManager().removeOntology(tmpOnt); cachedAxioms = new HashSet<OWLAxiom>(); } }
Example #14
Source File: OldSimpleOwlSim.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * generates view ontologies and pre-computes all LCSs. * These are added to the source ontology * * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws FileNotFoundException */ @Deprecated public void generateGroupingClasses() throws OWLOntologyCreationException, FileNotFoundException, OWLOntologyStorageException { createElementAttributeMapFromOntology(); removeUnreachableAxioms(); generateSourcePropertyViews(); generatePropertyViews(); this.saveOntology(Stage.VIEW); makeAllByAllLowestCommonSubsumer(); this.saveOntology(Stage.LCS); attributeElementCount = null; reason(); }
Example #15
Source File: ExhaustiveSimPreProcessorTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void exhaustiveTestOnGO() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException { /* ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOBO(getResourceIRIString("go-subset-t1.obo")); g = new OWLGraphWrapper(sourceOntol); IRI vpIRI = g.getOWLObjectPropertyByIdentifier("GOTESTREL:0000001").getIRI(); TableToAxiomConverter ttac = new TableToAxiomConverter(g); ttac.config.axiomType = AxiomType.CLASS_ASSERTION; ttac.config.property = vpIRI; ttac.config.isSwitchSubjectObject = true; ttac.parse("src/test/resources/simplegaf-t1.txt"); OWLPrettyPrinter pp = new OWLPrettyPrinter(g); AutomaticSimPreProcessor pproc = new AutomaticSimPreProcessor(); pproc.setInputOntology(sourceOntol); pproc.setOutputOntology(sourceOntol); pproc.preprocess(); */ }
Example #16
Source File: ParserWrapper.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void saveOWL(OWLOntology ont, OWLDocumentFormat owlFormat, String file) throws OWLOntologyStorageException, IOException { if ((owlFormat instanceof OBODocumentFormat) || (owlFormat instanceof OWLOboGraphsFormat) || (owlFormat instanceof OWLOboGraphsYamlFormat) || (owlFormat instanceof OWLJSONFormat) || (owlFormat instanceof OWLJsonLDFormat)){ try { FileOutputStream os = new FileOutputStream(new File(file)); saveOWL(ont, owlFormat, os); } catch (FileNotFoundException e) { throw new OWLOntologyStorageException("Could not open file: "+file, e); } } else { IRI iri; if (file.startsWith("file://")) { iri = IRI.create(file); } else { iri = IRI.create(new File(file)); } manager.saveOntology(ont, owlFormat, iri); } }
Example #17
Source File: OboOntologyReleaseRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void createModule(String ontologyId, String moduleName, Set<OWLEntity> signature) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { // create a new manager, avoid unnecessary change events final OWLOntologyManager m = OWLManager.createOWLOntologyManager(); // extract module SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, mooncat.getOntology(), ModuleType.BOT); Set<OWLAxiom> moduleAxioms = sme.extract(signature); OWLOntology module = m.createOntology(IRI.generateDocumentIRI()); m.addAxioms(module, moduleAxioms); // save module OutputStream moduleOutputStream = null; try { moduleOutputStream = getOutputSteam(getModuleFileName(ontologyId, moduleName)); m.saveOntology(module, moduleOutputStream); } finally { IOUtils.closeQuietly(moduleOutputStream); } }
Example #18
Source File: SimpleOntology.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
private @Nonnull OutputStream getOntologyDocument(PrefixDocumentFormatImpl prefixFormat) throws MobiOntologyException { OutputStream os; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OWLDocumentFormat format = owlManager.getOntologyFormat(owlOntology); if (format != null && format.isPrefixOWLDocumentFormat()) { prefixFormat.copyPrefixesFrom(format.asPrefixOWLDocumentFormat()); } try { owlManager.saveOntology(owlOntology, prefixFormat, outputStream); os = MobiStringUtils.replaceLanguageTag(outputStream); } catch (OWLOntologyStorageException e) { throw new MobiOntologyException("Unable to save to an ontology object", e); } finally { IOUtils.closeQuietly(outputStream); } return MobiStringUtils.removeOWLGeneratorSignature(os); }
Example #19
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void getSimilarClassesCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException { if (isHelp()) { info("Returns semantically similar classes using OWLSim2"); return; } headerOWL(); OWLClass a = this.resolveClass(); OwlSim sos = getOWLSim(); List<ScoreAttributeSetPair> saps = new ArrayList<ScoreAttributeSetPair>(); for (OWLClass b : this.getOWLOntology().getClassesInSignature()) { double score = sos.getAttributeJaccardSimilarity(a, b); saps.add(new ScoreAttributeSetPair(score, b) ); } Collections.sort(saps); int limit = 100; int n=0; for (ScoreAttributeSetPair sap : saps) { output(sap.getArbitraryAttributeClass()); this.outputLine("score="+sap.score); // todo - jsonify n++; if (n > limit) { break; } } }
Example #20
Source File: AssertInferenceTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void createUnsatisfiableModule(Collection<OWLEntity> unsatisfiable, OWLOntology ont) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { Set<OWLEntity> signature = new HashSet<OWLEntity>(unsatisfiable); final String moduleName = "unsatisfiable"; createModule(moduleName, signature, ont); }
Example #21
Source File: AssertInferenceTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void createPotentialRedundantModule(Collection<PotentialRedundant> redundants, OWLOntology ont) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { Set<OWLEntity> signature = new HashSet<OWLEntity>(); for (PotentialRedundant redundant : redundants) { signature.addAll(redundant.getAxiomOne().getSignature()); signature.addAll(redundant.getAxiomTwo().getSignature()); } final String moduleName = "potential-redundant"; createModule(moduleName, signature, ont); }
Example #22
Source File: OboOntologyReleaseRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void createUnsatisfiableModule(String ontologyId, Collection<OWLEntity> unsatisfiable) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { Set<OWLEntity> signature = new HashSet<OWLEntity>(unsatisfiable); final String moduleName = "unsatisfiable"; createModule(ontologyId, moduleName, signature); }
Example #23
Source File: OboOntologyReleaseRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void createEquivModule(String ontologyId, List<OWLEquivalentClassesAxiom> equivalentNamedClassPairs) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { Set<OWLEntity> signature = new HashSet<OWLEntity>(); for(OWLEquivalentClassesAxiom ax : equivalentNamedClassPairs) { signature.addAll(ax.getClassesInSignature()); } final String moduleName = "equivalent-classes"; createModule(ontologyId, moduleName, signature); }
Example #24
Source File: EquivalenceSetMergeUtilTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testMerge() throws OWLOntologyCreationException, IOException, IncoherentOntologyException, OWLOntologyStorageException { ParserWrapper pw = new ParserWrapper(); OWLGraphWrapper g = pw.parseToOWLGraph(getResourceIRIString("equivalence-set-merge-util-test.obo")); OWLOntology ont1 = g.getSourceOntology(); ElkReasonerFactory rf = new ElkReasonerFactory(); OWLReasoner reasoner = rf.createReasoner(ont1); EquivalenceSetMergeUtil esmu = new EquivalenceSetMergeUtil(g, reasoner); esmu.setPrefixScore("A", 8.0); esmu.setPrefixScore("B", 6.0); esmu.setPrefixScore("C", 4.0); OWLAnnotationProperty lp = g.getDataFactory().getOWLAnnotationProperty( OWLRDFVocabulary.RDFS_LABEL.getIRI() ); esmu.setPropertyPrefixScore( lp, "C", 5.0); esmu.setPropertyPrefixScore( lp, "B", 4.0); esmu.setPropertyPrefixScore( lp, "A", 3.0); OWLAnnotationProperty dp = g.getDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_IAO_0000115.getIRI() ); esmu.setPropertyPrefixScore( dp, "B", 5.0); esmu.setPropertyPrefixScore( dp, "A", 4.0); esmu.setPropertyPrefixScore( dp, "C", 3.0); esmu.setRemoveAxiomatizedXRefs(true); esmu.merge(); OWLDocumentFormat fmt = new OBODocumentFormat(); pw.saveOWL(g.getSourceOntology(), "target/esmu.owl"); //pw.setCheckOboDoc(false); pw.saveOWL(g.getSourceOntology(), fmt, "target/esmu.obo"); OWLOntology ont2 = pw.parseOWL(getResourceIRIString("equivalence-set-merge-util-expected.obo")); assertEquals(0, compare(ont1, ont2)); }
Example #25
Source File: IncrementalClassification.java From elk-reasoner with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws OWLOntologyStorageException, OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); // Load your ontology OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("path-to-ontology")); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont); // Classify the ontology. reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); OWLDataFactory factory = manager.getOWLDataFactory(); OWLClass subClass = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#AbsoluteShapeState")); OWLAxiom removed = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#ShapeState"))); OWLAxiom added = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#GeneralisedStructure"))); // Remove an existing axiom, add a new axiom manager.addAxiom(ont, added); manager.removeAxiom(ont, removed); // This is a buffering reasoner, so you need to flush the changes reasoner.flush(); // Re-classify the ontology, the changes should be accommodated // incrementally (i.e. without re-inferring all subclass relationships) // You should be able to see it from the log output reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // Terminate the worker threads used by the reasoner. reasoner.dispose(); }
Example #26
Source File: BridgeExtractor.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void save(String fn, OWLDocumentFormat format, OWLOntology xo) throws FileNotFoundException, OWLOntologyStorageException { fn = fn + "." + getSuffix(format); File file = new File(fn); file.getParentFile().mkdirs(); OutputStream os = new FileOutputStream(file); LOG.info("Saving: "+xo); ontology.getOWLOntologyManager().saveOntology(xo, format, os); }
Example #27
Source File: BasicOWLSimTestUsingSOS.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testBasicSim() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException, UnknownOWLClassException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("sim/mp-subset-1.obo")); g = new OWLGraphWrapper(sourceOntol); parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { owlsim = new SimpleOwlSim(sourceOntol); ((SimpleOwlSim) owlsim).setReasoner(reasoner); LOG.info("Reasoner="+owlsim.getReasoner()); //sos.saveOntology("/tmp/z.owl"); reasoner.flush(); for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) { //System.out.println("COMPARING: "+i); for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) { showSimOld(i,j); } } } finally { reasoner.dispose(); } }
Example #28
Source File: PhenoSimHQETest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testPhenoSimMouse() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("test_phenotype.owl")); g = new OWLGraphWrapper(sourceOntol); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { pproc = new PhenoSimHQEPreProcessor(); pproc.setInputOntology(sourceOntol); pproc.setOutputOntology(sourceOntol); pproc.setReasoner(reasoner); pproc.setOWLPrettyPrinter(owlpp); ((PhenoSimHQEPreProcessor)pproc).defaultLCSElementFrequencyThreshold = 0.7; //sos.setSimPreProcessor(pproc); //sos.preprocess(); pproc.preprocess(); reasoner.flush(); sos = new SimpleOwlSim(sourceOntol); sos.setSimPreProcessor(pproc); sos.createElementAttributeMapFromOntology(); //sos.saveOntology("/tmp/z.owl"); reasoner.flush(); for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) { for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) { showSim(i,j); } } } finally { reasoner.dispose(); } }
Example #29
Source File: PhenoSimHQETest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testPhenoSim() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException { ParserWrapper pw = new ParserWrapper(); sourceOntol = pw.parseOWL(getResourceIRIString("q-in-e.omn")); g = new OWLGraphWrapper(sourceOntol); owlpp = new OWLPrettyPrinter(g); // assume buffering OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol); try { pproc = new PhenoSimHQEPreProcessor(); pproc.setInputOntology(sourceOntol); pproc.setOutputOntology(sourceOntol); pproc.setReasoner(reasoner); pproc.setOWLPrettyPrinter(owlpp); ((PhenoSimHQEPreProcessor)pproc).defaultLCSElementFrequencyThreshold = 0.7; //sos.setSimPreProcessor(pproc); //sos.preprocess(); pproc.preprocess(); reasoner.flush(); sos = new SimpleOwlSim(sourceOntol); sos.setSimPreProcessor(pproc); sos.createElementAttributeMapFromOntology(); //sos.saveOntology("/tmp/z.owl"); reasoner.flush(); for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) { for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) { showSim(i,j); } } } finally { reasoner.dispose(); } }
Example #30
Source File: OboOntologyReleaseRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void createPotentialRedundantModule(String ontologyId, Collection<PotentialRedundant> redundants) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { Set<OWLEntity> signature = new HashSet<OWLEntity>(); for (PotentialRedundant redundant : redundants) { signature.addAll(redundant.getAxiomOne().getSignature()); signature.addAll(redundant.getAxiomTwo().getSignature()); } final String moduleName = "potential-redundant"; createModule(ontologyId, moduleName, signature); }