Skip to content

ontocast.tool.facts_validation.term_verdict

Whether a predicate or class IRI is acceptable, decided without messages.

Classes

TermVerdict

Bases: BaseModel

A term judged unacceptable.

Attributes:

Name Type Description
kind TermVerdictKind

The reason.

term str

The IRI judged.

vocabulary_title str | None

The well-known vocabulary's name, for WELL_KNOWN_MISSING.

Source code in ontocast/tool/facts_validation/term_verdict.py
class TermVerdict(BaseModel):
    """A term judged unacceptable.

    Attributes:
        kind: The reason.
        term: The IRI judged.
        vocabulary_title: The well-known vocabulary's name, for
            ``WELL_KNOWN_MISSING``.
    """

    kind: TermVerdictKind
    term: str
    vocabulary_title: str | None = None

Attributes

kind instance-attribute
term instance-attribute
vocabulary_title = None class-attribute instance-attribute

TermVerdictKind

Bases: StrEnum

Why a term is not acceptable.

Source code in ontocast/tool/facts_validation/term_verdict.py
class TermVerdictKind(StrEnum):
    """Why a term is not acceptable."""

    PLACEHOLDER_NAMESPACE = "placeholder_namespace"
    WELL_KNOWN_MISSING = "well_known_missing"
    CLOSED_NAMESPACE_MISSING = "closed_namespace_missing"
    NON_CATALOG_STRICT = "non_catalog_strict"

Attributes

CLOSED_NAMESPACE_MISSING = 'closed_namespace_missing' class-attribute instance-attribute
NON_CATALOG_STRICT = 'non_catalog_strict' class-attribute instance-attribute
PLACEHOLDER_NAMESPACE = 'placeholder_namespace' class-attribute instance-attribute
WELL_KNOWN_MISSING = 'well_known_missing' class-attribute instance-attribute

Functions:

term_verdict(text, *, catalog_terms, known_terms, fallback_terms, declared_namespaces, catalog_namespaces, standard_namespaces, vocabulary)

Judge one predicate or class IRI against the catalog.

Placeholder namespaces are rejected first. A catalog, known or fallback term passes, and so does a term of a well-known vocabulary that has it. A term the vocabulary lacks is rejected even with an empty catalog; the remaining verdicts need a catalog and leave standard namespaces alone.

Parameters:

Name Type Description Default
text str

The IRI.

required
catalog_terms Set[str]

Terms of the retrieved catalog.

required
known_terms Set[str]

Terms of the whole catalog.

required
fallback_terms Set[str]

Sanctioned fallback vocabulary that always passes.

required
declared_namespaces Set[str]

Namespaces the catalog closes.

required
catalog_namespaces Set[str]

Namespaces the catalog declares or borrows from.

required
standard_namespaces tuple[str, ...]

Namespace prefixes of standard vocabularies.

required
vocabulary Literal['strict', 'open']

strict closes every namespace outside the catalog's.

required

Returns:

Type Description
TermVerdict | None

The verdict, or None when the term is acceptable.

Source code in ontocast/tool/facts_validation/term_verdict.py
def term_verdict(
    text: str,
    *,
    catalog_terms: AbstractSet[str],
    known_terms: AbstractSet[str],
    fallback_terms: AbstractSet[str],
    declared_namespaces: AbstractSet[str],
    catalog_namespaces: AbstractSet[str],
    standard_namespaces: tuple[str, ...],
    vocabulary: Literal["strict", "open"],
) -> TermVerdict | None:
    """Judge one predicate or class IRI against the catalog.

    Placeholder namespaces are rejected first. A catalog, known or fallback
    term passes, and so does a term of a well-known vocabulary that has it.
    A term the vocabulary lacks is rejected even with an empty catalog; the
    remaining verdicts need a catalog and leave standard namespaces alone.

    Args:
        text: The IRI.
        catalog_terms: Terms of the retrieved catalog.
        known_terms: Terms of the whole catalog.
        fallback_terms: Sanctioned fallback vocabulary that always passes.
        declared_namespaces: Namespaces the catalog closes.
        catalog_namespaces: Namespaces the catalog declares or borrows from.
        standard_namespaces: Namespace prefixes of standard vocabularies.
        vocabulary: ``strict`` closes every namespace outside the catalog's.

    Returns:
        The verdict, or ``None`` when the term is acceptable.
    """
    if text.startswith(_FORBIDDEN_NAMESPACES):
        return TermVerdict(kind=TermVerdictKind.PLACEHOLDER_NAMESPACE, term=text)
    if text in catalog_terms or text in known_terms or text in fallback_terms:
        return None
    known_vocabulary = well_known_vocabulary(text)
    if known_vocabulary is not None and not known_vocabulary.has_term(
        _local_name(text)
    ):
        return TermVerdict(
            kind=TermVerdictKind.WELL_KNOWN_MISSING,
            term=text,
            vocabulary_title=known_vocabulary.title,
        )
    namespace = _namespace_of(text)
    if not catalog_terms or namespace.startswith(standard_namespaces):
        return None
    if namespace in declared_namespaces:
        return TermVerdict(kind=TermVerdictKind.CLOSED_NAMESPACE_MISSING, term=text)
    if vocabulary == "strict" and namespace not in catalog_namespaces:
        return TermVerdict(kind=TermVerdictKind.NON_CATALOG_STRICT, term=text)
    return None