public InflFeatureTreeModel(IFsFeatureSystem fdoFeatSys, IDictionary<IFsFeatDefn, object> inflFeats, Image complexImage, Image closedImage) { m_fdoFeatSys = fdoFeatSys; m_complexImage = complexImage; m_closedImage = closedImage; AddFeatures(Root, m_fdoFeatSys.FeaturesOC, inflFeats); }
/// <summary> /// /// </summary> /// <param name="featSys"></param> /// <param name="mediator"></param> /// <param name="launchedFromInsertMenu"></param> public void SetDlginfo(IFsFeatureSystem featSys, Mediator mediator, bool launchedFromInsertMenu) { // default to inflection features string sXmlFile = Path.Combine(DirectoryFinder.FWCodeDirectory, String.Format("Language Explorer{0}MGA{0}GlossLists{0}EticGlossList.xml", Path.DirectorySeparatorChar)); SetDlginfo(featSys, mediator, launchedFromInsertMenu, "masterInflFeatListDlg", sXmlFile); }
/// <summary> /// /// </summary> /// <param name="featSys"></param> /// <param name="mediator"></param> /// <param name="launchedFromInsertMenu"></param> /// <param name="sWindowKey">used to store location and size of dialog window</param> /// <param name="sXmlFile">file containing the XML form of the gloss list</param> public void SetDlginfo(IFsFeatureSystem featSys, Mediator mediator, bool launchedFromInsertMenu, string sWindowKey, string sXmlFile) { CheckDisposed(); m_featureSystem = featSys; m_featureList = featSys.FeaturesOC; m_launchedFromInsertMenu = launchedFromInsertMenu; m_mediator = mediator; if (mediator != null) { m_sWindowKeyLocation = sWindowKey + "Location"; m_sWindowKeySize = sWindowKey + "Size"; ResetWindowLocationAndSize(); m_helpTopicProvider = m_mediator.HelpTopicProvider; helpProvider = new HelpProvider(); helpProvider.HelpNamespace = m_helpTopicProvider.HelpFile; helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); } m_cache = featSys.Cache; LoadMasterFeatures(sXmlFile); m_tvMasterList.Cache = m_cache; }
/// <summary> /// /// </summary> /// <param name="featSys"></param> /// <param name="mediator"></param> /// <param name="launchedFromInsertMenu"></param> public void SetDlginfo(IFsFeatureSystem featSys, Mediator mediator, bool launchedFromInsertMenu) { // default to inflection features string sXmlFile = Path.Combine(DirectoryFinder.FWCodeDirectory, @"Language Explorer\MGA\GlossLists\EticGlossList.xml"); SetDlginfo(featSys, mediator, launchedFromInsertMenu, "masterInflFeatListDlg", sXmlFile); }
public InflFeatureTreeModel(IFsFeatureSystem fdoFeatSys, IDictionary <IFsFeatDefn, object> inflFeats, Image complexImage, Image closedImage) { m_fdoFeatSys = fdoFeatSys; m_complexImage = complexImage; m_closedImage = closedImage; AddFeatures(Root, m_fdoFeatSys.FeaturesOC, inflFeats); }
private IFsComplexFeature AddComplexFeature(IFsFeatureSystem featSys, string name, params IFsFeatDefn[] features) { IFsFeatStrucType type = AddFSType(featSys, name, features); IFsComplexFeature feat = Cache.ServiceLocator.GetInstance <IFsComplexFeatureFactory>().Create(); featSys.FeaturesOC.Add(feat); feat.Name.SetAnalysisDefaultWritingSystem(name); feat.Abbreviation.SetAnalysisDefaultWritingSystem(name); feat.TypeRA = type; return(feat); }
public void PopulateTreeFromFeatureSystem() { // Set up sample data IFsFeatStruc featStruct; ILangProject lp = CreateFeatureSystem(out featStruct); // Set up the xml fs description XmlDocument doc = new XmlDocument(); string sFileDir = Path.Combine(SIL.FieldWorks.Common.FwUtils.DirectoryFinder.FwSourceDirectory, Path.Combine(@"FDO", Path.Combine(@"FDOTests", @"TestData"))); string sFile = Path.Combine(sFileDir, "FeatureSystem2.xml"); doc.Load(sFile); XmlNode itemNeut = doc.SelectSingleNode("//item[@id='vNeut']"); // Add some complex features IFsFeatureSystem msfs = lp.MsFeatureSystemOA; msfs.AddFeatureFromXml(itemNeut); // Now add a feature that differs only in value XmlNode itemFem = doc.SelectSingleNode("//item[@id='vFem']"); msfs.AddFeatureFromXml(itemFem); // Now add another feature to the complex one XmlNode item1st = doc.SelectSingleNode("//item[@id='v1']"); msfs.AddFeatureFromXml(item1st); // now get a simple, top-level closed feature sFile = Path.Combine(sFileDir, "FeatureSystem3.xml"); doc.Load(sFile); XmlNode itemImpfv = doc.SelectSingleNode("//item[@id='vImpfv']"); msfs.AddFeatureFromXml(itemImpfv); XmlNode itemCont = doc.SelectSingleNode("//item[@id='vCont']"); msfs.AddFeatureFromXml(itemCont); using (var dlg = new FeatureSystemInflectionFeatureListDlg()) { ILexEntryInflType cobj = Cache.ServiceLocator.GetInstance <ILexEntryInflTypeFactory>().Create(); lp.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(cobj); dlg.SetDlgInfo(Cache, (Mediator)null, cobj, 0); // load some feature system values into treeview FeatureStructureTreeView tv = dlg.TreeView; Assert.AreEqual(2, tv.Nodes.Count, "Count of top level nodes in tree view"); TreeNodeCollection col = tv.Nodes[0].Nodes; Assert.AreEqual(3, col.Count, "Count of first level nodes in tree view"); } }
private IFsFeatStrucType AddFSType(IFsFeatureSystem featSys, string name, params IFsFeatDefn[] features) { IFsFeatStrucType type = Cache.ServiceLocator.GetInstance <IFsFeatStrucTypeFactory>().Create(); featSys.TypesOC.Add(type); type.Name.SetAnalysisDefaultWritingSystem(name); type.Abbreviation.SetAnalysisDefaultWritingSystem(name); foreach (IFsFeatDefn fd in features) { type.FeaturesRS.Add(fd); } return(type); }
private IFsClosedFeature AddClosedFeature(IFsFeatureSystem featSys, string name, params string[] values) { IFsClosedFeature feat = Cache.ServiceLocator.GetInstance <IFsClosedFeatureFactory>().Create(); featSys.FeaturesOC.Add(feat); feat.Name.SetAnalysisDefaultWritingSystem(name); feat.Abbreviation.SetAnalysisDefaultWritingSystem(name); foreach (string value in values) { IFsSymFeatVal symbol = Cache.ServiceLocator.GetInstance <IFsSymFeatValFactory>().Create(); feat.ValuesOC.Add(symbol); symbol.Name.SetAnalysisDefaultWritingSystem(value); symbol.Abbreviation.SetAnalysisDefaultWritingSystem(value); } return(feat); }
private ILangProject CreateFeatureSystem(out IFsFeatStruc featStruct) { featStruct = null; ILangProject lp = Cache.LanguageProject; // Set up the xml fs description XmlDocument doc = new XmlDocument(); string sFileDir = Path.Combine(SIL.FieldWorks.Common.FwUtils.DirectoryFinder.FwSourceDirectory, Path.Combine(@"FDO", Path.Combine(@"FDOTests", @"TestData"))); string sFile = Path.Combine(sFileDir, "FeatureSystem2.xml"); doc.Load(sFile); XmlNode itemNeut = doc.SelectSingleNode("//item[@id='vNeut']"); // Add the feature for first time IFsFeatureSystem msfs = lp.MsFeatureSystemOA; msfs.AddFeatureFromXml(itemNeut); // Now add a feature that differs only in value XmlNode itemFem = doc.SelectSingleNode("//item[@id='vFem']"); msfs.AddFeatureFromXml(itemFem); // now add to feature structure IPartOfSpeech pos = lp.PartsOfSpeechOA.PossibilitiesOS[0] as IPartOfSpeech; pos.DefaultFeaturesOA = Cache.ServiceLocator.GetInstance <IFsFeatStrucFactory>().Create(); featStruct = pos.DefaultFeaturesOA; // Add the first feature featStruct.AddFeatureFromXml(itemNeut, msfs); // Now add a feature that differs only in value; it should override the old one featStruct.AddFeatureFromXml(itemFem, msfs); // Now add another feature XmlNode item1st = doc.SelectSingleNode("//item[@id='v1']"); featStruct.AddFeatureFromXml(item1st, msfs); // Update inflectable features on pos XmlNode subjAgr = doc.SelectSingleNode("//item[@id='cSubjAgr']"); pos.AddInflectableFeatsFromXml(subjAgr); pos.AddInflectableFeatsFromXml(itemNeut); return(lp); }
private ILangProject CreateFeatureSystem(out IFsFeatStruc featStruct) { featStruct = null; ILangProject lp = Cache.LangProject; // Set up the xml fs description XmlDocument doc = new XmlDocument(); string sFileDir = Path.Combine(SIL.FieldWorks.Common.Utils.DirectoryFinder.FwSourceDirectory, @"FDO\FDOTests\TestData"); string sFile = Path.Combine(sFileDir, "FeatureSystem2.xml"); doc.Load(sFile); XmlNode itemNeut = doc.SelectSingleNode("//item[@id='vNeut']"); // Add the feature for first time FsFeatureSystem.AddFeatureAsXml(Cache, itemNeut); IFsFeatureSystem msfs = lp.MsFeatureSystemOA; // Now add a feature that differs only in value XmlNode itemFem = doc.SelectSingleNode("//item[@id='vFem']"); FsFeatureSystem.AddFeatureAsXml(Cache, itemFem); // now add to feature structure IPartOfSpeech pos = (IPartOfSpeech)lp.PartsOfSpeechOA.PossibilitiesOS.FirstItem; pos.DefaultFeaturesOA = new FsFeatStruc(); featStruct = pos.DefaultFeaturesOA; // Add the first feature featStruct.AddFeatureFromXml(Cache, itemNeut); // Now add a feature that differs only in value; it should override the old one featStruct.AddFeatureFromXml(Cache, itemFem); // Now add another feature XmlNode item1st = doc.SelectSingleNode("//item[@id='v1']"); featStruct.AddFeatureFromXml(Cache, item1st); // Update inflectable features on pos XmlNode subjAgr = doc.SelectSingleNode("//item[@id='cSubjAgr']"); pos.AddInflectableFeatsFromXml(Cache, subjAgr); pos.AddInflectableFeatsFromXml(Cache, itemNeut); return(lp); }
/// <summary> /// /// </summary> /// <param name="featSys"></param> /// <param name="mediator"></param> /// <param name="launchedFromInsertMenu"></param> /// <param name="sWindowKey">used to store location and size of dialog window</param> /// <param name="sXmlFile">file containing the XML form of the gloss list</param> public void SetDlginfo(IFsFeatureSystem featSys, Mediator mediator, bool launchedFromInsertMenu, string sWindowKey, string sXmlFile) { CheckDisposed(); m_featureSystem = featSys; m_featureList = featSys.FeaturesOC; m_launchedFromInsertMenu = launchedFromInsertMenu; m_mediator = mediator; if (mediator != null) { m_sWindowKeyLocation = sWindowKey + "Location"; m_sWindowKeySize = sWindowKey + "Size"; ResetWindowLocationAndSize(); } m_cache = featSys.Cache; LoadMasterFeatures(sXmlFile); m_tvMasterList.Cache = m_cache; }
protected override void CreateTestData() { m_noun = MakePartOfSpeech("noun"); m_verb = MakePartOfSpeech("verb"); m_adj = MakePartOfSpeech("adj"); IFsFeatureSystem msFeatSys = Cache.LanguageProject.MsFeatureSystemOA; m_inflType = AddFSType(msFeatSys, "infl", AddComplexFeature(msFeatSys, "nounAgr", AddClosedFeature(msFeatSys, "num", "sg", "pl")), AddClosedFeature(msFeatSys, "tense", "pres")); m_np = Cache.LangProject.GetDefaultTextTagList().ReallyReallyAllPossibilities.Single(poss => poss.Abbreviation.BestAnalysisAlternative.Text == "Noun Phrase"); ILexEntry ni = MakeEntry("ni-", m_verb, "1SgSubj"); ILexEntry him = MakeEntry("him-", m_verb, "3SgObj"); ILexEntry bili = MakeEntry("bili", m_verb, "to see"); ILexEntry ra = MakeEntry("-ra", m_verb, "Pres", new FS { { GetFeature("tense"), GetValue("pres") } }); ILexEntry pus = MakeEntry("pus", m_adj, "green"); ILexEntry yalo = MakeEntry("yalo", m_noun, "mat"); ILexEntry la = MakeEntry("-la", m_noun, "1SgPoss", new FS { { GetFeature("nounAgr"), new FS { { GetFeature("num"), GetValue("sg") } } } }); MakeWordform("nihimbilira", "I see", m_verb, ni, him, bili, ra); MakeWordform("pus", "green", m_adj, pus); MakeWordform("yalola", "my mat", m_noun, yalo, la); MakeWordform("ban", "test", MakePartOfSpeech("pos")); m_text = MakeText("nihimbilira pus, yalola ban."); var para = (IStTxtPara)m_text.ContentsOA.ParagraphsOS.First(); MakeTag(m_text, m_np, para.SegmentsOS.First(), 1, para.SegmentsOS.First(), 3); }
public override void AddToDatabase(FdoCache cache) { CheckDisposed(); if (m_fInDatabase) { return; // It's already in the database, so nothing more can be done. } string sType = XmlUtils.GetManditoryAttributeValue(m_node, "type"); if (sType == "feature") { cache.BeginUndoTask(MGAStrings.ksUndoCreatePhonologicalFeature, MGAStrings.ksRedoCreatePhonologicalFeature); ILangProject lp = cache.LangProject; IFsFeatureSystem featsys = lp.PhFeatureSystemOA as IFsFeatureSystem; // Since phonological features in the chooser only have features and no values, // we need to create the positive and negative value nodes string sName = XmlUtils.GetManditoryAttributeValue(m_node, "id"); const string sTemplate = "<item id='v{0}Positive' type='value'><abbrev ws='en'>+</abbrev><term ws='en'>positive</term>" + "<fs id='v{0}PositiveFS' type='Phon'><f name='{0}'><sym value='+'/></f></fs></item>" + "<item id='v{0}Negative' type='value'><abbrev ws='en'>-</abbrev><term ws='en'>negative</term>" + "<fs id='v{0}NegativeFS' type='Phon'><f name='{0}'><sym value='-'/></f></fs></item>"; StringBuilder sb = new StringBuilder(); sb.AppendFormat(sTemplate, sName.Substring(1)); m_node.InnerXml += sb.ToString(); // have to use a ndw document or, for some odd reason, it keeps on using an old value and not the new one... XmlDocument doc = new XmlDocument(); doc.LoadXml(m_node.OuterXml); // add positive value; note that the FsFeatDefn will be the same for both XmlNode valueNode = doc.SelectSingleNode("//item[contains(@id,'Positive')]"); m_featDefn = FsFeatureSystem.AddFeatureAsXml(cache, featsys, valueNode); // add negative value valueNode = doc.SelectSingleNode("//item[contains(@id,'Negative')]"); m_featDefn = FsFeatureSystem.AddFeatureAsXml(cache, featsys, valueNode); cache.EndUndoTask(); } }
/// <summary> /// Find feature defn based on XML or create it if not found /// </summary> /// <param name="item">Xml description of the item</param> /// <param name="featsys">FsFeatureSystem to add to</param> /// <param name="fst">the type</param> static public IFsFeatDefn FindOrCreateFeatureDefnBasedOnXmlNode(XmlNode item, IFsFeatureSystem featsys, IFsFeatStrucType fst) { IFsClosedFeature closed = null; IFsComplexFeature complex = null; XmlNodeList features = item.SelectNodes("fs/f"); foreach (XmlNode feature in features) { XmlNode featName = feature.SelectSingleNode("@name"); XmlNode fs = feature.SelectSingleNode("fs"); if (fs != null) { // do complex part // XmlNode type = fs.SelectSingleNode("@type"); string sType; if (type == null) sType = fst.Name.AnalysisDefaultWritingSystem; else sType = type.InnerText; IFsFeatStrucType complexFst = FindOrCreateFeatureTypeBasedOnXmlNode(featsys, sType, item); complex = FindOrCreateComplexFeatureBasedOnXmlNodes(featsys, featName, item, fst, complexFst); // use the type of the complex feature for the closed feature fst = complexFst; } closed = FindOrCreateClosedFeatureBasedOnXmlNodes(featsys, featName, item); SetFeaturesInTypeBasedOnXmlNode(fst, item, closed); FindOrCreateSymbolicValueBasedOnXmlNode(feature, closed, item); } if (complex != null) return complex; else return closed; }
IFsComplexFeature IFsComplexFeatureFactory.Create(Guid guid, IFsFeatureSystem owner) { if (owner == null) throw new ArgumentNullException("owner"); int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo(); int flid = m_cache.MetaDataCache.GetFieldId("FsFeatureSystem", "Features", false); var retval = new FsComplexFeature(m_cache, hvo, guid); owner.FeaturesOC.Add(retval); return retval; }
private void CreateNewPhonFeature(IFsFeatureSystem featSystem, XmlDocument phonFeatList, string sFeatureId) { XmlNode item = phonFeatList.SelectSingleNode("//item[@id='" + sFeatureId + "']"); // Since phonological features in the chooser only have features and no values, // we need to create the positive and negative value nodes string sName = XmlUtils.GetManditoryAttributeValue(item, "id"); const string sTemplate = "<item id='v{0}Positive' type='value'><abbrev ws='en'>+</abbrev><term ws='en'>positive</term>" + "<fs id='v{0}PositiveFS' type='Phon'><f name='{0}'><sym value='+'/></f></fs></item>" + "<item id='v{0}Negative' type='value'><abbrev ws='en'>-</abbrev><term ws='en'>negative</term>" + "<fs id='v{0}NegativeFS' type='Phon'><f name='{0}'><sym value='-'/></f></fs></item>"; StringBuilder sb = new StringBuilder(); sb.AppendFormat(sTemplate, sName.Substring(1)); item.InnerXml += sb.ToString(); // have to use a ndw document or, for some odd reason, it keeps on using an old value and not the new one... XmlDocument doc = new XmlDocument(); doc.LoadXml(item.OuterXml); // add positive value; note that the FsFeatDefn will be the same for both XmlNode valueNode = doc.SelectSingleNode("//item[contains(@id,'Positive')]"); FsFeatureSystem.AddFeatureAsXml(Cache, featSystem, valueNode); // add negative value valueNode = doc.SelectSingleNode("//item[contains(@id,'Negative')]"); FsFeatureSystem.AddFeatureAsXml(Cache, featSystem, valueNode); }
/// <summary> /// Add a feature to the feature system (unless it's already there) /// </summary> /// <param name="cache">FDO cache</param> /// <param name="featsys">the feature system to use</param> /// <param name="item">the node containing a description of the feature</param> static public IFsFeatDefn AddFeatureAsXml(FdoCache cache, IFsFeatureSystem featsys, XmlNode item) { XmlNode type; if (!FeatureCanBeAdded(cache, item, out type)) return null; IFsFeatStrucType fst = FindOrCreateFeatureTypeBasedOnXmlNode(featsys, type.InnerText, item); IFsFeatDefn defn = FindOrCreateFeatureDefnBasedOnXmlNode(item, featsys, fst); return defn; }
public void AddClosedFeaturesToFeatureSystemAndThenToAFeatureStructure() { ILangProject lp = Cache.LangProject; // Set up the xml fs description XmlDocument doc = new XmlDocument(); doc.LoadXml(m_ksFS1); XmlNode itemNeut = doc.SelectSingleNode("/item/item[3]"); // Add the feature for first time FsFeatureSystem.AddFeatureAsXml(Cache, itemNeut); IFsFeatureSystem msfs = lp.MsFeatureSystemOA; Assert.AreEqual(1, msfs.TypesOC.Count, "should have one type"); Assert.AreEqual(1, msfs.FeaturesOC.Count, "should have one feature"); foreach (IFsFeatStrucType type in msfs.TypesOC) { Assert.AreEqual("Agr", type.Abbreviation.AnalysisDefaultWritingSystem, "Expect to have Agr type"); Assert.AreEqual(1, type.FeaturesRS.Count, "Expect to have one feature in the type"); IFsClosedFeature closed = (IFsClosedFeature)type.FeaturesRS.FirstItem; Assert.AreEqual("gender", closed.Name.AnalysisDefaultWritingSystem, "Expect name of gender"); } foreach (IFsClosedFeature closed in msfs.FeaturesOC) { Assert.AreEqual("gender", closed.Name.AnalysisDefaultWritingSystem, "Expect to have gender feature"); foreach (IFsSymFeatVal value in closed.ValuesOC) { Assert.AreEqual("neuter gender", value.Name.AnalysisDefaultWritingSystem, "Expect neuter value"); } } // Now add a feature that differs only in value XmlNode itemFem = doc.SelectSingleNode("/item/item[2]"); FsFeatureSystem.AddFeatureAsXml(Cache, itemFem); Assert.AreEqual(1, msfs.TypesOC.Count, "should have one type"); Assert.AreEqual(1, msfs.FeaturesOC.Count, "should have one feature"); foreach (IFsFeatStrucType type in msfs.TypesOC) { Assert.AreEqual("Agr", type.Abbreviation.AnalysisDefaultWritingSystem, "Expect to have Agr type"); } foreach (IFsClosedFeature closed in msfs.FeaturesOC) { Assert.AreEqual("gender", closed.Name.AnalysisDefaultWritingSystem, "Expect to have gender feature"); Assert.AreEqual(2, closed.ValuesOC.Count, "should have two values"); foreach (IFsSymFeatVal cv in closed.ValuesOC) { if (cv.Name.AnalysisDefaultWritingSystem != "neuter gender" && cv.Name.AnalysisDefaultWritingSystem != "feminine gender") { Assert.Fail("Unexpected value found: {0}", cv.Name.AnalysisDefaultWritingSystem); } } } // now add to feature structure IPartOfSpeech pos = (IPartOfSpeech)lp.PartsOfSpeechOA.PossibilitiesOS.FirstItem; pos.DefaultFeaturesOA = new FsFeatStruc(); IFsFeatStruc featStruct = pos.DefaultFeaturesOA; // Add the first feature featStruct.AddFeatureFromXml(Cache, itemNeut); Assert.AreEqual("Agr", featStruct.TypeRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect type Agr"); Assert.AreEqual(1, featStruct.FeatureSpecsOC.Count, "should have one feature spec"); foreach (IFsClosedValue cv in featStruct.FeatureSpecsOC) { Assert.AreEqual("Gen", cv.FeatureRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect to have Gen feature name"); Assert.AreEqual("Neut", cv.ValueRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect to have Neut feature value"); } // Now add a feature that differs only in value; it should override the old one featStruct.AddFeatureFromXml(Cache, itemFem); Assert.AreEqual("Agr", featStruct.TypeRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect type Agr"); Assert.AreEqual(1, featStruct.FeatureSpecsOC.Count, "should have one feature spec"); foreach (IFsClosedValue cv in featStruct.FeatureSpecsOC) { if (cv.FeatureRA.Name.AnalysisDefaultWritingSystem != "gender" || cv.ValueRA.Name.AnalysisDefaultWritingSystem != "feminine gender") { Assert.Fail("Unexpected value found: {0}:{1}", cv.FeatureRA.Name.AnalysisDefaultWritingSystem, cv.ValueRA.Name.AnalysisDefaultWritingSystem); } } // Update inflectable features on pos pos.AddInflectableFeatsFromXml(Cache, itemNeut); Assert.AreEqual(1, pos.InflectableFeatsRC.Count, "should have 1 inflectable feature in pos"); foreach (IFsClosedFeature closed in pos.InflectableFeatsRC) { Assert.AreEqual("gender", closed.Name.AnalysisDefaultWritingSystem, "expect to find gender in pos inflectable features"); } // Check for correct ShortName string in closed Assert.AreEqual("Fem", featStruct.ShortName, "Incorrect ShortName for closed"); // Check for correct LongName string in complex Assert.AreEqual("[Gen:Fem]", featStruct.LongName, "Incorrect LongName for closed"); }
/// <summary> /// Find a feature structure type or create it if not already there; use XML item to do it /// </summary> /// <param name="featsys">feature system to use</param> /// <param name="sType">the type</param> /// <param name="item">the item that is going to be added</param> /// <returns>FsFeatStrucType corresponding to the type</returns> static public IFsFeatStrucType FindOrCreateFeatureTypeBasedOnXmlNode(IFsFeatureSystem featsys, string sType, XmlNode item) { IFsFeatStrucType fst = null; #if ForRandy bool fAlreadyThere = false; foreach (IFsFeatStrucType fst2 in featsys.TypesOC) { if (fst2.CatalogSourceId == sType) { fAlreadyThere = true; fst = fst2; break; } } if (!fAlreadyThere) { fst = featsys.TypesOC.Add(new FsFeatStrucType()); fst.CatalogSourceId = sType; XmlNode parentFsType = item.SelectSingleNode("ancestor::item[@type='fsType' and not(@status)]"); if (parentFsType == null) { // do not have any real values for abbrev, name, or description. Just use the abbreviation foreach (ILgWritingSystem ws in cache.LangProject.AnalysisWssRC) { fst.Abbreviation.SetAlternative(sType, ws.Hvo); fst.Name.SetAlternative(sType, ws.Hvo); } } else { foreach (ILgWritingSystem ws in cache.LangProject.AnalysisWssRC) { string sValue = GetValueOfPattern(sType, parentFsType, "abbrev", ws); fst.Abbreviation.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(sType, parentFsType, "term", ws); fst.Name.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(sType, parentFsType, "def", ws); fst.Description.SetAlternative(sValue, ws.Hvo); } } } #else FdoCache cache = featsys.Cache; int hvo = GetFeatureType(cache, sType); if (hvo > 0) fst = CmObject.CreateFromDBObject(cache, hvo) as IFsFeatStrucType; else { fst = featsys.TypesOC.Add(new FsFeatStrucType()); fst.CatalogSourceId = sType; XmlNode parentFsType = item.SelectSingleNode("ancestor::item[@type='fsType' and not(@status)]"); if (parentFsType == null) { // do not have any real values for abbrev, name, or description. Just use the abbreviation foreach (ILgWritingSystem ws in cache.LangProject.AnalysisWssRC) { fst.Abbreviation.SetAlternative(sType, ws.Hvo); fst.Name.SetAlternative(sType, ws.Hvo); } } else { foreach (ILgWritingSystem ws in cache.LangProject.AnalysisWssRC) { string sValue = GetValueOfPattern(parentFsType, "abbrev", ws); if (sValue != null) fst.Abbreviation.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(parentFsType, "term", ws); if (sValue != null) fst.Name.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(parentFsType, "def", ws); if (sValue != null) fst.Description.SetAlternative(sValue, ws.Hvo); } } } #endif return fst; }
/// <summary> /// Find a complex feature or create it if not already there; use XML item to do it /// </summary> /// <param name="featsys">feature system to use</param> /// <param name="featName">XML node containing the name of the complex feature</param> /// <param name="item">XML item</param> /// <param name="fst">feature structure type which refers to this complex feature</param> /// <param name="complexFst">feature structure type of the complex feature</param> /// <returns>IFsComplexFeature corresponding to the name</returns> static public IFsComplexFeature FindOrCreateComplexFeatureBasedOnXmlNodes(IFsFeatureSystem featsys, XmlNode featName, XmlNode item, IFsFeatStrucType fst, IFsFeatStrucType complexFst) { IFsComplexFeature complex = null; XmlNode id = item.SelectSingleNode("../../../@id"); if (id == null) return null; FdoCache cache = featsys.Cache; #if ForRandy bool fAlreadyThere = false; foreach (IFsFeatDefn defn in featsys.FeaturesOC) { if (defn.CatalogSourceId == id.InnerText) { complex = defn as IFsComplexFeature; fAlreadyThere = true; break; } } if (!fAlreadyThere) { #else int hvo = GetComplexFeature(cache, id.InnerText); if (hvo > 0) complex = CmObject.CreateFromDBObject(cache, hvo) as IFsComplexFeature; else { #endif // Had following, but causes problem in record clerk browse view because it invokes a PropChanged //complex = (FsComplexFeature)featsys.FeaturesOC.Add(new FsComplexFeature()); // CreateObject creates the entry without a PropChanged. int flid = (int)FsFeatureSystem.FsFeatureSystemTags.kflidFeatures; int featureHvo = cache.CreateObject(FsComplexFeature.kClassId, featsys.Hvo, flid, 0); // 0 is fine, since the owning prop is not a sequence. complex = FsComplexFeature.CreateFromDBObject(cache, featureHvo); complex.CatalogSourceId = id.InnerText; foreach (ILgWritingSystem ws in cache.LangProject.AnalysisWssRC) { string sValue = GetValueOfPattern(item, "../../../abbrev", ws); if (sValue != null) complex.Abbreviation.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(item, "../../../term", ws); if (sValue != null) complex.Name.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(item, "../../../def", ws); if (sValue != null) complex.Description.SetAlternative(sValue, ws.Hvo); } SetFeaturesInTypeBasedOnXmlNode(fst, item, complex); complex.TypeRA = complexFst; } return complex; }
/// <summary> /// Find a close feature or create it if not already there; use XML item to do it /// </summary> /// <param name="featsys">feature system to use</param> /// <param name="featName">XML node containing the name of the closed feature</param> /// <param name="item">XML item</param> /// <returns>FsClosedFeature corresponding to the name</returns> static public IFsClosedFeature FindOrCreateClosedFeatureBasedOnXmlNodes(IFsFeatureSystem featsys, XmlNode featName, XmlNode item) { IFsClosedFeature closed = null; XmlNode id = item.SelectSingleNode("ancestor::item[@type='feature']/@id"); if (id == null) return closed; #if ForRandy bool fAlreadyThere = false; foreach (IFsFeatDefn defn in featsys.FeaturesOC) { if (defn.CatalogSourceId == id.InnerText) { closed = defn as FsClosedFeature; fAlreadyThere = true; break; } } if (!fAlreadyThere) { // Had following, but causes problem in record clerk browse view because it invokes a PropChanged //closed = (FsClosedFeature)featsys.FeaturesOC.Add(new FsClosedFeature()); // CreateObject creates the entry without a PropChanged. ILgWritingSystemFactory wsFactory = cache.LanguageWritingSystemFactoryAccessor; int flid = (int) FsFeatureSystem.FsFeatureSystemTags.kflidFeatures; int featureHvo = cache.CreateObject(FsClosedFeature.kClassId, featsys.Hvo, flid, 0); // 0 is fine, since the owning prop is not a sequence. closed = FsClosedFeature.CreateFromDBObject(cache, featureHvo); closed.CatalogSourceId = id.InnerText; XmlNode featureNode = item.SelectSingleNode("ancestor::item[@type='feature']"); XmlNode abbr = featureNode.SelectSingleNode("abbrev"); SetInnerText(closed.Abbreviation, wsFactory, abbr); XmlNode term = featureNode.SelectSingleNode("term"); SetInnerText(closed.Name, wsFactory, term); XmlNode def = featureNode.SelectSingleNode("def"); SetInnerXml(closed.Description, wsFactory, def); } #else FdoCache cache = featsys.Cache; int hvo = GetClosedFeature(cache, id.InnerText); if (hvo > 0) closed = CmObject.CreateFromDBObject(cache, hvo) as IFsClosedFeature; else { // Had following, but causes problem in record clerk browse view because it invokes a PropChanged //closed = (FsClosedFeature)featsys.FeaturesOC.Add(new FsClosedFeature()); // CreateObject creates the entry without a PropChanged. int flid = (int) FsFeatureSystem.FsFeatureSystemTags.kflidFeatures; int featureHvo = cache.CreateObject(FsClosedFeature.kClassId, featsys.Hvo, flid, 0); // 0 is fine, since the owning prop is not a sequence. closed = FsClosedFeature.CreateFromDBObject(cache, featureHvo); closed.CatalogSourceId = id.InnerText; XmlNode featureNode = item.SelectSingleNode("ancestor::item[@type='feature']"); foreach (ILgWritingSystem ws in cache.LangProject.AnalysisWssRC) { string sValue = GetValueOfPattern(featureNode, "abbrev", ws); if (sValue != null) closed.Abbreviation.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(featureNode, "term", ws); if (sValue != null) closed.Name.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(featureNode, "def", ws); if (sValue != null) closed.Description.SetAlternative(sValue, ws.Hvo); } } #endif return closed; }
public void AddComplexFeaturesToFeatureSystemAndThenToAFeatureStructure() { ILangProject lp = Cache.LangProject; Assert.IsNotNull(lp.MsFeatureSystemOA, "Expect a feature system to be present"); // Set up the xml fs description XmlDocument doc = new XmlDocument(); string sFileDir = Path.Combine(SIL.FieldWorks.Common.Utils.DirectoryFinder.FwSourceDirectory, @"FDO\FDOTests\TestData"); string sFile = Path.Combine(sFileDir, "FeatureSystem2.xml"); doc.Load(sFile); XmlNode itemNeut = doc.SelectSingleNode("//item[@id='vNeut']"); // Add the feature for first time FsFeatureSystem.AddFeatureAsXml(Cache, itemNeut); IFsFeatureSystem msfs = lp.MsFeatureSystemOA; Assert.AreEqual(1, msfs.TypesOC.Count, "should have two types"); Assert.AreEqual(2, msfs.FeaturesOC.Count, "should have two features"); foreach (IFsFeatStrucType type in msfs.TypesOC) { string sName = type.Name.AnalysisDefaultWritingSystem; if (sName != "Subject agreement") { Assert.Fail("Unexpected fs type found: {0}", sName); } Assert.AreEqual(1, type.FeaturesRS.Count, "Expect to have one feature in the type"); IFsFeatDefn defn = (IFsFeatDefn)type.FeaturesRS.FirstItem; Assert.IsNotNull(defn, "first feature in type {0} is not null", sName); IFsComplexFeature complex = defn as IFsComplexFeature; if (complex != null) { Assert.AreEqual("subject agreement", complex.Name.AnalysisDefaultWritingSystem, "Expect name of subject agreement"); } IFsClosedFeature closed = defn as IFsClosedFeature; if (closed != null) { Assert.AreEqual("gender", closed.Name.AnalysisDefaultWritingSystem, "Expect to have gender feature"); foreach (IFsSymFeatVal value in closed.ValuesOC) { Assert.AreEqual("neuter gender", value.Name.AnalysisDefaultWritingSystem, "Expect neuter value"); } } } foreach (IFsFeatDefn defn in msfs.FeaturesOC) { IFsComplexFeature complex = defn as IFsComplexFeature; if (complex != null) { Assert.AreEqual("subject agreement", complex.Name.AnalysisDefaultWritingSystem, "Expect to have subject agreement feature"); } IFsClosedFeature closed = defn as IFsClosedFeature; if (closed != null) { Assert.AreEqual("gender", closed.Name.AnalysisDefaultWritingSystem, "Expect to have gender feature"); foreach (IFsSymFeatVal value in closed.ValuesOC) { Assert.AreEqual("neuter gender", value.Name.AnalysisDefaultWritingSystem, "Expect neuter value"); } } } // Now add a feature that differs only in value XmlNode itemFem = doc.SelectSingleNode("//item[@id='vFem']"); FsFeatureSystem.AddFeatureAsXml(Cache, itemFem); Assert.AreEqual(1, msfs.TypesOC.Count, "should have two types"); Assert.AreEqual(2, msfs.FeaturesOC.Count, "should have two features"); foreach (IFsFeatStrucType type in msfs.TypesOC) { string sName = type.Name.AnalysisDefaultWritingSystem; if (sName != "Subject agreement") { Assert.Fail("Unexpected fs type found: {0}", sName); } } foreach (IFsFeatDefn defn in msfs.FeaturesOC) { IFsComplexFeature complex = defn as IFsComplexFeature; if (complex != null) { Assert.AreEqual("subject agreement", complex.Name.AnalysisDefaultWritingSystem, "Expect to have subject agreement feature"); } IFsClosedFeature closed = defn as IFsClosedFeature; if (closed != null) { Assert.AreEqual("gender", closed.Name.AnalysisDefaultWritingSystem, "Expect to have gender feature"); Assert.AreEqual(2, closed.ValuesOC.Count, "should have two values"); foreach (IFsSymFeatVal cv in closed.ValuesOC) { if (cv.Name.AnalysisDefaultWritingSystem != "neuter gender" && cv.Name.AnalysisDefaultWritingSystem != "feminine gender") { Assert.Fail("Unexpected value found: {0}", cv.Name.AnalysisDefaultWritingSystem); } } } } // now add to feature structure IPartOfSpeech pos = (IPartOfSpeech)lp.PartsOfSpeechOA.PossibilitiesOS.FirstItem; Assert.IsNotNull(pos, "Need one non-null pos"); pos.DefaultFeaturesOA = new FsFeatStruc(); IFsFeatStruc featStruct = pos.DefaultFeaturesOA; // Add the first feature featStruct.AddFeatureFromXml(Cache, itemNeut); Assert.AreEqual("sbj", featStruct.TypeRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect type sbj"); Assert.AreEqual(1, featStruct.FeatureSpecsOC.Count, "should have one feature spec"); foreach (IFsFeatureSpecification fspec in featStruct.FeatureSpecsOC) { IFsComplexValue complex = fspec as IFsComplexValue; Assert.IsNotNull(complex, "Should have non-null complex feature value"); IFsFeatStruc nestedFs = (IFsFeatStruc)complex.ValueOA; Assert.IsNotNull(nestedFs, "Should have non-null nested fs"); foreach (IFsClosedValue cv in nestedFs.FeatureSpecsOC) { Assert.AreEqual("gen", cv.FeatureRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect to have gen feature name"); Assert.AreEqual("n", cv.ValueRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect to have 'n' feature value"); } } // Now add a feature that differs only in value; it should override the old one featStruct.AddFeatureFromXml(Cache, itemFem); Assert.AreEqual("sbj", featStruct.TypeRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect type sbj"); Assert.AreEqual(1, featStruct.FeatureSpecsOC.Count, "should have one feature spec"); foreach (IFsFeatureSpecification fspec in featStruct.FeatureSpecsOC) { IFsComplexValue complex = fspec as IFsComplexValue; Assert.IsNotNull(complex, "Should have non-null complex feature value"); IFsFeatStruc nestedFs = (IFsFeatStruc)complex.ValueOA; Assert.IsNotNull(nestedFs, "Should have non-null nested fs"); foreach (IFsClosedValue cv in nestedFs.FeatureSpecsOC) { if (cv.FeatureRA.Name.AnalysisDefaultWritingSystem != "gender" && cv.ValueRA.Name.AnalysisDefaultWritingSystem != "feminine gender") { Assert.Fail("Unexpected value found: {0}:{1}", cv.FeatureRA.Name.AnalysisDefaultWritingSystem, cv.ValueRA.Name.AnalysisDefaultWritingSystem); } } } // Now add another feature XmlNode item1st = doc.SelectSingleNode("//item[@id='v1']"); featStruct.AddFeatureFromXml(Cache, item1st); Assert.AreEqual("sbj", featStruct.TypeRA.Abbreviation.AnalysisDefaultWritingSystem, "Expect type sbj"); Assert.AreEqual(1, featStruct.FeatureSpecsOC.Count, "should have one feature spec at top feature structure"); foreach (IFsFeatureSpecification fspec in featStruct.FeatureSpecsOC) { IFsComplexValue complex = fspec as IFsComplexValue; Assert.IsNotNull(complex, "Should have non-null complex feature value"); IFsFeatStruc nestedFs = (IFsFeatStruc)complex.ValueOA; Assert.IsNotNull(nestedFs, "Should have non-null nested fs"); Assert.AreEqual(2, nestedFs.FeatureSpecsOC.Count, "should have two feature specs in nested feature structure"); foreach (IFsClosedValue cv in nestedFs.FeatureSpecsOC) { if (!(((cv.FeatureRA.Name.AnalysisDefaultWritingSystem == "gender") && (cv.ValueRA.Name.AnalysisDefaultWritingSystem == "feminine gender")) || ((cv.FeatureRA.Name.AnalysisDefaultWritingSystem == "person") && (cv.ValueRA.Name.AnalysisDefaultWritingSystem == "first person")))) { Assert.Fail("Unexpected value found: {0}:{1}", cv.FeatureRA.Name.AnalysisDefaultWritingSystem, cv.ValueRA.Name.AnalysisDefaultWritingSystem); } } } // Update inflectable features on pos pos.AddInflectableFeatsFromXml(Cache, itemNeut); Assert.AreEqual(1, pos.InflectableFeatsRC.Count, "should have 1 inflectable feature in pos"); foreach (IFsFeatDefn defn in pos.InflectableFeatsRC) { IFsComplexFeature complex = defn as IFsComplexFeature; if (complex != null) { Assert.AreEqual("subject agreement", complex.Name.AnalysisDefaultWritingSystem, "expect to find subject agreement in pos inflectable features"); } } // Check for correct ShortName string in complex Assert.AreEqual("1 f", featStruct.ShortName, "Incorrect ShortName for complex"); // Check for correct LongName string in complex Assert.AreEqual("[sbj:[pers:1 gen:f]]", featStruct.LongName, "Incorrect LongName for complex"); // Now add a closed feature not at the same level sFile = Path.Combine(sFileDir, "FeatureSystem3.xml"); doc = null; doc = new XmlDocument(); doc.Load(sFile); XmlNode itemAorist = doc.SelectSingleNode("//item[@id='xAor']"); FsFeatureSystem.AddFeatureAsXml(Cache, itemAorist); pos.AddInflectableFeatsFromXml(Cache, itemAorist); featStruct.AddFeatureFromXml(Cache, itemAorist); // Check for correct LongName Assert.AreEqual("[asp:aor sbj:[pers:1 gen:f]]", featStruct.LongName, "Incorrect LongName for complex and closed"); // Now add the features in the featurs struct in a different order pos.DefaultFeaturesOA = null; pos.DefaultFeaturesOA = new FsFeatStruc(); featStruct = pos.DefaultFeaturesOA; featStruct.AddFeatureFromXml(Cache, itemAorist); featStruct.AddFeatureFromXml(Cache, item1st); featStruct.AddFeatureFromXml(Cache, itemFem); // check for correct short name Assert.AreEqual("f 1 aor", featStruct.ShortName, "Incorrect ShortName for complex"); // Check for correct LongName Assert.AreEqual("[sbj:[gen:f pers:1] asp:aor]", featStruct.LongName, "Incorrect LongName for complex and closed"); }
private IFsComplexFeature AddComplexFeature(IFsFeatureSystem featSys, string name, params IFsFeatDefn[] features) { IFsFeatStrucType type = AddFSType(featSys, name, features); IFsComplexFeature feat = Cache.ServiceLocator.GetInstance<IFsComplexFeatureFactory>().Create(); featSys.FeaturesOC.Add(feat); feat.Name.SetAnalysisDefaultWritingSystem(name); feat.Abbreviation.SetAnalysisDefaultWritingSystem(name); feat.TypeRA = type; return feat; }
/// <summary> /// /// </summary> /// <param name="featSys"></param> /// <param name="mediator"></param> /// <param name="launchedFromInsertMenu"></param> public void SetDlginfo(IFsFeatureSystem featSys, Mediator mediator, bool launchedFromInsertMenu) { // default to inflection features string sXmlFile = Path.Combine(FwDirectoryFinder.CodeDirectory, String.Format("Language Explorer{0}MGA{0}GlossLists{0}EticGlossList.xml", Path.DirectorySeparatorChar)); SetDlginfo(featSys, mediator, launchedFromInsertMenu, "masterInflFeatListDlg", sXmlFile); }
private void CreateFeatStruc(IFsFeatureSystem featSys, IFsFeatStrucType type, IFsFeatStruc fs, FS featVals) { fs.TypeRA = type; foreach (KeyValuePair<string, object> featVal in featVals) { IFsFeatDefn fd = featSys.FeaturesOC.First(f => f.Abbreviation.AnalysisDefaultWritingSystem.Text == featVal.Key); var closedFeat = fd as IFsClosedFeature; if (closedFeat != null) { IFsSymFeatVal sym = closedFeat.ValuesOC.First(v => v.Abbreviation.AnalysisDefaultWritingSystem.Text == (string) featVal.Value); IFsClosedValue cv = Cache.ServiceLocator.GetInstance<IFsClosedValueFactory>().Create(); fs.FeatureSpecsOC.Add(cv); cv.FeatureRA = fd; cv.ValueRA = sym; } else { var complexFeat = (IFsComplexFeature) fd; IFsComplexValue cv = Cache.ServiceLocator.GetInstance<IFsComplexValueFactory>().Create(); fs.FeatureSpecsOC.Add(cv); IFsFeatStruc childFS = Cache.ServiceLocator.GetInstance<IFsFeatStrucFactory>().Create(); cv.FeatureRA = fd; cv.ValueOA = childFS; CreateFeatStruc(featSys, complexFeat.TypeRA, childFS, (FS) featVal.Value); } } }
private IFsClosedFeature AddClosedFeature(IFsFeatureSystem featSys, string name, params string[] values) { IFsClosedFeature feat = Cache.ServiceLocator.GetInstance<IFsClosedFeatureFactory>().Create(); featSys.FeaturesOC.Add(feat); feat.Name.SetAnalysisDefaultWritingSystem(name); feat.Abbreviation.SetAnalysisDefaultWritingSystem(name); foreach (string value in values) { IFsSymFeatVal symbol = Cache.ServiceLocator.GetInstance<IFsSymFeatValFactory>().Create(); feat.ValuesOC.Add(symbol); symbol.Name.SetAnalysisDefaultWritingSystem(value); symbol.Abbreviation.SetAnalysisDefaultWritingSystem(value); } return feat; }
private static XElement ExportFeatureSystem(IFsFeatureSystem featureSystem, string elementName, Icu.UNormalizationMode mode) { return new XElement(elementName, new XAttribute("Id", featureSystem.Hvo), new XElement("Types", from type in featureSystem.TypesOC select new XElement("FsFeatStrucType", new XAttribute("Id", type.Hvo), ExportBestAnalysis(type.Name, "Name", mode), ExportBestAnalysis(type.Description, "Description", mode), ExportBestAnalysis(type.Abbreviation, "Abbreviation", mode), new XElement("Features", from featureRef in type.FeaturesRS select ExportItemAsReference(featureRef, "Feature")))), new XElement("Features", from featDefn in featureSystem.FeaturesOC select ExportFeatureDefn(featDefn, mode))); }
private IFsFeatStrucType AddFSType(IFsFeatureSystem featSys, string name, params IFsFeatDefn[] features) { IFsFeatStrucType type = Cache.ServiceLocator.GetInstance<IFsFeatStrucTypeFactory>().Create(); featSys.TypesOC.Add(type); type.Name.SetAnalysisDefaultWritingSystem(name); type.Abbreviation.SetAnalysisDefaultWritingSystem(name); type.FeaturesRS.AddRange(features); return type; }