Skip to content

Commit

Permalink
- Update curie formation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
haideriqbal committed Oct 1, 2024
1 parent d832fbd commit 3422b93
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,25 @@ public static void annotateShortForms(OntologyGraph graph) {
}

String shortForm = extractShortForm(graph, ontologyBaseUris, preferredPrefix, c.uri);
String curie = shortForm.replaceFirst("_", ":");

/*
CURIEs are formed by following rules:
If there are more than one underscore "_" in the shortform just keep the curie same as shortform
If there is only one underscore "_" AND the characters after the underscore are numbers then replace the underscore with colon ":"
If there is only one underscore "_" and the characters after the underscore are not just numbers then just keep the curie same as shortform
*/

String curie;
if (shortForm.chars().filter(ch -> ch == '_').count() > 1) {
curie = shortForm;
} else {
int underscoreIndex = shortForm.indexOf('_');
if (underscoreIndex != -1 && shortForm.substring(underscoreIndex + 1).matches("\\d+")) {
curie = shortForm.replaceFirst("_", ":");
} else {
curie = shortForm;
}
}

c.properties.addProperty("shortForm", PropertyValueLiteral.fromString(shortForm));
c.properties.addProperty("curie", PropertyValueLiteral.fromString(curie));
Expand Down

0 comments on commit 3422b93

Please sign in to comment.