使用nltk从文本中提取动作/任务

你好,我第一次使用nltk,我想使用nltk从文本中提取动作/任务

Hi prakash, how are you ?. We need to complete the speech to action by 8 June  then you will have to finish the UI by 15 july

上面提到的语音转动作用户界面是动作。

我已经开始创建令牌,不知道接下来该做什么,请指导。

from nltk import sent_tokenizesample_text ="""Hi prakash, how are you ?. We need to complete the speech to action demo by 8 June  then you will have to finish the Ui by 15 july"""sentences = sent_tokenize(sample_text)print(sentences)    import nltkfrom nltk.tag import pos_tagfrom nltk.tokenize import word_tokenizesample_text = """Hi prakash, how are you ?. We need to complete the speech to action by todaythen you will have to finish the UI by 15 july after that you may go finish the mobile view"""sample_text = "need to complete the speech to action by today"tokens = word_tokenize(sample_text.lower())# the lower is very much required, as June and june have diffrent code NN, NNPpos_tags = pos_tag(tokens)result = []for i in range(len(tokens)):    if (pos_tags[i][1] == 'VB') and (pos_tags[i][0] in ['complete','finish']):        # Here we are looking for text like (finish, complete, done)        owner = ''        for back_tag in  pos_tags[:i][::-1]:            #traverse in back direction to know the owner who will (finish, complete, done)            if back_tag[1]=='PRP':                owner = back_tag[0]                break        message = ''        date = ''        for messae_index , token in enumerate(pos_tags[i:],i):            #traverse forward to know what has to be done            if token[1]=='IN':                for date_index, date_lookup in  enumerate(pos_tags[messae_index:],messae_index):                    if date_lookup[1]=='NN':                        date = pos_tags[date_index-1][0] + ' ' + pos_tags[date_index][0]                    if date_lookup[1]=='PRP':                        # This is trick to stop further propegation                        # Don't ask me why i am doing this, if you are still reading then read the nest line                        # Save futher interation as the next sentance is i/we/you                        break                break            else:                message = message + ' ' + token[0]        result += [dict(owner=owner, message=message, date=date)]print(result)

请指导如何从段落中提取动作(动作演示、用户界面)。


回答:

如果你使用NLTK,你可以获取令牌的POS标签,并使用这些标签创建一个正则表达式或模式。例如,动作将是一个动词。(为了获得更好的标记,你可能需要Spacy。还有另一个名为Pattern的库可用于这些目的)

但我不确定这是否对大规模应用有很大帮助。

注意:有经过良好训练的命名实体识别器可用,你可以尝试使用它们。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注