/// ----------------------------------------------------------------------------------- /// <summary> /// Load data from file. /// </summary> /// <param name="pathname">Pathname of file to load.</param> /// <returns>An instance of GAFAWSData, if successful.</returns> /// <remarks> /// [NOTE: This may throw some exceptions, if pathname is bad, /// or it is not a suitable file.] /// </remarks> /// ----------------------------------------------------------------------------------- public static GAFAWSData LoadData(string pathname) { GAFAWSData gd = null; XmlTextReader reader = new XmlTextReader(pathname); XmlSerializer serializer = new XmlSerializer(typeof(GAFAWSData)); try { gd = (GAFAWSData)serializer.Deserialize(reader); // Remove empty collections from Wordrecord objects, // since the loader makes them, but the XML schema has them as optional. foreach (WordRecord wr in gd.m_wordRecords) { if (wr.Prefixes.Count == 0) { wr.Prefixes = null; } if (wr.Suffixes.Count == 0) { wr.Suffixes = null; } } } finally { reader.Close(); } return(gd); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="gd">The main data layer object.</param> /// <param name="messages">List of status messages.</param> /// ----------------------------------------------------------------------------------- public ClassAssigner(GAFAWSData gd, Dictionary <string, string> messages) { m_messages = messages; m_fAssignedOk = true; m_gd = gd; m_fogBank = null; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Static method used to create a well-formed instance of a GAFAWSData obejct /// from code. /// </summary> /// <returns></returns> /// ----------------------------------------------------------------------------------- public static GAFAWSData Create() { GAFAWSData gd = new GAFAWSData(); gd.m_wordRecords = new List <WordRecord>(); gd.m_morphemes = new List <Morpheme>(); gd.m_classes = new Classes(); gd.m_challenges = new List <Challenge>(); return(gd); }
public void LoadDataWithEmptyFile() { string fileName = null; try { fileName = MakeFile(); m_gd = GAFAWSData.LoadData(fileName); } finally { DeleteFile(fileName); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Implements the IGAFAWS interface. /// </summary> /// <param name="pathInput">Pathname to the input data.</param> /// <returns>The pathname for the processed data.</returns> /// ----------------------------------------------------------------------------------- public string Process(string pathInput) { // Replaces 8 lines in C++. GAFAWSData gData = GAFAWSData.LoadData(pathInput); if (gData == null) { return(null); } Process(gData); string outPath = GetOutputPathname(pathInput); m_gd.SaveData(outPath); return(outPath); }
public void LoadDataWrongXML() { string fileName = null; try { fileName = MakeFile("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<NOTGAFAWSData xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" + "</NOTGAFAWSData>"); m_gd = GAFAWSData.LoadData(fileName); } finally { DeleteFile(fileName); } }
public void LoadGoodData() { string fileName = null; try { Assert.AreEqual(0, m_gd.Morphemes.Count); // Shouldn't have any at this point. fileName = MakeFile(m_dataBefore); m_gd = GAFAWSData.LoadData(fileName); Assert.AreEqual(1, m_gd.Morphemes.Count); // Should be 1 of them now. Assert.AreEqual(1, m_gd.WordRecords.Count, "Wrong word record count."); WordRecord wr = m_gd.WordRecords[0]; Assert.IsNull(wr.Prefixes, "Should have null preffix collection."); Assert.IsNull(wr.Suffixes, "Should have null suffix collection."); } finally { DeleteFile(fileName); } }
public void AddOtherContents() { m_anyTop = m_otherTop.XmlElements; Assert.IsNotNull(m_anyTop); XmlDocument doc = new XmlDocument(); m_xe = doc.CreateElement("MyStuff"); string name = m_xe.Name; m_xe.SetAttribute("val", "true"); m_anyTop.Add(m_xe); XmlElement xeys = doc.CreateElement("YourStuff"); xeys.SetAttribute("ID", "YS1"); m_xe.AppendChild(xeys); m_gd.SaveData(m_fileName); m_otherTop = null; m_anyTop = null; m_gd = null; // Make sure it is there. m_gd = GAFAWSData.LoadData(m_fileName); }
public void LoadDataWithNullPathname() { m_gd = GAFAWSData.LoadData(null); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Static method used to create a well-formed instance of a GAFAWSData obejct /// from code. /// </summary> /// <returns></returns> /// ----------------------------------------------------------------------------------- public static GAFAWSData Create() { GAFAWSData gd = new GAFAWSData(); gd.m_wordRecords = new List<WordRecord>(); gd.m_morphemes = new List<Morpheme>(); gd.m_classes = new Classes(); gd.m_challenges = new List<Challenge>(); return gd; }
internal void Convert(SqlCommand cmd, GAFAWSData gData, Dictionary<string, FwMsa> prefixes, Dictionary<string, List<FwMsa>> stems, Dictionary<string, FwMsa> suffixes) { if (!CanConvert) return; WordRecord wr = new WordRecord(); // Deal with prefixes, if any. int startStemOrd = 0; foreach (KeyValuePair<int, FwMorphBundle> kvp in m_morphBundles) { FwMorphBundle mb = kvp.Value; string msaKey = mb.GetMsaKey(cmd); if (mb.MSA.Class == 5001 || mb.MSA.Class == 5031 || mb.MSA.Class == 5032 || mb.MSA.Class == 5117) // What about 5117-MoUnclassifiedAffixMsa? { // stem or derivational prefix, so bail out of this loop. startStemOrd = kvp.Key; break; } // Add prefix, if not already present. if (wr.Prefixes == null) wr.Prefixes = new List<Affix>(); if (!prefixes.ContainsKey(msaKey)) { prefixes.Add(msaKey, mb.MSA); gData.Morphemes.Add(new Morpheme(MorphemeType.prefix, msaKey)); } Affix afx = new Affix(); afx.MIDREF = msaKey; wr.Prefixes.Add(afx); } // Deal with suffixes, if any. // Work through the suffixes from the end of the word. // We stop when we hit the stem or a derivational suffix. int endStemOrd = 0; for (int i = m_morphBundles.Count; i > 0; --i) { FwMorphBundle mb = m_morphBundles[i]; string msaKey = mb.GetMsaKey(cmd); if (mb.MSA.Class == 5001 || mb.MSA.Class == 5031 || mb.MSA.Class == 5032 || mb.MSA.Class == 5117) // What about 5117-MoUnclassifiedAffixMsa? { // stem or derivational suffix, so bail out of this loop. endStemOrd = i; break; } // Add suffix, if not already present. if (wr.Suffixes == null) wr.Suffixes = new List<Affix>(); if (!suffixes.ContainsKey(msaKey)) { suffixes.Add(msaKey, mb.MSA); gData.Morphemes.Add(new Morpheme(MorphemeType.suffix, msaKey)); } Affix afx = new Affix(); afx.MIDREF = msaKey; wr.Suffixes.Insert(0, afx); } // Deal with stem. List<FwMsa> localStems = new List<FwMsa>(); string sStem = ""; foreach (KeyValuePair<int, FwMorphBundle> kvp in m_morphBundles) { FwMorphBundle mb = kvp.Value; int currentOrd = kvp.Key; if (currentOrd >= startStemOrd && currentOrd <= endStemOrd) { string msaKey = mb.GetMsaKey(cmd); string spacer = (currentOrd == 1) ? "" : " "; sStem += spacer + msaKey; } } if (!stems.ContainsKey(sStem)) { stems.Add(sStem, localStems); gData.Morphemes.Add(new Morpheme(MorphemeType.stem, sStem)); } Stem stem = new Stem(); stem.MIDREF = sStem; wr.Stem = stem; // Add wr. gData.WordRecords.Add(wr); }
internal void Convert(SqlCommand cmd, GAFAWSData gData, Dictionary<string, FwMsa> prefixes, Dictionary<string, List<FwMsa>> stems, Dictionary<string, FwMsa> suffixes) { foreach (FwAnalysis anal in m_analyses) anal.Convert(cmd, gData, prefixes, stems, suffixes); }
internal static void Reset() { s_gd = null; ANARecord.Reset(); ANAAnalysis.Reset(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="gd">Main GAFAWS data layer object.</param> /// <param name="messages">Set of status messages.</param> /// ----------------------------------------------------------------------------------- public SuffixClassAssigner(GAFAWSData gd, Dictionary <string, string> messages) : base(gd, messages) { m_classes = gd.Classes.SuffixClasses; m_classPrefix = "SP"; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Implements the IGAFAWS interface. /// </summary> /// <param name="gData">GAFAWSData to process.</param> /// ----------------------------------------------------------------------------------- public void Process(GAFAWSData gData) { LoadMessages(); // Replaces 8 lines in C++. m_gd = gData; if (m_gd == null) { return; } // Replaces CJGParadigm::GetAffixesFromDom() // 52 lines in C++. foreach (Morpheme m in m_gd.Morphemes) { switch (m.type) { case "pfx": m_prefixes.Add(m.MID, new MorphemeWrapper(m)); break; case "sfx": m_suffixes.Add(m.MID, new MorphemeWrapper(m)); break; //case "s": // Skip stems. } } if ((m_prefixes.Count + m_suffixes.Count) == 0) { return; // Nothing to do. } if (!AssignToSets()) { return; // Nothing to do. } // Find the classes for prefixes. PrefixClassAssigner pca = new PrefixClassAssigner(m_gd, m_messages); if (!pca.AssignClasses(m_prefixes)) { return; } // Find the classes for suffixes. SuffixClassAssigner sca = new SuffixClassAssigner(m_gd, m_messages); if (!sca.AssignClasses(m_suffixes)) { return; } foreach (KeyValuePair <string, MorphemeWrapper> kvp in m_prefixes) { kvp.Value.SetStartAndEnd(); } foreach (KeyValuePair <string, MorphemeWrapper> kvp in m_suffixes) { kvp.Value.SetStartAndEnd(); } // Set date and time. // Replaces 44 lines of C++ code. DateTime dt = DateTime.Now; m_gd.date = dt.ToLongDateString(); m_gd.time = dt.ToLongTimeString(); }
public void Init() { m_fileName = MakeFile(); m_gd = GAFAWSData.Create(); m_otherTop = new Other(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// ----------------------------------------------------------------------------------- public GafawsProcessor() { m_gd = GAFAWSData.Create(); }
public void Init() { m_gd = GAFAWSData.Create(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Implements the IGAFAWS interface. /// </summary> /// <param name="gData">GAFAWSData to process.</param> /// ----------------------------------------------------------------------------------- public void Process(GAFAWSData gData) { LoadMessages(); // Replaces 8 lines in C++. m_gd = gData; if (m_gd == null) return; // Replaces CJGParadigm::GetAffixesFromDom() // 52 lines in C++. foreach(Morpheme m in m_gd.Morphemes) { switch (m.type) { case "pfx": m_prefixes.Add(m.MID, new MorphemeWrapper(m)); break; case "sfx": m_suffixes.Add(m.MID, new MorphemeWrapper(m)); break; //case "s": // Skip stems. } } if ((m_prefixes.Count + m_suffixes.Count) == 0) return; // Nothing to do. if (!AssignToSets()) return; // Nothing to do. // Find the classes for prefixes. PrefixClassAssigner pca = new PrefixClassAssigner(m_gd, m_messages); if (!pca.AssignClasses(m_prefixes)) return; // Find the classes for suffixes. SuffixClassAssigner sca = new SuffixClassAssigner(m_gd, m_messages); if (!sca.AssignClasses(m_suffixes)) return; foreach (KeyValuePair<string, MorphemeWrapper> kvp in m_prefixes) kvp.Value.SetStartAndEnd(); foreach (KeyValuePair<string, MorphemeWrapper> kvp in m_suffixes) kvp.Value.SetStartAndEnd(); // Set date and time. // Replaces 44 lines of C++ code. DateTime dt = DateTime.Now; m_gd.date = dt.ToLongDateString(); m_gd.time = dt.ToLongTimeString(); }