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); }
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>(); } }
@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); } }
@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); } }
@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); } }
@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); } }
@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); } }
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"; }
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); } }
/** * Writes a model into a file * @param m the manager * @param o the ontology to write * @param f the format in which should be written * @param outPath */ public static void writeModel(OWLOntologyManager m, OWLOntology o, OWLDocumentFormat f, String outPath){ OutputStream out=null; try { out = new FileOutputStream(outPath); m.saveOntology(o, f, out); out.close(); } catch (Exception ex) { System.out.println("Error while writing the model to file "+ex.getMessage()); if(out!=null){ try{ out.close(); }catch(Exception e){} } } }
/** * Export the ABox, will try to set the ontologyID to the given modelId (to * ensure import assumptions are met) * * @param model * @param ontologyFormat * @return modelContent * @throws OWLOntologyStorageException */ public String exportModel(ModelContainer model, OWLDocumentFormat ontologyFormat) throws OWLOntologyStorageException { final OWLOntology aBox = model.getAboxOntology(); final OWLOntologyManager manager = aBox.getOWLOntologyManager(); // make sure the exported ontology has an ontologyId and that it maps to the modelId final IRI expectedABoxIRI = model.getModelId(); Optional<IRI> currentABoxIRI = aBox.getOntologyID().getOntologyIRI(); if (currentABoxIRI.isPresent() == false) { manager.applyChange(new SetOntologyID(aBox, expectedABoxIRI)); } else { if (expectedABoxIRI.equals(currentABoxIRI) == false) { OWLOntologyID ontologyID = new OWLOntologyID(Optional.of(expectedABoxIRI), Optional.of(expectedABoxIRI)); manager.applyChange(new SetOntologyID(aBox, ontologyID)); } } // write the model into a buffer ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); if (ontologyFormat != null) { manager.saveOntology(aBox, ontologyFormat, outputStream); } else { manager.saveOntology(aBox, outputStream); } // extract the string from the buffer String modelString = outputStream.toString(); return modelString; }
/** * 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)); }
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); }
@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)); }
@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) { System.out.println(stringWriter.toString()); ParserWrapper pw = new ParserWrapper(); OWLDocumentFormat owlFormat = new OWLJSONFormat(); File foo = folder.newFile("foo.json"); pw.saveOWL(wrapper.getSourceOntology(), owlFormat , foo.getAbsolutePath()); } }
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); } } }
public Owlbuilder() throws Exception{ config = new Config(""); if (DBConnection.probeConnection()){ connection = DBConnection.getDBConnection(); } else{ connection = DBConnection.getMockConnection(); } testWrapper = new OWLGraphWrapper(targetIRI); rfactory = new Reasoner.ReasonerFactory(); elkFactory = new ElkReasonerFactory(); iriManager = connection.getIRIManager(); final OWLDocumentFormat format = testWrapper.getManager().getOntologyFormat(testWrapper.getSourceOntology()); format.asPrefixOWLOntologyFormat().setPrefix("doi", "http://dx.doi.org/"); }
public Owlbuilder(AbstractConnection existingConnection) throws Exception{ config = new Config(""); connection = existingConnection; testWrapper = new OWLGraphWrapper(targetIRI); rfactory = new Reasoner.ReasonerFactory(); elkFactory = new ElkReasonerFactory(); iriManager = connection.getIRIManager(); final OWLDocumentFormat format = testWrapper.getManager().getOntologyFormat(testWrapper.getSourceOntology()); format.asPrefixOWLOntologyFormat().setPrefix("doi", "http://dx.doi.org/"); }
@Override public OWLDocumentFormat getFormat() { return new TurtleDocumentFormat(); }
private OWLDocumentFormat getOWLOntologyFormat() { return getOWLOntologyFormat(getFormat()); }
public void saveOntology(String fn) throws FileNotFoundException, OWLOntologyStorageException { FileOutputStream os = new FileOutputStream(new File(fn)); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); owlOntologyManager.saveOntology(sourceOntology, owlFormat, os); }
public void saveOWL(OWLOntology ont, String file) throws OWLOntologyStorageException, IOException { OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); saveOWL(ont, owlFormat, file); }
/** * @return the defaultFormat */ public OWLDocumentFormat getDefaultFormat() { return defaultFormat; }
/** * @return the owlXMLFormat */ public OWLDocumentFormat getOwlXMLFormat() { return owlXMLFormat; }
/** * @return the owlOFNFormat */ public OWLDocumentFormat getOwlOfnFormat() { return owlOFNFormat; }
/** * Export the ABox for the given modelId in the given ontology format.<br> * Warning: The mapping from String to {@link OWLDocumentFormat} does not * map every format! * * @param model * @param format * @return modelContent * @throws OWLOntologyStorageException */ public String exportModel(ModelContainer model, String format) throws OWLOntologyStorageException { OWLDocumentFormat ontologyFormat = getOWLOntologyFormat(format); if (ontologyFormat == null) { ontologyFormat = this.ontologyFormat; } return exportModel(model, ontologyFormat); }