/** * Performs lookahead with a 100 kB limit. * * @param content * @param parser * @param format * @return * @throws IOException */ public static OWLOntologyID guessOntologyID(InputStream content, Parser parser, String format) throws IOException { return guessOntologyID(content, parser, format, _LOOKAHEAD_LIMIT_DEFAULT); }
/** * Removes either the fragment, or query, or last path component from a URI, whatever it finds first. * * @param iri * @return */ public static IRI upOne(IRI iri) { return upOne(iri.toURI()); }
@Override public String toString() { return "<ONTOLOGY_CONTENT>" + OWLUtils.extractOntologyID(getRootOntology()); }
/** * Replaces terminating hash ('#') characters with their URL-encoded versions ("%23"). Any non-terminating * hashes will be left as they are (though they are not to be expected if the IRI denotes an URL). * * @param iri * the IRI to sanitize * @return the sanitized IRI */ public static IRI sanitize(IRI iri) { return IRI.create(sanitize(iri.toString())); }
/** * URL-decodes any terminating hash characters ("%23"). Any non-terminating URL-encoded hashes will be * left as they are (since there should be no intermediate hashes in a URL). * * @param iri * the IRI to desanitize * @return the desanitized IRI */ public static IRI desanitize(IRI iri) { return IRI.create(desanitize(iri.toString())); }
@Override public String toString() { return "<GRAPH_CONTENT>" + OWLUtils.guessOntologyIdentifier(getRootOntology()); }
@Override public String getKey(IRI ontologyIri) { ontologyIri = URIUtils.sanitizeID(ontologyIri); UriRef ur = keymap.getMapping(new OWLOntologyID(ontologyIri)); log.debug("key for {} is {}", ontologyIri, ur); return (ur == null) ? null : ur.getUnicodeString(); }
/** * Provides a standardized string format for an OWL Ontology ID. The string returned is of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>":::"</tt> present in <tt>ontologyIRI</tt> or * <tt>versionIRI</tt> will be URL-encoded (i.e. converted to <tt>"%3A%3A%3A"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are sanitized in the process. No other * URL encoding occurs. * * @param id * the OWL ontology ID to encode * @return the string form of this ID. * @see URIUtils#sanitize(IRI) */ public static String encode(OWLOntologyID id) { if (id == null) throw new IllegalArgumentException("Cannot encode a null OWLOntologyID."); if (id.getOntologyIRI() == null) throw new IllegalArgumentException( "Cannot encode an OWLOntologyID that is missing an ontologyIRI."); String s = ""; s += URIUtils.sanitize(id.getOntologyIRI()).toString().replace(":::", "%3A%3A%3A"); if (id.getVersionIRI() != null) s += (":::") + URIUtils.sanitize(id.getVersionIRI()).toString() .replace(":::", "%3A%3A%3A"); return s; }
/** * Extracts an OWL Ontology ID from its standard string form. The string must be of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>"%3A%3A%3A"</tt> present in <tt>ontologyIRI</tt> * or <tt>versionIRI</tt> will be URL-decoded (i.e. converted to <tt>":::"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are desanitized in the process. * * @param stringForm * the string to decode * @return the string form of this ID. * @see URIUtils#desanitize(IRI) */ public static OWLOntologyID decode(String stringForm) { if (stringForm == null || stringForm.isEmpty()) throw new IllegalArgumentException( "Supplied string form must be non-null and non-empty."); IRI oiri, viri; String[] split = stringForm.split(":::"); if (split.length >= 1) { oiri = URIUtils.desanitize(IRI.create(split[0].replace("%3A%3A%3A", ":::"))); viri = (split.length > 1) ? URIUtils.desanitize(IRI.create(split[1].replace("%3A%3A%3A", ":::"))) : null; return (viri != null) ? new OWLOntologyID(oiri, viri) : new OWLOntologyID(oiri); } else return null; // Anonymous but versioned ontologies are not acceptable. }
@Override public String toString() { return "<ONTOLOGY_CONTENT>" + OWLUtils.extractOntologyID(getRootOntology()); }
public static OWLOntologyID guessOntologyID(InputStream content, Parser parser, String format, int limit, int versionIriOffset) throws IOException { long before = System.currentTimeMillis(); log.info("Guessing ontology ID. Read limit = {} triples; offset = {} triples.", limit, versionIriOffset); BufferedInputStream bIn = new BufferedInputStream(content); bIn.mark(limit * 512); // set an appropriate limit OntologyLookaheadGraph graph = new OntologyLookaheadGraph(limit, versionIriOffset); try { parser.parse(graph, bIn, format); } catch (RuntimeException e) { log.error("Parsing failed for format {}. Returning null.", format); } OWLOntologyID result; if (graph.getOntologyIRI() == null) { // No Ontology ID found log.warn(" *** No ontology ID found, ontology has a chance of being anonymous."); result = new OWLOntologyID(); } else { // bIn.reset(); // reset set the stream to the start IRI oiri = IRI.create(graph.getOntologyIRI().getUnicodeString()); result = graph.getVersionIRI() == null ? new OWLOntologyID(oiri) : new OWLOntologyID(oiri, IRI.create(graph.getVersionIRI().getUnicodeString())); log.info(" *** Guessed ID : {}", result); } log.info(" ... Triples scanned : {}; filtered in : {}", graph.getScannedTripleCount(), graph.size()); log.info(" ... Time : {} ms", System.currentTimeMillis() - before);
@Override public String toString() { return "<ONTOLOGY_CONTENT>" + OWLUtils.guessOntologyIdentifier(getRootOntology()); }
/** * Provides a standardized string format for an OWL Ontology ID. The string returned is of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>":::"</tt> present in <tt>ontologyIRI</tt> or * <tt>versionIRI</tt> will be URL-encoded (i.e. converted to <tt>"%3A%3A%3A"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are sanitized in the process. No other * URL encoding occurs. * * @param id * the OWL ontology ID to encode * @return the string form of this ID. * @see URIUtils#sanitize(IRI) */ public static String encode(OWLOntologyID id) { if (id == null) throw new IllegalArgumentException("Cannot encode a null OWLOntologyID."); if (id.getOntologyIRI() == null) throw new IllegalArgumentException( "Cannot encode an OWLOntologyID that is missing an ontologyIRI."); String s = ""; s += URIUtils.sanitize(id.getOntologyIRI()).toString().replace(":::", "%3A%3A%3A"); if (id.getVersionIRI() != null) s += (":::") + URIUtils.sanitize(id.getVersionIRI()).toString() .replace(":::", "%3A%3A%3A"); return s; }
/** * Extracts an OWL Ontology ID from its standard string form. The string must be of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>"%3A%3A%3A"</tt> present in <tt>ontologyIRI</tt> * or <tt>versionIRI</tt> will be URL-decoded (i.e. converted to <tt>":::"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are desanitized in the process. * * @param stringForm * the string to decode * @return the string form of this ID. * @see URIUtils#desanitize(IRI) */ public static OWLOntologyID decode(String stringForm) { if (stringForm == null || stringForm.isEmpty()) throw new IllegalArgumentException( "Supplied string form must be non-null and non-empty."); IRI oiri, viri; String[] split = stringForm.split(":::"); if (split.length >= 1) { oiri = URIUtils.desanitize(IRI.create(split[0].replace("%3A%3A%3A", ":::"))); viri = (split.length > 1) ? URIUtils.desanitize(IRI.create(split[1].replace("%3A%3A%3A", ":::"))) : null; return (viri != null) ? new OWLOntologyID(oiri, viri) : new OWLOntologyID(oiri); } else return null; // Anonymous but versioned ontologies are not acceptable. }
@Override public String loadInStore(InputStream data, String formatIdentifier, String preferredKey, boolean force) { try { OWLOntology o = store.loadOntologyFromOntologyDocument(data); return OWLUtils.guessOntologyIdentifier(o).toString(); } catch (OWLOntologyCreationException e) { throw new IllegalArgumentException(e); } }
@Override public Set<String> getKeys() { Set<String> result = new HashSet<String>(); for (OWLOntology o : store.getOntologies()) result.add(OWLUtils.guessOntologyIdentifier(o).toString()); return result; }
private void performAdd(OntologyInputSource<?,?> ontSrc) { Object obj = ontSrc.getRootOntology(); OWLOntology ontology = (OWLOntology) obj; // Should not modify the child ontology in any way. // TODO implement transaction control. // See to it that the ontology is copied to this manager. OWLOntology newOnt = reload((OWLOntology) ontology, ontologyManager, true, false); // if (newOnt!=null) managedOntologies.put(OWLUtils.guessOntologyIdentifier(newOnt), newOnt); try { // Store the top ontology if (!(this instanceof SessionOntologySpace)) { // No longer storing in OWLAPI implementation! // if (storage == null) log.warn( // "No ontology storage found. Ontology {} will be stored in-memory only.", ontology); // else { // // storage = new ClerezzaOntologyStorage(tcManager, wtcProvider) // storage.store(ontology); // } } // ONManager.get().getOntologyStore().load(rootOntology.getOntologyID().getOntologyIRI()); } catch (Exception ex) { log.warn("An error occurred while storing ontology " + ontology + " . Ontology management will be volatile.", ex); } fireOntologyAdded(OWLUtils.guessOntologyIdentifier(ontology)); }
@Override public String loadInStore(IRI location, String formatIdentifier, String preferredKey, boolean force) { OWLOntology o = null; try { o = store.loadOntologyFromOntologyDocument(location); } catch (OWLOntologyAlreadyExistsException e) { if (!force) o = store.getOntology(e.getOntologyID()); } catch (OWLOntologyDocumentAlreadyExistsException e) { if (!force) o = store.getOntology(e.getOntologyDocumentIRI()); } catch (OWLOntologyCreationException e) { throw new IllegalArgumentException(e); } return OWLUtils.guessOntologyIdentifier(o).toString(); }
protected Set<TripleCollection> getImportedGraphs(TripleCollection g, boolean recursive) { Set<TripleCollection> result = new HashSet<TripleCollection>(); UriRef u = OWLUtils.guessOntologyIdentifier(g); Iterator<Triple> it = g.filter(u, OWL.imports, null); while (it.hasNext()) { Resource r = it.next().getObject(); if (r instanceof UriRef) { TripleCollection gr = TcManager.getInstance().getTriples((UriRef) r); // Avoid calls to getGraph() to save memory // if (gr instanceof Graph) result.add(/* (Graph) */gr); // else if (gr instanceof MGraph) result.add(((MGraph) gr).getGraph()); if (recursive) result.addAll(getImportedGraphs(gr, true)); } } return result; }
IRI idd = OWLUtils.guessOntologyIdentifier(ontology); if (mgr == null) mgr = ontologyManager; Set<OWLOntology> closure = withClosure ? ontology.getOWLOntologyManager().getImportsClosure(ontology) IRI id2 = OWLUtils.guessOntologyIdentifier(o);