Upload 89 files
Browse files
app/engine/__pycache__/lexical.cpython-311.pyc
CHANGED
|
Binary files a/app/engine/__pycache__/lexical.cpython-311.pyc and b/app/engine/__pycache__/lexical.cpython-311.pyc differ
|
|
|
app/engine/lexical.py
CHANGED
|
@@ -452,6 +452,19 @@ def _unglossed_verb_allowed(
|
|
| 452 |
return False
|
| 453 |
|
| 454 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
def _pick_verb_candidate(
|
| 456 |
token,
|
| 457 |
doc,
|
|
@@ -461,11 +474,20 @@ def _pick_verb_candidate(
|
|
| 461 |
*,
|
| 462 |
effective_min: float,
|
| 463 |
gain_floor: float,
|
|
|
|
|
|
|
| 464 |
) -> tuple[float, str, float, Any] | None:
|
| 465 |
"""Choose a verb synonym from a few top senses with collocational safety."""
|
| 466 |
obj = _object_lemma(token)
|
| 467 |
src_lemma = token.lemma_.lower()
|
| 468 |
weak_gloss = max(float(effective_min), 0.25)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
options: list[tuple[float, int, float, float, str, Any]] = []
|
| 470 |
ordered = sorted(
|
| 471 |
synsets[:6],
|
|
@@ -483,14 +505,25 @@ def _pick_verb_candidate(
|
|
| 483 |
if score < effective_min and simplicity_gain < gain_floor:
|
| 484 |
continue
|
| 485 |
cand_lemma = _candidate_lemma_for_replacement(synset, token, replacement)
|
| 486 |
-
|
| 487 |
-
synset,
|
| 488 |
-
source_lemma=src_lemma,
|
| 489 |
-
cand_lemma=cand_lemma,
|
| 490 |
-
stop_words=stop_words,
|
| 491 |
-
):
|
| 492 |
-
continue
|
| 493 |
if score < weak_gloss:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
multiword_parent = False
|
| 495 |
try:
|
| 496 |
for word in synset.words():
|
|
@@ -508,6 +541,20 @@ def _pick_verb_candidate(
|
|
| 508 |
# (blocks create→make results while allowing purchase→buy).
|
| 509 |
if obj and src_colloc >= 4.7 and score < weak_gloss and score < effective_min:
|
| 510 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
options.append(
|
| 512 |
(
|
| 513 |
score,
|
|
@@ -679,6 +726,8 @@ def refine_sentence(
|
|
| 679 |
stop_words,
|
| 680 |
effective_min=effective_min,
|
| 681 |
gain_floor=verb_gain_floor,
|
|
|
|
|
|
|
| 682 |
)
|
| 683 |
if not picked_verb:
|
| 684 |
continue
|
|
@@ -922,6 +971,7 @@ def _force_one_safe_swap(
|
|
| 922 |
stop_words,
|
| 923 |
effective_min=0.08,
|
| 924 |
gain_floor=0.30,
|
|
|
|
| 925 |
)
|
| 926 |
if not picked_verb:
|
| 927 |
continue
|
|
|
|
| 452 |
return False
|
| 453 |
|
| 454 |
|
| 455 |
+
def _polish_headword_upgrade(synset, source_lemma: str, cand_lemma: str) -> bool:
|
| 456 |
+
"""Polish-only: allow source→headword upgrades in small verb synsets.
|
| 457 |
+
|
| 458 |
+
Example: maintain→keep on keep/maintain/hold. Blocks identify→place where
|
| 459 |
+
the source is already the headword.
|
| 460 |
+
"""
|
| 461 |
+
lemmas = _synset_single_word_lemmas(synset)
|
| 462 |
+
if not lemmas or lemmas[0] != cand_lemma:
|
| 463 |
+
return False
|
| 464 |
+
source_rank = _source_lemma_rank(synset, source_lemma)
|
| 465 |
+
return 1 <= source_rank <= 2 and 2 <= len(lemmas) <= 4
|
| 466 |
+
|
| 467 |
+
|
| 468 |
def _pick_verb_candidate(
|
| 469 |
token,
|
| 470 |
doc,
|
|
|
|
| 474 |
*,
|
| 475 |
effective_min: float,
|
| 476 |
gain_floor: float,
|
| 477 |
+
polish: bool = False,
|
| 478 |
+
aggressive: bool = False,
|
| 479 |
) -> tuple[float, str, float, Any] | None:
|
| 480 |
"""Choose a verb synonym from a few top senses with collocational safety."""
|
| 481 |
obj = _object_lemma(token)
|
| 482 |
src_lemma = token.lemma_.lower()
|
| 483 |
weak_gloss = max(float(effective_min), 0.25)
|
| 484 |
+
# Prenominal/predicative participles often act like adjectives
|
| 485 |
+
# ("satisfying customer experience") — never trust unglossed verb senses.
|
| 486 |
+
adjectival_participle = token.tag_ == "VBG" and token.dep_ in {
|
| 487 |
+
"amod",
|
| 488 |
+
"acomp",
|
| 489 |
+
"oprd",
|
| 490 |
+
}
|
| 491 |
options: list[tuple[float, int, float, float, str, Any]] = []
|
| 492 |
ordered = sorted(
|
| 493 |
synsets[:6],
|
|
|
|
| 505 |
if score < effective_min and simplicity_gain < gain_floor:
|
| 506 |
continue
|
| 507 |
cand_lemma = _candidate_lemma_for_replacement(synset, token, replacement)
|
| 508 |
+
high_gain_ok = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
if score < weak_gloss:
|
| 510 |
+
if adjectival_participle:
|
| 511 |
+
continue
|
| 512 |
+
unglossed_ok = _unglossed_verb_allowed(
|
| 513 |
+
synset,
|
| 514 |
+
source_lemma=src_lemma,
|
| 515 |
+
cand_lemma=cand_lemma,
|
| 516 |
+
stop_words=stop_words,
|
| 517 |
+
)
|
| 518 |
+
# Polish may upgrade to the synset headword (maintain→keep) when
|
| 519 |
+
# the source is a secondary lemma. Aggressive/ensure stay stricter.
|
| 520 |
+
high_gain_ok = (
|
| 521 |
+
polish
|
| 522 |
+
and simplicity_gain >= 0.70
|
| 523 |
+
and _polish_headword_upgrade(synset, src_lemma, cand_lemma)
|
| 524 |
+
)
|
| 525 |
+
if not unglossed_ok and not high_gain_ok:
|
| 526 |
+
continue
|
| 527 |
multiword_parent = False
|
| 528 |
try:
|
| 529 |
for word in synset.words():
|
|
|
|
| 541 |
# (blocks create→make results while allowing purchase→buy).
|
| 542 |
if obj and src_colloc >= 4.7 and score < weak_gloss and score < effective_min:
|
| 543 |
continue
|
| 544 |
+
if (
|
| 545 |
+
score < weak_gloss
|
| 546 |
+
and polish
|
| 547 |
+
and high_gain_ok
|
| 548 |
+
and obj
|
| 549 |
+
and (
|
| 550 |
+
cand_colloc + 0.05 < src_colloc
|
| 551 |
+
# Large collocation jumps often mark a different sense
|
| 552 |
+
# (identify areas → name areas), while modest ones are OK
|
| 553 |
+
# (maintain attitude → keep attitude).
|
| 554 |
+
or (src_colloc >= 4.2 and cand_colloc - src_colloc >= 0.45)
|
| 555 |
+
)
|
| 556 |
+
):
|
| 557 |
+
continue
|
| 558 |
options.append(
|
| 559 |
(
|
| 560 |
score,
|
|
|
|
| 726 |
stop_words,
|
| 727 |
effective_min=effective_min,
|
| 728 |
gain_floor=verb_gain_floor,
|
| 729 |
+
polish=polish,
|
| 730 |
+
aggressive=aggressive,
|
| 731 |
)
|
| 732 |
if not picked_verb:
|
| 733 |
continue
|
|
|
|
| 971 |
stop_words,
|
| 972 |
effective_min=0.08,
|
| 973 |
gain_floor=0.30,
|
| 974 |
+
aggressive=True,
|
| 975 |
)
|
| 976 |
if not picked_verb:
|
| 977 |
continue
|