org.semanticweb.owlapi.model.OWLDocumentFormat Java Examples
The following examples show how to use
org.semanticweb.owlapi.model.OWLDocumentFormat.
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: 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 #2
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 #3
Source File: BridgeExtractor.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
private String getSuffix(OWLDocumentFormat format) { if (format instanceof RDFXMLDocumentFormat) { return "owl"; } if (format instanceof FunctionalSyntaxDocumentFormat) { return "ofn"; } if (format instanceof OWLXMLDocumentFormat) { return "owx"; } if (format instanceof ManchesterSyntaxDocumentFormat) { return "omn"; } return "owl"; }
Example #4
Source File: MgiGAFOWLBridgeTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testConversionToIndividuals() throws Exception{ ParserWrapper pw = new ParserWrapper(); OWLOntology ont = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLGraphWrapper g = new OWLGraphWrapper(ont); g.addSupportOntology(pw.parse(getResourceIRIString("gorel.owl"))); GafObjectsBuilder builder = new GafObjectsBuilder(); GafDocument gafdoc = builder.buildDocument(getResource("mgi-exttest.gaf")); GAFOWLBridge bridge = new GAFOWLBridge(g); bridge.setGenerateIndividuals(false); OWLOntology gafOnt = g.getManager().createOntology(); bridge.setTargetOntology(gafOnt); bridge.setBasicAboxMapping(true); bridge.translate(gafdoc); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); g.getManager().saveOntology(gafOnt, owlFormat, IRI.create(new File("target/gaf-abox.owl"))); for (OWLAxiom ax : gafOnt.getAxioms()) { //LOG.info("AX:"+ax); } }
Example #5
Source File: MgiGAFOWLBridgeTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testConversion() throws Exception{ ParserWrapper pw = new ParserWrapper(); OWLOntology ont = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLGraphWrapper g = new OWLGraphWrapper(ont); g.addSupportOntology(pw.parse(getResourceIRIString("gorel.owl"))); GafObjectsBuilder builder = new GafObjectsBuilder(); GafDocument gafdoc = builder.buildDocument(getResource("mgi-exttest.gaf")); GAFOWLBridge bridge = new GAFOWLBridge(g); bridge.setGenerateIndividuals(false); OWLOntology gafOnt = g.getManager().createOntology(); bridge.setTargetOntology(gafOnt); bridge.translate(gafdoc); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); g.getManager().saveOntology(gafOnt, owlFormat, IRI.create(new File("target/gaf.owl"))); for (OWLAxiom ax : gafOnt.getAxioms()) { //LOG.info("AX:"+ax); } }
Example #6
Source File: BasicAboxBridgeTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testConversion() throws Exception{ ParserWrapper pw = new ParserWrapper(); OWLOntology ont = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLGraphWrapper g = new OWLGraphWrapper(ont); g.addSupportOntology(pw.parse(getResourceIRIString("gorel.owl"))); GafObjectsBuilder builder = new GafObjectsBuilder(); GafDocument gafdoc = builder.buildDocument(getResource("xp_inference_test.gaf")); BasicABox bridge = new BasicABox(g); OWLOntology gafOnt = g.getManager().createOntology(); bridge.setTargetOntology(gafOnt); bridge.translate(gafdoc); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); g.getManager().saveOntology(gafOnt, owlFormat, IRI.create(new File("target/foo.owl"))); for (OWLAxiom ax : gafOnt.getAxioms()) { LOG.info("AX:"+ax); } }
Example #7
Source File: GAFOWLBridgeTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testConversion() throws Exception{ ParserWrapper pw = new ParserWrapper(); OWLOntology ont = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLGraphWrapper g = new OWLGraphWrapper(ont); g.addSupportOntology(pw.parse(getResourceIRIString("gorel.owl"))); GafObjectsBuilder builder = new GafObjectsBuilder(); GafDocument gafdoc = builder.buildDocument(getResource("xp_inference_test.gaf")); GAFOWLBridge bridge = new GAFOWLBridge(g); OWLOntology gafOnt = g.getManager().createOntology(); bridge.setTargetOntology(gafOnt); bridge.translate(gafdoc); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); g.getManager().saveOntology(gafOnt, owlFormat, IRI.create(new File("/tmp/gaf.owl"))); for (OWLAxiom ax : gafOnt.getAxioms()) { LOG.info("AX:"+ax); } }
Example #8
Source File: PombeGAFOWLBridgeTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Ignore @Test public void testConversion() throws Exception { ParserWrapper pw = new ParserWrapper(); OWLOntology ont = pw.parse("http://purl.obolibrary.org/obo/go.owl"); OWLGraphWrapper g = new OWLGraphWrapper(ont); GafObjectsBuilder builder = new GafObjectsBuilder(); GafDocument gafdoc = builder.buildDocument("http://geneontology.org/gene-associations/gene_association.GeneDB_Spombe.gz"); GAFOWLBridge bridge = new GAFOWLBridge(g); OWLOntology gafOnt = g.getManager().createOntology(); bridge.setTargetOntology(gafOnt); bridge.translate(gafdoc); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); g.getManager().saveOntology(gafOnt, owlFormat, IRI.create(new File("/tmp/gaf.owl"))); for (OWLAxiom ax : gafOnt.getAxioms()) { //LOG.info("AX:"+ax); } }
Example #9
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 #10
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void headerOWL() { if (isOWLOntologyFormat()) { LOG.info("using OWL ontology header"); OWLDocumentFormat ofmt = this.getOWLOntologyFormat(); if (ofmt instanceof RDFXMLDocumentFormat) { response.setContentType("application/rdf+xml;charset-utf-8"); } else if (ofmt instanceof OWLXMLDocumentFormat) { response.setContentType("application/xml;charset-utf-8"); } else { response.setContentType("text/plain;charset-utf-8"); } } else { response.setContentType("text/plain;charset-utf-8"); } response.setStatus(HttpServletResponse.SC_OK); }
Example #11
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 #12
Source File: GafCommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Created to mimic the translation to OWL for GAF checks * * @param opts * @throws Exception */ @CLIMethod("--gaf2owl-simple") public void gaf2OwlSimple(Opts opts) throws Exception { opts.info("-o FILE", "translates previously loaded GAF document into OWL, requires a loaded ontology to lookup ids"); String out = null; while (opts.hasOpts()) { if (opts.nextEq("-o")) { out = opts.nextOpt(); } else break; } if (g == null) { LOG.error("An ontology is required."); exit(-1); } else if (gafdoc == null) { LOG.error("A GAF document is required."); exit(-1); } else if (out == null) { LOG.error("An output file is required."); exit(-1); } LOG.info("Creating OWL represenation of annotations."); GAFOWLBridge bridge = new GAFOWLBridge(g); bridge.setGenerateIndividuals(false); bridge.setBasicAboxMapping(false); bridge.setBioentityMapping(BioentityMapping.CLASS_EXPRESSION); bridge.setSkipNotAnnotations(true); OWLOntology translated = bridge.translate(gafdoc); File outputFile = new File(out); OWLOntologyManager manager = translated.getOWLOntologyManager(); OWLDocumentFormat ontologyFormat= new FunctionalSyntaxDocumentFormat(); manager.saveOntology(translated, ontologyFormat, IRI.create(outputFile)); }
Example #13
Source File: OboOntologyReleaseRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void write(OWLOntologyManager manager, OWLOntology ont, OWLDocumentFormat format, OutputStream out) throws OWLOntologyStorageException { try { manager.saveOntology(ont, format, out); } finally { try { out.close(); } catch (IOException e) { logWarn("Could not close stream.", e); } } }
Example #14
Source File: OWLGsonRendererTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testOnt() throws Exception{ OWLGraphWrapper wrapper = getOBO2OWLOntologyWrapper("caro.obo"); final StringWriter stringWriter = new StringWriter(); OWLGsonRenderer gr = new OWLGsonRenderer(new PrintWriter(stringWriter)); gr.render(wrapper.getSourceOntology()); if (RENDER_FLAG) { LOG.debug(stringWriter.toString()); ParserWrapper pw = new ParserWrapper(); OWLDocumentFormat owlFormat = new OWLJSONFormat(); File foo = folder.newFile("foo.json"); pw.saveOWL(wrapper.getSourceOntology(), owlFormat , foo.getAbsolutePath()); } }
Example #15
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 #16
Source File: SimpleOntology.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
protected synchronized void setSesameModel() throws MobiOntologyException { sesameModel = new org.eclipse.rdf4j.model.impl.LinkedHashModel(); RDFHandler rdfHandler = new StatementCollector(sesameModel); OWLDocumentFormat format = this.owlOntology.getFormat(); format.setAddMissingTypes(false); RioRenderer renderer = new RioRenderer(this.owlOntology, rdfHandler, format); renderer.render(); }
Example #17
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 #18
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 #19
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 #20
Source File: OldSimpleOwlSim.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void saveOntology(String fn) throws FileNotFoundException, OWLOntologyStorageException { FileOutputStream os = new FileOutputStream(new File(fn)); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); owlOntologyManager.saveOntology(sourceOntology, owlFormat, os); }
Example #21
Source File: ParserWrapper.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void saveOWL(OWLOntology ont, String file) throws OWLOntologyStorageException, IOException { OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); saveOWL(ont, owlFormat, file); }
Example #22
Source File: SnomedFunctionalSyntaxStorer.java From snomed-owl-toolkit with Apache License 2.0 | 4 votes |
@Override public boolean canStoreOntology(OWLDocumentFormat ontologyFormat) { return ontologyFormat instanceof SnomedFunctionalSyntaxDocumentFormat; }
Example #23
Source File: OWLHandler.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
private OWLDocumentFormat getOWLOntologyFormat() { return getOWLOntologyFormat(getFormat()); }
Example #24
Source File: OortConfiguration.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @return the defaultFormat */ public OWLDocumentFormat getDefaultFormat() { return defaultFormat; }
Example #25
Source File: OortConfiguration.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @return the owlXMLFormat */ public OWLDocumentFormat getOwlXMLFormat() { return owlXMLFormat; }
Example #26
Source File: OortConfiguration.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @return the owlOFNFormat */ public OWLDocumentFormat getOwlOfnFormat() { return owlOFNFormat; }
Example #27
Source File: QueryRewriterFactory.java From neo4j-sparql-extension with GNU General Public License v3.0 | 4 votes |
@Override public OWLDocumentFormat getFormat() { return new TurtleDocumentFormat(); }