public void setDefinition(ProjectId projectId, OWLEntity term, OBOTermDefinition definition) {
List<OBOXRef> xRefs = definition.getXRefs();
Set<OWLAnnotation> xrefAnnotations = convertOBOXRefsToOWLAnnotations(projectId, xRefs);
OWLAPIProject project = getProject(projectId);
IRI subject = term.getIRI();
OWLDataFactory df = project.getDataFactory();
final IRI defIRI = getIRI(OBOFormatConstants.OboFormatTag.TAG_DEF);
OWLAnnotationProperty defAnnotationProperty = df.getOWLAnnotationProperty(defIRI);
OWLLiteral defLiteral = df.getOWLLiteral(definition.getDefinition());
OWLAnnotationAssertionAxiom definitionAssertion = df.getOWLAnnotationAssertionAxiom(defAnnotationProperty, subject, defLiteral, xrefAnnotations);
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
OWLOntology ont = project.getRootOntology();
for (OWLAnnotationAssertionAxiom existingAx : ont.getAnnotationAssertionAxioms(subject)) {
if (existingAx.getProperty().getIRI().equals(defIRI)) {
changes.add(new RemoveAxiom(ont, existingAx));
Set<OWLAnnotation> nonXRefAnnotations = getAxiomAnnotationsExcludingXRefs(existingAx);
OWLAxiom fullyAnnotatedDefinitionAssertion = definitionAssertion.getAnnotatedAxiom(nonXRefAnnotations);
changes.add(new AddAxiom(ont, fullyAnnotatedDefinitionAssertion));
}
}
if (changes.isEmpty()) {
// New
changes.add(new AddAxiom(ont, definitionAssertion));
}
UserId userId = getUserInSessionAndEnsureSignedIn();
project.applyChanges(userId, changes, "Set term definition");
}