This is my attempt to create a machine translator from and to multiple natural languages. The method is based on formal (Chomsky) grammars and equivalency rules. The input sentence is parsed into a tree, an equivalent tree is constructed in the target language and traversed to yield the translated text. Currently, I am working on my native Serbian, and English. Future support may include Russian, Spanish and German.
Write the algorithm to search for palindromes with multiple words.
The grammar should be relaxed/ignored, or palindromes with more grammatical sense should be scored higher.
Focus on Serbian language.
The input to the algorithm:
list of words (non-nominal words) including all the word forms
the max palindrome length
The algorithm:
Make a trie out of the list of words
Make a trie out of the list of inverted words (e.g. abc -> cba)
Recursively walk both tries such that the same char is taken
if both tries are at wordEnd=bool nodes, an even count palindrome with two halves is found
if you can walk the prefix of one trie into another, an even count palindrome is found with center in midword
right before the recursive call, check if the char being advanced is the same letter in the word. If yes, a palindrome is found with center in midword
At the end perform grammar analysis on each palindrome and sort them by grammar compliance. Grammar compliance can be defined as number of grammar nodes found.
class trie_node
{
bool wordEnd;
map<char, trie_node*> children;
}
Write the algorithm to search for palindromes with multiple words.
The grammar should be relaxed/ignored, or palindromes with more grammatical sense should be scored higher.
Focus on Serbian language.
The input to the algorithm:
The algorithm: