public OWLContainer() { this(new RDFXMLOntologyFormat()); }
public OWLConverter(IBSDLRegistry registry) { this(registry, new OWLContainer(new RDFXMLOntologyFormat())); }
@Override public boolean setValue(String to) { if (to.equals("owlxml")) { this.value = new OWLXMLOntologyFormat(); } else if (to.contains("manchester")) { this.value = new ManchesterOWLSyntaxOntologyFormat(); } else if (to.contains("RDF")) { this.value = new RDFXMLOntologyFormat(); } else { failureMessage = "don't know format '" + to + "' -- reverting to default: " + value; return false; } return true; }
private static void writeUntranslatableAxioms(final String path, Collection<OWLAxiom> untranslatableAxioms, OWLOntologyManager manager) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException { // create temporary ontology with untranslatable axioms OWLOntology ontology = manager.createOntology(); Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(untranslatableAxioms); manager.addAxioms(ontology, axioms); // write temporary ontology to file final FileOutputStream outputStream = new FileOutputStream(new File(path)); OWLOntologyFormat format = new RDFXMLOntologyFormat(); // TODO make this configurable manager.saveOntology(ontology, format, outputStream); outputStream.close(); }
protected OWLOntologyFormat parseFormat(CommandLine cmd) { OWLOntologyFormat format = new RDFXMLOntologyFormat(); String formatString = getOptionValue(cmd, ONTOLOGY_FORMAT_OPTION); if (formatString == null) { ; } else if (formatString.equals("owlxml")) { format = new OWLXMLOntologyFormat(); } else if (formatString.equals("rdfxml")) { format = new RDFXMLOntologyFormat(); } else if (formatString.equals("functional")) { format = new OWLFunctionalSyntaxOntologyFormat(); } else { System.out.println("Unknown format type " + formatString); } return format; }
private boolean isOntologyRDFXML(OWLOntology owlOntology) { return owlOntologyManager.getOntologyFormat(owlOntology).equals(new RDFXMLOntologyFormat()); } }
public OntologyFormatPanel() { List<Object> formats = new ArrayList<Object>(); formats.add(new RDFXMLOntologyFormat()); formats.add(new OWLXMLOntologyFormat()); formats.add(new OWLFunctionalSyntaxOntologyFormat()); formats.add(new ManchesterOWLSyntaxOntologyFormat()); formats.add(new OBOOntologyFormat()); formats.add(new KRSS2OntologyFormat()); formats.add(new LatexOntologyFormat()); formats.add(new TurtleOntologyFormat()); formatComboBox = new JComboBox(formats.toArray()); setLayout(new BorderLayout(12, 12)); add(formatComboBox, BorderLayout.SOUTH); formatComboBox.setSelectedItem(formats.get(0)); }
public OntologyFormatPanel() { List<Object> formats = new ArrayList<Object>(); formats.add(new RDFXMLOntologyFormat()); formats.add(new OWLXMLOntologyFormat()); formats.add(new OWLFunctionalSyntaxOntologyFormat()); formats.add(new ManchesterOWLSyntaxOntologyFormat()); formats.add(new OBOOntologyFormat()); formats.add(new KRSS2OntologyFormat()); formats.add(new LatexOntologyFormat()); formats.add(new TurtleOntologyFormat()); formatComboBox = new JComboBox(formats.toArray()); setLayout(new BorderLayout(12, 12)); add(formatComboBox, BorderLayout.SOUTH); formatComboBox.setSelectedItem(formats.get(0)); }
@Deprecated public static void printOntology(OWLOntology o, PrintStream printer) { OWLOntologyManager mgr = OWLManager.createOWLOntologyManager(); StringDocumentTarget tgt = new StringDocumentTarget(); try { mgr.saveOntology(o, new RDFXMLOntologyFormat(), tgt); } catch (OWLOntologyStorageException e) { e.printStackTrace(printer); } printer.println(tgt.toString()); }
@Deprecated public static void printOntology(OWLOntology o, PrintStream printer) { OWLOntologyManager mgr = OWLManager.createOWLOntologyManager(); StringDocumentTarget tgt = new StringDocumentTarget(); try { mgr.saveOntology(o, new RDFXMLOntologyFormat(), tgt); } catch (OWLOntologyStorageException e) { e.printStackTrace(printer); } printer.println(tgt.toString()); }
/** * * Converts a OWL API {@link OWLOntology} to Clerezza {@link Graph}. * * @param ontology * {@link OWLOntology} * @return the equivalent Clerezza {@link Graph}. */ public static org.apache.clerezza.commons.rdf.Graph owlOntologyToClerezzaGraph(OWLOntology ontology) { org.apache.clerezza.commons.rdf.Graph mGraph = null; ByteArrayOutputStream out = new ByteArrayOutputStream(); OWLOntologyManager manager = ontology.getOWLOntologyManager(); try { manager.saveOntology(ontology, new RDFXMLOntologyFormat(), out); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); ParsingProvider parser = new JenaParserProvider(); mGraph = new SimpleGraph(); parser.parse(mGraph, in, SupportedFormat.RDF_XML, null); } catch (OWLOntologyStorageException e) { log.error("Failed to serialize OWL Ontology " + ontology + "for conversion", e); } return mGraph; }
private static synchronized void cacheOntology(URI physicalRemoteUri, File file, OWLOntology ont) throws UnknownOWLOntologyException, OWLOntologyStorageException { uris.put(physicalRemoteUri, file); oiri.put(physicalRemoteUri, ont.getOntologyID().getOntologyIRI()); manager.setOntologyDocumentIRI(ont, IRI.create(file)); manager.saveOntology(ont, new RDFXMLOntologyFormat(), IRI.create(file)); }
private static synchronized void cacheOntology(URI physicalRemoteUri, File file, OWLOntology ont) throws UnknownOWLOntologyException, OWLOntologyStorageException { uris.put(physicalRemoteUri, file); oiri.put(physicalRemoteUri, ont.getOntologyID().getOntologyIRI()); manager.setOntologyDocumentIRI(ont, IRI.create(file)); manager.saveOntology(ont, new RDFXMLOntologyFormat(), IRI.create(file)); }
public static void printOntology(OWLOntology o, PrintStream printer) { OWLOntologyManager mgr = OWLManager.createOWLOntologyManager(); StringDocumentTarget tgt = new StringDocumentTarget(); try { mgr.saveOntology(o, new RDFXMLOntologyFormat(), tgt); } catch (OWLOntologyStorageException e) { e.printStackTrace(printer); } printer.println(tgt.toString()); }
/** * Static convenience method which: * (1) creates an Obo2Owl bridge object * (2) parses an obo file from a URL * (3) converts that to an OWL ontology * (4) saves the OWL ontology as RDF/XML * * @param iri * @param outFile * @throws IOException * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws OBOFormatParserException */ public static void convertURL(String iri, String outFile, OWLOntologyManager manager) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, OBOFormatParserException { Obo2Owl bridge = new Obo2Owl(manager); OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new URL(iri)); OWLOntology ontology = bridge.convert(obodoc); IRI outputStream = IRI.create(outFile); OWLOntologyFormat format = new RDFXMLOntologyFormat(); LOG.log(Level.WARNING, "saving to " + outputStream + " fmt=" + format); manager.saveOntology(ontology, format, outputStream); }
/** * See {@link #convertURL(String iri, String outFile)} * * @param iri * @param outFile * @param defaultOnt -- e.g. "go". If the obo file contains no "ontology:" header tag, this is added * @throws IOException * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws OBOFormatParserException */ public static void convertURL(String iri, String outFile, String defaultOnt, OWLOntologyManager manager) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, OBOFormatParserException { Obo2Owl bridge = new Obo2Owl(manager); OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new URL(iri)); obodoc.addDefaultOntologyHeader(defaultOnt); OWLOntology ontology = bridge.convert(obodoc); IRI outputStream = IRI.create(outFile); OWLOntologyFormat format = new RDFXMLOntologyFormat(); LOG.log(Level.WARNING, "saving to " + outputStream + " fmt=" + format); manager.saveOntology(ontology, format, outputStream); }
@Override public void write(Ontology ontology, DataTarget target, String format) { if (ontology instanceof OWLAPIOntology) { try { manager.saveOntology(((OWLAPIOntology) ontology).onto, IRI.create(target.asURL())); } catch (Exception x) { try { if (format.equals("RDFXML")) { manager.saveOntology(((OWLAPIOntology) ontology).onto, new RDFXMLOntologyFormat(), target.asOutputStream()); } else if (format.equals("TURTLE")) { manager.saveOntology(((OWLAPIOntology) ontology).onto, new TurtleOntologyFormat(), target.asOutputStream()); } else { manager.saveOntology(((OWLAPIOntology) ontology).onto, new OWLXMLOntologyFormat(), target.asOutputStream()); } } catch (Exception x2) { // log.stackTrace(x); // log.stackTrace(x); throw new RuntimeException("Could not write OWL ontology"); } } } else { throw new IllegalArgumentException("Cannot serializer an ontology I did not create!"); } }
@Override public void write(Ontology ontology, Writer target, OntologyFormat format) { if (ontology instanceof OWLAPIOntology) { try { if (format.equals(OntologyFormat.RDFXML)) { manager.saveOntology(((OWLAPIOntology) ontology).onto, new RDFXMLOntologyFormat(), new WriterDocumentTarget(target)); } else if (format.equals(OntologyFormat.TURTLE)) { manager.saveOntology(((OWLAPIOntology) ontology).onto, new TurtleOntologyFormat(), new WriterDocumentTarget(target)); } else if (format.equals(OntologyFormat.OWLXML)) { manager.saveOntology(((OWLAPIOntology) ontology).onto, new OWLXMLOntologyFormat(), new WriterDocumentTarget(target)); } else { throw new IllegalArgumentException("Unsupported format " + format); } } catch (Exception x2) { // log.stackTrace(x2); throw new RuntimeException("Could not write OWL ontology"); } } else { throw new IllegalArgumentException("Cannot serializer an ontology I did not create!"); } }
public static OWLOntology getSessionMetadataRDFasOntology(Session session) { OWLOntologyManager mgr = OWLManager.createOWLOntologyManager(); OWLOntology ont = null; try { ont = mgr.createOntology(IRI.create(session.getID() + "/meta.owl")); } catch (OWLOntologyCreationException e) { LoggerFactory.getLogger(ScopeSetRenderer.class).error( "KReS :: could not create empty ontology for rendering sesion metadata.", e); return null; } List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>(); OWLNamedIndividual iSes = __factory.getOWLNamedIndividual(IRI.create(session.getID())); additions.add(new AddAxiom(ont, __factory.getOWLClassAssertionAxiom(cSession, iSes))); OWLDatatype anyURI = __factory.getOWLDatatype(IRI.create("http://www.w3.org/2001/XMLSchema#anyURI")); OWLLiteral hasIdValue = __factory.getOWLTypedLiteral(session.getID().toString(), anyURI); additions.add(new AddAxiom(ont, __factory.getOWLDataPropertyAssertionAxiom(hasId, iSes, hasIdValue))); mgr.applyChanges(additions); StringDocumentTarget tgt = new StringDocumentTarget(); try { mgr.saveOntology(ont, new RDFXMLOntologyFormat(), tgt); return ont; } catch (OWLOntologyStorageException e) { LoggerFactory.getLogger(ScopeSetRenderer.class).error( "KReS :: could not save session metadata ontology.", e); return null; } }
public boolean handleNewRequest() throws Exception { OWLOntologyID id = createDefaultOntologyId(); OWLOntology ont = getModelManager().createNewOntology(id, id.getDefaultDocumentIRI().toURI()); OWLOntologyManager owlOntologyManager = getModelManager().getOWLOntologyManager(); owlOntologyManager.setOntologyFormat(ont, new RDFXMLOntologyFormat()); return true; }