Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions tripper/triplestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,26 +746,30 @@ def has(
# Methods providing additional functionality
# ------------------------------------------
def expand_iri(self, iri: str):
"""Return the full IRI if `iri` is prefixed. Otherwise `iri` is
returned.
"""
Return the full IRI if `iri` is prefixed.
Otherwise `iri` isreturned.

Examples:
>>> from tripper import Triplestore
>>> ts = Triplestore(backend="rdflib")
```python
>>> from tripper import Triplestore
>>> ts = Triplestore(backend="rdflib")

# Unknown prefix raises an exception
>>> ts.expand_iri("ex:Concept") # doctest: +ELLIPSIS
Traceback (most recent call last):
...
tripper.errors.NamespaceError: unknown namespace: 'ex'
# Unknown prefix raises an exception
>>> ts.expand_iri("ex:Concept") # doctest: +ELLIPSIS
Traceback (most recent call last):
...
tripper.errors.NamespaceError: unknown namespace: 'ex'

>>> EX = ts.bind("ex", "http://example.com#")
>>> ts.expand_iri("ex:Concept")
'http://example.com#Concept'
>>> EX = ts.bind("ex", "http://example.com#")
>>> ts.expand_iri("ex:Concept")
'http://example.com#Concept'

# Returns `iri` if it has no prefix
>>> ts.expand_iri("http://example.com#Concept")
'http://example.com#Concept'
# Returns iri if it has no prefix
>>> ts.expand_iri("http://example.com#Concept")
'http://example.com#Concept'

```

"""
match = re.match(_MATCH_PREFIXED_IRI, iri)
Expand Down