簡體   English   中英

無意義的空間名詞

[英]Meaningless Spacy Nouns

我正在使用 Spacy 從句子中提取名詞。 這些句子在語法上很差,也可能包含一些拼寫錯誤。

這是我正在使用的代碼:

代碼

import spacy
import re

nlp = spacy.load("en_core_web_sm")

sentence= "HANDBRAKE - slow and fast (SFX)"
string= sentence.lower()
cleanString = re.sub('\W+',' ', string )
cleanString=cleanString.replace("_", " ")

doc= nlp(cleanString)

for token in doc:
    if token.pos_=="NOUN":
        print (token.text)
 

Output:

sfx

同樣對於句子“fast foward2”,我得到 Spacy 名詞為

foward2

這表明這些名詞有一些無意義的詞,如:sfx、foward2、ms、64x、bit、pwm、r、brailledisplayfastmovement等。

我只想保留包含有意義的單詞名詞的短語,例如 broom、ticker、pool、highway 等。

我已經嘗試過 Wordnet 來過濾 wordnet 和 spacy 之間的常用名詞,但它有點嚴格並且過濾了一些合理的名詞。 例如,它過濾諸如motorbike、whoosh、trolley、metal、suitcase、zip等名詞

因此,我正在尋找一種解決方案,在該解決方案中,我可以從我獲得的 spacy 名詞列表中過濾掉最明智的名詞。

看來您可以使用pyenchant

Enchant 用於檢查單詞的拼寫並建議對拼寫錯誤的單詞進行更正。 它可以使用許多流行的拼寫檢查包來執行此任務,包括 ispell、aspell 和 MySpell。 它在處理多種字典和多種語言方面非常靈活。

更多信息請訪問 Enchant 網站:

https://abiword.github.io/enchant/

樣品 Python 代碼:

import spacy, re
import enchant                        #pip install pyenchant

d = enchant.Dict("en_US")
nlp = spacy.load("en_core_web_sm")

sentence = "For example, it filters nouns like motorbike, whoosh, trolley, metal, suitcase, zip etc"
cleanString = re.sub('[\W_]+',' ', sentence.lower()) # Merging \W and _ into one regex

doc= nlp(cleanString)
for token in doc:
    if token.pos_=="NOUN" and d.check(token.text):
        print (token.text)
# => [example, nouns, motorbike, whoosh, trolley, metal, suitcase, zip]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM