public static void Main(string[] args) { // Trie implementation from https://github.com/rmandvikar/csharp-trie Console.WriteLine("The program read all words from 'text.txt',"); Console.WriteLine("adds them in a Trie and prnt the first 1000 words"); Console.WriteLine("along with the occurrences of each word"); Console.WriteLine("Press any key to begin.."); Console.ReadKey(); ITrie trie = TrieFactory.CreateTrie(); var reader = new StreamReader("../../text.txt"); ReadWordsFromText(reader, trie); var counter = 0; foreach (var currentWord in trie.GetWords()) { counter++; if (counter == 1000) { break; } var wordCounter = trie.WordCount(currentWord); Console.WriteLine("{0} - {1}", currentWord, wordCounter); } }
public void CreateDataSet() { var start = DateTime.UtcNow; _testInitializeTime = DateTime.UtcNow - start; Utils.CheckFileExists(DataFile); var file = new FileInfo(DataFile); try { var array = new byte[file.Length]; using (var stream = file.OpenRead()) { stream.Read(array, 0, (int)file.Length); } _provider = TrieFactory.Create(array); } catch (OutOfMemoryException) { Assert.Inconclusive( "Not enough memory to perform memory test on data file '{0}' of size '{1}'MB", file.Name, file.Length / (1024 * 1024)); } _testInitializeTime = DateTime.UtcNow - start; }
public static void Main() { Console.WriteLine("Generating a very big mothereffing lorem text. Please stand by..."); RandomDataGenerator.GenerateLorem(LoremPath); var trie = TrieFactory.CreateTrie(); var wordsSet = new List <string>(1000); Console.WriteLine("Reading words from file..."); var words = File.ReadAllLines(LoremPath).SelectMany(x => x.Split(new[] { ' ', ',', '.', '!', '?' }, StringSplitOptions.RemoveEmptyEntries)); Console.WriteLine("Saving words..."); foreach (var word in words) { trie.AddWord(word); if (!wordsSet.Contains(word) && wordsSet.Count < 999) { wordsSet.Add(word); } } var sb = new StringBuilder(); Console.WriteLine("Counting words..."); foreach (var word in wordsSet) { sb.AppendLine(string.Format("{0} occured {1} times in the text.", word, trie.WordCount(word))); } Console.WriteLine(sb.ToString()); }
public void AddWord_EmptyString01() { trie = TrieFactory.CreateTrie(); Assert.AreEqual(0, trie.GetWords().Count); trie.AddWord(""); Assert.AreNotEqual(0, trie.GetWords().Count); }
static void Setup() { /*Setup dictionary*/ _dictionary = TrieFactory.CreateTrie(); StreamReader reader = new StreamReader("..\\..\\..\\SampleText.txt"); string[] words = reader.ReadToEnd().Split(' ', '.', ',', '?', '!', ':', ';'); foreach (var word in words) { _dictionary.AddWord(word.ToLower()); } /*end dictionary*/ /*setup sample sentence*/ _sentence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; /*end sample sentence*/ /*setup random encryption*/ _encryption = Service.GetRandomEncryption(); /*end random encryption*/ /*encrypt sentence*/ _encryptedSentence = Service.Encrypt(_sentence, _encryption); /*end ecnryption*/ }
internal static void Init() { DataProviderSettings providerSettings = ConfigurationManager.GetSection("dictionaryService") as DataProviderSettings; var providers = providerSettings.Instances; foreach (DataProviderSetting setting in providers) { Stopwatch timer = new Stopwatch(); timer.Start(); IDataProvider dataProvider = null; try { dataProvider = (IDataProvider)Activator.CreateInstance(Type.GetType(setting.ProviderType, true), new object[] { setting }); TrieFactory.LoadFromDataProvider(dataProvider); } catch (FileNotFoundException e) { logger.Error("Invalid provider setting: " + setting.ProviderType); }catch (TypeLoadException e) { logger.Error("Invalid provider setting: " + setting.ProviderType); } timer.Stop(); logger.InfoFormat("{0}: {1:0.00} seconds", setting.Name, timer.ElapsedMilliseconds / 1000.0); } }
public void CreateDataSet() { var start = DateTime.UtcNow; Utils.CheckFileExists(DataFile); _provider = TrieFactory.Create(DataFile); _testInitializeTime = DateTime.UtcNow - start; }
public void InsertIntoTrie() { Trie trie = TrieFactory.Create(); Tuple <string, int> tuple = new Tuple <string, int>("bogus", 99); trie.Insert(tuple.Item1, tuple.Item2); Assert.AreEqual(trie.Count(), 1); Assert.AreEqual(trie.Get(tuple.Item1), tuple.Item2); }
public static void Main() { var trie = TrieFactory.CreateTrie(); var words = GenerateRandomWords(1000000); var uniqueWords = new HashSet <string>(words); AddWordsToTrie(words, trie); GetCountOfAllUniqueWords(uniqueWords, trie); }
public void TestLoadTrieTreeFromPanguDict() { var mockPanguProviderSetting = new Mock <IDataProviderSetting>(); mockPanguProviderSetting.Setup(s => s.Uri).Returns(DictLoadTest.UnitTestProjectFolder + @"\Data\panguDict.dct"); mockPanguProviderSetting.Setup(s => s.ProviderType).Returns("PanguDictProvider"); var panguProvider = new PanguDictProvider(mockPanguProviderSetting.Object); TrieTree tt = TrieFactory.LoadFromDataProvider(panguProvider); TrieTreeNode ttn = tt.GetNode("测试"); Assert.IsNotNull(ttn); Assert.AreEqual(POSType.D_N, (POSType)ttn.POSValue); }
public void Test13() { var trie = TrieFactory.CreateTrie(); trie.AddWord(""); trie.AddWord(""); Assert.AreEqual(1, trie.GetWords().Count); trie.RemoveWord(""); Assert.AreEqual(0, trie.GetWords().Count); trie.AddWord(""); Assert.AreEqual(1, trie.GetWords().Count); trie.RemoveWord(""); Assert.AreEqual(0, trie.GetWords().Count); }
private ITrie LowerCaseWords() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "this", "test", "the", "temp", "token", "take", "thump" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
private ITrie UpperCaseWords() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "THIS", "TEST", "THE", "TEMP", "TOKEN", "TAKE", "THUMP" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
private ITrie Digits() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "123", "1", "23" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
public void TestLoadTrieTreeFromMongoDB() { var mockProviderSetting = new Mock <IDataProviderSetting>(); mockProviderSetting.Setup(s => s.Uri).Returns("mongodb://localhost:28001"); mockProviderSetting.Setup(s => s.ProviderType).Returns("MongoDBDataProvider"); mockProviderSetting.Setup(s => s.DBName).Returns("nameResearch"); mockProviderSetting.Setup(s => s.CollectionName).Returns("placeNames"); var dataProvider = new MongoDBDataProvider(mockProviderSetting.Object); TrieTree tt = TrieFactory.LoadFromDataProvider(dataProvider); Assert.IsNotNull(tt); Assert.IsNotNull(tt.Root); Assert.IsTrue(tt.Root.Children.Count > 100); }
private ITrie Words() { ITrie trie = TrieFactory.CreateTrie(); string[] strings = { "this", "test", "the", "TEMP", "TOKEN", "TAKE", "THUMP" }; foreach (string s in strings) { trie.AddWord(s); } return(trie); }
public static void Main(string[] args) { var words = ReadAllWords(); var trie = TrieFactory.GetTrie(); foreach (var word in words) { trie.AddWord(word); } var toSearch = new string[] { "curtain", "you", "well", "lighted" }; foreach (var word in toSearch) { Console.WriteLine("{0} - {1}", word, trie.WordCount(word)); } }
static void Main() { var date = DateTime.Now; var words = GetWords(); Console.WriteLine(DateTime.Now - date); var trie = TrieFactory.GetTrie(); foreach (var word in words) { trie.AddWord(word); } var searched = new[] { "buddhism", "wikipedia", "the", "of", "factors" }; Console.WriteLine(string.Join(" | ", searched.Select(word => string.Format("{0} {1}", word, trie.WordCount(word))))); }
public static ITrie BuildTree() { var wordTrie = TrieFactory.GetTrie(); using (StreamReader textReader = new StreamReader(FileLocation)) { string line = textReader.ReadLine(); while (line != null) { var words = line.Split(Separators, StringSplitOptions.RemoveEmptyEntries); foreach (var word in words) { wordTrie.AddWord(word); } line = textReader.ReadLine(); } } return(wordTrie); }
public static void Main() { ITrie trie = TrieFactory.CreateTrie(); using (var reader = new StreamReader(@"..\..\Files\text.txt")) { while (!reader.EndOfStream) { reader .ReadLine() .Split(' ', '.', ',', '?', '!', ':') .ToList() .ForEach(word => { trie.AddWord(word); }); } } var countOfLorem = trie.WordCount("lorem"); Console.WriteLine("Lorem -> {0} times", countOfLorem); }
public void TraverseTriePreOrder() { Trie trie = TrieFactory.Create(); List <Tuple <string, int> > tuples = new List <Tuple <string, int> >() { new Tuple <string, int>("bogus", 99), new Tuple <string, int>("aack", 88), new Tuple <string, int>("zebra", 77), new Tuple <string, int>("kangaroo", 66), new Tuple <string, int>("donkey", 55), new Tuple <string, int>("dog", 44) }; foreach (Tuple <string, int> tuple in tuples) { trie.Insert(tuple.Item1, tuple.Item2); } Assert.AreEqual(trie.Count(), tuples.Count); TestVisitor testVisitor = new TestVisitor(); trie.Traverse(TraversalType.PreOrder, testVisitor); Console.WriteLine(testVisitor.ToString()); }
static void Main(string[] args) { var trie = TrieFactory.CreateTrie(); HashSet <string> words = new HashSet <string>(); using (StreamReader reader = new StreamReader("../../100MB.txt")) { string line; while ((line = reader.ReadLine()) != null) { foreach (var word in line.Split(' ')) { words.Add(word); trie.AddWord(word); } } } foreach (var word in words) { Console.WriteLine("{0} - {1} times", word, trie.WordCount(word)); } }
public static void Main() { System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); timer.Start(); var words = GetWords(); timer.Stop(); Console.WriteLine("Adding the words to a collection: {0}", timer.Elapsed); var trie = TrieFactory.GetTrie(); timer.Start(); foreach (var word in words) { trie.AddWord(word); } timer.Stop(); Console.WriteLine("Adding words to the trie: " + timer.Elapsed); timer.Restart(); Console.WriteLine("Number of occurrences of \"the\": {0}", trie.WordCount("the")); Console.WriteLine("Counting the word \"the\": {0}", timer.Elapsed); }
public void GetFromEmptyTrie() { Trie trie = TrieFactory.Create(); string key = "bogus"; int value = trie.Get(key); }
public void CreateDataSet() { Utils.CheckFileExists(DataFile); _provider = TrieFactory.Create(DataFile); }
public void CreateDataSet() { _memory = new Utils.MemoryMonitor(); Utils.CheckFileExists(DataFile); _provider = TrieFactory.Create(DataFile); }