Skip to content

ontocast.tool.agg.match_common

Stateless helpers for RDF graph matching and evaluation.

collect_ontology_entities(triples)

URIRefs that are class/concept/schema nodes (s/o), not relation predicates.

Source code in ontocast/tool/agg/match_common.py
def collect_ontology_entities(
    triples: set[tuple[Node, Node, Node]],
) -> frozenset[URIRef]:
    """URIRefs that are class/concept/schema nodes (s/o), not relation predicates."""
    ontology_entities: set[URIRef] = set()
    for subject, predicate, obj in triples:
        if predicate == RDF.type and isinstance(obj, URIRef):
            ontology_entities.add(obj)
        elif predicate == RDFS.subClassOf:
            if isinstance(subject, URIRef):
                ontology_entities.add(subject)
            if isinstance(obj, URIRef):
                ontology_entities.add(obj)
        if isinstance(subject, URIRef) and _is_generic_vocab_entity(subject):
            ontology_entities.add(subject)
        if isinstance(obj, URIRef) and _is_generic_vocab_entity(obj):
            ontology_entities.add(obj)
    return frozenset(ontology_entities)