Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b77afa7
add IDE files to gitignore (IntelliJ IDE)
vemonet Oct 6, 2015
0a99d60
adding sonatype-snapshots maven repository to pom.xml to be able to r…
vemonet Oct 7, 2015
a9f04cd
Changing the place where the owlapi_wrapper.jar is built
vemonet Oct 7, 2015
6425179
New method addOntologyURI that add the ontology URI to the submission…
vemonet Oct 7, 2015
c30f9e7
add the ontology used to import
vemonet Apr 29, 2016
9666288
rename test file
vemonet Apr 29, 2016
0c4b238
change extension of skos file to owl because owlapi_wrapper could onl…
vemonet Apr 29, 2016
d512d2f
extracting ontology IRI directly from localMaster ontology to avoid g…
vemonet Apr 30, 2016
876947e
fix bug where omv:URI was considered as a annotation property
vemonet Jun 2, 2016
3a39914
merge with NCBO master (a lot of change, with metrics extracted from …
vemonet Jun 2, 2016
b462ca2
Merge branch 'master' into sifr_owlapi
vemonet Sep 20, 2016
7b73cab
Merge branch 'master' of https://github.com/ncbo/owlapi_wrapper into …
vemonet Apr 5, 2017
92d24e4
reformate OntologyParser Class
vemonet Apr 5, 2017
6b590ac
add comments
vemonet Apr 5, 2017
5b7c533
add comments. And comment a block where we create a now useless tripl…
vemonet Apr 5, 2017
5a12888
stop using addGroundMetadata (was getting metadata for imports also),…
vemonet Apr 5, 2017
34a4cfc
add a test for SIFR (to test ontology parsing)
vemonet Apr 5, 2017
952c19a
add a repertory and foodon.owl to do test for SIFR project (to test o…
vemonet Apr 5, 2017
42456a5
add comment on test output redirection in the pom.xml
vemonet Apr 5, 2017
0dbbcfc
merge with NCBO owlapi_wrapper after update
vemonet Apr 12, 2017
b12f5e5
remove useless tests files (wrong place)
vemonet Apr 21, 2017
e285151
fix how we get versionInfo for OBO ontologies
vemonet May 6, 2017
cb97bae
now adding all ontologies metadata to the output file (even imported …
vemonet May 8, 2017
9e6fbca
Fixing merge conflicts with NCBO master
Apr 28, 2020
7374627
Reinjecting previous commit (5a128888588e3655acaa1d52f01c86e827f38442)
May 13, 2020
528b50b
Reinjecting previous commit (e2851510d659155afc873174c58e495fe737295f)
May 13, 2020
763d048
Reinjecting previous commit (cb97bae50534dce7dea67227be6139a8ed33c99a)
May 13, 2020
0ef64a4
Merge branch 'master' of https://github.com/ncbo/owlapi_wrapper into …
ontoportal-bot-lirmm Jul 7, 2020
8107d8b
Merge branch 'master' of https://github.com/ncbo/owlapi_wrapper into …
ontoportal-bot-lirmm Jul 10, 2020
98ac732
Fixing missing dependency while parsing a file extracted from an arch…
Jul 22, 2020
268aad5
Merge branch 'virtual-appliance-3.0-merge'
Sep 10, 2020
e6bc50c
merge to upstream v1.3.8
syphax-bouazzouni May 12, 2022
1e5be4c
Merge remote-tracking branch 'upstream/master'
syphax-bouazzouni Jul 29, 2022
652b428
Merge branch 'pr/feature/add-ontology-iri-triple'
syphax-bouazzouni Aug 3, 2022
56e1684
add omv:useImports
syphax-bouazzouni Aug 3, 2022
6ff3a96
Merge remote-tracking branch 'upstream/master'
syphax-bouazzouni Sep 26, 2022
b58dfce
Merge remote-tracking branch 'upstream/master' into upstream
syphax-bouazzouni Dec 21, 2022
5a17c74
add test to count annotions of the source ontology vs generated one
syphax-bouazzouni Dec 21, 2022
e0ad8c7
remove sourceOwlManager.getOntologies() loops
syphax-bouazzouni Dec 21, 2022
10c4525
Merge branch 'pr/fix/add-only-master-ontology-annotations'
syphax-bouazzouni Dec 24, 2022
168cb9b
remove sourceOwlManager.getOntologies() loop for addOntologyAnnotations
syphax-bouazzouni Dec 21, 2022
177277d
Merge branch 'pr/fix/add-only-master-ontology-annotations'
syphax-bouazzouni Dec 24, 2022
62808e1
add guard to avoid .get() of absent value
RaimiSol May 24, 2023
fb407d6
Merge pull request #5 from BiodivPortal/master
syphax-bouazzouni May 25, 2023
fb48d92
Add an IRI mapper for the SKOS Core Vocabulary (#1)
jvendetti Nov 13, 2023
8cd3885
move sub.get() after the check to prevent expection
syphax-bouazzouni May 21, 2024
68379d3
Merge remote-tracking branch 'upstream/master' into fix/resource-with…
syphax-bouazzouni May 21, 2024
d70cd40
Revert "Merge branch 'pr/fix/add-only-master-ontology-annotations'"
syphax-bouazzouni May 28, 2024
e6792c4
Merge pull request #6 from ontoportal-lirmm/fix/resource-with-no-owl-…
syphax-bouazzouni Sep 30, 2024
ba18bbd
Merge branch 'master' into pr/fix/add-only-master-ontology-annotations
syphax-bouazzouni Mar 20, 2025
282dc07
fix the parsing to import the axiom of the imported ontologies withou…
syphax-bouazzouni Jun 19, 2025
81eb188
Merge branch 'master' into fix/ontology-level-annotation-imports
syphax-bouazzouni Jun 19, 2025
3f4033f
Merge remote-tracking branch 'ontoportal/master' into fix/ontology-le…
syphax-bouazzouni Jun 19, 2025
9156d1c
Merge branch 'fix/ontology-level-annotation-imports' into pr/fix/add-…
syphax-bouazzouni Jun 19, 2025
72117fa
Merge branch 'ontoportal-lirmm-pr/fix/add-only-master-ontology-annota…
mdorf Jun 19, 2025
ec9b6a7
updated OWLAPI Wrapper to support mixed ontology level annotations, p…
mdorf Jun 19, 2025
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
2 changes: 1 addition & 1 deletion build_install.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mvn assembly:assembly -DskipTests && cp target/owlapi_wrapper-0.0.1-SNAPSHOT-jar-with-dependencies.jar ../ontologies_linked_data/bin/owlapi_wrapper.jar
mvn assembly:assembly -DskipTests && cp target/owlapi_wrapper-0.0.1-SNAPSHOT-jar-with-dependencies.jar ../owlapi_wrapper.jar
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
<version>1.10.0</version>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>

</dependencies>

<build>
Expand Down
107 changes: 69 additions & 38 deletions src/main/java/org/stanford/ncbo/owlapi/wrapper/OntologyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

public class OntologyParser {
private final static Logger log = LoggerFactory.getLogger(OntologyParser.class.getName());
public static final String USE_IMPORTS_IRI = "http://omv.ontoware.org/2005/05/ontology#useImports";
public static final String VERSION_SUBJECT = "http://bioportal.bioontology.org/ontologies/versionSubject";

protected ParserInvocation parserInvocation = null;
Expand Down Expand Up @@ -169,6 +170,33 @@ private void addOntologyIRI(OWLOntology sourceOnt) {
}
}

/**
* Get ontology imports and them to <ONTOLOGY_URI>
* omv:useImports <import_URI>
*
* @param fact
* @param sourceOnt
*/
private void addOntologyImports(OWLDataFactory fact, OWLOntology sourceOnt){
Optional<IRI> sub = sourceOnt.getOntologyID().getOntologyIRI();

if(!sub.isPresent()){
return;
}

IRI ontologyIRI = sub.get();

// Get imports and add them as omv:useImports
OWLAnnotationProperty useImportProp = fact.getOWLAnnotationProperty(IRI.create(USE_IMPORTS_IRI));
for (OWLOntology imported : sourceOnt.getImports()) {
if (!imported.getOntologyID().isAnonymous()) {
log.info("useImports: " + imported.getOntologyID().getOntologyIRI().get());
OWLAnnotationAssertionAxiom useImportAxiom = fact.getOWLAnnotationAssertionAxiom(useImportProp, ontologyIRI, imported.getOntologyID().getOntologyIRI().get());
this.targetOwlManager.addAxiom(targetOwlOntology, useImportAxiom);
}
}
}

/**
* Copies ontology-level annotation axioms from the source ontology to the target ontology.
* <p>
Expand All @@ -188,6 +216,7 @@ private void addGroundMetadata(IRI documentIRI, OWLDataFactory factory, OWLOntol
}

for (OWLAnnotation annotation : sourceOntology.getAnnotations()) {

IRI subjectIRI = ontologyID.getOntologyIRI().get();
OWLAnnotationProperty annotationProperty = annotation.getProperty();
OWLAnnotationValue annotationValue = annotation.getValue();
Expand All @@ -212,6 +241,7 @@ private boolean buildOWLOntology(OWLOntology masterOntology, boolean isOBO) {
try {
targetOwlOntology = targetOwlManager.createOntology();
addOntologyIRI(masterOntology);
addOntologyImports(fact, masterOntology);
} catch (OWLOntologyCreationException e) {
log.error(e.getMessage());
parserLog.addError(ParserError.OWL_CREATE_ONTOLOGY_EXCEPTION, "Error buildOWLOntology" + e.getMessage());
Expand All @@ -232,51 +262,52 @@ private boolean buildOWLOntology(OWLOntology masterOntology, boolean isOBO) {

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 Expand Up @@ -449,7 +480,7 @@ private void escapeXMLLiterals(OWLOntology target) {
targetOwlManager.addAxiom(target, annAsse);
Set<OWLAnnotationAssertionAxiom> del = new HashSet<OWLAnnotationAssertionAxiom>();
del.add(ann);
targetOwlManager.removeAxioms(target,del);
targetOwlManager.removeAxioms(target,del);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.stanford.ncbo.owlapi.wrapper.preferred_labels;

import org.semanticweb.owlapi.model.OWLOntology;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stanford.ncbo.owlapi.wrapper.ParserInvocation;
import org.stanford.ncbo.owlapi.wrapper.metrics.OntologyMetrics;

public class PreferredLabels {
private static final Logger logger = LoggerFactory.getLogger(OntologyMetrics.class);

private OWLOntology ontology;

private ParserInvocation parserInvocation;

public PreferredLabels(OWLOntology ontology, ParserInvocation parserInvocation) {
this.ontology = ontology;
this.parserInvocation = parserInvocation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ public class OntologyParserTest {
public void setUp() throws Exception {

}

// Run this test: mvn -Dtest=OntologyParserTest#sifrTestParse test
// parse_OntologyENVO_ReturnsTrue fonctionne pour comparer
@Test
public void sifrTestParse() throws Exception {
ParserInvocation pi = new ParserInvocation("./src/test/resources/repo/input/sifr",
"./src/test/resources/repo/output/sifr", "foodon.owl", true);
// SKOS: anaee-france-thesaurus.rdf
// OWL: AnimalDiseasesOntology.owl.xml
OntologyParser parser = new OntologyParser(pi);
parser.parse();
//assertFalse(parser.parse());
}

@Test
public void getLocalOntologies_MultipleOntologies_Found() throws Exception {
Expand Down Expand Up @@ -165,6 +178,25 @@ public void parse_ImportSKOSCoreVocab_ShouldLoad() throws Exception {
OWLClass skosConceptClass = factory.getOWLClass(skosConceptIRI);
assertNotNull(skosConceptClass);
}
@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
Loading