Skip to content

Commit

Permalink
Add CurieUtil.getCuriePrefix(iri) for Issue prefixcommons#4
Browse files Browse the repository at this point in the history
  • Loading branch information
julesjacobsen committed Apr 3, 2019
1 parent 5973895 commit 016f13f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/prefixcommons/CurieUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public Optional<String> getCurie(String iri) {
}
}

public Optional<String> getCuriePrefix(String iri) {
String prefix = trie.getMatchingPrefix(iri);
if (prefix.equals("")) {
return Optional.empty();
}
return Optional.of(curieMap.inverse().get(prefix));
}

/***
* Expands a CURIE to a full IRI, if mapped.
*
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/prefixcommons/CurieUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ public void fromJsonLdFile() throws IOException {
is(Optional.of("http://purl.obolibrary.org/obo/XAO_foo")));
}

@Test
public void getIriPrefix() {
assertThat(util.getCuriePrefix("http://x.org/a_12345"), is(Optional.of("A")));
assertThat(util.getCuriePrefix("http://x.org/C_C12345"), is(Optional.of("CC")));
}
}

0 comments on commit 016f13f

Please sign in to comment.