ontometer_corpus.metrics.abstractness¶
Abstractness of terms and ontologies, in two senses that are kept apart.
Generality (sense G) is taxonomic: how much of the world a class subsumes. It is read off a subsumption DAG — depth from the roots, and intrinsic information content (IC), which falls as a class gathers descendants.
Class-likeness (sense C) is terminological: whether a term is used as a class (it has instances or subclasses, it constrains a property) or as an instance (it is typed, it takes part in facts). Across many ontologies one IRI can play both roles, so the share of documents using it as a class is a continuous quantity rather than the TBox/ABox binary.
The two are different constructs — a leaf class is maximally specific yet wholly class-like — so nothing here blends them.
The ontology-level quantities transpose Martin's package metrics: instability
I = Ce / (Ca + Ce) from efferent and afferent specialisation couplings, and
the distance D = |A + I - 1| from the line on which stability and
abstractness balance.
The DAG routines work on integer node ids. A subsumption DAG merged across
many ontologies is large and has multiple inheritance; the naive
dynamic-programming count of descendants sums paths, which over-counts at
every diamond. :func:dag_closure counts exactly by propagating ancestor sets
in topological order, releasing each set once its last child has consumed it.
Needs the corpus extra (numpy, scipy).
Classes¶
DagClosure
dataclass
¶
Per-node closure statistics of a subsumption DAG.
Nodes in a cycle are collapsed to their strongly connected component and
share its values; cyclic marks them.
Source code in ontometer_corpus/metrics/abstractness.py
Attributes¶
depth_long
instance-attribute
¶
depth_short
instance-attribute
¶
n_anc
instance-attribute
¶
n_desc
instance-attribute
¶
n_leaves
instance-attribute
¶
is_leaf
instance-attribute
¶
cyclic
instance-attribute
¶
n_nodes
property
¶
Number of nodes in the DAG, including those collapsed into a cycle.
Methods:¶
__init__(depth_long, depth_short, n_anc, n_desc, n_leaves, is_leaf, cyclic)
¶
Functions:¶
dag_closure(n, child, parent)
¶
Exact closure counts for a subsumption graph over nodes 0..n-1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of nodes; ids must lie in |
required |
child
|
ndarray
|
Child id of each |
required |
parent
|
ndarray
|
Parent id of each edge. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
DagClosure
|
|
DagClosure
|
leaves at depth 0. |
Source code in ontometer_corpus/metrics/abstractness.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
encode_edges(edges)
¶
Map string (child, parent) edges to integer ids; self-loops dropped.
Returns:
| Type | Description |
|---|---|
tuple[list[str], ndarray, ndarray]
|
|
Source code in ontometer_corpus/metrics/abstractness.py
ic_seco(n_desc, n_nodes)
¶
Intrinsic IC after Seco et al. (2004): 1 - log(desc + 1) / log(N).
1 for a leaf, falling towards 0 for a class that subsumes everything.
Source code in ontometer_corpus/metrics/abstractness.py
ic_sanchez(n_leaves, n_anc)
¶
Intrinsic IC after Sánchez et al. (2011), normalised to [0, 1].
-log((leaves / subsumers + 1) / (max_leaves + 1)) divided by its
maximum log(max_leaves + 1). Subsumers include the class itself, which
lets two classes with the same leaves differ by how specialised they are.
Source code in ontometer_corpus/metrics/abstractness.py
role_share(df_class, df_inst)
¶
Share of the documents using a term that use it as a class.
NaN where the term is observed in neither role.
Source code in ontometer_corpus/metrics/abstractness.py
entropy(counts)
¶
Shannon entropy (nats) of a count vector; 0 for an empty one.
Source code in ontometer_corpus/metrics/abstractness.py
effective_number(counts)
¶
exp(H): how many equally used categories the spread amounts to.
martin_instability(ca, ce)
¶
I = Ce / (Ca + Ce); NaN for an ontology coupled in neither direction.
Ca (afferent) counts ontologies that specialise its classes, Ce
(efferent) the ontologies whose classes it specialises. 0 is maximally
stable — depended on, depending on nothing.
Source code in ontometer_corpus/metrics/abstractness.py
main_sequence_distance(abstractness, instability)
¶
D = |A + I - 1|, the distance from the main sequence.
Near 0, an ontology is as abstract as it is stable. Stable and concrete
(A and I both low) is the zone of pain: much depends on it and it
is hard to change. Abstract and unstable is the zone of uselessness:
general classes that nobody specialises.