我想在 python 中使用 NLP 找到所有表示时间的单词。在英语中也称为时序词。这包括像“晚上”、“早上”、“第一”、“5 点钟”等作品。我无法找到一种方法来做到这一点,而不必用英语列出每个时间顺序词。我需要这个英语到美国手语句子翻译器,它应该将英语句子转换为 ASL 句子的正确语法结构。在美国手语中,在大多数情况下,时间顺序词应该在句子的开头。
我在 spaCy 或 NLTK 上找不到任何适合我的东西,如果有人知道我错过的任何功能,请告诉我。这是我当前的代码:
import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
import string
import spacy
nltk.download('punkt', )
nltk.download('averaged_perceptron_tagger')
nlp = spacy.load('en_core_web_sm')
# nlp = spacy.load('en_core_web_lg') #takess longer to load but is a larger dictionary
sentences=["The big black cat stared at the small dog.",
"I didn't watch her brother in the evenings.",
"Which car did Jane buy?"]
doc = nlp(sentences[1])
# for word in doc
tokens_list = []
signs_list = []
for token in doc:
# remove auxilaries, punctuation, determiners, prepositions
if token.pos_ not in ['AUX', 'PUNCT'] and token.tag_ not in ['DT','IN']:
tokens_list.append([token.text, token.lemma_, token.pos_, token.tag_,])
signs_list.append(token.lemma_)
for sign in signs_list:
signs_list[signs_list.index(sign)] = sign.lower()
signs_list
if 'not' in signs_list:
ind = signs_list.index('not')
signs_list[ind], signs_list[ind+1] = signs_list[ind+1], signs_list[ind]
# not comes after the verb it negates in ASL
if 'i' in signs_list:
ind = signs_list.index('i')
signs_list[ind] = 'me'
# 'me' is used instead of 'i' in ASL
signs_list
你可以使用wordnet的知识库。它是一个有组织的单词数据库,分为同义词集 (synsets)。这些被组织成一个层次结构。例如,一天中的时间有一个高级同义词集,其中包括您要查找的词:http://wordnetweb.princeton.edu/perl/webwn?o2=&o0=1&o8=1&o1=1&o7=&o5=&o9 =&o6=&o3=&o4=&r=1&s=time+of+day&i=1&h=1000#c
您可以通过 nltk(或者 omw 或 wn 包)访问 wordnet:from nltk.corpus import wordnet.