data: expand Friends expressions to 611 (337 curated-verified + 274 corpus-mined phrasal verbs, with real counts)
This commit is contained in:
+103
-3
@@ -414,7 +414,7 @@ def strip_tags(s: str) -> str:
|
||||
return html.unescape(s).replace("\u2019", "'").replace("\u2018", "'")
|
||||
|
||||
|
||||
def load_corpus() -> str:
|
||||
def load_corpus() -> list[str]:
|
||||
parts = []
|
||||
for f in glob.glob(str(CORPUS / "season" / "*.html")):
|
||||
t = strip_tags(Path(f).read_text(encoding="latin-1"))
|
||||
@@ -428,7 +428,98 @@ def load_corpus() -> str:
|
||||
line = re.sub(r"\s+", " ", line).strip()
|
||||
if line:
|
||||
parts.append(line)
|
||||
return "\n".join(parts).lower()
|
||||
return [p.lower() for p in parts]
|
||||
|
||||
|
||||
# ---- 挖掘:短语动词(词频驱动,非人工清单) ----
|
||||
VERBS = set("""get go come take give make put look hold hang turn keep figure freak check end find
|
||||
feel work point run show bring break call cut drop fall pick pull push set shut sit stand stay stick
|
||||
throw try wake watch wear write pass pay play move mess screw blow calm carry cheer clean close count
|
||||
deal eat fix follow grow hand head help hit knock lay leave let lie light meet mix open pack read ride
|
||||
ring roll rush save see sell send sign slow sort speak split start step stop switch talk tear tell think
|
||||
tie touch use wait walk warm wash
|
||||
act add agree allow answer appear argue arrive ask avoid bear beat beg behave believe belong bend bet
|
||||
bind bite blame block boil book bother bother bounce bow breathe brush burn burst bury buy cancel care
|
||||
cast catch cause chase chat cheat chew chop claim clear climb cling collect combine compare complain
|
||||
complete concentrate confess confirm confuse connect consider consist contain continue convince cook
|
||||
cool cope copy correct cost cough cover crash crawl create cross cry cure curl damage dance dare decide
|
||||
declare defend delay deliver demand deny depend describe deserve design destroy develop die dig direct
|
||||
disagree disappear discover discuss divide doubt drag draw dream dress drink drive dry dump earn employ
|
||||
encourage enjoy enter escape examine exchange excuse exercise exist expand expect explain explode explore
|
||||
express extend face fail fancy fasten fear fetch fight fill fit flash flee float flow fly fold force
|
||||
forget forgive form freeze gain gather glance grab greet guess guide handle happen harm hate heal heat
|
||||
hesitate hide hire hop hope hug hunt hurry hurt ignore imagine impress improve include increase influence
|
||||
inform insist inspire install intend interrupt introduce invent invite involve join joke judge jump kick
|
||||
kiss kneel land last laugh launch lead leak lean leap learn lend lift limit link list live load lock
|
||||
lose love lower mark marry match matter measure melt mention mind miss notice obey observe obtain occur
|
||||
offer operate order organize owe own pack paint park perform permit persuade phone pick place plant
|
||||
please plug polish pour practice praise pray prefer prepare present preserve press pretend prevent print
|
||||
produce promise pronounce protect prove provide publish pull punch punish purchase pursue question quit
|
||||
race raise reach realize receive recognize recommend record recover reduce refer reflect refuse regret
|
||||
reject relax release rely remain remember remind remove repair repeat replace reply report represent
|
||||
request rescue research resist respect respond rest retire return reveal review reward rob rub ruin rule
|
||||
sail satisfy scare scatter schedule score scratch scream search secure seek seem select separate serve
|
||||
settle sew shake shape share shave shine shock shoot shout shove sigh sing sink skip sleep slide slip
|
||||
smell smoke solve sound spare spell spill spin spit spoil spot spread squeeze stare steal steer stir
|
||||
stretch strike struggle study stuff succeed suffer suggest suit supply support suppose surprise survive
|
||||
swallow swear sweep swim swing tap taste tease tempt test thank threaten tidy tip tolerate translate
|
||||
travel treat trick trip trust twist type understand unite vary visit volunteer vote wander warn waste
|
||||
wave weigh welcome whisper wipe wonder worry wrap yell""".split())
|
||||
PART = set("up out off on in down over away back through along around about across ahead apart aside forth forward together under".split())
|
||||
# 真正常接小品词的常见动词(精确,避免 book about 之类假阳性)
|
||||
COREV = set("""get go come take give make put look hold hang turn keep figure freak check end find
|
||||
feel work point run show bring break call cut drop fall pick pull push set shut sit stand stay stick
|
||||
throw try wake watch wear write pass pay play move mess screw blow calm carry cheer clean close count
|
||||
deal eat fix follow grow hand head help hit knock lay leave let lie light meet mix open pack read ride
|
||||
ring roll save see sell send sign slow sort speak split start step stop switch talk tear tell think
|
||||
tie touch use wait walk warm wash ask back beat catch draw dress jump join kick live pull settle shake
|
||||
step stick sweep throw""".split())
|
||||
PREP = set("with to of for from about on in into at".split())
|
||||
PRO = set("it that this him her them me you us one".split())
|
||||
# 挖掘假阳性(动词+介词的非固定搭配)手剔
|
||||
BLACK = {
|
||||
"back in", "back on", "back over", "deal about", "feel about", "find in", "hand up",
|
||||
"head on", "look under", "play in", "play on", "ring on", "see about", "see in",
|
||||
"set on", "sit in", "sit on", "stop on", "talk in", "think on", "walk over", "walk up",
|
||||
"walk in", "live in", "live on", "live together", "run down", "look in", "look down",
|
||||
"jump out", "jump up", "start out", "hand on", "head in", "head up", "head down",
|
||||
"go across", "work in",
|
||||
}
|
||||
|
||||
|
||||
def mine_phrasal(utts: list[str], names: set[str], pmi_min: float = 7.0):
|
||||
import math
|
||||
from collections import Counter
|
||||
c2, c3, cp = Counter(), Counter(), Counter()
|
||||
uni = Counter()
|
||||
toks = []
|
||||
for u in utts:
|
||||
t = re.findall(r"[a-z]+(?:'[a-z]+)?", u)
|
||||
toks.append(t)
|
||||
uni.update(t)
|
||||
N = sum(uni.values())
|
||||
|
||||
def pmi(g, n):
|
||||
den = 1.0
|
||||
for w in g.split():
|
||||
den *= uni[w] / N
|
||||
return math.log2((n / N) / den) if den > 0 else 0
|
||||
|
||||
for t in toks:
|
||||
for i in range(len(t) - 1):
|
||||
if t[i] in COREV and t[i+1] in PART:
|
||||
c2[f"{t[i]} {t[i+1]}"] += 1
|
||||
for i in range(len(t) - 2):
|
||||
if t[i] in COREV and t[i+1] in PART and t[i+2] in PREP:
|
||||
c3[f"{t[i]} {t[i+1]} {t[i+2]}"] += 1
|
||||
if t[i] in COREV and t[i+1] in PRO and t[i+2] in PART:
|
||||
cp[f"{t[i]} {t[i+1]} {t[i+2]}"] += 1
|
||||
out = {}
|
||||
for g, n in list(c2.items()) + list(c3.items()) + list(cp.items()):
|
||||
th = 4 if g.count(" ") == 1 else 3
|
||||
if n >= th and not any(w in names for w in g.split()):
|
||||
out[g] = max(n, out.get(g, 0))
|
||||
return out
|
||||
|
||||
|
||||
def main() -> int:
|
||||
@@ -438,7 +529,8 @@ def main() -> int:
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
|
||||
text = load_corpus()
|
||||
utts = load_corpus()
|
||||
text = "\n".join(utts)
|
||||
seed = []
|
||||
seen = set()
|
||||
for ln in SEED.strip().splitlines():
|
||||
@@ -458,6 +550,14 @@ def main() -> int:
|
||||
rows.append({"phrase": phrase, "fn": fn, "count": cnt})
|
||||
rows.sort(key=lambda r: (-r["count"], r["phrase"]))
|
||||
|
||||
# 挖掘短语动词(首词限于常见动词,故不会命中专名)
|
||||
mined = {g: n for g, n in mine_phrasal(utts, set()).items() if g not in BLACK}
|
||||
have = {r["phrase"] for r in rows}
|
||||
for g, n in sorted(mined.items(), key=lambda x: -x[1]):
|
||||
if g not in have:
|
||||
rows.append({"phrase": g, "fn": "短语动词", "count": n})
|
||||
rows.sort(key=lambda r: (-r["count"], r["phrase"]))
|
||||
|
||||
# 用 word 表推 level(取短语里最难的词)
|
||||
conn = langdb.connect()
|
||||
wl = {r["item"]: r["level"] for r in conn.execute(
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user