예제 #1
0
        public Text Parse()
        {
            var text            = new Text();
            var sentence        = new Sentence();
            var word            = new Word();
            var punctuationMark = new PunctuationMark();

            string line = String.Empty;

            string[] splitted;

            try
            {
                while ((line += streamReader.ReadLine()) != null)
                {
                    sentence = GetSentence(line);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(text);
        }
예제 #2
0
        public void Separate(char currentSymbol)
        {
            if (PunctuationInSetnenceSetted == false && PunctuationSentenceFinisherSetted == false)
            {
                SetWord();
                InSentenseSeparator separator = new InSentenseSeparator(currentSymbol);
                SentenceBuffer.Add(separator);
            }

            if (PunctuationInSetnenceSetted == true)
            {
                PunctuationMark punctuationMark = new PunctuationMark(CharBuffer);
                CharBuffer.Clear();
                InSentenseSeparator separator = new InSentenseSeparator(currentSymbol);
                SentenceBuffer.Add(separator);
            }

            if (PunctuationSentenceFinisherSetted == true)
            {
                PunctuationMark punctuationMark = new PunctuationMark(CharBuffer);
                CharBuffer.Clear();
                PunctuationSentenceFinisherSetted = false;
                Sentence sentence = new Sentence(SentenceBuffer);
                ResultTextModel.Add(sentence);
                SentenceBuffer.Clear();
                SentenseSeparator separator = new SentenseSeparator(currentSymbol);
                ResultTextModel.Add(sentence);
            }
        }
예제 #3
0
        public ITextItem Create(List <Symbol> symbols, int pageNumber)
        {
            ITextItem textElement;

            if (!Separators.SentenceSeparators.Contains(symbols.Last().Value.ToString()) &&
                !Separators.InnerSentenceSeparators.Contains(symbols.Last().Value.ToString()))
            {
                textElement = new Word(symbols);
                ((Word)textElement).PageNumber = pageNumber;
            }
            else
            {
                if (Separators.InnerSentenceSeparators.Contains(symbols.Last().Value.ToString()) ||
                    Separators.SentenceSeparators.Contains(symbols.Last().Value.ToString()))
                {
                    textElement = new PunctuationMark(symbols);
                }
                else
                {
                    throw new Exception("Unknown data");
                }
            }

            return(textElement);
        }
예제 #4
0
        public IEnumerable <ISentence> GetSentences(PunctuationMark punctuationMark)
        {
            IEnumerable <ISentence> retVal = new List <ISentence>();

            foreach (Paragraph paragraph in _items)
            {
                retVal = retVal.Union(paragraph.Items.Where(item => item.GetEndSentence().Equals(punctuationMark)));
            }

            return(retVal);
        }
예제 #5
0
        public Sentence Create(List <ITextItem> elementsOfText)
        {
            Sentence sent;

            PunctuationMark punct = elementsOfText.Last() as PunctuationMark;

            if (punct != null && punct.SymbolEndOfSent)
            {
                sent = new Sentence(elementsOfText);
            }
            else
            {
                throw new Exception("Error in a sentece");
            }

            return(sent);
        }
예제 #6
0
 private static void SearchSeparator(string line, out int firstSentenceSeparatorOccurence, out PunctuationMark firstSentenceSeparator)
 {
     firstSentenceSeparatorOccurence = line.Length;
     firstSentenceSeparator          = default(PunctuationMark);
     for (int i = 0; i < PunctuationMarkContainer.AllMarks.Count; i++)
     {
         int a = line.IndexOf(PunctuationMarkContainer.AllMarks.ElementAt(i).Value);
         if (a >= 0 && firstSentenceSeparatorOccurence > a)
         {
             firstSentenceSeparatorOccurence = a;
             firstSentenceSeparator          = PunctuationMarkContainer.AllMarks.ElementAt(i);
         }
     }
 }
예제 #7
0
 public Punctuation(IEnumerable <char> item, PunctuationMark punctuationMark)
 {
     _items           = item.ToArray();
     _punctuationMark = punctuationMark;
 }
예제 #8
0
 public Punctuation(string item, PunctuationMark punctuationMark)
 {
     _items           = item.Select(x => x).ToArray();
     _punctuationMark = punctuationMark;
 }
예제 #9
0
 public bool TestCharacter(char c)
 {
     return(PunctuationMark.TestCharacter(c));
 }