【问题标题】:How can I extract all phrases from a sentence?如何从一个句子中提取所有短语?
【发布时间】:2019-11-24 17:54:27
【问题描述】:

我想从一个句子中提取所有可能的有意义的短语 例如: “当地餐厅的食物很棒,餐厅非常浪漫。” 我想要: 食物很棒 当地餐厅的食物很棒 餐厅非常浪漫 等等

我不介意是否会出现一些额外的短语,因为我计划使用 Vader 情绪分析来删除中性短语。另一种对我有用的方法是,如果有一种方法可以提取关键字周围的短语,那么我可以使用 python rake 来获取关键字

这是一个为我们收集的 UGC 评论提取所有可能的正面和负面短语的项目,我们最初的方法是使用正则表达式模式来提取短语,然后将它们传递给 Vader 以获取情绪,但这省略了很多短语,现在我们正在尝试筛选出带有情绪的句子,然后从中提取短语,

【问题讨论】:

    标签: python nlp spacy


    【解决方案1】:

    你可能会做a constituency parse的句子并逐渐删除短语。

    可以使用Berkeley Neural Parser 将 11 种语言的选区解析添加到 spacy。

    这是来自 github 的 sn-p:

    >>> import spacy
    >>> from benepar.spacy_plugin import BeneparComponent
    >>> nlp = spacy.load('en')
    >>> nlp.add_pipe(BeneparComponent("benepar_en2"))
    >>> doc = nlp(u"The time for action is now. It's never too late to do something.")
    >>> sent = list(doc.sents)[0]
    >>> print(sent._.parse_string)
    (S (NP (NP (DT The) (NN time)) (PP (IN for) (NP (NN action)))) (VP (VBZ is) (ADVP (RB now))) (. .))
    >>> sent._.labels
    ('S',)
    >>> list(sent._.children)[0]
    The time for action
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-27
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多