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

Preserve prefix declarations from input ontology. #328

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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);
}
}

}