SemanticallyProcessable

class SemanticallyProcessable[source]

Bases: ABC, Generic[X]

A class that can be processed with a converter.

The goal of this class is to standardize objects that come with unprocessed URIs that can be processed into references with respect to a curies.Converter. For example, this is useful for obographs and jskos.

from pydantic import BaseModel
from curies import SemanticallyProcessable


class ProcessedEntity(BaseModel):
    reference: Reference


class RawEntity(BaseModel, SemanticallyProcessable[ProcessedEntity]):
    uri: str

    def process(self, converter: Converter) -> ProcessedEntity:
        return ProcessedEntity(
            reference=converter.parse_uri(self.uri, strict=True).to_pydantic()
        )

curies provides a high-level interface for standardizing classes in curies.process().

from curies import Converter

converter = Converter.from_prefix_map({"CHEBI": "http://purl.obolibrary.org/obo/CHEBI_"})

e1 = RawEntity(uri="http://purl.obolibrary.org/obo/CHEBI_1")
e2 = RawEntity(uri="http://purl.obolibrary.org/obo/CHEBI_2")

# can be used directly on an object
assert ProcessedEntity(reference=Reference.from_curie("CHEBI:1")) == curies.standardize(
    e1, converter
)

# can also be used on an iterable/collection
assert [
    ProcessedEntity(reference=Reference.from_curie("CHEBI:1")),
    ProcessedEntity(reference=Reference.from_curie("CHEBI:2")),
] == curies.process((e1, e2), converter)

Methods Summary

process(converter)

Process this raw instance.

Methods Documentation

abstractmethod process(converter: Converter) X[source]

Process this raw instance.