protected Dictionary <string, string> GlomDictionary(string filename, string error) { string[] lines = File.ReadAllLines(filename); if (lines == null) { throw new FileLoadException("Failed to open transitive verbal phrase table"); } Dictionary <string, string> result = new Dictionary <string, string>(); foreach (string line in lines) { if (line.Length == 0) { break; } AuxString auxstr = new AuxString(line); AppendString(result, auxstr.Word(0), auxstr.Word(1), "#"); } return(result); }
public void ReadNounNumber(string filename, Dictionary <string, string> toSingular, Dictionary <string, string> toPlural) { string[] lines = File.ReadAllLines(filename); if (lines == null) { throw new FileLoadException("Failed to open noun number data"); } for (int ii = 0; ii < lines.Length; ii += 2) { if (lines[ii].Length == 0) { break; } AuxString auxstr1 = new AuxString(lines[ii]); AuxString auxstr2 = new AuxString(lines[ii + 1]); string t1, line1; if (auxstr1.WordCount() > 1) { t1 = auxstr1.Word(1); line1 = auxstr1.Word(0).ToLower(); } else { t1 = ""; line1 = lines[ii].ToLower(); } string t2, line2; if (auxstr2.WordCount() > 1) { t2 = auxstr2.Word(1); line2 = auxstr2.Word(0).ToLower(); } else { t2 = ""; line2 = lines[ii + 1].ToLower(); } if (t1 == "P" || t1 == "TP") { toSingular.Add(line2, "#"); } else if (t2 == "P") { toSingular.Add(line2, ""); } else if (t1 != "S") { if (t1.Length > 0 && t1 != "T") { Console.WriteLine(string.Format("T1={0}", t1)); } toSingular.Add(line2, line1); } if (t1 == "S") { toPlural.Add(line1, "#"); } else { toPlural.Add(line1, line2); } if (t2.Length > 0 && t2 != "P") { if (t2.Length == 1 && t2 != "T") { Console.WriteLine(string.Format("T2={0}", t2)); } else if (t2 != "T") { toSingular.Add(t2, line2); } } } }
public void ReadNounNumber(string filename, Dictionary<string, string> toSingular, Dictionary<string, string> toPlural) { string[] lines = File.ReadAllLines(filename); if (lines == null) throw new FileLoadException("Failed to open noun number data"); for (int ii = 0; ii < lines.Length; ii += 2) { if (lines[ii].Length == 0) break; AuxString auxstr1 = new AuxString(lines[ii]); AuxString auxstr2 = new AuxString(lines[ii + 1]); string t1, line1; if (auxstr1.WordCount() > 1) { t1 = auxstr1.Word(1); line1 = auxstr1.Word(0).ToLower(); } else { t1 = ""; line1 = lines[ii].ToLower(); } string t2, line2; if (auxstr2.WordCount() > 1) { t2 = auxstr2.Word(1); line2 = auxstr2.Word(0).ToLower(); } else { t2 = ""; line2 = lines[ii + 1].ToLower(); } if (t1 == "P" || t1 == "TP") toSingular.Add(line2, "#"); else if (t2 == "P") toSingular.Add(line2, ""); else if (t1 != "S") { if (t1.Length > 0 && t1 != "T") Console.WriteLine(string.Format("T1={0}", t1)); toSingular.Add(line2, line1); } if (t1 == "S") toPlural.Add(line1, "#"); else toPlural.Add(line1, line2); if (t2.Length > 0 && t2 != "P") { if (t2.Length == 1 && t2 != "T") Console.WriteLine(string.Format("T2={0}", t2)); else if (t2 != "T") toSingular.Add(t2, line2); } } }
public VerbsData(string basedir) { base_past = new Dictionary<string, TwoTuple<string,string>>(); past_base = new Dictionary<string, TwoTuple<string,string>>(); base_pastpart = new Dictionary<string,string>(); pastpart_base = new Dictionary<string,string>(); verb_tobase = new Dictionary<string,string>(); string[] lines = File.ReadAllLines(basedir + "verb_table.txt"); if (lines == null) throw new FileLoadException(string.Format("Failed to open verb table")); foreach (string line in lines) { if (line.Length == 0) break; AuxString auxstr = new AuxString(line); base_past[auxstr.Word(0)] = new TwoTuple<string, string>(auxstr.Word(1), auxstr.Word(3)); past_base[auxstr.Word(1)] = new TwoTuple<string, string>(auxstr.Word(0), auxstr.Word(3)); base_pastpart[auxstr.Word(0)] = auxstr.Word(2); pastpart_base[auxstr.Word(2)] = auxstr.Word(0); } lines = File.ReadAllLines(basedir + "verb_exceptions.txt"); if (lines == null) throw new FileLoadException("Failed to open verb exceptions"); for (int ii = 0; ii < lines.Length; ii += 2) { if (lines[ii].Length == 0) break; verb_tobase.Add(lines[ii], lines[ii + 1]); } todouble = FillBag(basedir + "verb_todouble.txt", "Failed to open verb double table"); either = FillBag(basedir + "verb_either.txt", "Failed to open verb either table"); transitive = FillBag(basedir + "verb_transitive.txt", "Failed to open verb transitive table"); intransitive = FillBag(basedir + "verb_intransitive.txt", "Failed to open verb intransitive table"); phrVerbT = GlomDictionary(basedir + "verb_adv_transitive.txt", "Failed to open transitive verbal phrase table"); phrVerbI = GlomDictionary(basedir + "verb_adv_intransitive.txt", "Failed to open intransitive verbal phrase table"); phrVerbE = GlomDictionary(basedir + "verb_adv_either.txt", "Failed to open either verbal phrase table"); lines = File.ReadAllLines(basedir + "verb_adv_prep.txt"); if (lines == null) throw new FileLoadException("Failed to open either verbal phrase table"); phrVAP = new Dictionary<string,string>(); foreach (string line in lines) { if (line.Length == 0) break; AuxString auxstr = new AuxString(line); AppendString(phrVAP, auxstr.Word(0), auxstr.Word(1) + " " + auxstr.Word(2), "#"); } verb_ING = new Dictionary<string, TwoTuple<string,string>>(); verb_ED = new Dictionary<string, TwoTuple<string,string>>(); verb_S = new Dictionary<string, TwoTuple<string,string>>(); lines = File.ReadAllLines(basedir + "verb_special.txt"); if (lines == null) throw new FileLoadException(string.Format("Failed to open verb special table")); foreach (string line in lines) { if (line.Length == 0) break; AuxString auxstr = new AuxString(line); if (auxstr.Letter(0) != '#') // ignore comments { if (auxstr.WordCount() == 0) continue; if (auxstr.WordCount() != 5) throw new FieldAccessException(string.Format("Bad format in special table at \"{0}\"", line)); else { string base_word = auxstr.Word(0); string base_ing = auxstr.Word(1); string base_ed = auxstr.Word(2); string base_s = auxstr.Word(3); string type = auxstr.Word(4); if (base_ing != "-") verb_ING.Add(base_ing, new TwoTuple<string, string>(base_word, type)); if (base_ed != "-") verb_ED.Add(base_ed, new TwoTuple<string, string>(base_word, type)); if (base_s != "-") verb_S.Add(base_s, new TwoTuple<string, string>(base_word, type)); } } } }
protected Dictionary<string, string> GlomDictionary(string filename, string error) { string[] lines = File.ReadAllLines(filename); if (lines == null) throw new FileLoadException("Failed to open transitive verbal phrase table"); Dictionary<string, string> result = new Dictionary<string,string>(); foreach (string line in lines) { if (line.Length == 0) break; AuxString auxstr = new AuxString(line); AppendString(result, auxstr.Word(0), auxstr.Word(1), "#"); } return result; }
public VerbsData(string basedir) { base_past = new Dictionary <string, TwoTuple <string, string> >(); past_base = new Dictionary <string, TwoTuple <string, string> >(); base_pastpart = new Dictionary <string, string>(); pastpart_base = new Dictionary <string, string>(); verb_tobase = new Dictionary <string, string>(); string[] lines = File.ReadAllLines(basedir + "verb_table.txt"); if (lines == null) { throw new FileLoadException(string.Format("Failed to open verb table")); } foreach (string line in lines) { if (line.Length == 0) { break; } AuxString auxstr = new AuxString(line); base_past[auxstr.Word(0)] = new TwoTuple <string, string>(auxstr.Word(1), auxstr.Word(3)); past_base[auxstr.Word(1)] = new TwoTuple <string, string>(auxstr.Word(0), auxstr.Word(3)); base_pastpart[auxstr.Word(0)] = auxstr.Word(2); pastpart_base[auxstr.Word(2)] = auxstr.Word(0); } lines = File.ReadAllLines(basedir + "verb_exceptions.txt"); if (lines == null) { throw new FileLoadException("Failed to open verb exceptions"); } for (int ii = 0; ii < lines.Length; ii += 2) { if (lines[ii].Length == 0) { break; } verb_tobase.Add(lines[ii], lines[ii + 1]); } todouble = FillBag(basedir + "verb_todouble.txt", "Failed to open verb double table"); either = FillBag(basedir + "verb_either.txt", "Failed to open verb either table"); transitive = FillBag(basedir + "verb_transitive.txt", "Failed to open verb transitive table"); intransitive = FillBag(basedir + "verb_intransitive.txt", "Failed to open verb intransitive table"); phrVerbT = GlomDictionary(basedir + "verb_adv_transitive.txt", "Failed to open transitive verbal phrase table"); phrVerbI = GlomDictionary(basedir + "verb_adv_intransitive.txt", "Failed to open intransitive verbal phrase table"); phrVerbE = GlomDictionary(basedir + "verb_adv_either.txt", "Failed to open either verbal phrase table"); lines = File.ReadAllLines(basedir + "verb_adv_prep.txt"); if (lines == null) { throw new FileLoadException("Failed to open either verbal phrase table"); } phrVAP = new Dictionary <string, string>(); foreach (string line in lines) { if (line.Length == 0) { break; } AuxString auxstr = new AuxString(line); AppendString(phrVAP, auxstr.Word(0), auxstr.Word(1) + " " + auxstr.Word(2), "#"); } verb_ING = new Dictionary <string, TwoTuple <string, string> >(); verb_ED = new Dictionary <string, TwoTuple <string, string> >(); verb_S = new Dictionary <string, TwoTuple <string, string> >(); lines = File.ReadAllLines(basedir + "verb_special.txt"); if (lines == null) { throw new FileLoadException(string.Format("Failed to open verb special table")); } foreach (string line in lines) { if (line.Length == 0) { break; } AuxString auxstr = new AuxString(line); if (auxstr.Letter(0) != '#') // ignore comments { if (auxstr.WordCount() == 0) { continue; } if (auxstr.WordCount() != 5) { throw new FieldAccessException(string.Format("Bad format in special table at \"{0}\"", line)); } else { string base_word = auxstr.Word(0); string base_ing = auxstr.Word(1); string base_ed = auxstr.Word(2); string base_s = auxstr.Word(3); string type = auxstr.Word(4); if (base_ing != "-") { verb_ING.Add(base_ing, new TwoTuple <string, string>(base_word, type)); } if (base_ed != "-") { verb_ED.Add(base_ed, new TwoTuple <string, string>(base_word, type)); } if (base_s != "-") { verb_S.Add(base_s, new TwoTuple <string, string>(base_word, type)); } } } } }