use of org.semanticweb.owlapi.model.OWLOntologyStorageException in project webprotege by protegeproject.
the class CreateNewProjectActionHandler method execute.
@Nonnull
@Override
public CreateNewProjectResult execute(@Nonnull CreateNewProjectAction action, @Nonnull ExecutionContext executionContext) {
try {
UserId userId = executionContext.getUserId();
if (!accessManager.hasPermission(forUser(userId), ApplicationResource.get(), CREATE_EMPTY_PROJECT)) {
throw new PermissionDeniedException("You do not have permission to create new projects", userInSessionFactory.getUserInSession(userId));
}
NewProjectSettings newProjectSettings = action.getNewProjectSettings();
if (newProjectSettings.hasSourceDocument()) {
if (!accessManager.hasPermission(forUser(userId), ApplicationResource.get(), UPLOAD_PROJECT)) {
throw new PermissionDeniedException("You do not have permission to upload projects", userInSessionFactory.getUserInSession(userId));
}
}
ProjectId projectId = pm.createNewProject(newProjectSettings);
if (!projectDetailsManager.isExistingProject(projectId)) {
projectDetailsManager.registerProject(projectId, newProjectSettings);
applyDefaultPermissions(projectId, userId);
}
return new CreateNewProjectResult(projectDetailsManager.getProjectDetails(projectId));
} catch (OWLOntologyCreationException | OWLOntologyStorageException | IOException e) {
throw new RuntimeException(e);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyStorageException in project webprotege by protegeproject.
the class RootOntologyLoader method loadRootOntology.
public OWLOntology loadRootOntology() {
// The delegate - we use the concurrent ontology manager
OWLOntologyManager delegateManager = WebProtegeOWLManager.createConcurrentOWLOntologyManager();
// We only support the binary format for speed
delegateManager.getOntologyStorers().add(new RDFXMLStorerFactory());
delegateManager.getOntologyStorers().add(new OWLXMLStorerFactory());
delegateManager.getOntologyStorers().add(new FunctionalSyntaxStorerFactory());
delegateManager.getOntologyStorers().add(new ManchesterSyntaxStorerFactory());
delegateManager.getOntologyParsers().add(new BinaryOWLOntologyDocumentParserFactory());
// The wrapper manager
ProjectOWLOntologyManager manager = new ProjectOWLOntologyManager();
manager.setDelegate(delegateManager);
int threadPriority = Thread.currentThread().getPriority();
try {
Thread.currentThread().setPriority(3);
OWLOntology rootOntology = documentStore.initialiseOntologyManagerWithProject(manager.getDelegate());
manager.sealDelegate();
return rootOntology;
} catch (OWLOntologyCreationException | OWLOntologyStorageException e) {
throw new RuntimeException("Failed to load project: " + e.getMessage(), e);
} finally {
Thread.currentThread().setPriority(threadPriority);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyStorageException in project goci by EBISPOT.
the class DefaultGWASOWLPublisher method saveGWASDataInferredView.
public void saveGWASDataInferredView(OWLReasoner reasoner, File outputFile) throws OWLConversionException {
try {
// create new ontology to hold inferred axioms
OWLOntology inferredOntology = getConverter().createConversionOntology();
getLog().info("Saving inferred view...");
List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
// we require all inferred stuff except for disjoints...
gens.add(new InferredClassAssertionAxiomGenerator());
gens.add(new InferredDataPropertyCharacteristicAxiomGenerator());
gens.add(new InferredEquivalentClassAxiomGenerator());
gens.add(new InferredEquivalentDataPropertiesAxiomGenerator());
gens.add(new InferredEquivalentObjectPropertyAxiomGenerator());
gens.add(new InferredInverseObjectPropertiesAxiomGenerator());
gens.add(new InferredObjectPropertyCharacteristicAxiomGenerator());
gens.add(new InferredPropertyAssertionGenerator());
gens.add(new InferredSubClassAxiomGenerator());
gens.add(new InferredSubDataPropertyAxiomGenerator());
gens.add(new InferredSubObjectPropertyAxiomGenerator());
// now create the target ontology and save
OWLOntologyManager inferredManager = inferredOntology.getOWLOntologyManager();
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
iog.fillOntology(inferredManager, inferredOntology);
inferredManager.saveOntology(inferredOntology, IRI.create(outputFile));
getLog().info("Inferred view saved ok");
} catch (OWLOntologyStorageException e) {
throw new OWLConversionException("Failed to save GWAS data (inferred view)", e);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyStorageException in project stanbol by apache.
the class ODPRegistryCacheManager method retrieveRemoteResource.
/**
* Gets the remote ontology and saves it locally
*
* @param uri
* @return
* @throws OWLOntologyCreationException
* @throws UnknownOWLOntologyException
* @throws OWLOntologyStorageException
*/
private static synchronized OWLOntology retrieveRemoteResource(URI uri) throws OWLOntologyCreationException, UnknownOWLOntologyException, OWLOntologyStorageException {
manager.setSilentMissingImportsHandling(true);
manager.addMissingImportListener(new MissingImportListener() {
public void importMissing(MissingImportEvent arg0) {
if (!getUnresolvedURIs().contains(arg0.getImportedOntologyURI()))
getUnresolvedURIs().add(arg0.getImportedOntologyURI().toURI());
}
});
manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
@Override
public void startedLoadingOntology(LoadingStartedEvent event) {
// Nothing to do
}
@Override
public void finishedLoadingOntology(LoadingFinishedEvent event) {
URI onturi = event.getDocumentIRI().toURI();
if (event.getException() != null) {
getUnresolvedURIs().add(onturi);
LoggerFactory.getLogger(ODPRegistryCacheManager.class).warn("Failed to resolve ontology at " + onturi + " . Skipping.", event.getException());
return;
}
try {
if (!uris.containsKey(onturi)) {
cacheOntology(onturi, newFile(), manager.getOntology(event.getOntologyID()));
}
} catch (UnknownOWLOntologyException e) {
LoggerFactory.getLogger(ODPRegistryCacheManager.class).warn("Failed to cache ontology at " + onturi + " . Skipping.", e);
getUnresolvedURIs().add(onturi);
} catch (OWLOntologyStorageException e) {
LoggerFactory.getLogger(ODPRegistryCacheManager.class).warn("Failed to cache ontology at " + onturi + " . Skipping.", e);
getUnresolvedURIs().add(onturi);
}
}
});
OWLOntology ont;
try {
ont = manager.loadOntologyFromOntologyDocument(IRI.create(uri));
} catch (OWLOntologyAlreadyExistsException e) {
ont = manager.getOntology(e.getOntologyID().getOntologyIRI());
}
File file = newFile();
cacheOntology(uri, file, ont);
return ont;
}
use of org.semanticweb.owlapi.model.OWLOntologyStorageException in project stanbol by apache.
the class RecipeWriter method writeTo.
@Override
public void writeTo(Recipe recipe, 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.");
if (mediaType.toString().equals(MediaType.TEXT_PLAIN)) {
String recipeString = recipe.toString();
out.write(recipeString.getBytes());
} else if (mediaType.toString().equals(MediaType.TEXT_HTML)) {
String recipeString = recipe.toString();
out.write(recipeString.getBytes());
} else {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntology ontology;
try {
ontology = manager.createOntology();
RuleList rules = recipe.getRuleList();
IRI recipeID = recipe.getRecipeID();
String recipeURI = recipeID.toString().replace("<", "").replace(">", "");
org.semanticweb.owlapi.model.IRI recipeIRI = org.semanticweb.owlapi.model.IRI.create(recipeURI);
OWLIndividual recipeIndividual = factory.getOWLNamedIndividual(recipeIRI);
String descriptionURI = Symbols.description.toString().replace("<", "").replace(">", "");
org.semanticweb.owlapi.model.IRI descriptionIRI = org.semanticweb.owlapi.model.IRI.create(descriptionURI);
OWLDataProperty descriptionProperty = factory.getOWLDataProperty(descriptionIRI);
OWLAxiom axiom;
String recipeDescription = recipe.getRecipeDescription();
if (recipeDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, recipeIndividual, recipeDescription);
manager.addAxiom(ontology, axiom);
}
if (rules != null) {
for (Rule rule : rules) {
IRI ruleID = rule.getRuleID();
String ruleName = rule.getRuleName();
String ruleDescription = rule.getDescription();
String ruleURI = ruleID.toString().replace("<", "").replace(">", "");
String ruleNameURI = Symbols.ruleName.toString().replace("<", "").replace(">", "");
String ruleBodyURI = Symbols.ruleBody.toString().replace("<", "").replace(">", "");
String ruleHeadURI = Symbols.ruleHead.toString().replace("<", "").replace(">", "");
String hasRuleURI = Symbols.hasRule.toString().replace("<", "").replace(">", "");
String ruleContent = rule.toString();
String[] ruleParts = ruleContent.split("\\->");
org.semanticweb.owlapi.model.IRI ruleIRI = org.semanticweb.owlapi.model.IRI.create(ruleURI);
org.semanticweb.owlapi.model.IRI ruleNameIRI = org.semanticweb.owlapi.model.IRI.create(ruleNameURI);
org.semanticweb.owlapi.model.IRI ruleBodyIRI = org.semanticweb.owlapi.model.IRI.create(ruleBodyURI);
org.semanticweb.owlapi.model.IRI ruleHeadIRI = org.semanticweb.owlapi.model.IRI.create(ruleHeadURI);
org.semanticweb.owlapi.model.IRI hasRuleIRI = org.semanticweb.owlapi.model.IRI.create(hasRuleURI);
OWLIndividual ruleIndividual = factory.getOWLNamedIndividual(ruleIRI);
OWLObjectProperty hasRule = factory.getOWLObjectProperty(hasRuleIRI);
OWLDataProperty nameProperty = factory.getOWLDataProperty(ruleNameIRI);
OWLDataProperty ruleBodyProperty = factory.getOWLDataProperty(ruleBodyIRI);
OWLDataProperty ruleHeadProperty = factory.getOWLDataProperty(ruleHeadIRI);
// add the name to the rule individual
axiom = factory.getOWLDataPropertyAssertionAxiom(nameProperty, ruleIndividual, ruleName);
manager.addAxiom(ontology, axiom);
// add the description to the rule individual
if (ruleDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, ruleIndividual, ruleDescription);
manager.addAxiom(ontology, axiom);
}
// add the rule body to the rule individual
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleBodyProperty, ruleIndividual, ruleParts[0]);
manager.addAxiom(ontology, axiom);
// add the rule head to the rule individual
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleHeadProperty, ruleIndividual, ruleParts[1]);
manager.addAxiom(ontology, axiom);
// bind the rule to the recipe
axiom = factory.getOWLObjectPropertyAssertionAxiom(hasRule, recipeIndividual, ruleIndividual);
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();
}
Aggregations