Skip to content

Commit

Permalink
Allow using a custom separator when merging annotations.
Browse files Browse the repository at this point in the history
Add an optional argument to OntologyHelper.mergeExtraAnnotations to
allow the caller to specify the separator string to insert between
annotation values, when merging annotations together. The default
separator is a single space character.

This is a code-level feature only. The separator string is _not_
customizable from the command-line, when comment annotations are merged
as part of `--clean-obo merge-comments`.
  • Loading branch information
gouttegd committed Jan 27, 2025
1 parent 8876d9e commit ceccf1f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions robot-core/src/main/java/org/obolibrary/robot/OntologyHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1829,16 +1829,30 @@ public static void removeExtraAnnotations(OWLOntology ontology, Set<IRI> propert
}

/**
* Merges supernumerary annotations on all entities in the given ontology.
* Merges supernumerary annotations on all entities in the given ontology, using a single space
* character between each annotation value.
*
* @param ontology OWLOntology in which to merge supernumerary annotations
* @param properties set of annotation property IRIs to merge
*/
public static void mergeExtraAnnotations(OWLOntology ontology, Set<IRI> properties) {
mergeExtraAnnotations(ontology, properties, " ");
}

/**
* Merges supernumerary annotations on all entities in the given ontology, using a custom
* separator between each annotation value.
*
* <p>This method iterates over all entities (excluding imported entities) of the given ontology;
* if an entity is found to have more than one annotation for each of the indicated properties,
* they are merged into a single annotation.
*
* @param ontology OWLOntology in which to merge supernumerary annotations
* @param properties set of annotation property IRIs to merge
* @param separator Separator string to insert between each annotation value (may be {@code null})
*/
public static void mergeExtraAnnotations(OWLOntology ontology, Set<IRI> properties) {
public static void mergeExtraAnnotations(
OWLOntology ontology, Set<IRI> properties, String separator) {
Set<OWLAnnotationAssertionAxiom> axiomsToRemove = new HashSet<>();
Set<OWLAnnotationAssertionAxiom> axiomsToAdd = new HashSet<>();
OWLDataFactory factory = ontology.getOWLOntologyManager().getOWLDataFactory();
Expand All @@ -1865,8 +1879,8 @@ public static void mergeExtraAnnotations(OWLOntology ontology, Set<IRI> properti
Set<OWLAnnotation> axiomAnnotations = new HashSet<>();
boolean first = true;
for (OWLAnnotationAssertionAxiom ax : sortAxioms(axioms)) {
if (!first) {
sb.append(' ');
if (!first && separator != null) {
sb.append(separator);
} else {
first = false;
}
Expand Down

0 comments on commit ceccf1f

Please sign in to comment.