use of org.semanticweb.owlapi.model.OWLClass in project goci by EBISPOT.
the class AbstractOntologyLoader method getStringLiteralAnnotationValues.
protected Set<String> getStringLiteralAnnotationValues(OWLOntology ontology, OWLClass ontologyClass, OWLAnnotationProperty annotationProperty) {
Set<String> vals = new HashSet<>();
Collection<OWLAnnotation> annotations = ontologyClass.getAnnotations(ontology, annotationProperty);
annotations.stream().filter(annotation -> annotation.getValue() instanceof OWLLiteral).forEach(annotation -> {
OWLLiteral val = (OWLLiteral) annotation.getValue();
vals.add(val.getLiteral());
});
return vals;
}
use of org.semanticweb.owlapi.model.OWLClass in project goci by EBISPOT.
the class AssertedOntologyLoader method indexOntology.
protected OWLOntology indexOntology(final OWLOntology ontology) throws OWLOntologyCreationException {
Set<OWLClass> allClasses = ontology.getClassesInSignature();
removeExcludedClasses(ontology, allClasses, superclass -> getSubClasses(ontology, superclass));
int labelCount = 0;
int labelledClassCount = 0;
int synonymCount = 0;
int synonymedClassCount = 0;
getLog().debug("Loading labels and synonyms...");
for (OWLClass ontologyClass : allClasses) {
IRI clsIri = ontologyClass.getIRI();
// get IRI fragment/path
Optional<String> accession = evaluateAccessionValue(ontology, ontologyClass);
if (accession.isPresent()) {
addClassAccession(clsIri, accession.get());
}
// get label annotations
Optional<String> label = evaluateLabelAnnotationValue(ontology, ontologyClass);
if (label.isPresent()) {
addClassLabel(clsIri, label.get());
labelledClassCount++;
labelCount++;
}
// get all synonym annotations
getLog().debug("Loading synonyms...");
Set<String> synonyms = evaluateSynonymAnnotationValues(ontology, ontologyClass);
if (!synonyms.isEmpty()) {
addSynonyms(clsIri, synonyms);
synonymCount += synonyms.size();
synonymedClassCount++;
}
// get parent labels
getLog().debug("Loading parents...");
Set<String> parentLabelSet = new HashSet<>();
Set<OWLClass> parents = getSuperClasses(ontology, ontologyClass);
// only add type if the parent isn't excluded
parents.stream().filter(allClasses::contains).forEach(parentClass -> {
getLog().debug("Next parent of " + label + ": " + parentClass);
evaluateLabelAnnotationValue(ontology, parentClass).ifPresent(parentLabelSet::add);
});
addClassParentLabels(clsIri, parentLabelSet);
// get child labels
getLog().debug("Loading children...");
Set<String> childLabelSet = new HashSet<>();
// always add current class to the parents
label.ifPresent(childLabelSet::add);
Set<OWLClass> children = getSubClasses(ontology, ontologyClass);
// only add type if the child isn't excluded
children.stream().filter(allClasses::contains).forEach(childClass -> {
getLog().debug("Next child of " + label + ": " + childClass);
evaluateLabelAnnotationValue(ontology, childClass).ifPresent(childLabelSet::add);
});
addClassChildLabels(clsIri, childLabelSet);
// todo - get relationships
}
getLog().debug("Successfully indexed " + labelCount + " labels on " + labelledClassCount + " classes and " + synonymCount + " synonyms on " + synonymedClassCount + " classes!");
return ontology;
}
use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.
the class ClassAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
OWLDataFactory factory = OWLManager.getOWLDataFactory();
IObjectAtom classResource = tmp.getClassResource();
IObjectAtom argument = tmp.getArgument1();
SWRLAtom classResourceAtom = (SWRLAtom) adapter.adaptTo(classResource, SWRLRule.class);
SWRLAtom argumentAtom = (SWRLAtom) adapter.adaptTo(argument, SWRLRule.class);
OWLClass classPredicate;
SWRLIArgument argumentResource;
if (classResourceAtom instanceof ArgumentSWRLAtom) {
classPredicate = factory.getOWLClass(IRI.create(((ArgumentSWRLAtom) classResourceAtom).getId()));
} else {
throw new RuleAtomCallExeption(getClass());
}
if (argumentAtom instanceof ArgumentSWRLAtom) {
argumentResource = (SWRLIArgument) ((ArgumentSWRLAtom) argumentAtom).getSwrlArgument();
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) factory.getSWRLClassAtom(classPredicate, argumentResource);
}
use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.
the class SessionManagerResource method listSessions.
@GET
@Produces(value = { RDF_XML, OWL_XML, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON, N3, N_TRIPLE, TEXT_PLAIN })
public Response listSessions(@Context UriInfo uriInfo, @Context HttpHeaders headers) {
OWLOntologyManager ontMgr = OWLManager.createOWLOntologyManager();
OWLDataFactory df = ontMgr.getOWLDataFactory();
OWLClass cSession = df.getOWLClass(IRI.create("http://stanbol.apache.org/ontologies/meta/Session"));
OWLOntology o;
try {
o = ontMgr.createOntology(IRI.create(uriInfo.getRequestUri()));
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
for (String id : sessionManager.getRegisteredSessionIDs()) {
IRI sessionid = IRI.create(sessionManager.getDefaultNamespace() + sessionManager.getID() + "/" + id);
OWLNamedIndividual ind = df.getOWLNamedIndividual(sessionid);
changes.add(new AddAxiom(o, df.getOWLClassAssertionAxiom(cSession, ind)));
}
ontMgr.applyChanges(changes);
} catch (OWLOntologyCreationException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
ResponseBuilder rb = Response.ok(o);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null)
rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.
the class TestOWLAPIInputSources method testOfflineImport.
/**
* Uses a {@link ParentPathInputSource} to load an ontology importing a modified FOAF, both located in the
* same resource directory.
*
* @throws Exception
*/
@Test
public void testOfflineImport() throws Exception {
URL url = getClass().getResource("/ontologies/maincharacters.owl");
assertNotNull(url);
File f = new File(url.toURI());
assertNotNull(f);
OntologyInputSource<OWLOntology> coreSource = new ParentPathInputSource(f);
// // Check that all the imports closure is made of local files
// Set<OWLOntology> closure = coreSource.getImports(true);
// for (OWLOntology o : closure)
// assertEquals("file", o.getOWLOntologyManager().getOntologyDocumentIRI(o).getScheme());
assertEquals(coreSource.getRootOntology().getOntologyID().getOntologyIRI(), IRI.create(Constants.PEANUTS_MAIN_BASE));
// Linus is stated to be a foaf:Person
OWLNamedIndividual iLinus = df.getOWLNamedIndividual(IRI.create(Constants.PEANUTS_MAIN_BASE + "#Linus"));
// Lucy is stated to be a foaf:Perzon
OWLNamedIndividual iLucy = df.getOWLNamedIndividual(IRI.create(Constants.PEANUTS_MAIN_BASE + "#Lucy"));
OWLClass cPerzon = df.getOWLClass(IRI.create("http://xmlns.com/foaf/0.1/Perzon"));
Set<OWLIndividual> instances = cPerzon.getIndividuals(coreSource.getRootOntology());
assertTrue(!instances.contains(iLinus) && instances.contains(iLucy));
}
Aggregations