【问题标题】:Given a document, select a relevant snippet给定一个文档,选择一个相关的片段
【发布时间】:2011-02-19 05:37:33
【问题描述】:

当我在这里提出问题时,自动搜索返回的问题的工具提示给出了问题的前一小部分,但其中相当一部分没有给出任何对理解更有用的文本问题比标题。有没有人知道如何制作过滤器来剔除问题中无用的部分?

我的第一个想法是修剪任何仅包含某个列表中的单词的前导句子(例如,停用词,加上标题中的单词,加上与标签相关性非常弱的 SO 语料库中的单词,即无论标签如何,都同样可能出现在任何问题中)

【问题讨论】:

标签: statistics nlp text-processing heuristics


【解决方案1】:

自动文本摘要

听起来您对automatic text summarization 感兴趣。要对问题、涉及的问题和可用算法有一个很好的概述,请查看 Das 和 Martin 的论文 A Survey on Automatic Text Summarization (2007)。

简单算法

一个简单但相当有效的摘要算法是从原始文本中选择有限数量的句子,其中包含最频繁的内容词(即最频繁的句子不包括stop list 词)。

Summarizer(originalText, maxSummarySize):
   // start with the raw freqs, e.g. [(10,'the'), (3,'language'), (8,'code')...]
   wordFrequences = getWordCounts(originalText)
   // filter, e.g. [(3, 'language'), (8, 'code')...]
   contentWordFrequences = filtStopWords(wordFrequences)
   // sort by freq & drop counts, e.g. ['code', 'language'...]
   contentWordsSortbyFreq = sortByFreqThenDropFreq(contentWordFrequences)

   // Split Sentences
   sentences = getSentences(originalText)

   // Select up to maxSummarySize sentences
   setSummarySentences = {}
   foreach word in contentWordsSortbyFreq:
      firstMatchingSentence = search(sentences, word)
      setSummarySentences.add(firstMatchingSentence)
      if setSummarySentences.size() = maxSummarySize:
         break

   // construct summary out of select sentences, preserving original ordering
   summary = ""
   foreach sentence in sentences:
     if sentence in setSummarySentences:
        summary = summary + " " + sentence

   return summary

一些使用该算法进行汇总的开源包是:

Classifier4J (Java)

如果您使用的是 Java,则可以使用 Classifier4J 的模块 SimpleSummarizer

使用here的例子,假设原文是:

Classifier4J 是一个用于处理文本的 java 包。 Classifier4J 包括一个摘要器。 Summariser 允许对文本进行摘要。 Summariser 真的很酷。我不认为有任何其他的 java 总结。

如下面的sn-p所示,你可以轻松创建一个简单的一句话总结:

// Request a 1 sentence summary
String summary = summariser.summarise(longOriginalText, 1);

使用上面的算法,这将产生Classifier4J includes a summariser.

NClassifier (C#)

如果您使用 C#,则有一个 Classifier4J 到 C# 的端口,称为 NClassifier

Tristan Havelick 的 NLTK 总结器(Python)

Classifier4J 的摘要器的 Python 端口正在开发中,该端口使用 Python 的 Natural Language Toolkit (NLTK) 可用 here 构建。

【讨论】:

  • 不知道C#版本是否足够快,可以用于本站?
  • 算法非常简单,所以它确实应该足够快。它首先确定原始文本中最常见的内容词。然后它遍历它们并在包含每个单词的原始字符串中选择最早的句子。这一直持续到选择所需数量的 N 多个句子。
  • 我最近使用了这个算法,相信我用 C# 实现它真的很容易,而且效果很好。我需要在这里和那里进行一些设置,例如摆脱空白或返回键空间。这需要几次尝试。谢谢。
猜你喜欢
  • 2020-08-02
  • 1970-01-01
  • 1970-01-01
  • 2018-02-13
  • 2011-05-10
  • 2015-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多