idnameraj commited on
Commit
24a8675
·
verified ·
1 Parent(s): b543594

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
@@ -462,7 +462,44 @@ def _polish_headword_upgrade(synset, source_lemma: str, cand_lemma: str) -> bool
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(
@@ -499,10 +536,25 @@ def _pick_verb_candidate(
499
  for synset in ordered:
500
  score = _sense_score(synset, context, stop_words)
501
  picked = _candidate_for_synset(synset, token, doc)
 
 
 
 
 
 
 
 
 
 
 
502
  if not picked:
503
  continue
504
  replacement, simplicity_gain = picked
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
@@ -519,7 +571,7 @@ def _pick_verb_candidate(
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:
 
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 <= 4 and 2 <= len(lemmas) <= 5
466
+
467
+
468
+ def _headword_candidate_for_synset(synset, token, doc) -> tuple[str, float] | None:
469
+ """Try the synset headword directly for polish-only verb upgrades."""
470
+ lemmas = _synset_single_word_lemmas(synset)
471
+ if not lemmas:
472
+ return None
473
+ head = lemmas[0]
474
+ replacement = _inflect(head, token)
475
+ if not replacement or replacement.lower() == token.text.lower():
476
+ return None
477
+ source = token.lemma_.lower()
478
+ source_surface = token.text.lower()
479
+ source_frequency = max(
480
+ zipf_frequency(source, "en"),
481
+ zipf_frequency(source_surface, "en"),
482
+ )
483
+ left, right = _neighbor_words(doc, token)
484
+ source_phrase = _phrase_zipf(source_surface, left, right)
485
+ if not _collocation_ok(
486
+ source,
487
+ head,
488
+ token,
489
+ left=left,
490
+ right=right,
491
+ ):
492
+ return None
493
+ candidate_frequency = zipf_frequency(head, "en")
494
+ rank_frequency = zipf_frequency(replacement.lower(), "en")
495
+ if not _frequency_ok(source_frequency, max(candidate_frequency, rank_frequency)):
496
+ return None
497
+ phrase = _phrase_zipf(replacement.lower(), left, right)
498
+ if phrase + 0.55 < source_phrase:
499
+ return None
500
+ if not substitution_pos_stable(doc.text, token.i, replacement):
501
+ return None
502
+ return replacement, max(candidate_frequency, rank_frequency) - source_frequency
503
 
504
 
505
  def _pick_verb_candidate(
 
536
  for synset in ordered:
537
  score = _sense_score(synset, context, stop_words)
538
  picked = _candidate_for_synset(synset, token, doc)
539
+ headword_polish = False
540
+ if (
541
+ polish
542
+ and not aggressive
543
+ and score < weak_gloss
544
+ and _source_lemma_rank(synset, src_lemma) >= 1
545
+ ):
546
+ headword_pick = _headword_candidate_for_synset(synset, token, doc)
547
+ if headword_pick is not None:
548
+ picked = headword_pick
549
+ headword_polish = True
550
  if not picked:
551
  continue
552
  replacement, simplicity_gain = picked
553
+ if (
554
+ score < effective_min
555
+ and simplicity_gain < gain_floor
556
+ and not headword_polish
557
+ ):
558
  continue
559
  cand_lemma = _candidate_lemma_for_replacement(synset, token, replacement)
560
  high_gain_ok = False
 
571
  # the source is a secondary lemma. Aggressive/ensure stay stricter.
572
  high_gain_ok = (
573
  polish
574
+ and simplicity_gain >= 0.08
575
  and _polish_headword_upgrade(synset, src_lemma, cand_lemma)
576
  )
577
  if not unglossed_ok and not high_gain_ok: