Exemple #1
0
 internal void CopyTo(WordsCollection col, int index)
 {
     for (var i = index; i < List.Count; i++)
     {
         col.Add(this[i]);
     }
 }
Exemple #2
0
        private static WordsCollection Read(Stream stream)
        {
            using (var reader = new StreamReader(stream))
            {
                var list = new List <string>();

                while (true)
                {
                    var line = reader.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    var splitedWords = line.Split(';', ',');
                    list.AddRange(splitedWords.Select(word => word.Trim()));
                }

                var words = new WordsCollection
                {
                    Words = list.ToArray()
                };

                return(words);
            }
        }
Exemple #3
0
 /// <summary>
 /// Copy this WordsCollection to another one
 /// starting at the specified index position
 /// </summary>
 /// <param name="col" type="WordsCollection">
 /// WordsCollection to be copied to
 /// </param>
 /// <param name="index" type="integer">
 /// Starting index to begin copy operations
 /// </param>
 public void CopyTo(WordsCollection col, int index)
 {
     for (int i = index; i < List.Count; i++)
     {
         col.Add(this[i]);
     }
 }
Exemple #4
0
            /// <summary>
            /// Further processing of a string
            /// </summary>
            /// <param name="words">
            /// Collection that new word(s) will be added in
            /// </param>
            /// <param name="prefix">
            /// prefix come with the string
            /// </param>
            /// <param name="word">
            /// A string that may be a real word or have leading or tailing
            /// special character
            /// </param>
            /// <param name="suffix">
            /// suffix comes with the string.
            /// </param>
            private static void processWord(WordsCollection words,
                                            string prefix, string word, string suffix)
            {
                // the passed in word may have leading special
                // characters such as '(', '"' etc or tailing
                // punctuations. We need to sort this out.
                int length = word.Length;

                if (length == 1)
                {
                    words.Add(new Word(word, prefix, suffix));
                }
                else if (!char.IsLetterOrDigit(word[0]))
                {
                    // it is some kind of special character in the first place
                    // report it separately
                    words.Add(new Word(word[0].ToString(), prefix, ""));
                    words.Add(new Word(word.Substring(1), "", suffix));
                    return;
                }
                else if (char.IsPunctuation(word[length - 1]))
                {
                    // there is a end punctuation
                    words.Add(new Word(word.Substring(0, length - 1), prefix, ""));
                    words.Add(new Word(word[length - 1].ToString(), "", suffix));
                }
                else
                {
                    // it is a real word(hope so)
                    words.Add(new Word(word, prefix, suffix));
                }
            }
Exemple #5
0
        public void Get()
        {
            // The client code may or may not know about the Concrete Iterator
            // or Collection classes, depending on the level of indirection you
            // want to keep in your program.
            var collection = new WordsCollection();

            collection.AddItem("First");
            collection.AddItem("Second");
            collection.AddItem("Third");

            Console.WriteLine("Straight traversal:");

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }

            Console.WriteLine("\nReverse traversal:");

            collection.ReverseDirection();

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }
        }
        public static void Execute()
        {
            ConsoleExtension.WriteSeparator("Conceptual example");

            // The client code may or may not know about the concrete iterator  or collection classes,
            // depending on the level of indirection you want to keep in your program.
            var collection = new WordsCollection
            {
                "First",
                "Second",
                "Third"
            };

            Console.WriteLine("Straight traversal:");

            foreach (var item in collection)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nReverse traversal:");
            collection.ReverseDirection();

            foreach (var item in collection)
            {
                Console.WriteLine(item);
            }
        }
Exemple #7
0
            internal Merger(List <SegmentSection> original, List <SegmentSection> modified)
            {
                _original = TextParser.Parse(original);
                _modified = TextParser.Parse(modified);

                _fwdVector = new IntVector(_original.Count + _modified.Count + 2);
                _bwdVector = new IntVector(_original.Count + _modified.Count + 2);
            }
Exemple #8
0
 public AlphabeticalOrderIterator(WordsCollection collection, bool reverse = false)
 {
     this.collection = collection;
     this.reverse    = reverse;
     if (reverse)
     {
         position = collection.Collection.Count;
     }
 }
Exemple #9
0
 private string GetNextWord(WordsCollection words)
 {
     if (words.Count == 0)
     {
         Speaker speaker = new Speaker();
         speaker.Speak("Add Some Words", ApplicationContext);
         base.OnBackPressed();
     }
     return(words.getWord());
 }
Exemple #10
0
        public AlphabeticalOrderIterator(WordsCollection collection, bool reverse = false)
        {
            this._collection = collection;
            this._reverse    = reverse;

            if (reverse)
            {
                _position = collection.getItems().Count;
            }
        }
Exemple #11
0
        public AlphabeticalOrderIterator(WordsCollection collection, bool isDirectionReversed = false)
        {
            _collection          = collection;
            _isDirectionReversed = isDirectionReversed;

            if (isDirectionReversed)
            {
                _position = collection.Count;
            }
        }
 public void ShouldReturnTheOnlyInputedWordAndCalculateItsPercantageWeight()
 {
     var kek = new Word("KEK") {Weight = 100500};
     var wc = new WordsCollection(new [] {kek});
     var coll = wc.ToArray();
     Assert.AreEqual(1, coll.Length);
     Assert.AreSame(kek, coll.First());
     Assert.AreEqual(1.00, kek.PercantageWeight);
     Assert.AreEqual(100500, kek.Weight);
 }
        public AlphabeticalOrderIterator(WordsCollection collection, bool reserve = false)
        {
            _collection = collection;
            _reserve    = reserve;

            if (reserve)
            {
                _position = collection.GetItems().Count - 1;
            }
        }
Exemple #14
0
 public Lexico()
 {
     c      = ' ';
     estado = 0;
     indice = -1;
     //tipo = string.Empty;
     simbolo   = new WordsCollection();
     idSimbolo = 1;
     idLinea   = 1;
 }
 public void ShouldSortAndCalculatePercantageWeight()
 {
     var word1 = new Word("KEK") { Weight = 20 };
     var word2 = new Word("LOL") { Weight = 10 };
     var wc = new WordsCollection(new[] { word2, word1 });
     var coll = wc.ToArray();
     Assert.AreEqual(2, coll.Length);
     Assert.AreSame(word1, coll.First());
     Assert.AreSame(word2, coll.Last());
     Assert.AreEqual(1.00, word1.PercantageWeight);
     Assert.AreEqual(0.50, word2.PercantageWeight);
 }
        //TODO: use nhibernate join
        private async void LoadWordsCollection(NHibernate.Criterion.ICriterion expression = null)
        {
            var allWords = new List <Word>();

            WordsCollection.Clear();
            var collection = await WordsService.GetDataAsync <Word>(expression);

            if (collection != null)
            {
                foreach (var item in collection)
                {
                    if (!allWords.Exists(x => x.Id == item.Id))
                    {
                        allWords.Add(item);
                    }
                }
            }
            foreach (var item in allWords)
            {
                WordsCollection.Add(new WordViewModel {
                    WordToDisplay = item
                });
            }
            var alreadyAdded = allWords.Count;

            //only in case of searching it does matter
            if (expression != null)
            {
                var collection2 = await WordsService.GetDataAsync <Translation>(expression);

                if (collection2 != null)
                {
                    foreach (var item in collection2)
                    {
                        foreach (var w in item.WordsStoredIn)
                        {
                            if (!allWords.Exists(x => x.Id == w.Id))
                            {
                                allWords.Add(w);
                            }
                        }
                    }
                }
            }

            foreach (var item in allWords.Skip(alreadyAdded))
            {
                WordsCollection.Add(new WordViewModel {
                    WordToDisplay = item
                });
            }
            allWords = null;
        }
Exemple #17
0
        static void Main(string[] args)
        {
            long before = GC.GetTotalMemory(false);

            WordsCollection.InitializeWordsCollection();
            var  worker = new TelegramWorkerService(new Logger.Logger());
            long after  = GC.GetTotalMemory(false);
            long consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Memory consumed in megabytes : {consumedInMegabytes}");
            worker.ExecuteCore();
        }
        public static void DrawCloud(WordsCollection words, CloudBuilder cloudBuilder, WordRenderer renderer, RenderTarget target)
        {
            if (words == null)
                throw new ArgumentNullException(nameof(words));
            if (cloudBuilder == null)
                throw new ArgumentNullException(nameof(cloudBuilder));
            if (renderer == null)
                throw new ArgumentNullException(nameof(renderer));

            target.Render(g =>
                renderer.Render(cloudBuilder(words, renderer, g), g)
                );
        }
Exemple #19
0
        public Merger(string original, string modified)
        {
            // parse the passed in string to words
            // collections
            _original = HtmlTextParser.parse(original);
            _modified = HtmlTextParser.parse(modified);

            // for hold the forward searching front-line
            // in previous searching loop
            fwdVector = new IntVector(_original.Count + _modified.Count);

            // for hold the backward searching front-line
            // in the previous seaching loop
            bwdVector = new IntVector(_original.Count + _modified.Count);
        }
Exemple #20
0
        public Merger(string original, string modified)
        {
            // parse the passed in string to words
            // collections
            _original = HtmlTextParser.parse(original);
            _modified = HtmlTextParser.parse(modified);

            // for hold the forward searching front-line
            // in previous searching loop
            fwdVector = new IntVector(_original.Count + _modified.Count);

            // for hold the backward searching front-line
            // in the previous seaching loop
            bwdVector = new IntVector(_original.Count + _modified.Count);
        }
Exemple #21
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Test);

            words = new WordsCollection(WordsFileHandler.GetWordsList());

            curWord = GetNextWord(words);

            nextButton        = FindViewById <Button>(Resource.Id.nextWordBtn);
            nextButton.Text   = "First Word";
            nextButton.Click += NextButtonClick;

            repeatButton        = FindViewById <Button>(Resource.Id.repeatWordBtn);
            repeatButton.Click += RepeatButtonClick;

            quitButton        = FindViewById <Button>(Resource.Id.quitBtn);
            quitButton.Click += QuitButtonClick;
        }
        private void RemoveWord(object o)
        {
            var word = o as WordViewModel;

            if (word == null)
            {
                return;
            }

            var r = ModernDialog.ShowMessage("do you really want to remove word?", "word removing", MessageBoxButton.YesNo);

            if (r == MessageBoxResult.No)
            {
                return;
            }

            WordsService.Remove <Word>(word.WordToDisplay);

            WordsCollection.Remove(word);
        }
Exemple #23
0
        public static List <string> GetNumbersWithNounDeclension(string noun)
        {
            var result            = new List <string>();
            var singularNounCases = WordsCollection.GetNounSingularCases(noun);
            var pluralNounCases   = WordsCollection.GetNounPluralCases(noun);

            for (var i = 0; i < NumbersDeclension.Count; i++)
            {
                var ending = GetEnding(i);
                var cases  = i > 0 ? pluralNounCases : singularNounCases;
                result.Add($"{NumbersDeclension[i].NominativeCase} {noun}{ending}");
                result.Add($"{NumbersDeclension[i].GenitiveCase} {cases.GenitiveCase}");
                result.Add($"{NumbersDeclension[i].DativeCase} {cases.DativeCase}");
                result.Add($"{NumbersDeclension[i].AccusativeCase} {noun}{ending}");
                result.Add($"{NumbersDeclension[i].InstrumentalCase} {cases.InstrumentalCase}");
                result.Add($"{NumbersDeclension[i].PrepositionalCase} {cases.PrepositionalCase}");
            }

            return(result.Distinct().ToList());
        }
Exemple #24
0
        static void Main(string[] args)
        {
            WordsCollection wordsCollection = new WordsCollection();

            try
            {
                StreamReader sr=new StreamReader(_pathIn);
                while (!sr.EndOfStream)
                {
                    wordsCollection.Add(new WordsLine(LineBuilder.StringSplit(sr.ReadLine(), _seperator)));
                }
                sr.Close();

                try
                {
                    StreamWriter sw = new StreamWriter(_pathOut);
                    foreach (var i in wordsCollection.GetSingleOrderWords())
                    {
                        sw.WriteLine("[{0}] ", i.Key);
                        foreach (var j in i)
                        {
                             sw.WriteLine("{0} - {1} - {2}",
                            j,
                            wordsCollection.GetWordsLinesCount(j),
                            String.Join(",", wordsCollection.GetPositionsWord(j).ToArray()));
                        }
                    }
                    sw.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine("The process failed: {0}", e);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The process failed: {0}", e);
            }

            Console.ReadKey();
        }
        public void IteratorTest()
        {
            // The client code may or may not know about the Concrete Iterator
            // or Collection classes, depending on the level of indirection you
            // want to keep in your program.
            var collection = new WordsCollection();

            collection.AddItem("First");
            collection.AddItem("Second");
            collection.AddItem("Third");

            collection.Should().Equal(new List <string> {
                "First", "Second", "Third"
            });

            collection.ReverseDirection();

            collection.Should().Equal(new List <string> {
                "Third", "Second", "First"
            });
        }
Exemple #26
0
        public void Test_words()
        {
            var collection = new WordsCollection();

            collection.AddItem("Tuan");
            collection.AddItem("Hello");
            collection.AddItem("First");

            Assert.That(collection.GetItems().Count == 3);

            {
                var iterator = collection.GetEnumerator();

                Assert.That(iterator.Current, Is.EqualTo("Tuan"));

                iterator.MoveNext(); Assert.That(iterator.Current, Is.EqualTo("Hello"));
                iterator.MoveNext(); Assert.That(iterator.Current, Is.EqualTo("First"));

                iterator.Reset(); Assert.That(iterator.Current, Is.EqualTo("Tuan"));
                iterator.MoveNext();
                iterator.MoveNext();
                Assert.That(iterator.Current, Is.EqualTo("First"));
            }

            collection.ReserveDirection();
            {
                var iterator = collection.GetEnumerator();

                Assert.That(iterator.Current, Is.EqualTo("First"));

                iterator.MoveNext(); Assert.That(iterator.Current, Is.EqualTo("Hello"));
                iterator.MoveNext(); Assert.That(iterator.Current, Is.EqualTo("Tuan"));

                iterator.Reset(); Assert.That(iterator.Current, Is.EqualTo("First"));
                iterator.MoveNext();
                iterator.MoveNext();
                Assert.That(iterator.Current, Is.EqualTo("Tuan"));
            }
        }
Exemple #27
0
            private static void ProcessWord(WordsCollection words, string prefix, string word, string suffix)
            {
                var length = word.Length;

                if (length == 1)
                {
                    AddWordsCollection(words, prefix, word, suffix);
                }
                else if (!char.IsLetterOrDigit(word[0]))
                {
                    AddWordsCollection(words, prefix, word[0].ToString(), string.Empty);
                    AddWordsCollection(words, string.Empty, word.Substring(1), suffix);
                }
                else if (char.IsPunctuation(word[length - 1]))
                {
                    AddWordsCollection(words, prefix, word.Substring(0, length - 1), string.Empty);
                    AddWordsCollection(words, string.Empty, word[length - 1].ToString(), suffix);
                }
                else
                {
                    AddWordsCollection(words, prefix, word, suffix);
                }
            }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.DeleteWords);

            ListView        wordsListView = FindViewById <ListView>(Resource.Id.wordListView);
            WordsCollection words         = new WordsCollection();
            WordsAdapter    adapter       = new WordsAdapter(words, this);

            wordsListView.Adapter = adapter;

            // Create your application here
            wordsListView.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e)
            {
            };

            Button selectAllBtn = FindViewById <Button>(Resource.Id.selectAllBtn);

            selectAllBtn.Click += delegate {
                for (int view = 0; view <= wordsListView.Count; view++)
                {
                }
            };
        }
Exemple #29
0
        public void ClientCode()
        {
            var collection = new WordsCollection();

            collection.AddItem("First");
            collection.AddItem("Second");
            collection.AddItem("Third");

            Console.WriteLine("Straight traversal:");

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }

            Console.WriteLine("\nReverse traversal:");

            collection.ReverseDirection();

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }
        }
Exemple #30
0
        public static void Run()
        {
            var collection = new WordsCollection();

            collection.AddItem("first");
            collection.AddItem("second");
            collection.AddItem("third");

            System.Console.WriteLine("Straight traversal:");

            foreach (var element in collection)
            {
                System.Console.WriteLine(element);
            }

            System.Console.WriteLine("\nReverse traversal:");

            collection.ReverseDirection();

            foreach (var element in collection)
            {
                System.Console.WriteLine(element);
            }
        }
Exemple #31
0
            /// <summary>
            /// Static method that parses the passed-in string into
            /// Words collection
            /// </summary>
            /// <param name="s">
            /// String
            /// </param>
            /// <returns>
            /// Words Collection
            /// </returns>
            static public WordsCollection parse(string s)
            {
                int             curPos = 0;
                int             prevPos;
                string          prefix = string.Empty;
                string          suffix = string.Empty;
                string          word   = string.Empty;
                WordsCollection words  = new WordsCollection();

                while (curPos < s.Length)
                {
                    // eat the leading or tailing white spaces
                    prevPos = curPos;
                    while (curPos < s.Length &&
                           (char.IsControl(s[curPos]) ||
                            char.IsWhiteSpace(s[curPos])))
                    {
                        curPos++;
                    }
                    prefix += s.Substring(prevPos, curPos - prevPos);

                    if (curPos == s.Length)
                    {
                        // it is possible that there are
                        // something in the prefix
                        if (prefix != string.Empty)
                        {
                            // report a empty word with prefix.
                            words.Add(new Word("", prefix, ""));
                        }
                        break;
                    }

                    // we have 3 different cases here,
                    // 1) if the string starts with '<', we assume
                    //    that it is a html tag which will be put
                    //    into prefix.
                    // 2) starts with '&', we need to check if it is
                    //    "&nbsp;" or "&#xxx;". If it is the former,
                    //    we treat it as prefix and if it is latter,
                    //    we treat it as a word.
                    // 3) a string that may be a real word or a set
                    //    of words separated by "&nbsp;" or may have
                    //    leading special character or tailing
                    //    punctuation.
                    //
                    // Another possible case that is too complicated
                    // or expensive to handle is that some special
                    // characters are embeded inside the word with
                    // no space separation
                    if (s[curPos] == '<')
                    {
                        // it is a html tag, consume it
                        // as prefix.
                        prevPos = curPos;
                        while (s[curPos] != '>' && curPos < s.Length)
                        {
                            curPos++;
                        }
                        prefix += s.Substring(prevPos, curPos - prevPos + 1);

                        if (curPos == s.Length)
                        {
                            // if we come to this point, it means
                            // the html tag is not closed. Anyway,
                            // we are not validating html, so just
                            // report a empty word with prefix.
                            words.Add(new Word("", prefix, ""));
                            break;
                        }
                        // curPos is pointing to '>', move
                        // it to next.
                        curPos++;
                        if (curPos == s.Length)
                        {
                            // the html tag is closed but nothing more
                            // behind, so report a empty word with prefix.
                            words.Add(new Word("", prefix, ""));
                            break;
                        }
                        continue;
                    }
                    else if (s[curPos] == '&')
                    {
                        prevPos = curPos;

                        // case for html whitespace
                        if (curPos + 6 < s.Length &&
                            s.Substring(prevPos, 6) == "&nbsp;")
                        {
                            prefix += "&nbsp;";
                            curPos += 6;
                            continue;
                        }

                        // case for special character like "&#123;" etc
                        string pattern = @"&#[0-9]{3};";
                        Regex  r       = new Regex(pattern);

                        if (curPos + 6 < s.Length &&
                            r.IsMatch(s.Substring(prevPos, 6)))
                        {
                            words.Add(new Word(s.Substring(prevPos, 6), prefix, ""));
                            prefix  = string.Empty;
                            curPos += 6;
                            continue;
                        }

                        // case for special character like "&#12;" etc
                        pattern = @"&#[0-9]{2};";
                        r       = new Regex(pattern);
                        if (curPos + 5 < s.Length &&
                            r.IsMatch(s.Substring(prevPos, 5)))
                        {
                            words.Add(new Word(s.Substring(prevPos, 5), prefix, ""));
                            prefix  = string.Empty;
                            curPos += 5;
                            continue;
                        }

                        // can't think of anything else that is special,
                        // have to treat it as a '&' leaded word. Hope
                        // it is just single '&' for and in meaning.
                        prevPos = curPos;
                        while (curPos < s.Length &&
                               !char.IsControl(s[curPos]) &&
                               !char.IsWhiteSpace(s[curPos]) &&
                               s[curPos] != '<')
                        {
                            curPos++;
                        }
                        word = s.Substring(prevPos, curPos - prevPos);

                        // eat the following witespace as suffix
                        prevPos = curPos;
                        while (curPos < s.Length &&
                               (char.IsControl(s[curPos]) ||
                                char.IsWhiteSpace(s[curPos])))
                        {
                            curPos++;
                        }
                        suffix += s.Substring(prevPos, curPos - prevPos);

                        words.Add(new Word(word, prefix, suffix));
                        prefix = string.Empty;
                        suffix = string.Empty;
                    }
                    else
                    {
                        // eat the word
                        prevPos = curPos;
                        while (curPos < s.Length &&
                               !char.IsControl(s[curPos]) &&
                               !char.IsWhiteSpace(s[curPos]) &&
                               s[curPos] != '<' &&
                               s[curPos] != '&')
                        {
                            curPos++;
                        }
                        word = s.Substring(prevPos, curPos - prevPos);

                        // if there are newlines or spaces follow
                        // the word, consume it as suffix
                        prevPos = curPos;
                        while (curPos < s.Length &&
                               (char.IsControl(s[curPos]) ||
                                char.IsWhiteSpace(s[curPos])))
                        {
                            curPos++;
                        }
                        suffix = s.Substring(prevPos, curPos - prevPos);
                        processWord(words, prefix, word, suffix);
                        prefix = string.Empty;
                        suffix = string.Empty;
                    }
                }
                return(words);
            }
 public static Cloud BuildCloud(WordsCollection words, WordRenderer renderer, Graphics g)
     => new RandomCloudBuilder().Build(words, renderer, g);
Exemple #33
0
 /// <summary>
 /// Overloaded. Copy this WordsCollection to another one
 /// starting at the index zero
 /// </summary>
 /// <param name="col" type="WordCollection">
 /// WordsCollection to copy to
 /// </param>
 public void CopyTo(WordsCollection col)
 {
     this.CopyTo(col, 0);
 }
Exemple #34
0
            /// <summary>
            /// Further processing of a string
            /// </summary>
            /// <param name="words">
            /// Collection that new word(s) will be added in
            /// </param>
            /// <param name="prefix">
            /// prefix come with the string 
            /// </param>
            /// <param name="word">
            /// A string that may be a real word or have leading or tailing 
            /// special character
            /// </param>
            /// <param name="suffix">
            /// suffix comes with the string.
            /// </param>
            private static void processWord(WordsCollection words,
                string prefix, string word, string suffix)
            {
                // the passed in word may have leading special
                // characters such as '(', '"' etc or tailing
                // punctuations. We need to sort this out.
                int length = word.Length;

                if (length == 1)
                {
                    words.Add(new Word(word, prefix, suffix));
                }
                else if (!char.IsLetterOrDigit(word[0]))
                {
                    // it is some kind of special character in the first place
                    // report it separately
                    words.Add(new Word(word[0].ToString(), prefix, ""));
                    words.Add(new Word(word.Substring(1), "", suffix));
                    return;
                }
                else if (char.IsPunctuation(word[length - 1]))
                {
                    // there is a end punctuation
                    words.Add(new Word(word.Substring(0, length - 1), prefix, ""));
                    words.Add(new Word(word[length - 1].ToString(), "", suffix));
                }
                else
                {
                    // it is a real word(hope so)
                    words.Add(new Word(word, prefix, suffix));
                }
            }
Exemple #35
0
            private static void AddWordsCollection(WordsCollection words, string prefix, string word, string suffix)
            {
                #region  |  prefix  |
                if (prefix != string.Empty)
                {
                    if (prefix.Trim() == string.Empty && prefix.Length > 1)
                    {
                        //check for double spaces
                        var chars = prefix.ToCharArray();
                        for (var i = 0; i < chars.Length; i++)
                        {
                            words.Add(i == 0
                                ? new Word(string.Empty, chars[i].ToString(), string.Empty)
                                : new Word(((char)160).ToString(), string.Empty, string.Empty));
                        }
                    }
                    else
                    {
                        words.Add(new Word("", prefix, ""));
                    }
                }
                #endregion

                #region  |  word  |
                var wortTmp = string.Empty;
                foreach (var _char in word.ToCharArray())
                {
                    if (Processor.Settings.comparisonType == Settings.ComparisonType.Characters) //every character is a treated as a word
                    {
                        words.Add(new Word(_char.ToString(), string.Empty, string.Empty));
                    }
                    else
                    {
                        if (Encoding.UTF8.GetByteCount(_char.ToString()) > 2) //double byte characters?
                        {
                            if (wortTmp != string.Empty)
                            {
                                words.Add(new Word(wortTmp, string.Empty, string.Empty));
                            }
                            wortTmp = string.Empty;

                            words.Add(new Word(_char.ToString(), string.Empty, string.Empty));
                        }
                        else
                        {
                            wortTmp += _char.ToString();
                        }
                    }
                }
                if (wortTmp != string.Empty)
                {
                    words.Add(new Word(wortTmp, string.Empty, string.Empty));
                }
                #endregion

                #region  |  suffix  |

                if (suffix == string.Empty)
                {
                    return;
                }
                {
                    if (suffix.Trim() == string.Empty && suffix.Length > 1)
                    {
                        //check for double spaces
                        var chars = suffix.ToCharArray();
                        for (var i = 0; i < chars.Length; i++)
                        {
                            words.Add(i == 0
                                ? new Word(string.Empty, string.Empty, chars[i].ToString())
                                : new Word(((char)160).ToString(), string.Empty, string.Empty));
                        }
                    }
                    else
                    {
                        words.Add(new Word(string.Empty, string.Empty, suffix));
                    }
                }

                #endregion
            }
Exemple #36
0
        static void Main(string[] args)
        {
            LinesBuilder linesBuilder = new LinesBuilder(_seperatorLine, _seperatorSentence);

            WordsCollection wordsCollection = new WordsCollection();

            List<String> linesList = new List<String>();
            try
            {
                StreamReader sr=new StreamReader(_pathIn);
                while (!sr.EndOfStream)
                {
                    foreach (var i in linesBuilder.GetLinesFromString(sr.ReadLine()))
                    {
                        linesList.Add(i);
                    }
                }
                sr.Close();

                foreach (var i in linesList)
                {
                    wordsCollection.Add(new WordsLine(linesBuilder.GetSentencesFromString(i).ToArray()));
                }

                foreach (var i in wordsCollection)
                {
                    Console.WriteLine(i.ToString());
                }

                Console.WriteLine("\n - wordsCollection.GetLinesSortedByWordsCount()");
                foreach (var i in wordsCollection.GetLinesSortedByWordsCount())
                {
                     Console.WriteLine(i.ToString());
                }

                Console.WriteLine("\n - wordsCollection.GetWordsInQuestionLines(1)");
                foreach (var i in wordsCollection.GetWordsInQuestionLines(1))
                {
                    Console.WriteLine(i.ToString());
                }

                Console.WriteLine("\n - wordsCollection.GetLinesWithDeletedWords(5, seperstorConsonants)");
                var seperstorConsonants = new char[]
                {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'};
                foreach (var i in wordsCollection.GetLinesWithDeletedWords(5, seperstorConsonants))
                {
                    Console.WriteLine(i.ToString());
                }

                Console.WriteLine("\n - wordsCollection.GetLinesWithReplacedWords(4,'yelow')");
                foreach (var i in wordsCollection.GetLinesWithReplacedWords(4,"yelow"))
                {
                    Console.WriteLine(i.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The process failed: {0}", e);
            }

            Console.ReadKey();
        }
Exemple #37
0
            public static WordsCollection Parse(List <SegmentSection> xSegmentSections)
            {
                var prefix = string.Empty;
                var words  = new WordsCollection();

                foreach (var xSegmentSection in xSegmentSections)
                {
                    string suffix;
                    if (xSegmentSection.Type != SegmentSection.ContentType.Text)
                    {
                        prefix = string.Empty;
                        suffix = string.Empty;
                        words.Add(new Word("<" + MarkupTag + ">" + xSegmentSection.Content + "</" + MarkupTag + ">", prefix, suffix));
                        prefix = string.Empty;
                    }
                    else
                    {
                        var curPos = 0;
                        while (curPos < xSegmentSection.Content.Length)
                        {
                            var prevPos = curPos;
                            while (curPos < xSegmentSection.Content.Length &&
                                   (char.IsControl(xSegmentSection.Content[curPos]) ||
                                    char.IsWhiteSpace(xSegmentSection.Content[curPos])))
                            {
                                curPos++;
                            }
                            prefix += xSegmentSection.Content.Substring(prevPos, curPos - prevPos);

                            if (curPos == xSegmentSection.Content.Length)
                            {
                                if (prefix != string.Empty)
                                {
                                    words.Add(new Word(string.Empty, prefix, string.Empty));
                                }
                                break;
                            }

                            prevPos = curPos;
                            while (curPos < xSegmentSection.Content.Length &&
                                   !char.IsControl(xSegmentSection.Content[curPos]) &&
                                   !char.IsWhiteSpace(xSegmentSection.Content[curPos]))
                            {
                                curPos++;
                            }
                            var word = xSegmentSection.Content.Substring(prevPos, curPos - prevPos);


                            prevPos = curPos;
                            while (curPos < xSegmentSection.Content.Length &&
                                   (char.IsControl(xSegmentSection.Content[curPos]) ||
                                    char.IsWhiteSpace(xSegmentSection.Content[curPos])))
                            {
                                curPos++;
                            }
                            suffix = xSegmentSection.Content.Substring(prevPos, curPos - prevPos);
                            ProcessWord(words, prefix, word, suffix);
                            prefix = string.Empty;
                        }
                    }
                }
                return(words);
            }
Exemple #38
0
 internal void CopyTo(WordsCollection col)
 {
     CopyTo(col, 0);
 }
Exemple #39
0
 /// <summary>
 /// Copy this WordsCollection to another one 
 /// starting at the specified index position
 /// </summary>
 /// <param name="col" type="WordsCollection">
 /// WordsCollection to be copied to
 /// </param>
 /// <param name="index" type="integer">
 /// Starting index to begin copy operations
 /// </param>
 public void CopyTo(WordsCollection col, int index)
 {
     for (int i = index; i < List.Count; i++)
     {
         col.Add(this[i]);
     }
 }
Exemple #40
0
 /// <summary>
 /// Overloaded. Copy this WordsCollection to another one 
 /// starting at the index zero
 /// </summary>
 /// <param name="col" type="WordCollection">
 /// WordsCollection to copy to
 /// </param>
 public void CopyTo(WordsCollection col)
 {
     this.CopyTo(col, 0);
 }
 public Cloud Build(WordsCollection words, WordRenderer renderer, Graphics g)
 {
     var blocks = BuildBlocks(words, renderer, g).ToList();
     Pack(blocks, g);
     return new Cloud(blocks);
 }
Exemple #42
0
            /// <summary>
            /// Static method that parses the passed-in string into
            /// Words collection 
            /// </summary>
            /// <param name="s">
            /// String
            /// </param>
            /// <returns>
            /// Words Collection
            /// </returns>
            public static WordsCollection parse(string s)
            {
                int curPos = 0;
                int prevPos;
                string prefix = string.Empty;
                string suffix = string.Empty;
                string word = string.Empty;
                WordsCollection words = new WordsCollection();

                while (curPos < s.Length)
                {
                    // eat the leading or tailing white spaces
                    prevPos = curPos;
                    while (curPos < s.Length &&
                       (char.IsControl(s[curPos]) ||
                        char.IsWhiteSpace(s[curPos])))
                    {
                        curPos++;
                    }
                    prefix += s.Substring(prevPos, curPos - prevPos);

                    if (curPos == s.Length)
                    {
                        // it is possible that there are
                        // something in the prefix
                        if (prefix != string.Empty)
                        {
                            // report a empty word with prefix.
                            words.Add(new Word("", prefix, ""));
                        }
                        break;
                    }

                    // we have 3 different cases here,
                    // 1) if the string starts with '<', we assume
                    //    that it is a html tag which will be put
                    //    into prefix.
                    // 2) starts with '&', we need to check if it is
                    //    "&nbsp;" or "&#xxx;". If it is the former,
                    //    we treat it as prefix and if it is latter,
                    //    we treat it as a word.
                    // 3) a string that may be a real word or a set
                    //    of words separated by "&nbsp;" or may have
                    //    leading special character or tailing
                    //    punctuation.
                    //
                    // Another possible case that is too complicated
                    // or expensive to handle is that some special
                    // characters are embeded inside the word with
                    // no space separation
                    if (s[curPos] == '<')
                    {
                        // it is a html tag, consume it
                        // as prefix.
                        prevPos = curPos;
                        while (s[curPos] != '>' && curPos < s.Length)
                        {
                            curPos++;
                        }
                        prefix += s.Substring(prevPos, curPos - prevPos + 1);

                        if (curPos == s.Length)
                        {
                            // if we come to this point, it means
                            // the html tag is not closed. Anyway,
                            // we are not validating html, so just
                            // report a empty word with prefix.
                            words.Add(new Word("", prefix, ""));
                            break;
                        }
                        // curPos is pointing to '>', move
                        // it to next.
                        curPos++;
                        if (curPos == s.Length)
                        {
                            // the html tag is closed but nothing more
                            // behind, so report a empty word with prefix.
                            words.Add(new Word("", prefix, ""));
                            break;
                        }
                        continue;
                    }
                    else if (s[curPos] == '&')
                    {
                        prevPos = curPos;

                        // case for html whitespace
                        if (curPos + 6 < s.Length &&
                            s.Substring(prevPos, 6) == "&nbsp;")
                        {
                            prefix += "&nbsp;";
                            curPos += 6;
                            continue;
                        }

                        // case for special character like "&#123;" etc
                        string pattern = @"&#[0-9]{3};";
                        Regex r = new Regex(pattern);

                        if (curPos + 6 < s.Length &&
                            r.IsMatch(s.Substring(prevPos, 6)))
                        {
                            words.Add(new Word(s.Substring(prevPos, 6), prefix, ""));
                            prefix = string.Empty;
                            curPos += 6;
                            continue;
                        }

                        // case for special character like "&#12;" etc
                        pattern = @"&#[0-9]{2};";
                        r = new Regex(pattern);
                        if (curPos + 5 < s.Length &&
                            r.IsMatch(s.Substring(prevPos, 5)))
                        {
                            words.Add(new Word(s.Substring(prevPos, 5), prefix, ""));
                            prefix = string.Empty;
                            curPos += 5;
                            continue;
                        }

                        // can't think of anything else that is special,
                        // have to treat it as a '&' leaded word. Hope
                        // it is just single '&' for and in meaning.
                        prevPos = curPos;
                        while (curPos < s.Length &&
                            !char.IsControl(s[curPos]) &&
                            !char.IsWhiteSpace(s[curPos]) &&
                            s[curPos] != '<')
                        {
                            curPos++;
                        }
                        word = s.Substring(prevPos, curPos - prevPos);

                        // eat the following witespace as suffix
                        prevPos = curPos;
                        while (curPos < s.Length &&
                            (char.IsControl(s[curPos]) ||
                            char.IsWhiteSpace(s[curPos])))
                        {
                            curPos++;
                        }
                        suffix += s.Substring(prevPos, curPos - prevPos);

                        words.Add(new Word(word, prefix, suffix));
                        prefix = string.Empty;
                        suffix = string.Empty;
                    }
                    else
                    {
                        // eat the word
                        prevPos = curPos;
                        while (curPos < s.Length &&
                            !char.IsControl(s[curPos]) &&
                            !char.IsWhiteSpace(s[curPos]) &&
                            s[curPos] != '<' &&
                            s[curPos] != '&')
                        {
                            curPos++;
                        }
                        word = s.Substring(prevPos, curPos - prevPos);

                        // if there are newlines or spaces follow
                        // the word, consume it as suffix
                        prevPos = curPos;
                        while (curPos < s.Length &&
                            (char.IsControl(s[curPos]) ||
                            char.IsWhiteSpace(s[curPos])))
                        {
                            curPos++;
                        }
                        suffix = s.Substring(prevPos, curPos - prevPos);
                        processWord(words, prefix, word, suffix);
                        prefix = string.Empty;
                        suffix = string.Empty;
                    }
                }
                return words;
            }
 public Cloud Build(WordsCollection words, WordRenderer renderer, Graphics g) 
     => new Cloud(ContinousBuild(words, renderer, g));
 public void ShouldBeEmptyOnEmptyInput()
 {
     var wc = new WordsCollection(new Word[] {});
     Assert.IsEmpty(wc);
 }