2014-12-19 111 views
2

假设我有单词'buddy'根据另一个阵列的值拆分阵列

第一个数组将单词按音节打破,例如。 ['bud','dy']

第二个数组是由他们的唱片分手例如。 ['b','u','dd',y']

现在我的问题是表音文字'dd'应该是'd','d',因为在那里有一个音节突破,但是我想不出一种有效的方式来解析这两个数组并且打破唱片,这样它是['b','u','d','d',y']

这里是其他一些例子

字:车道

音节:['drive','way']

个表音文字:['d','r','i','ew','ay']

应为:['d','r','i','v','e','w','ay']

字:越来越

音节:['get','ting']

录音制品:['g','e','tt','i','ng']

应该是:['g','e','t','t','i','ng']

任何人都知道我可以做到这一点的方式?

+1

这不是关于JavaScript的实际。应该标记_natural语言处理_,_nlp_或相对的东西。对于像我这样的JS人来说,这仍然是一个有趣的问题。 – Leo 2014-12-19 02:35:21

+0

'每天'不包含音节'['drive','way']',你可能想要清理那个例子。解析这两个数组并打破唱片的低效率方法是什么? – adamdc78 2014-12-19 02:36:37

+0

这是因为我试图编写一个脚本来比较两个数组,并解决他们是否被分割 – Ardenexal 2014-12-19 02:37:14

回答

0

我会尝试这个[伪]

given i = 0, word = "" 
for phono in phonograms  //loop over all phonograms 
     word += phonograms[phono] //and try to assemble the current syllable 
     if word === syllable[i]     //we may have found a sullable 
      i++ 
      word = "" 
      continue 
     if not the syllable[i] starts with word //if not syllable starts with word, 
               //then we have a phono that 
               //breaks our rules 
      phonos = phonograms[phono].split("") //so let's split that into characters 
      for j in phonos 
       phonograms.splice(phono++, 0, phonos[j]) //and insert to 
                 //the list of phonograms 
      i++