Esempio n. 1
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
                if (m_tvMasterList != null)
                {
                    m_tvMasterList.Dispose();
                }
            }
            m_cache        = null;
            m_selFeatDefn  = null;
            m_featureList  = null;
            m_mediator     = null;
            m_tvMasterList = null;

            base.Dispose(disposing);
        }
        private void AddNode(IFsFeatureSpecification spec, FeatureTreeNode parentNode)
        {
            IFsFeatDefn        defn = spec.FeatureRA;
            TreeNodeCollection col;

            if (parentNode == null)
            {
                col = Nodes;
            }
            else
            {
                col = parentNode.Nodes;
            }
            IFsClosedValue closed = spec as IFsClosedValue;

            if (closed != null)
            {
                foreach (FeatureTreeNode node in col)
                {
                    if (defn.Hvo == node.Hvo)
                    {                     // already there (which is to be expected); see if its value is, too
                        AddNodeFromFS(closed.ValueRA, node);
                        return;
                    }
                }
                // did not find the node, so add it and its value (not to be expected, but we'd better deal with it)
                FeatureTreeNode newNode = new FeatureTreeNode(defn.Name.AnalysisDefaultWritingSystem,
                                                              (int)ImageKind.feature, (int)ImageKind.feature, defn.Hvo, FeatureTreeNodeInfo.NodeKind.Closed);
                InsertNode(newNode, parentNode);
                IFsSymFeatVal val = closed.ValueRA;
                if (val != null)
                {
                    FeatureTreeNode newValueNode = new FeatureTreeNode(val.Name.AnalysisDefaultWritingSystem,
                                                                       (int)ImageKind.radioSelected, (int)ImageKind.radioSelected, val.Hvo, FeatureTreeNodeInfo.NodeKind.SymFeatValue);
                    newValueNode.Chosen = true;
                    InsertNode(newValueNode, newNode);
                }
            }
            IFsComplexValue complex = spec as IFsComplexValue;

            if (complex != null)
            {
                foreach (FeatureTreeNode node in col)
                {
                    if (defn.Hvo == node.Hvo)
                    {                     // already there (which is to be expected); see if its value is, too
                        AddNode((IFsFeatStruc)complex.ValueOA, node);
                        return;
                    }
                }
                // did not find the node, so add it and its value (not to be expected, but we'd better deal with it)
                FeatureTreeNode newNode = new FeatureTreeNode(defn.Name.AnalysisDefaultWritingSystem,
                                                              (int)ImageKind.complex, (int)ImageKind.complex, defn.Hvo, FeatureTreeNodeInfo.NodeKind.Complex);
                InsertNode(newNode, parentNode);
                AddNode((IFsFeatStruc)complex.ValueOA, newNode);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Set description based on the content of the BasicIPASymbol field and the BasicIPAInfo document
        /// </summary>
        public void SetFeaturesBasedOnIPA()
        {
            var phoneme = (IPhPhoneme)m_obj;

            if (phoneme.BasicIPASymbol.Length > 0 && (m_justChangedFeatures || phoneme.FeaturesOA == null || phoneme.FeaturesOA.FeatureSpecsOC.Count == 0))
            {
                // Mono XPath processing crashes when the expression starts out with // here.  See FWNX-730.
                string sXPath = "/SegmentDefinitions/SegmentDefinition[Representations/Representation[.='" +
                                XmlUtils.MakeSafeXmlAttribute(phoneme.BasicIPASymbol.Text) +
                                "']]/Features";
                XElement features = s_ipaInfoDocument.XPathSelectElement(sXPath);
                if (features != null)
                {
                    bool fCreatedNewFS = false;
                    foreach (XElement feature in features.Elements("FeatureValuePair"))
                    {
                        var         sFeature = (string)feature.Attribute("feature");
                        var         sValue   = (string)feature.Attribute("value");
                        IFsFeatDefn featDefn = m_cache.LanguageProject.PhFeatureSystemOA.GetFeature(sFeature);
                        if (featDefn == null)
                        {
                            continue;
                        }

                        IFsSymFeatVal symVal = m_cache.LanguageProject.PhFeatureSystemOA.GetSymbolicValue(sValue);
                        if (symVal == null)
                        {
                            continue;
                        }
                        if (phoneme.FeaturesOA == null)
                        {
                            phoneme.FeaturesOA = m_cache.ServiceLocator.GetInstance <IFsFeatStrucFactory>().Create();
                            fCreatedNewFS      = true;
                        }
                        IFsClosedValue value = m_cache.ServiceLocator.GetInstance <IFsClosedValueFactory>().Create();
                        phoneme.FeaturesOA.FeatureSpecsOC.Add(value);
                        value.FeatureRA       = featDefn;
                        value.ValueRA         = symVal;
                        m_justChangedFeatures = true;
                    }
                }
            }
            else if (phoneme.BasicIPASymbol.Length == 0 && m_justChangedFeatures)
            {
                if (phoneme.FeaturesOA != null)
                {
                    // user has cleared the basic IPA symbol; clear the features
                    phoneme.FeaturesOA.FeatureSpecsOC.Clear();
                }
                m_justChangedFeatures = true;
            }
            else
            {
                m_justChangedFeatures = false;
            }
        }
 bool ContainsFeature(IEnumerable <IPhFeatureConstraint> vars, IFsFeatDefn feat)
 {
     foreach (IPhFeatureConstraint var in vars)
     {
         if (var.FeatureRA == feat)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 5
0
        /// <summary>
        /// If OK, then add relevant inflection features to DB.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MasterListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            switch (DialogResult)
            {
            default:
                m_selFeatDefn = null;
                break;

            case DialogResult.OK:
            {
                Cursor = Cursors.WaitCursor;
                if (m_tvMasterList.TerminalsUseCheckBoxes)
                {
                    UpdateAllCheckedItems(m_tvMasterList.Nodes);
                    int fsysHvo    = m_featureSystem.Hvo;
                    int flid       = (int)FsFeatureSystem.FsFeatureSystemTags.kflidFeatures;
                    int featureHvo = m_selFeatDefn.Hvo;
                    ForceRecordClerkToReload(fsysHvo, flid, featureHvo);
                }
                else
                {
                    MasterItem mi = m_tvMasterList.SelectedNode.Tag as MasterItem;
                    if (mi != null)
                    {
                        mi.AddToDatabase(m_cache);
                        m_selFeatDefn = mi.FeatureDefn;
                        DoFinalActions(mi);
                    }
                }
                Cursor = Cursors.Default;
                break;
            }

            case DialogResult.Yes:
            {
                // Closing via the hotlink.
                // Do nothing special, except avoid setting m_selFeatDefn to null, as in the default case.
                break;
            }
            }

            if (m_mediator != null)
            {
                m_mediator.PropertyTable.SetProperty(m_sWindowKeyLocation, Location);
                m_mediator.PropertyTable.SetProperty(m_sWindowKeySize, Size);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// If OK, then add relevant inflection features to DB.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MasterListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            switch (DialogResult)
            {
            default:
                m_selFeatDefn = null;
                break;

            case DialogResult.OK:
            {
                using (new WaitCursor(this))
                {
                    if (m_tvMasterList.TerminalsUseCheckBoxes)
                    {
                        UpdateAllCheckedItems(m_tvMasterList.Nodes);
                    }
                    else
                    {
                        MasterItem mi = m_tvMasterList.SelectedNode.Tag as MasterItem;
                        if (mi != null)
                        {
                            mi.AddToDatabase(m_cache);
                            m_selFeatDefn = mi.FeatureDefn;
                        }
                    }
                }
                break;
            }

            case DialogResult.Yes:
            {
                // Closing via the hotlink.
                // Do nothing special, except avoid setting m_selFeatDefn to null, as in the default case.
                break;
            }
            }

            if (m_mediator != null)
            {
                m_mediator.PropertyTable.SetProperty(m_sWindowKeyLocation, Location);
                m_mediator.PropertyTable.SetProperty(m_sWindowKeySize, Size);
            }
        }
Esempio n. 7
0
 private void UpdateAllCheckedItems(TreeNodeCollection nodes)
 {
     foreach (TreeNode node in nodes)
     {
         if (node.Nodes != null && node.Nodes.Count > 0)
         {
             UpdateAllCheckedItems(node.Nodes);
         }
         else
         {
             if (node.Checked)
             {
                 MasterItem mi = node.Tag as MasterItem;
                 if (!mi.InDatabase)
                 {
                     mi.AddToDatabase(m_cache);
                     m_selFeatDefn = mi.FeatureDefn;
                 }
             }
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            m_cache       = null;
            m_selFeatDefn = null;
            m_featureList = null;
            m_mediator    = null;

            base.Dispose(disposing);
        }
        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 PopulateTreeFromInflectableFeat(IFsFeatDefn defn)
		{
			CheckDisposed();

			AddNode(defn, null);
		}
		private void AddNode(IFsFeatDefn defn, FeatureTreeNode parentNode)
		{
			var closed = defn as IFsClosedFeature;
			if (closed != null)
			{
				if (!AlreadyInTree(closed.Hvo, parentNode))
				{ // avoid duplicates
					FeatureTreeNode newNode = new FeatureTreeNode(closed.Name.AnalysisDefaultWritingSystem.Text,
																	  (int)ImageKind.feature, (int)ImageKind.feature,
																	  closed.Hvo, FeatureTreeNodeInfo.NodeKind.Closed);
					InsertNode(newNode, parentNode);

					foreach (var val in closed.ValuesSorted)
					{
						AddNode(val, newNode);
					}
				}
			}
			var 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);
					var type = complex.TypeRA;
					foreach (var defn2 in type.FeaturesRS)
						AddNode(defn2, newNode);
				}
			}
		}
		/// <summary>
		/// Checks if the specified feature definition is valid for the
		/// specified category.
		/// </summary>
		/// <param name="pos">the category to check for validity</param>
		/// <param name="fDefn">the feature definition</param>
		/// <returns>true if the feature is valid, otherwise false</returns>
		protected bool IsFeatureValid(IPartOfSpeech pos, IFsFeatDefn fDefn)
		{
			if (fDefn == null)
				return false;
			while (pos != null)
			{
				if (pos.InflectableFeatsRC.Contains(fDefn))
					return true;
				pos = pos.Owner as IPartOfSpeech; // May not cast to POS if it is the owning list.
			}

			return false;
		}
		private bool ContainsFeature(IEnumerable<IPhFeatureConstraint> vars, IFsFeatDefn feat)
		{
			foreach (IPhFeatureConstraint var in vars)
			{
				if (var.FeatureRA == feat)
					return true;
			}
			return false;
		}
		private IPhFeatureConstraint GetFeatureConstraint(IEnumerable<IPhFeatureConstraint> featConstrs, IFsFeatDefn feat)
		{
			foreach (var curConstr in featConstrs)
			{
				if (curConstr.FeatureRA == feat)
					return curConstr;
			}
			return null;
		}
Esempio n. 15
0
		/// <summary>
		/// If OK, then add relevant inflection features to DB.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void MasterListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			switch (DialogResult)
			{
				default:
					m_selFeatDefn = null;
					break;
				case DialogResult.OK:
				{
					Cursor = Cursors.WaitCursor;
					if (m_tvMasterList.TerminalsUseCheckBoxes)
					{
						UpdateAllCheckedItems(m_tvMasterList.Nodes);
						int fsysHvo = m_featureSystem.Hvo;
						int flid = (int)FsFeatureSystem.FsFeatureSystemTags.kflidFeatures;
						int featureHvo = m_selFeatDefn.Hvo;
						ForceRecordClerkToReload(fsysHvo, flid, featureHvo);
					}
					else
					{
						MasterItem mi = m_tvMasterList.SelectedNode.Tag as MasterItem;
						if (mi != null)
						{
							mi.AddToDatabase(m_cache);
							m_selFeatDefn = mi.FeatureDefn;
							DoFinalActions(mi);
						}
					}
					Cursor = Cursors.Default;
					break;
				}
				case DialogResult.Yes:
				{
					// Closing via the hotlink.
					// Do nothing special, except avoid setting m_selFeatDefn to null, as in the default case.
					break;
				}
			}

			if (m_mediator != null)
			{
				m_mediator.PropertyTable.SetProperty(m_sWindowKeyLocation, Location);
				m_mediator.PropertyTable.SetProperty(m_sWindowKeySize, Size);
			}
		}
Esempio n. 16
0
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			m_cache = null;
			m_selFeatDefn = null;
			m_featureList = null;
			m_mediator = null;

			base.Dispose( disposing );
		}
Esempio n. 17
0
        public override ITsString DisplayVariant(IVwEnv vwenv, int tag, int frag)
        {
            // we use display variant to display literal strings that are editable
            ITsString tss = null;

            switch (frag)
            {
            case kfragFeatureLine:
                ComplexConcPatternNode node = ((ComplexConcPatternSda)vwenv.DataAccess).Nodes[vwenv.CurrentObject()];
                switch (tag)
                {
                case ktagType:
                    string typeStr = null;
                    if (node is ComplexConcMorphNode)
                    {
                        typeStr = ITextStrings.ksComplexConcMorph;
                    }
                    else if (node is ComplexConcWordNode)
                    {
                        typeStr = ITextStrings.ksComplexConcWord;
                    }
                    else if (node is ComplexConcTagNode)
                    {
                        typeStr = ITextStrings.ksComplexConcTag;
                    }
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcType, typeStr, m_cache.DefaultUserWs);
                    break;

                case ktagForm:
                    ITsString form          = null;
                    var       formMorphNode = node as ComplexConcMorphNode;
                    if (formMorphNode != null)
                    {
                        form = formMorphNode.Form;
                    }
                    else
                    {
                        var formWordNode = node as ComplexConcWordNode;
                        if (formWordNode != null)
                        {
                            form = formWordNode.Form;
                        }
                    }
                    Debug.Assert(form != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcForm, form, false);
                    break;

                case ktagEntry:
                    ITsString entry          = null;
                    var       entryMorphNode = node as ComplexConcMorphNode;
                    if (entryMorphNode != null)
                    {
                        entry = entryMorphNode.Entry;
                    }
                    Debug.Assert(entry != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcEntry, entry, false);
                    break;

                case ktagGloss:
                    ITsString gloss          = null;
                    var       glossMorphNode = node as ComplexConcMorphNode;
                    if (glossMorphNode != null)
                    {
                        gloss = glossMorphNode.Gloss;
                    }
                    else
                    {
                        var glossWordNode = node as ComplexConcWordNode;
                        if (glossWordNode != null)
                        {
                            gloss = glossWordNode.Gloss;
                        }
                    }
                    Debug.Assert(gloss != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcGloss, gloss, false);
                    break;

                case ktagCategory:
                    IPartOfSpeech category     = null;
                    bool          catNegated   = false;
                    var           catMorphNode = node as ComplexConcMorphNode;
                    if (catMorphNode != null)
                    {
                        category   = catMorphNode.Category;
                        catNegated = catMorphNode.NegateCategory;
                    }
                    else
                    {
                        var catWordNode = node as ComplexConcWordNode;
                        if (catWordNode != null)
                        {
                            category   = catWordNode.Category;
                            catNegated = catWordNode.NegateCategory;
                        }
                    }
                    Debug.Assert(category != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcCategory, category.Abbreviation.BestAnalysisAlternative, catNegated);
                    break;

                case ktagTag:
                    ICmPossibility tagPoss = null;
                    var            tagNode = node as ComplexConcTagNode;
                    if (tagNode != null)
                    {
                        tagPoss = tagNode.Tag;
                    }
                    Debug.Assert(tagPoss != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcTag, tagPoss.Abbreviation.BestAnalysisAlternative, false);
                    break;

                case ktagInfl:
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcInflFeatures, null, false);
                    break;

                default:
                    IFsFeatDefn feature = m_curInflFeatures.Keys.Single(f => f.Hvo == tag);
                    if (feature is IFsComplexFeature)
                    {
                        tss = CreateFeatureLine(feature.Abbreviation.BestAnalysisAlternative, null, false);
                    }
                    else if (feature is IFsClosedFeature)
                    {
                        var value = (ClosedFeatureValue)m_curInflFeatures[feature];
                        tss = CreateFeatureLine(feature.Abbreviation.BestAnalysisAlternative, value.Symbol.Abbreviation.BestAnalysisAlternative, value.Negate);
                    }
                    break;
                }
                break;

            case kfragNodeMax:
                // if the max value is -1, it indicates that it is infinite
                ComplexConcPatternNode node1 = ((ComplexConcPatternSda)vwenv.DataAccess).Nodes[vwenv.CurrentObject()];
                tss = node1.Maximum == -1 ? m_infinity : m_cache.TsStrFactory.MakeString(node1.Maximum.ToString(CultureInfo.InvariantCulture), m_cache.DefaultUserWs);
                break;

            case kfragNodeMin:
                ComplexConcPatternNode node2 = ((ComplexConcPatternSda)vwenv.DataAccess).Nodes[vwenv.CurrentObject()];
                tss = m_cache.TsStrFactory.MakeString(node2.Minimum.ToString(CultureInfo.InvariantCulture), m_cache.DefaultUserWs);
                break;

            case kfragOR:
                tss = m_or;
                break;

            case kfragHash:
                tss = m_hash;
                break;

            default:
                tss = base.DisplayVariant(vwenv, tag, frag);
                break;
            }
            return(tss);
        }
Esempio n. 18
0
        public void PopulateTreeFromInflectableFeat(IFsFeatDefn defn)
        {
            CheckDisposed();

            AddNode(defn, null);
        }
Esempio n. 19
0
		static private void SetFeaturesInTypeBasedOnXmlNode(IFsFeatStrucType fst, XmlNode item, IFsFeatDefn featDefn)
		{
			if (fst == null)
				return;
			XmlNode id = item.SelectSingleNode("../@id");
			bool fAlreadyThere = false;
			foreach (IFsFeatDefn defn in fst.FeaturesRS)
			{
				if (defn.CatalogSourceId == id.InnerText)
				{
					fAlreadyThere = true;
					break;
				}
			}
			if (!fAlreadyThere)
			{
				if (featDefn.ClassID == FsComplexFeature.kclsidFsComplexFeature)
				{ // for complex features, if they have a higher containing feature structure type, then all we want are the closed features
					if (item.SelectSingleNode("ancestor::item[@type='fsType' and not(@status)]") != null)
						return;
				}
				fst.FeaturesRS.Append(featDefn);
			}
		}
Esempio n. 20
0
		private void UpdateAllCheckedItems(TreeNodeCollection nodes)
		{
			foreach (TreeNode node in nodes)
			{
				if (node.Nodes != null && node.Nodes.Count > 0)
					UpdateAllCheckedItems(node.Nodes);
				else
				{
					if (node.Checked)
					{
						MasterItem mi = node.Tag as MasterItem;
						if (!mi.InDatabase)
						{
							mi.AddToDatabase(m_cache);
							m_selFeatDefn = mi.FeatureDefn;
						}
					}
				}
			}
		}
Esempio n. 21
0
		/// <summary>
		/// Attempt to add feature to category as an inflectable feature
		/// </summary>
		/// <param name="cache">FDO cache</param>
		/// <param name="node">MGA node</param>
		/// <param name="feat">feature to add</param>
		public static void TryToAddInflectableFeature(FdoCache cache, XmlNode node, IFsFeatDefn feat)
		{
			if (node == null || feat == null)
				return;
			string sPosId = XmlUtils.GetOptionalAttributeValue(node, "posid");
			while (node.ParentNode != null && sPosId == null)
			{
				node = node.ParentNode;
				sPosId = XmlUtils.GetOptionalAttributeValue(node, "posid");
			}
			IPartOfSpeech pos = PartOfSpeech.GoldPOS(cache, sPosId);
			if (pos != null)
				pos.InflectableFeatsRC.Add(feat);
		}
Esempio n. 22
0
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			m_cache = null;
			m_selFeatDefn = null;
			m_featureList = null;
			m_mediator = null;

			base.Dispose( disposing );
		}
Esempio n. 23
0
        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");
        }
        IPhFeatureConstraint RemoveFeatureConstraint(IFdoReferenceSequence <IPhFeatureConstraint> featConstrs, IFsFeatDefn feat)
        {
            var constrToRemove = GetFeatureConstraint(featConstrs, feat);

            if (constrToRemove != null)
            {
                featConstrs.Remove(constrToRemove);
            }
            return(constrToRemove);
        }
Esempio n. 25
0
		/// <summary>
		/// If OK, then add relevant inflection features to DB.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void MasterListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			switch (DialogResult)
			{
				default:
					m_selFeatDefn = null;
					break;
				case DialogResult.OK:
				{
					using (new WaitCursor(this))
					{
						if (m_tvMasterList.TerminalsUseCheckBoxes)
						{
							UpdateAllCheckedItems(m_tvMasterList.Nodes);
						}
						else
						{
							MasterItem mi = m_tvMasterList.SelectedNode.Tag as MasterItem;
							if (mi != null)
							{
								mi.AddToDatabase(m_cache);
								m_selFeatDefn = mi.FeatureDefn;
							}
						}
					}
					break;
				}
				case DialogResult.Yes:
				{
					// Closing via the hotlink.
					// Do nothing special, except avoid setting m_selFeatDefn to null, as in the default case.
					break;
				}
			}

			if (m_mediator != null)
			{
				m_mediator.PropertyTable.SetProperty(m_sWindowKeyLocation, Location);
				m_mediator.PropertyTable.SetProperty(m_sWindowKeySize, Size);
			}
		}
 IPhFeatureConstraint GetFeatureConstraint(IEnumerable <IPhFeatureConstraint> featConstrs, IFsFeatDefn feat)
 {
     foreach (var curConstr in featConstrs)
     {
         if (curConstr.FeatureRA == feat)
         {
             return(curConstr);
         }
     }
     return(null);
 }
Esempio n. 27
0
		private static XElement ExportFeatureDefn(IFsFeatDefn featureDefn, Icu.UNormalizationMode mode)
		{
			switch (featureDefn.ClassName)
			{
				default:
					// FsOpenFeature doesn't appear to be exported as of 14 November 2009.
					throw new ArgumentException("Unrecognized IFsFeatDefn");
				case "FsClosedFeature":
					var closedFD = (IFsClosedFeature)featureDefn;
					return new XElement("FsClosedFeature",
						new XAttribute("Id", featureDefn.Hvo),
						ExportBestAnalysis(featureDefn.Name, "Name", mode),
						ExportBestAnalysis(featureDefn.Description, "Description", mode),
						ExportBestAnalysis(closedFD.Abbreviation, "Abbreviation", mode),
						new XElement("Values",
							from value in closedFD.ValuesOC
								 select new XElement("FsSymFeatVal",
									 new XAttribute("Id", value.Hvo),
									 ExportBestAnalysis(value.Name, "Name", mode),
									 ExportBestAnalysis(value.Description, "Description", mode),
									 ExportBestAnalysis(value.Abbreviation, "Abbreviation", mode))));
				case "FsComplexFeature":
					var complexFD = (IFsComplexFeature) featureDefn;
					return new XElement("FsComplexFeature",
						new XAttribute("Id", featureDefn.Hvo),
						ExportBestAnalysis(featureDefn.Name, "Name", mode),
						ExportBestAnalysis(featureDefn.Description, "Description", mode),
						ExportBestAnalysis(complexFD.Abbreviation, "Abbreviation", mode),
						ExportItemAsReference(complexFD.TypeRA, "Type"));
			}
		}
		private IPhFeatureConstraint RemoveFeatureConstraint(IFdoReferenceSequence<IPhFeatureConstraint> featConstrs, IFsFeatDefn feat)
		{
			var constrToRemove = GetFeatureConstraint(featConstrs, feat);
			if (constrToRemove != null)
				featConstrs.Remove(constrToRemove);
			return constrToRemove;
		}