あなたが提供したこの小さなテストデータのセットだけを考えると、私はこれを思いつきました:
def list = [[['o', 'g'], ['g', 'o']], [['o', 'g', 'o', 'd']], [['o', 'd']], [['t', 's', 'n', 'e', 'e', 'e', 'n', 'c', 's']], [['t', 's', 'n', 'e', 'e']], [['e', 'n', 'c', 's']]]
// For every combination of the lists
def result = list.combinations().collect { combination ->
// Join them into strings
combination*.join().with { stringcombo ->
// Then find every string in the list
stringcombo.findAll { word ->
// Which is not a substring of another string in the list
(stringcombo - word).every { it.indexOf( word ) == -1 }
}
}.permutations()*.join() // Then get every String permutation of these remaining strings
}.flatten().unique() // and get them into a single unique list
// And print them out
result.each {
println it
}
どちらが出力されますか:
ogodtsneeencs
tsneeencsogod
より多くのデータがなければ、それが正しいかどうかを判断するのは困難ですが、それはあなたにとって良い出発点になるかもしれません
編集
有効なトークンのすべての順列を返すように更新されました