Ejemplo n.º 1
0
            public static TemplateCluster ParseTemplate(string template)
            {
                TemplateCluster cluster = new TemplateCluster(template);

                TemplatePhrase currentPhrase = new TemplatePhrase();

                int  startIndex       = 0;
                bool indexOnSeparator = true;

                for (int i = 0; i <= template.Length; i++)
                {
                    if (i == template.Length || separators.Contains(template[i]) || phraseSeparators.Contains(template[i]))
                    {
                        if (!indexOnSeparator)
                        {
                            currentPhrase.AddWord(new TemplateWord(template, startIndex, i - startIndex));
                            if (i == template.Length || (phraseSeparators.Contains(template[i]) && currentPhrase.WordCount() > 0))
                            {
                                cluster.AddPhrase(currentPhrase);
                                currentPhrase = new TemplatePhrase();
                            }
                        }

                        startIndex       = i;
                        indexOnSeparator = true;
                    }
                    else
                    {
                        if (indexOnSeparator)
                        {
                            indexOnSeparator = false;
                            startIndex       = i;
                        }
                    }
                }

                return(cluster);
            }
Ejemplo n.º 2
0
 public void AddPhrase(TemplatePhrase phrase)
 {
     phrases.Add(phrase);
 }