public bool Read(System.IO.StreamReader sr, LanguageDictionary coupledObject) { //_spellings = new List<string>(); _spellings.ReadFromSingleLines(sr); _definitions.ReadList(sr, coupledObject, delegate(string s, LanguageDictionary d) { return(Definition.blankForReading(d)); }); _pronunciations.ReadList(sr, Pronunciation.newObject); return(true); }
//-------------------------------------------------------------------------------------------- // Constructors and factory methods //-------------------------------------------------------------------------------------------- public static LanguageDictionary fromFile(string fileName) { LanguageDictionary dic = new LanguageDictionary(); using (StreamReader sr = File.OpenText(fileName)) { dic.Read(sr); } return(dic); }
public static LanguageDictionary fromGCIDE_XML(string xmlPath = @"X:\Programming\Resources\dictionaries\gcide_xml") { List <GCIDEWord> wordList = LoadXML(); //Dictionary<string, GCIDEWord> words = GCIDEWord.formulateSimepleDictionary(wordList); List <GCIDEWord> words = GCIDEWord.formulateDictionary(wordList); //words.Add("razzamatazz", new GCIDEWord("razzamatazz", "A flamboyant (gaudy) display intended to awe, impress, bewilder, confuse or deceive. 2. razzle-dazzle", "n.")); List <GCIDEWord> badWords = words.Where(W => !GCIDEWord.isNormalWord(W)).ToList(); foreach (var badWord in badWords) { Console.WriteLine("Pruning: " + badWord); words.Remove(badWord); } //ExportDictionary(words, out maxWord, out maxDef); //frequency stuff /*GC.Collect(); * string refText = File.ReadAllText(@"X:\uni\c++ assignment\all - ansi - clean.txt"); * string[] allWords = getAllWords(refText); * foreach (string str in allWords) * { * //proper noun match? * List<GCIDEWord> sameWords = words.Where(W => W.Text == str).ToList(); * if (sameWords.Count == 0) * { * string strClean = GCIDEWord.cleanWordText(str); * sameWords = words.Where(W => W.Text == strClean).ToList(); * } * * foreach (GCIDEWord sameWord in sameWords) * { * sameWord.Freq = sameWord.Freq + 1; * } * } * * allWords = null; refText = null;*/ GC.Collect(); //build the dictionary LanguageDictionary dic = new LanguageDictionary(); foreach (GCIDEWord word in words) { dic.MergeWordIntoSortedDictionary(word.toWord(dic)); } return(dic); }
public static LanguageDictionary Load(string path) { LanguageDictionary ld = new LanguageDictionary(); using (StreamReader sr = File.OpenText(path)) { if (ld.Read(sr)) { return(ld); } } return(null); }
public static LanguageDictionary loadInternalEnglish() { string internal_dictionary = "WDLang.Dictionaries.english_gcide.dic"; var assembly = Assembly.GetExecutingAssembly(); using (var s = assembly.GetManifestResourceStream(internal_dictionary)) { if (s != null) { using (var sr = new StreamReader(s)) { LanguageDictionary ld = new LanguageDictionary(); if (ld.Read(sr)) { return(ld); } } } } throw new Exception($"Unable to load internal dictionary {internal_dictionary}"); }
internal static Word newObject(string type, LanguageDictionary coupledObject) { if (type == "Word") { return(new Word()); } else if (type == "Noun") { return(new Noun()); } else if (type == "Adjective") { return(new Adjective()); } else if (type == "Verb") { return(new Verb()); } else if (type == "Adverb") { return(new Adverb()); } else if (type == "Preposition") { return(new Preposition()); } else if (type == "ProperNoun") { return(new ProperNoun()); } else if (type == "MiscWord") { return(new MiscWord()); } else { throw new InvalidOperationException("No word type: " + type); } }