private void m_tree_TreeLoad(object sender, EventArgs e) { if (m_PhonologicalFeatureTreeManager == null) { if (!String.IsNullOrEmpty(m_featDefnAbbr)) { // Find the feature definition this editor was created to choose options from var featDefns = from s in m_cache.LangProject.PhFeatureSystemOA.FeaturesOC where s.Abbreviation.BestAnalysisAlternative.Text == m_featDefnAbbr select s; if (featDefns.Any()) { m_closedFeature = featDefns.First() as IFsClosedFeature; } } m_PhonologicalFeatureTreeManager = new PhonologicalFeaturePopupTreeManager(m_tree, m_cache, false, m_mediator, (Form) m_mediator.PropertyTable.GetValue( "window"), m_displayWs, m_closedFeature); m_PhonologicalFeatureTreeManager.AfterSelect += new TreeViewEventHandler(m_PhonFeaturePopupTreeManager_AfterSelect); } m_PhonologicalFeatureTreeManager.LoadPopupTree(0); }
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 void AddNode(IFsFeatDefn defn, FeatureTreeNode parentNode) { IFsClosedFeature closed = defn as IFsClosedFeature; if (closed != null) { if (!AlreadyInTree(closed.Hvo, parentNode)) { // avoid duplicates FeatureTreeNode newNode = new FeatureTreeNode(closed.Name.AnalysisDefaultWritingSystem, (int)ImageKind.feature, (int)ImageKind.feature, closed.Hvo, FeatureTreeNodeInfo.NodeKind.Closed); InsertNode(newNode, parentNode); foreach (IFsSymFeatVal val in closed.ValuesOC) { AddNode(val, newNode); } } } IFsComplexFeature complex = defn as IFsComplexFeature; if (complex != null) { if (!AlreadyInTree(complex.Hvo, parentNode)) { // avoid infinite loop if a complex feature's type is the same as other features. FeatureTreeNode newNode = new FeatureTreeNode(complex.Name.BestAnalysisAlternative.Text, (int)ImageKind.complex, (int)ImageKind.complex, complex.Hvo, FeatureTreeNodeInfo.NodeKind.Complex); InsertNode(newNode, parentNode); IFsFeatStrucType type = complex.TypeRA; foreach (IFsFeatDefn defn2 in type.FeaturesRS) { AddNode(defn2, newNode); } } } }
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"); }
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"); }
/// <summary> /// Constructor. /// </summary> public PhonologicalFeaturePopupTreeManager(TreeCombo treeCombo, FdoCache cache, bool useAbbr, Mediator mediator, Form parent, int wsDisplay, IFsClosedFeature closedFeature) : base(treeCombo, cache, mediator, cache.LanguageProject.PartsOfSpeechOA, wsDisplay, useAbbr, parent) { m_closedFeature = closedFeature; }
private void m_tree_TreeLoad(object sender, EventArgs e) { if (m_PhonologicalFeatureTreeManager == null) { if (!String.IsNullOrEmpty(m_featDefnAbbr)) { // Find the feature definition this editor was created to choose options from var featDefns = from s in m_cache.LangProject.PhFeatureSystemOA.FeaturesOC where s.Abbreviation.BestAnalysisAlternative.Text == m_featDefnAbbr select s; if (featDefns.Any()) m_closedFeature = featDefns.First() as IFsClosedFeature; } m_PhonologicalFeatureTreeManager = new PhonologicalFeaturePopupTreeManager(m_tree, m_cache, false, m_mediator, (Form) m_mediator.PropertyTable.GetValue( "window"), m_displayWs, m_closedFeature); m_PhonologicalFeatureTreeManager.AfterSelect += new TreeViewEventHandler(m_PhonFeaturePopupTreeManager_AfterSelect); } m_PhonologicalFeatureTreeManager.LoadPopupTree(0); }
IFsSymFeatVal IFsSymFeatValFactory.Create(Guid guid, IFsClosedFeature owner) { if (owner == null) throw new ArgumentNullException("owner"); int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo(); int flid = m_cache.MetaDataCache.GetFieldId("FsClosedFeature", "Values", false); var retval = new FsSymFeatVal(m_cache, hvo, guid); owner.ValuesOC.Add(retval); return retval; }
private static void CheckFeatureAndItsValues(string sFeatureName, IFsClosedFeature closedf) { Assert.AreEqual(sFeatureName, closedf.Name.AnalysisDefaultWritingSystem.Text, "Expect to have " + sFeatureName + " feature"); Assert.AreEqual(2, closedf.ValuesOC.Count, "Expect consonantal to have two values"); var value = closedf.ValuesOC.First(); Assert.AreEqual("positive", value.Name.AnalysisDefaultWritingSystem.Text, "Expect positive first value"); value = closedf.ValuesOC.Last(); Assert.AreEqual("negative", value.Name.AnalysisDefaultWritingSystem.Text, "Expect negative last value"); }
/// <summary> /// Find a symbolic feature value or create it if not already there; use XML item to do it /// </summary> /// <param name="feature">Xml description of the fs</param> /// <param name="closed">closed feature containing symbolic feature values</param> /// <param name="item">Xml item</param> /// <returns>FsSymFeatVal corresponding to the feature</returns> static public IFsSymFeatVal FindOrCreateSymbolicValueBasedOnXmlNode(XmlNode feature, IFsClosedFeature closed, XmlNode item) { XmlNode id = feature.SelectSingleNode("ancestor::item[@id][position()=1]/@id"); if (id == null) return null; IFsSymFeatVal symFV = null; #if ForRandy bool fAlreadyThere; fAlreadyThere = false; foreach (IFsSymFeatVal fsfv in closed.ValuesOC) { if (fsfv.CatalogSourceId == id.InnerText) { symFV = fsfv; fAlreadyThere = true; break; } } if (!fAlreadyThere) { ILgWritingSystemFactory wsFactory = closed.Cache.LanguageWritingSystemFactoryAccessor; symFV = closed.ValuesOC.Add(new FsSymFeatVal()); symFV.CatalogSourceId = id.InnerText; XmlNode abbr = item.SelectSingleNode("abbrev"); SetInnerText(symFV.Abbreviation, wsFactory, abbr); XmlNode term = item.SelectSingleNode("term"); SetInnerText(symFV.Name, wsFactory, term); XmlNode def = item.SelectSingleNode("def"); SetInnerXml(symFV.Description, wsFactory, def); symFV.ShowInGloss = true; } #else FdoCache cache = closed.Cache; int hvo = GetSymbolicValue(cache, id.InnerText); if (hvo > 0) symFV = CmObject.CreateFromDBObject(cache, hvo) as IFsSymFeatVal; else { symFV = closed.ValuesOC.Add(new FsSymFeatVal()); string sId = id.InnerText; symFV.CatalogSourceId = sId; foreach (ILgWritingSystem ws in cache.LangProject.AnalysisWssRC) { string sValue = GetValueOfPattern(item, "abbrev", ws); if (sValue != null) symFV.Abbreviation.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(item, "term", ws); if (sValue != null) symFV.Name.SetAlternative(sValue, ws.Hvo); sValue = GetValueOfPattern(item, "def", ws); if (sValue != null) symFV.Description.SetAlternative(sValue, ws.Hvo); } symFV.ShowInGloss = true; } #endif return symFV; }
/// <summary> /// Constructor. /// </summary> public PhonologicalFeaturePopupTreeManager(TreeCombo treeCombo, LcmCache cache, bool useAbbr, Mediator mediator, PropertyTable propertyTable, Form parent, int wsDisplay, IFsClosedFeature closedFeature) : base(treeCombo, cache, mediator, propertyTable, cache.LanguageProject.PartsOfSpeechOA, wsDisplay, useAbbr, parent) { m_closedFeature = closedFeature; }
public ClosedFeatureNode(IFsClosedFeature feature) { m_feature = feature; Value = new SymbolicValue(null); }
public ClosedFeatureNode(IFsClosedFeature feature) { m_feature = feature; Value = new SymbolicValue(null); }