MappingServiceGraph

class MappingServiceGraph(*args: Any, converter: Converter, predicates: None | str | list[str] = None, **kwargs: Any)[source]

Bases: Graph

A service that implements identifier mapping based on a converter.

Instantiate the graph.

Parameters:
  • args – Positional arguments to pass to rdflib.Graph.__init__()

  • converter – A converter object

  • predicates – A predicate or set of predicates. If not given, this service will use owl:sameAs as a predicate for mapping IRIs.

  • kwargs – Keyword arguments to pass to rdflib.Graph.__init__()

In the following example, a service graph is instantiated using a small example converter, then an example SPARQL query is made directly to show how it makes results:

from curies import Converter
from curies.mapping_service import CURIEServiceGraph

converter = Converter.from_priority_prefix_map(
    {
        "CHEBI": [
            "https://www.ebi.ac.uk/chebi/searchId.do?chebiId=",
            "http://identifiers.org/chebi/",
            "http://purl.obolibrary.org/obo/CHEBI_",
        ],
        "GO": ["http://purl.obolibrary.org/obo/GO_"],
        "OBO": ["http://purl.obolibrary.org/obo/"],
        ...,
    }
)
graph = MappingServiceGraph(converter=converter)

res = graph.query('''
    SELECT ?o WHERE {
        VALUES ?s {
            <http://purl.obolibrary.org/obo/CHEBI_1>
        }
        ?s owl:sameAs ?o
    }
''')

The results of this are:

subject

object

http://purl.obolibrary.org/obo/CHEBI_1

http://purl.obolibrary.org/obo/CHEBI_1

http://purl.obolibrary.org/obo/CHEBI_1

http://identifiers.org/chebi/1

http://purl.obolibrary.org/obo/CHEBI_1

https://www.ebi.ac.uk/chebi/searchId.do?chebiId=1

Methods Summary

triples(triple)

Generate triples, overriden to dynamically generate mappings based on this graph's converter.

Methods Documentation

triples(triple: tuple[URIRef, URIRef, URIRef]) Iterable[tuple[URIRef, URIRef, URIRef]][source]

Generate triples, overriden to dynamically generate mappings based on this graph’s converter.