Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/extraction/cue.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,15 @@
"не ни нет также тоже часто обычно ещё еще уже просто даже только очень довольно слишком крайне "
"как из в во на при для с со от до к ко по о об обо про за над под между через без "
"быть был была было были есть буду будет будут стал стала стало стали "
"может могут мочь можно нужно надо следует стоит".split()
"может могут мочь можно нужно надо следует стоит "
# Discourse connectives. These join clauses; they are never the head of the
# thing being reasoned about, and «поэтому система уменьшает вмешательство»
# produced a node called «поэтому система». English has the same hole
# (`therefore`, `hence` and `thus` are absent from this list too) but its
# gold never lands on it, so only the Cyrillic side is filled -- which is
# what keeps the English figures identical.
"поэтому следовательно иначе зато однако впрочем причём причем притом "
"кстати наконец ведь вот ну итак значит".split()
)
TRAILING_DROP = frozenset(
"too again also anyway though however as well over time at all in turn itself themselves him her them it "
Expand Down Expand Up @@ -628,6 +636,22 @@ def add_node(span: dict[str, object]) -> str | None:
abstentions.append(f"dropped node {nd['label']!r} below threshold")
kept_ids = {nid for nid, nd in nodes.items() if float(nd["extract_conf"]) >= self.drop_threshold}
relations = [r for r in relations if r["source"] in kept_ids and r["target"] in kept_ids]
# A relation whose one end says everything the other says and more is
# not a claim about two things -- it is one thing related to a sentence
# containing it. Unification by stem containment can produce these, and
# what a person reads is «Постоянная помощь --prevents--> Постоянная
# помощь мешает ребёнку научиться балансировать».
def _degenerate(rel: Mapping[str, Any]) -> bool:
src, dst = nodes.get(rel["source"]), nodes.get(rel["target"])
if src is None or dst is None:
return False
a = set(_stems(str(src["label"])))
b = set(_stems(str(dst["label"])))
return bool(a) and bool(b) and (a < b or b < a)
for rel in [r for r in relations if _degenerate(r)]:
abstentions.append(
f"one end of {rel['type']} restates the other; nothing is claimed")
relations = [r for r in relations if not _degenerate(r)]
node_list = [nd for nid, nd in nodes.items() if nid in kept_ids]
# node ids are derived from spans + role; recompute now that roles are final
rename: dict[str, str] = {}
Expand Down
40 changes: 40 additions & 0 deletions tests/test_russian_prose_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,46 @@ def test_a_real_causal_claim_in_the_same_document_still_reads(self):
self.assertEqual(got[0][1], "causes")


class ConnectivesAreNotThingsTests(unittest.TestCase):
"""Second round of the same complaint, from the same person, on the same card.

After «что» stopped becoming a node, «поэтому» started heading one:
«поэтому система --prevents--> вмешательство». A discourse connective joins
clauses; it is never the head of the thing being reasoned about.

English has the same hole — `therefore`, `hence` and `thus` are absent from
`LEADING_DROP` too — but its gold never lands on it, so only the Cyrillic
side is filled and the English figures stay identical.
"""

def test_a_connective_does_not_head_a_label(self):
text = ("Постоянная помощь мешает ребёнку научиться балансировать, "
"поэтому система постепенно уменьшает вмешательство.")
labels = [n["label"] for n in graph_of(text)["nodes"]]
for label in labels:
self.assertFalse(label.lower().startswith(("поэтому", "следовательно", "иначе", "однако")),
f"a connective headed a node label: {label!r}")

def test_a_relation_may_not_restate_one_end_in_the_other(self):
"""Unification by stem containment could relate a thing to a sentence
containing it, which a person read as «Постоянная помощь --prevents-->
Постоянная помощь мешает ребёнку научиться балансировать». Nothing is
claimed by that, so it is abstained rather than shown.

This one is not Cyrillic-scoped — it applies to both languages — and
the extraction gate is unchanged by it, so English never produced one.
"""
text = ("Постоянная помощь мешает ребёнку научиться балансировать, "
"поэтому система постепенно уменьшает вмешательство.")
d = graph_of(text)
by = {n["id"]: n["label"] for n in d["nodes"]}
from src.semantics import stems
for r in d["relations"]:
a, b = set(stems(by[r["source"]])), set(stems(by[r["target"]]))
self.assertFalse(a < b or b < a,
f"{by[r['source']]!r} --{r['type']}--> {by[r['target']]!r}")


class CyrillicSegmentationTests(unittest.TestCase):
def test_sentences_split_on_a_cyrillic_capital(self):
from src.extraction.cue import sentences
Expand Down