use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class ODPRegistryCacheManager method getOntologyInputSource.
public static synchronized OWLOntologyDocumentSource getOntologyInputSource(URI uri) throws ODPRegistryCacheException, URIUnresolvableException {
if (getUnresolvedURIs().contains(uri))
throw new URIUnresolvableException();
if (uris.containsKey(uri)) {
File f = uris.get(uri);
FileDocumentSource fds = new FileDocumentSource(f);
return fds;
} else {
try {
retrieveRemoteResource(uri);
return getOntologyInputSource(uri);
} catch (UnknownOWLOntologyException e) {
throw new ODPRegistryCacheException(e);
} catch (OWLOntologyCreationException e) {
throw new ODPRegistryCacheException(e);
} catch (OWLOntologyStorageException e) {
throw new ODPRegistryCacheException(e);
}
}
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class AbstractOntologyCollectorImpl method addOntology.
@Override
public synchronized OWLOntologyID addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
// Check for error conditions.
if (locked)
throw new UnmodifiableOntologyCollectorException(this);
if (ontologySource == null)
throw new IllegalArgumentException("Ontology source cannot be null.");
log.debug("Adding ontology to collector {}", getID());
OWLOntologyID key = null;
if (ontologySource.hasRootOntology()) {
long before = System.currentTimeMillis();
Object o = ontologySource.getRootOntology();
// Check the origin anyhow, as it may be useful for setting aliases with physical locations etc.
if (ontologySource.hasOrigin())
key = ontologyProvider.loadInStore(o, false, ontologySource.getOrigin());
else
key = ontologyProvider.loadInStore(o, false);
if (key != null) {
managedOntologies.add(key);
// Note that imported ontologies are not considered as managed! TODO should we change this?
log.info("Add ontology completed in {} ms.", (System.currentTimeMillis() - before));
// Fire the event
fireOntologyAdded(key);
}
} else if (ontologySource.hasOrigin()) {
// Just the origin : see if it is satisfiable
log.debug("Checking origin satisfiability...");
Origin<?> origin = ontologySource.getOrigin();
Object ref = origin.getReference();
log.debug("Origin wraps a {}", ref.getClass().getCanonicalName());
if (ref instanceof org.semanticweb.owlapi.model.IRI)
try {
log.debug("Deferring addition to physical IRI {} (if available).", ref);
key = addOntology(new RootOntologySource((org.semanticweb.owlapi.model.IRI) ref));
} catch (OWLOntologyCreationException e) {
throw new RuntimeException(e);
}
else if (ref instanceof IRI) {
log.debug("Deferring addition to stored Clerezza graph {} (if available).", ref);
key = addOntology(new GraphSource((IRI) ref));
} else if (ref instanceof OWLOntologyID) {
OWLOntologyID idref = (OWLOntologyID) ref;
log.debug("Deferring addition to stored ontology with public key {} (if available).", ref);
if (!ontologyProvider.hasOntology(idref))
throw new MissingOntologyException(this, idref);
key = idref;
if (managedOntologies.add(idref))
fireOntologyAdded(idref);
} else
throw new IllegalArgumentException("Invalid origin " + origin);
} else
throw new IllegalArgumentException("Ontology source must provide either an ontology object, or a way to reference one (i.e. an origin).");
log.info("Public key : {}", key);
return key;
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class RuleListWriter method writeTo.
@Override
public void writeTo(RuleList ruleList, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType mediaType, MultivaluedMap<String, Object> arg5, OutputStream out) throws IOException, WebApplicationException {
Logger log = LoggerFactory.getLogger(getClass());
log.debug("Rendering the list of recipes.");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntology ontology;
try {
ontology = manager.createOntology();
String recipeClassURI = Symbols.Recipe.toString().replace("<", "").replace(">", "");
IRI recipeClassIRI = IRI.create(recipeClassURI);
OWLClass owlRecipeClass = factory.getOWLClass(recipeClassIRI);
String ruleClassURI = Symbols.Rule.toString().replace("<", "").replace(">", "");
IRI ruleClassIRI = IRI.create(ruleClassURI);
OWLClass owlRuleClass = factory.getOWLClass(ruleClassIRI);
String descriptionURI = Symbols.description.toString().replace("<", "").replace(">", "");
IRI descriptionIRI = IRI.create(descriptionURI);
OWLDataProperty descriptionProperty = factory.getOWLDataProperty(descriptionIRI);
String hasRuleURI = Symbols.hasRule.toString().replace("<", "").replace(">", "");
IRI hasRuleIRI = IRI.create(hasRuleURI);
OWLObjectProperty hasRule = factory.getOWLObjectProperty(hasRuleIRI);
String ruleBodyURI = Symbols.ruleBody.toString().replace("<", "").replace(">", "");
IRI ruleBodyIRI = IRI.create(ruleBodyURI);
OWLDataProperty ruleBody = factory.getOWLDataProperty(ruleBodyIRI);
String ruleHeadURI = Symbols.ruleHead.toString().replace("<", "").replace(">", "");
IRI ruleHeadIRI = IRI.create(ruleHeadURI);
OWLDataProperty ruleHead = factory.getOWLDataProperty(ruleHeadIRI);
if (ruleList != null) {
for (Rule rule : ruleList) {
String recipeId = rule.getRecipe().getRecipeID().toString().replace("<", "").replace(">", "");
IRI reicpeIRI = IRI.create(recipeId);
OWLIndividual owlRecipe = factory.getOWLNamedIndividual(reicpeIRI);
String ruleId = rule.getRuleID().toString().replace("<", "").replace(">", "");
IRI ruleIRI = IRI.create(ruleId);
OWLIndividual owlRule = factory.getOWLNamedIndividual(ruleIRI);
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(owlRecipeClass, owlRecipe);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLClassAssertionAxiom(owlRuleClass, owlRule);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLObjectPropertyAssertionAxiom(hasRule, owlRecipe, owlRule);
manager.addAxiom(ontology, axiom);
String recipeDescription = rule.getRecipe().getRecipeDescription();
String ruleDescription = rule.getDescription();
if (recipeDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, owlRecipe, recipeDescription);
manager.addAxiom(ontology, axiom);
}
if (ruleDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, owlRule, ruleDescription);
manager.addAxiom(ontology, axiom);
}
String ruleContent = rule.toString();
String[] parts = ruleContent.split("\\->");
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleBody, owlRule, parts[0]);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleHead, owlRule, parts[1]);
manager.addAxiom(ontology, axiom);
}
}
if (mediaType.toString().equals(KRFormat.RDF_XML)) {
try {
manager.saveOntology(ontology, new RDFXMLOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.OWL_XML)) {
try {
manager.saveOntology(ontology, new OWLXMLOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.MANCHESTER_OWL)) {
try {
manager.saveOntology(ontology, new ManchesterOWLSyntaxOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.FUNCTIONAL_OWL)) {
try {
manager.saveOntology(ontology, new OWLFunctionalSyntaxOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.TURTLE)) {
try {
manager.saveOntology(ontology, new TurtleOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.RDF_JSON)) {
Graph mGraph = OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(ontology);
RdfJsonSerializingProvider provider = new RdfJsonSerializingProvider();
provider.serialize(out, mGraph, SupportedFormat.RDF_JSON);
}
} catch (OWLOntologyCreationException e1) {
log.error("An error occurred.", e1);
}
out.flush();
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class RefactorResource method applyRefactoring.
// public RefactorResource(@Context ServletContext servletContext) {
// refactorer = (Refactorer) ContextHelper.getServiceFromContext(Refactorer.class, servletContext);
// if (refactorer == null) throw new IllegalStateException("Refactorer missing in ServletContext");
// ruleStore = (RuleStore) ContextHelper.getServiceFromContext(RuleStore.class, servletContext);
// if (ruleStore == null) throw new IllegalStateException("RuleStore missing in ServletContext");
// }
/**
* The apply mode allows the client to compose a recipe, by mean of string containg the rules, and apply
* it "on the fly" to the graph in input.
*
* @param recipe
* String
* @param input
* InputStream
* @return a Response containing the transformed graph
*/
@POST
@Path("/apply")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(value = { TURTLE, RDF_XML, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, RDF_JSON, X_TURTLE })
public Response applyRefactoring(MultiPartBody data, @Context HttpHeaders headers) {
String recipe = null;
InputStream input = null;
if (data.getTextParameterValues(recipe) != null) {
recipe = data.getTextParameterValues(recipe)[0];
}
if (data.getFormFileParameterValues("input") != null) {
input = new ByteArrayInputStream(data.getFormFileParameterValues("input")[0].getContent());
}
if (recipe == null || input == null) {
throw new WebApplicationException(BAD_REQUEST);
}
ResponseBuilder rb;
OWLOntology output = null;
try {
output = doRefactoring(input, RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/refactor/", recipe));
} catch (OWLOntologyCreationException e1) {
throw new WebApplicationException(e1, INTERNAL_SERVER_ERROR);
} catch (RefactoringException e1) {
throw new WebApplicationException(e1, BAD_REQUEST);
}
if (output != null) {
rb = Response.ok(output);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null)
rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
} else
rb = Response.status(NOT_FOUND);
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations