ReferenceTuple

class ReferenceTuple(prefix: str, identifier: str)[source]

Bases: NamedTuple

A pair of a prefix (corresponding to a semantic space) and a local unique identifier in that semantic space.

This class derives from the “named tuple” which means that it acts like a tuple in most senses - it can be hashed and unpacked like most other tuples. Underneath, it has a C implementation and is very efficient.

A reference tuple can be constructed two ways:

>>> ReferenceTuple("chebi", "1234")
ReferenceTuple(prefix='chebi', identifier='1234')
>>> ReferenceTuple.from_curie("chebi:1234")
ReferenceTuple(prefix='chebi', identifier='1234')

A reference tuple can be formatted as a CURIE string with the curie attribute

>>> ReferenceTuple.from_curie("chebi:1234").curie
'chebi:1234'

Reference tuples can be sliced like regular 2-tuples

>>> t = ReferenceTuple.from_curie("chebi:1234")
>>> t[0]
'chebi'
>>> t[1]
'1234'

Similarly, reference tuples can be unpacked like regular 2-tuples

>>> prefix, identifier = ReferenceTuple.from_curie("chebi:1234")
>>> prefix
'chebi'
>>> identifier
'1234'

Because they are named tuples, reference tuples can be accessed with attributes

>>> t = ReferenceTuple.from_curie("chebi:1234")
>>> t.prefix
'chebi'
>>> t.identifier
'1234'

Create new instance of ReferenceTuple(prefix, identifier)

Attributes Summary

curie

Get the reference as a CURIE string.

identifier

Alias for field number 1

prefix

Alias for field number 0

Methods Summary

from_curie(curie[, sep])

Parse a CURIE string and populate a reference tuple.

Attributes Documentation

curie

Get the reference as a CURIE string.

Returns:

A string representation of a compact URI (CURIE).

>>> ReferenceTuple("chebi", "1234").curie
'chebi:1234'
identifier: str

Alias for field number 1

prefix: str

Alias for field number 0

Methods Documentation

classmethod from_curie(curie: str, sep: str = ':') ReferenceTuple[source]

Parse a CURIE string and populate a reference tuple.

Parameters:
  • curie – A string representation of a compact URI (CURIE)

  • sep – The separator

Returns:

A reference tuple

>>> ReferenceTuple.from_curie("chebi:1234")
ReferenceTuple(prefix='chebi', identifier='1234')