|
|
|
@@ -59,7 +59,7 @@ class FulltextQueryer: |
|
|
|
"", |
|
|
|
), |
|
|
|
(r"(^| )(what|who|how|which|where|why)('re|'s)? ", " "), |
|
|
|
(r"(^| )('s|'re|is|are|were|was|do|does|did|don't|doesn't|didn't|has|have|be|there|you|me|your|my|mine|just|please|may|i|should|would|wouldn't|will|won't|done|go|for|with|so|the|a|an|by|i'm|it's|he's|she's|they|they're|you're|as|by|on|in|at|up|out|down|of) ", " ") |
|
|
|
(r"(^| )('s|'re|is|are|were|was|do|does|did|don't|doesn't|didn't|has|have|be|there|you|me|your|my|mine|just|please|may|i|should|would|wouldn't|will|won't|done|go|for|with|so|the|a|an|by|i'm|it's|he's|she's|they|they're|you're|as|by|on|in|at|up|out|down|of|to|or|and|if) ", " ") |
|
|
|
] |
|
|
|
for r, p in patts: |
|
|
|
txt = re.sub(r, p, txt, flags=re.IGNORECASE) |
|
|
|
@@ -67,7 +67,7 @@ class FulltextQueryer: |
|
|
|
|
|
|
|
def question(self, txt, tbl="qa", min_match:float=0.6): |
|
|
|
txt = re.sub( |
|
|
|
r"[ :\r\n\t,,。??/`!!&\^%%()^\[\]]+", |
|
|
|
r"[ :|\r\n\t,,。??/`!!&^%%()\[\]{}<>]+", |
|
|
|
" ", |
|
|
|
rag_tokenizer.tradi2simp(rag_tokenizer.strQ2B(txt.lower())), |
|
|
|
).strip() |
|
|
|
@@ -81,16 +81,20 @@ class FulltextQueryer: |
|
|
|
tks_w = [(re.sub(r"[ \\\"'^]", "", tk), w) for tk, w in tks_w] |
|
|
|
tks_w = [(re.sub(r"^[a-z0-9]$", "", tk), w) for tk, w in tks_w if tk] |
|
|
|
tks_w = [(re.sub(r"^[\+-]", "", tk), w) for tk, w in tks_w if tk] |
|
|
|
tks_w = [(tk.strip(), w) for tk, w in tks_w if tk.strip()] |
|
|
|
syns = [] |
|
|
|
for tk, w in tks_w: |
|
|
|
syn = self.syn.lookup(tk) |
|
|
|
syn = rag_tokenizer.tokenize(" ".join(syn)).split() |
|
|
|
keywords.extend(syn) |
|
|
|
syn = ["\"{}\"^{:.4f}".format(s, w / 4.) for s in syn if s] |
|
|
|
syn = ["\"{}\"^{:.4f}".format(s, w / 4.) for s in syn if s.strip()] |
|
|
|
syns.append(" ".join(syn)) |
|
|
|
|
|
|
|
q = ["({}^{:.4f}".format(tk, w) + " {})".format(syn) for (tk, w), syn in zip(tks_w, syns) if tk and not re.match(r"[.^+\(\)-]", tk)] |
|
|
|
for i in range(1, len(tks_w)): |
|
|
|
left, right = tks_w[i - 1][0].strip(), tks_w[i][0].strip() |
|
|
|
if not left or not right: |
|
|
|
continue |
|
|
|
q.append( |
|
|
|
'"%s %s"^%.4f' |
|
|
|
% ( |