Skip to content

Commit

Permalink
Add is_curie and is_uri functions
Browse files Browse the repository at this point in the history
Closes #89
  • Loading branch information
cthoyt committed Nov 4, 2023
1 parent 0fa19c9 commit 178ef48
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/curies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ def format_curie(self, prefix: str, identifier: str) -> str:
"""Format a prefix and identifier into a CURIE string."""
return f"{prefix}{self.delimiter}{identifier}"

def is_uri(self, uri: str) -> bool:
"""Check if a string is a valid URI based on the records in this converter."""
prefix, _ = self.parse_uri(uri)
return prefix is not None

def compress_strict(self, uri: str) -> str:
"""Compress a URI to a CURIE, and raise an error of not possible."""
return self.compress(uri, strict=True)
Expand Down Expand Up @@ -1040,6 +1045,10 @@ def parse_uri(self, uri: str) -> Union[ReferenceTuple, Tuple[None, None]]:
else:
return ReferenceTuple(prefix, uri[len(value) :])

def is_curie(self, curie: str) -> bool:
"""Check if the CURIE is parsable under this converter."""
return self.expand(curie) is None

def expand_strict(self, curie: str) -> str:
"""Expand a CURIE to a URI, and raise an error of not possible."""
return self.expand(curie, strict=True)
Expand Down

0 comments on commit 178ef48

Please sign in to comment.