annotationItems = CommandLineHelper.getOptionValues(line, "annotation");
@@ -199,6 +202,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(annotationFormatError, e);
}
+ if (interpolate) {
+ value = expandValue(value, ontology);
+ }
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addOntologyAnnotation(ontology, iri, IOHelper.createLiteral(value));
}
@@ -214,6 +220,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(linkAnnotationFormatError, e);
}
+ if (interpolate) {
+ value = expandValue(value, ontology);
+ }
IRI propIRI = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
IRI valueIRI = CommandLineHelper.maybeCreateIRI(ioHelper, value, "value");
OntologyHelper.addOntologyAnnotation(ontology, propIRI, valueIRI);
@@ -232,6 +241,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(langAnnotationFormatError, e);
}
+ if (interpolate) {
+ value = expandValue(value, ontology);
+ }
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addOntologyAnnotation(
ontology, iri, IOHelper.createTaggedLiteral(value, lang));
@@ -250,6 +262,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(typedAnnotationFormatError, e);
}
+ if (interpolate) {
+ value = expandValue(value, ontology);
+ }
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addOntologyAnnotation(ontology, iri, ioHelper.createTypedLiteral(value, type));
}
@@ -265,6 +280,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(axiomAnnotationFormatError, e);
}
+ if (interpolate) {
+ value = expandValue(value, ontology);
+ }
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addAxiomAnnotations(ontology, iri, IOHelper.createLiteral(value));
}
@@ -334,4 +352,31 @@ public CommandState execute(CommandState state, String[] args) throws Exception
return state;
}
+
+ /**
+ * Expands placeholders within the given string with values derived from the ontology.
+ *
+ * Placeholders are keywords enclosed within %{...}
. Currently supported
+ * placeholders are:
+ *
+ *
+ * ontology_iri
: replaced by the ontology's IRI;
+ * version_iri
: replaced by the ontology's version IRI.
+ *
+ *
+ * @param value the string in which to replace placeholders
+ * @param ontology the ontology from which placeholder values should be derived
+ * @return the updated string
+ */
+ private String expandValue(String value, OWLOntology ontology) {
+ IRI ontologyIRI = ontology.getOntologyID().getOntologyIRI().orNull();
+ IRI versionIRI = ontology.getOntologyID().getVersionIRI().orNull();
+ if (ontologyIRI != null) {
+ value = value.replace("%{ontology_iri}", ontologyIRI.toString());
+ }
+ if (versionIRI != null) {
+ value = value.replace("%{version_iri}", versionIRI.toString());
+ }
+ return value;
+ }
}