【问题标题】:Generating a list of all the longest common substrings and a list of variations生成所有最长公共子串的列表和变体列表
【发布时间】:2014-02-14 20:25:51
【问题描述】:

高级

我正在尝试折叠句子列表中的常见子字符串,并仅显示它们不同的区域。所以拿这个:

Please don't kick any of the cats
Please do kick any of the cats
Please don't kick any of the dogs
Please do kick any of the dogs
Please don't kick any of the garden snakes
Please do pet any of the garden snakes

然后返回:

Please [don't|do] [kick|pet] any of the [cats|dogs|garden snakes]

更多详情

  • 我一直在研究最长的公共子字符串算法,但这似乎只比较两个字符串。
  • 我只对比较字符串中的整个单词感兴趣。
  • 只想从左到右评估字符串。
  • 不常见子串的长度不会是相同的单词数(“cat” vs “garden snake”)

我正在寻求算法方面的帮助。我相信这是 LCS 问题的变体,我认为是对后缀树的某种处理。可以解释和实现的伪代码是理想的。

另一个例子

Please join thirteen of your friends at the Midnight Bash this Friday
Don't forget to join your friend John at the Midnight Bash tomorrow
Don't forget to join your friends John and Julie at the Midnight Bash tonight

变成:

[Please|Don't forget to]
join
[thirteen of your friends|your friend John|your friends John and Julie]
at the Midnight Bash
[this Friday|tomorrow|tonight]

也许这种方法

这种方法怎么样...

for an array of sentences
  loop with the remaining sentence
    find the "first common substring (FCS)"
    split the sentences on the FCS
    every unique phrase before the FCS is part of the set of uncommon phrases
    trim the sentence by the first uncommon phrase
  end loop

【问题讨论】:

  • ...你到底在问什么?
  • 已编辑以更清楚地了解我要求的内容......算法方面的帮助。

标签: c# algorithm set-theory longest-substring


【解决方案1】:

将每个唯一的单词映射到一个对象。然后构建一个条件概率表(参见Markov chains)来枚举单词跟随每个序列的次数。

【讨论】:

    【解决方案2】:

    有趣的是,我很久以前就一直在考虑创造像你这样的东西,直到我意识到这实际上是一种人工智能。需要考虑的因素太多:语法、句法、情况、错误等。但是如果您的输入总是固定的,例如“请 [A1|A2|..] [B1|B2|..] [C1 |C2|..]",那么也许一个简单的正则表达式模式就可以了:"^Please\s*(?(don't|do))\s*(?\w+)+\s*any of the\s *(?.)*$".

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多