use of org.semanticweb.owlapi.model.OWLClass in project Vitro by vivo-project.
the class TBoxInferencesAccumulator method populateEquivalentClasses.
private void populateEquivalentClasses(OWLClass c, OWLReasoner r, Model m) {
for (OWLClass equiv : r.getEquivalentClasses(c).getEntities()) {
log.debug("Equivalent class: " + c + ", " + equiv);
m.add(toResource(c), OWL_EQUIVALENT_CLASS, toResource(equiv));
}
}
use of org.semanticweb.owlapi.model.OWLClass in project onprom by onprom.
the class OBDAMaterializerImpl method retrieveAllClassInstances.
// ////////////////////////////////////////////////////////////////////////////
// Some supporting methods
// ////////////////////////////////////////////////////////////////////////////
public List<OWLClassAssertionAxiom> retrieveAllClassInstances() throws OWLException {
// Collect all class names in the target ontology
Set<OWLClass> classes = this.targetOntology.getClassesInSignature();
ArrayList<OWLClassAssertionAxiom> results = new ArrayList<OWLClassAssertionAxiom>();
QuestOWLConnection conn = questReasoner.getConnection();
QuestOWLStatement st = conn.createStatement();
try {
OWLIndividual clsInstance;
for (OWLClass cls : classes) {
clsInstance = null;
// System.out.println("\n\n------------------------------------\nProcessing the OWLClass "+ cls+"\n------------------------------------");
String q = String.format(this.qClassRetrieverTemplate, cls.toString());
// System.out.println("query: \n\t" + q +"\n");
QuestOWLResultSet rs = st.executeTuple(q);
// System.out.println("Creating Class Axiom for the class "+ cls);
while (rs.nextRow()) {
clsInstance = rs.getOWLIndividual(this.qClassRetrieverTemplateAnsVar);
// System.out.println("clsInstance: "+clsInstance);
results.add(this.owlDataFactory.getOWLClassAssertionAxiom(cls, clsInstance));
}
}
} finally {
if (st != null && !st.isClosed())
st.close();
if (conn != null && !conn.isClosed())
conn.close();
}
return results;
}
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 -> {
// only add type if the parent isn't excluded
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 -> {
// only add type if the parent isn't excluded
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 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 CheckingService method validateEfoTrait.
public void validateEfoTrait(EfoTrait trait) {
String uri = trait.getUri();
String traitLabel = trait.getTrait();
OWLClass cls = null;
try {
cls = ontologyService.getOWLClassByURI(uri);
} catch (Exception e) {
getLog().debug("IRI " + uri + " is not a valid IRI");
}
if (cls != null) {
String label = ontologyLoader.getLabel(cls.getIRI());
if (label != null) {
boolean found = false;
if (label.equalsIgnoreCase(traitLabel)) {
found = true;
}
if (!found) {
Set<String> syns = ontologyLoader.getSynonyms(cls.getIRI());
for (String syn : syns) {
if (syn.equalsIgnoreCase(traitLabel)) {
found = true;
}
}
if (!found) {
getLog().info("Class " + uri + " (label: " + label + ") does not have a label or synonym of " + traitLabel + ". DB ID is " + trait.getId());
}
}
} else {
getLog().info("Class " + uri + " does not have a label");
}
} else {
getLog().info(uri + " is not a valid EFO URI");
Collection<OWLClass> classes = ontologyService.getOWLClassesByLabel(traitLabel);
if (classes.isEmpty()) {
getLog().info("No EFO classes match the label " + traitLabel);
}
}
}
Aggregations