Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Mixed ontology level annotations #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 40 additions & 41 deletions src/main/java/org/stanford/ncbo/owlapi/wrapper/OntologyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,65 +206,64 @@ private boolean buildOWLOntology(OWLOntology masterOntology, boolean isOBO) {
return false;
}


for (OWLOntology sourceOnt : sourceOwlManager.getOntologies()) {
IRI documentIRI = sourceOwlManager.getOntologyDocumentIRI(sourceOnt);

addGroundMetadata(documentIRI, fact, sourceOnt);
generateGroundTriplesForAxioms(allAxioms, fact, sourceOnt);

if (isOBO) {
if (!documentIRI.toString().startsWith("owlapi:ontology")) {
generateSKOSInObo(allAxioms, fact, sourceOnt);
}
if (isOBO && !documentIRI.toString().startsWith("owlapi:ontology")) {
generateSKOSInObo(allAxioms, fact, sourceOnt);
}

boolean isPrefixedOWL = sourceOwlManager.getOntologyFormat(sourceOnt).isPrefixOWLOntologyFormat();
log.info("isPrefixOWLOntologyFormat: {}", isPrefixedOWL);
if (isPrefixedOWL == true && !isOBO) {
if (isPrefixedOWL && !isOBO) {
generateSKOSInOwl(allAxioms, fact, sourceOnt);
}
}

targetOwlManager.addAxioms(targetOwlOntology, allAxioms);
for (OWLAnnotation ann : targetOwlOntology.getAnnotations()) {
targetOwlManager.addAxioms(targetOwlOntology, allAxioms);
for (OWLAnnotation ann : targetOwlOntology.getAnnotations()) {
AddOntologyAnnotation addAnn = new AddOntologyAnnotation(targetOwlOntology, ann);
targetOwlManager.applyChange(addAnn);
}

if (isOBO) {
String oboVersion = parserInvocation.getOBOVersion();
if (oboVersion != null) {
log.info("Adding version: {}", oboVersion);
OWLAnnotationProperty prop = fact.getOWLAnnotationProperty(IRI.create(OWLRDFVocabulary.OWL_VERSION_INFO.toString()));
IRI versionSubjectIRI = IRI.create(VERSION_SUBJECT);
OWLAnnotationAssertionAxiom annVersion = fact.getOWLAnnotationAssertionAxiom(prop, versionSubjectIRI, fact.getOWLLiteral(oboVersion));
targetOwlManager.addAxiom(targetOwlOntology, annVersion);
}
}

addOntologyAnnotations(masterOntology);
escapeXMLLiterals(targetOwlOntology);

OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(targetOwlOntology);
InferredSubClassAxiomGenerator isc = new InferredSubClassAxiomGenerator();
Set<OWLSubClassOfAxiom> subAxs = isc.createAxioms(targetOwlOntology.getOWLOntologyManager().getOWLDataFactory(), reasoner);
targetOwlManager.addAxioms(targetOwlOntology, subAxs);
deprecateBranch();

log.info("isOBO: {}", isOBO);
if (isOBO) {
replicateHierarchyAsTreeview(fact);
}
return true;
}

private void addOntologyAnnotations(OWLOntology masterOntology){
for (OWLAnnotation ann : masterOntology.getAnnotations()) {
AddOntologyAnnotation addAnn = new AddOntologyAnnotation(targetOwlOntology, ann);
targetOwlManager.applyChange(addAnn);
}

if (isOBO) {
String oboVersion = parserInvocation.getOBOVersion();
if (oboVersion != null) {
log.info("Adding version: {}", oboVersion);
OWLAnnotationProperty prop = fact.getOWLAnnotationProperty(IRI.create(OWLRDFVocabulary.OWL_VERSION_INFO.toString()));
IRI versionSubjectIRI = IRI.create(VERSION_SUBJECT);
OWLAnnotationAssertionAxiom annVersion = fact.getOWLAnnotationAssertionAxiom(prop, versionSubjectIRI, fact.getOWLLiteral(oboVersion));
targetOwlManager.addAxiom(targetOwlOntology, annVersion);
}
}

for (OWLOntology sourceOnt : sourceOwlManager.getOntologies()) {
for (OWLAnnotation ann : sourceOnt.getAnnotations()) {
AddOntologyAnnotation addAnn = new AddOntologyAnnotation(targetOwlOntology, ann);
targetOwlManager.applyChange(addAnn);
}
}

escapeXMLLiterals(targetOwlOntology);

OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(targetOwlOntology);
InferredSubClassAxiomGenerator isc = new InferredSubClassAxiomGenerator();
Set<OWLSubClassOfAxiom> subAxs = isc.createAxioms(targetOwlOntology.getOWLOntologyManager().getOWLDataFactory(), reasoner);
targetOwlManager.addAxioms(targetOwlOntology, subAxs);
deprecateBranch();

log.info("isOBO: {}", isOBO);
if (isOBO) {
replicateHierarchyAsTreeview(fact);
}
return true;
}

private void replicateHierarchyAsTreeview(OWLDataFactory fact) {
Set<OWLAxiom> treeViewAxs = new HashSet<OWLAxiom>();
for (OWLAxiom axiom : targetOwlOntology.getAxioms()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Before;
import org.junit.Test;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;

import java.io.File;

Expand Down Expand Up @@ -144,6 +145,25 @@ public void parse_DetectsOntologyIRI_ReturnsTrue() throws Exception {
assertEquals(sourceIRI, targetIRI);

}
@Test
public void parse_OntologyAnnotationCount_ReturnsTrue() throws Exception {
String outputRepositoryFolder = "./src/test/resources/repo/output/cno";
ParserInvocation pi = new ParserInvocation("./src/test/resources/repo/input/cno",
outputRepositoryFolder, "cnov0_5.owl", true);
assertTrue(pi.valid());

OntologyParser parser = new OntologyParser(pi);
assertTrue(parser.parse());
assertEquals(1, parser.getLocalOntologies().size());

OWLOntology targetOwlOntology = parser.getTargetOwlOntology();
OWLOntology sourceOntology = parser.getParsedOntologies().stream().findFirst().orElse(null);

assertNotNull(sourceOntology);
assertEquals(sourceOntology.getAnnotations().size(), targetOwlOntology.getAnnotations().size());

}


@After
public void tearDown() throws Exception {
Expand Down