示例#1
0
def test_expand(query):
    iri = expand(query[0], prefix_maps=None, fallback=True)
    # get the IRI
    assert iri == query[1]

    # provide custom prefix_maps, with fallback
    iri = expand(query[0],
                 prefix_maps=[{
                     'HGNC': 'https://identifiers.org/hgnc:'
                 }],
                 fallback=True)
    # get the alternate IRI
    assert iri == query[2]

    # provide custom prefix_maps, but no fallback
    iri = expand(query[0],
                 prefix_maps=[{
                     'hgnc': 'https://example.org/hgnc:'
                 }],
                 fallback=False)
    # get back the CURIE
    assert iri == query[0]

    # provide no prefix_maps, and no fallback
    iri = expand(query[0], prefix_maps=None, fallback=False)
    # get the IRI
    assert iri == query[1]
示例#2
0
def test_expand(query):
    """
    Test expand method for expanding a CURIE to an IRI.
    """
    iri = expand(query[0], prefix_maps=None, fallback=True)
    # get the IRI
    assert iri == query[1]

    # provide custom prefix_maps, with fallback
    iri = expand(
        query[0], prefix_maps=[{"HGNC": "https://identifiers.org/hgnc:"}], fallback=True
    )
    # get the alternate IRI
    assert iri == query[2]

    # provide custom prefix_maps, but no fallback
    iri = expand(
        query[0], prefix_maps=[{"hgnc": "https://example.org/hgnc:"}], fallback=False
    )
    # get back the CURIE
    assert iri == query[0]

    # provide no prefix_maps, and no fallback
    iri = expand(query[0], prefix_maps=None, fallback=False)
    # get the IRI
    assert iri == query[1]
示例#3
0
    def expand(self, curie: str, fallback: bool = True) -> str:
        """
        Expand a given CURIE to an URI, based on mappings from `prefix_map`.

        Parameters
        ----------
        curie: str
            A CURIE
        fallback: bool
            Determines whether to fallback to default prefix mappings, as determined
            by `prefixcommons.curie_util`, when CURIE prefix is not found in `prefix_map`.

        Returns
        -------
        str
            A URI corresponding to the CURIE

        """
        uri = expand(curie, [self.prefix_map], fallback)
        return uri