【发布时间】:2014-02-18 23:21:51
【问题描述】:
假设我有一个序列:
Seq = 'hello my name'
还有一个字符串:
Str = 'hello hello my friend, my awesome name is John, oh my god!'
然后我在字符串中查找我的序列的匹配项,因此我为单元格数组中序列的每个单词获取每个匹配项的“单词”索引,因此第一个元素是包含匹配项的单元格hello',第二个元素包含匹配 'my' 和第三个匹配 'name'。
Match = {[1 2]; %'hello' matches
[3 5 11]; %'my' matches
[7]} %'name' matches
我需要代码以某种方式得到一个答案,说明可能的子序列匹配是:
Answer = [1 3 7; %[hello my name]
1 5 7; %[hello my name]
2 3 7; %[hello my name]
2 5 7;] %[hello my name]
以这样一种方式,“答案”包含所有可能的有序序列(这就是为什么 my(word 11) 永远不会出现在“答案”中,位置 11 之后必须有一个“名称”匹配。
注意:“Seq”的长度和匹配数可能会有所不同。
【问题讨论】:
标签: matlab word sequence distance