[英]Generating a list of all the longest common substrings and a list of variations
我試圖將常見的子字符串折疊到句子列表中,並僅介紹它們不同的區域。 因此,采取此:
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]
我正在尋找有關算法的幫助。 我認為這是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
將每個唯一的單詞映射到單個對象。 然后建立一個條件概率表(請參閱Markov鏈 ),以枚舉單詞在每個序列中跟隨多少次的計數。
有趣的是,很久以前我一直在考慮創建類似您的東西,直到我意識到這實際上是一種AI。 要考慮的因素太多:語法,語法,情況,錯誤等。但是,如果您輸入的內容總是固定不變,例如“請[A1 | A2 | ..] [B1 | B2 | ..]任何[C1 | C2 | ..]],那么也許一個簡單的Regex模式就可以做到:“ ^ Please \\ s *(?(don | t | do))\\ s *(?\\ w +)+ \\ s * \\ s *(?。)* $“。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.