Skip to content

Commit 895b273

Browse files
committed
Preserve prefix declarations from input ontology.
1 parent 16fa9a4 commit 895b273

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

OWLTools-Core/src/main/java/owltools/io/OWLOboGraphsFormat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public String getKey() {
2020

2121
@Override
2222
public boolean isPrefixOWLOntologyFormat() {
23-
return true;
23+
return false;
2424
}
2525

2626
@Override

OWLTools-Core/src/main/java/owltools/io/OWLOboGraphsYamlFormat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public String getKey() {
2020

2121
@Override
2222
public boolean isPrefixOWLOntologyFormat() {
23-
return true;
23+
return false;
2424
}
2525

2626
@Override

OWLTools-Oort/src/main/java/owltools/ontologyrelease/OboOntologyReleaseRunner.java

+12
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,7 @@ private void saveOntologyInAllFormats(String idspace, String fileNameBase, Strin
17521752

17531753
private void write(OWLOntologyManager manager, OWLOntology ont, OWLDocumentFormat format, OutputStream out) throws OWLOntologyStorageException {
17541754
try {
1755+
copyPrefixDefinitionsToOutputFormat(ont, format);
17551756
manager.saveOntology(ont, format, out);
17561757
} finally {
17571758
try {
@@ -1763,6 +1764,17 @@ private void write(OWLOntologyManager manager, OWLOntology ont, OWLDocumentForma
17631764

17641765
}
17651766

1767+
private void copyPrefixDefinitionsToOutputFormat(OWLOntology ont, OWLDocumentFormat format) {
1768+
OWLDocumentFormat previousFormat = ont.getOWLOntologyManager().getOntologyFormat(ont);
1769+
if (format != null && format.isPrefixOWLOntologyFormat()
1770+
&& previousFormat != null
1771+
&& previousFormat.isPrefixOWLOntologyFormat()) {
1772+
String defaultNamespace = format.asPrefixOWLOntologyFormat().getDefaultPrefix();
1773+
format.asPrefixOWLOntologyFormat().copyPrefixesFrom(previousFormat.asPrefixOWLOntologyFormat());
1774+
format.asPrefixOWLOntologyFormat().setDefaultPrefix(defaultNamespace);
1775+
}
1776+
}
1777+
17661778
private void saveReasonerReport(String ontologyId,
17671779
List<String> reasonerReportLines) {
17681780

OWLTools-Runner/src/main/java/owltools/cli/CommandRunner.java

+12
Original file line numberDiff line numberDiff line change
@@ -3695,6 +3695,7 @@ else if (ofmtname.equals("obo")) {
36953695
}
36963696
ofmt = new OBODocumentFormat();
36973697
}
3698+
copyPrefixDefinitionsToOutputFormat(g.getSourceOntology(), ofmt);
36983699
}
36993700
else if (opts.nextEq("--prefix")) {
37003701
opts.info("PREFIX URIBASE","use PREFIX as prefix. Note: specify this sub-arg AFTER -f");
@@ -6637,4 +6638,15 @@ private void showEdges(Set<OWLGraphEdge> edges) {
66376638
}
66386639
}
66396640

6641+
private void copyPrefixDefinitionsToOutputFormat(OWLOntology ont, OWLDocumentFormat format) {
6642+
OWLDocumentFormat previousFormat = ont.getOWLOntologyManager().getOntologyFormat(ont);
6643+
if (format != null && format.isPrefixOWLOntologyFormat()
6644+
&& previousFormat != null
6645+
&& previousFormat.isPrefixOWLOntologyFormat()) {
6646+
String defaultNamespace = format.asPrefixOWLOntologyFormat().getDefaultPrefix();
6647+
format.asPrefixOWLOntologyFormat().copyPrefixesFrom(previousFormat.asPrefixOWLOntologyFormat());
6648+
format.asPrefixOWLOntologyFormat().setDefaultPrefix(defaultNamespace);
6649+
}
6650+
}
6651+
66406652
}

0 commit comments

Comments
 (0)