Skip to content

Commit

Permalink
Preserve prefix declarations from input ontology.
Browse files Browse the repository at this point in the history
  • Loading branch information
balhoff committed Sep 9, 2024
1 parent 16fa9a4 commit 895b273
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String getKey() {

@Override
public boolean isPrefixOWLOntologyFormat() {
return true;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String getKey() {

@Override
public boolean isPrefixOWLOntologyFormat() {
return true;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ private void saveOntologyInAllFormats(String idspace, String fileNameBase, Strin

private void write(OWLOntologyManager manager, OWLOntology ont, OWLDocumentFormat format, OutputStream out) throws OWLOntologyStorageException {
try {
copyPrefixDefinitionsToOutputFormat(ont, format);
manager.saveOntology(ont, format, out);
} finally {
try {
Expand All @@ -1763,6 +1764,17 @@ private void write(OWLOntologyManager manager, OWLOntology ont, OWLDocumentForma

}

private void copyPrefixDefinitionsToOutputFormat(OWLOntology ont, OWLDocumentFormat format) {
OWLDocumentFormat previousFormat = ont.getOWLOntologyManager().getOntologyFormat(ont);
if (format != null && format.isPrefixOWLOntologyFormat()
&& previousFormat != null
&& previousFormat.isPrefixOWLOntologyFormat()) {
String defaultNamespace = format.asPrefixOWLOntologyFormat().getDefaultPrefix();
format.asPrefixOWLOntologyFormat().copyPrefixesFrom(previousFormat.asPrefixOWLOntologyFormat());
format.asPrefixOWLOntologyFormat().setDefaultPrefix(defaultNamespace);
}
}

private void saveReasonerReport(String ontologyId,
List<String> reasonerReportLines) {

Expand Down
12 changes: 12 additions & 0 deletions OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3695,6 +3695,7 @@ else if (ofmtname.equals("obo")) {
}
ofmt = new OBODocumentFormat();
}
copyPrefixDefinitionsToOutputFormat(g.getSourceOntology(), ofmt);
}
else if (opts.nextEq("--prefix")) {
opts.info("PREFIX URIBASE","use PREFIX as prefix. Note: specify this sub-arg AFTER -f");
Expand Down Expand Up @@ -6637,4 +6638,15 @@ private void showEdges(Set<OWLGraphEdge> edges) {
}
}

private void copyPrefixDefinitionsToOutputFormat(OWLOntology ont, OWLDocumentFormat format) {
OWLDocumentFormat previousFormat = ont.getOWLOntologyManager().getOntologyFormat(ont);
if (format != null && format.isPrefixOWLOntologyFormat()
&& previousFormat != null
&& previousFormat.isPrefixOWLOntologyFormat()) {
String defaultNamespace = format.asPrefixOWLOntologyFormat().getDefaultPrefix();
format.asPrefixOWLOntologyFormat().copyPrefixesFrom(previousFormat.asPrefixOWLOntologyFormat());
format.asPrefixOWLOntologyFormat().setDefaultPrefix(defaultNamespace);
}
}

}

0 comments on commit 895b273

Please sign in to comment.