ontometer_corpus.steps.term_coupling¶
Term-level coupling per ontology, from a re-parse of each file.
The parse phase keeps, per ontology, only the set of namespaces it references (referenced_namespaces / own_namespaces); it discards the individual terms to stay memory-bounded on very large files. A dependency ratio computed from those sets is therefore a namespace-breadth measure: FOAF counts once whether an ontology borrows one term from it or five hundred.
The term-level coupling ratio asks the finer question — of the domain terms an ontology actually uses, what fraction are borrowed from other vocabularies rather than its own — which is only answerable by re-reading each file. This script does that re-parse once and writes the per-ontology term tallies; consumers load that small table instead of re-parsing the corpus.
<corpus>/corpus.db (latest-version, parsed rows with their
namespace claims and parse_format), structural sidecars, and the raw files under
$ONTOMETER_STORE/objects/.
Runs after: ontometer-corpus process (parse and dedup phases).
Needs --store (or $ONTOMETER_STORE).
Keyed by raw-byte file_hash (the same key the structural sidecars use), so files with the same coarse class/property signature remain independently measured; join the result back to latest-version rows on file_hash.
Method, per ontology:
- Collect every distinct referenced term (URIRef) via the same parse path
that succeeded for this file in the parse phase (parse_format says which):
obo -> flat-file scan of logical-axiom lines
turtle / json-ld / nt -> rdflib
xml / stream_xml_cvt -> rdflib (RDF/XML)
owl_xml / owlready2 -> owlready2 (via the pipeline's try_owlready2)
- Bucket each term by namespace with ontometer_corpus.namespaces.iri_namespace
(OBO-prefix-aware: .../obo/GO_ , not the bare .../obo/), so buckets line
up exactly with the stored own_namespaces.
- A term is "external" if its namespace resolves to another ontology (or
outside the corpus) under the shared pick_home ownership rule; "domain"
if reference_kind does not identify its namespace as a representation
language, metadata/identifier, or malformed. The headline coupling ratio is
external-domain / total-domain, so language terms and citation metadata
are excluded from both sides.
- Each term is also classified by how the file uses it (logical, annotation,
declaration only; ontometer_corpus.usage). n_terms_logical and
n_ext_logical restrict the domain tallies to terms used logically, so
a vocabulary used only for metadata (Dublin Core on the header) does not
count as coupling while the same vocabulary used for modelling does.
Large files: a file above the 50 MB in-memory guard that the parse phase
streamed (parse_format stream_xml_cvt / stream_nt_cvt) is converted to
N-Triples with the same pyoxigraph reader and read line by line, so it
gets the same measurements. --only-failed re-reads just the files the
existing tables record as failed and splices them in.
OBO caveat: OBO cannot be converted to RDF by any tool available here
(pyoxigraph does not read OBO; owlready2 fails on these files), so OBO term
capture is limited to IDs appearing in logical-axiom lines (is_a,
relationship, intersection_of, union_of, disjoint_from, equivalent_to) plus
the ontology's own id: stanzas — it does not see IRIs buried in annotation
values the way the rdflib path does. OBO rows also leave
n_logical_statements empty, so they fall outside that comparison.
Usage
ontometer-corpus term-coupling --store /path/to/ontologies ontometer-corpus term-coupling --store /path/to/ontologies --limit 50 ontometer-corpus term-coupling --store /path/to/ontologies --only-failed --workers 3
Attributes¶
Classes¶
Functions:¶
build(paths, limit=None, workers=8, only_failed=False, timeout=_PER_FILE_TIMEOUT_S)
¶
Re-read every latest parsed file, or with only_failed just those the
existing term_coupling.parquet records as failed, replacing their rows
in both output tables.
Source code in ontometer_corpus/steps/term_coupling.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |
main(limit, workers, only_failed, timeout, paths)
¶
Term-level coupling per ontology. Needs the object store.