Exemplo n.º 1
0
        private static Text SplitSentencesIntoWords(string[] sentences)
        {
            Text parsedText = new Text();

            char[] delimiterChars = { ' ', ',', ':', '\t' };
            foreach (var sent in sentences)
            {
                // split into words
                string[] words = sent.Split(delimiterChars);
                List<Word> listWords = words.Where(w => w != "")
                    .Select(word => new Word() { Item = word }).ToList();

                Sentence sentence = AddWordsToSentence(listWords);

                // sort words
                sentence.Words.Sort();
                parsedText.Add(sentence);
            }
            return parsedText;
        }
Exemplo n.º 2
0
        private void WriteDoc(XmlWriter writer, Text text)
        {
            // write xml document
            writer.WriteStartDocument(true);		//true						// <?xml version="1.0"?>
            writer.WriteStartElement(TextItems.text.ToString());			// <Text>

            // write sentences
            foreach (var sentence in text.Sentences)
            {
                writer.WriteStartElement(TextItems.sentence.ToString());	// <Sentence>

                // write words
                foreach (var word in sentence.Words)
                {
                    writer.WriteStartElement(TextItems.word.ToString());	// </Word>
                    writer.WriteString(word.Item);
                    writer.WriteEndElement();								// </Word>
                }
                writer.WriteEndElement();									// </Sentence>
            }
            writer.WriteEndElement();										// </Text>
            writer.Close();
        }