コード例 #1
0
            private int DeterminePOSLocationInfo(FdoCache cache, IPartOfSpeech subItemOwner, MasterCategory parent, ICmPossibilityList posList,
                                                 out int newOwningFlid, out int insertLocation)
            {
                int newOwner;
                // This is the index of the new object in the list.  See LT-5608.
                var posFactory = cache.ServiceLocator.GetInstance <IPartOfSpeechFactory>();

                if (subItemOwner != null)
                {
                    newOwner       = subItemOwner.Hvo;
                    newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = subItemOwner.SubPossibilitiesOS.Count;
                    m_pos          = posFactory.Create();
                    subItemOwner.SubPossibilitiesOS.Add(m_pos);
                }
                else if (parent != null && parent.m_pos != null)
                {
                    newOwner       = parent.m_pos.Hvo;
                    newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = parent.m_pos.SubPossibilitiesOS.Count;
                    m_pos          = posFactory.Create();
                    parent.m_pos.SubPossibilitiesOS.Add(m_pos);
                }
                else
                {
                    newOwner       = posList.Hvo;
                    newOwningFlid  = CmPossibilityListTags.kflidPossibilities;
                    insertLocation = posList.PossibilitiesOS.Count;
                    m_pos          = posFactory.Create();
                    posList.PossibilitiesOS.Add(m_pos);
                }
                return(newOwner);
            }
コード例 #2
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_fs         = null;
            m_highestPOS = null;
            m_poses      = null;
            m_mediator   = null;
            m_cache      = null;

            base.Dispose(disposing);
        }
コード例 #3
0
        public void Action_WithOneItemInMongoGrammar_ShouldUpdateThatOneItemInFdoGrammar()
        {
            // Setup
            var           lfProj = _lfProj;
            FdoCache      cache  = lfProj.FieldWorksProject.Cache;
            int           grammarCountBeforeTest = cache.LangProject.AllPartsOfSpeech.Count;
            IPartOfSpeech secondPosBeforeTest    = cache.LangProject.AllPartsOfSpeech.Skip(1).FirstOrDefault();
            var           data         = new SampleData();
            BsonDocument  grammarEntry = new BsonDocument();

            grammarEntry.Add("key", "k");
            grammarEntry.Add("value", "v");
            grammarEntry.Add("abbreviation", "a");
            grammarEntry.Add("guid", secondPosBeforeTest.Guid.ToString());
            data.bsonOptionListData["items"] = new BsonArray(new BsonDocument[] { grammarEntry });

            _conn.UpdateMockOptionList(data.bsonOptionListData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            int           grammarCountAfterTest = cache.LangProject.AllPartsOfSpeech.Count;
            IPartOfSpeech secondPosAfterTest    = cache.LangProject.AllPartsOfSpeech.Skip(1).FirstOrDefault();

            Assert.That(grammarCountAfterTest, Is.EqualTo(grammarCountBeforeTest));
            Assert.That(secondPosAfterTest, Is.Not.Null);
            Assert.That(secondPosAfterTest.Guid, Is.EqualTo(secondPosBeforeTest.Guid));
            Assert.That(secondPosAfterTest, Is.SameAs(secondPosBeforeTest));
            Assert.That(secondPosAfterTest.Name.BestAnalysisVernacularAlternative.Text, Is.EqualTo("v"));
            Assert.That(secondPosAfterTest.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.EqualTo("a"));
            // LF key shouldn't be copied to FDO, so don't test that one
        }
コード例 #4
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)
            {
                foreach (TreeNode tn in m_nodes)
                {
                    MasterCategory mc = tn.Tag as MasterCategory;
                    tn.Tag = null;
                    mc.Dispose();
                }
                if (components != null)
                {
                    components.Dispose();
                }
                if (m_nodes != null)
                {
                    m_nodes.Clear();
                }
            }
            m_posList  = null;
            m_mediator = null;
            m_cache    = null;
            m_selPOS   = null;
            m_nodes    = null;

            base.Dispose(disposing);
        }
コード例 #5
0
        /// <summary>
        /// Will find a grammatical category (if one exists) with the given (analysis ws) name.
        /// If not found, will create a grammatical category either as a possibility of a list,
        /// or as a subpossibility of a category.
        /// </summary>
        /// <param name="catName"></param>
        /// <param name="owningList"></param>
        /// <param name="owningCategory"></param>
        /// <returns></returns>
        protected IPartOfSpeech GetGrammaticalCategoryOrCreateOne(string catName, ICmPossibilityList owningList,
                                                                  IPartOfSpeech owningCategory)
        {
            Assert.True(m_posFact != null, "Fixture Initialization is not complete.");
            Assert.True(m_window != null, "No window.");
            var category = m_posRepo.AllInstances().Where(
                someposs => someposs.Name.AnalysisDefaultWritingSystem.Text == catName).FirstOrDefault();

            if (category != null)
            {
                return(category);
            }
            var ws = Cache.DefaultAnalWs;

            if (owningList == null)
            {
                if (owningCategory == null)
                {
                    throw new ArgumentException(
                              "Grammatical category not found and insufficient information given to create one.");
                }
                category = m_posFact.Create(new Guid(), owningCategory);
            }
            else
            {
                category = m_posFact.Create(new Guid(), owningList);
            }
            category.Name.set_String(ws, catName);
            return(category);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="posList"></param>
        /// <param name="mediator"></param>
        /// <param name="launchedFromInsertMenu"></param>
        /// <param name="subItemOwner"></param>
        public void SetDlginfo(ICmPossibilityList posList, Mediator mediator, bool launchedFromInsertMenu, IPartOfSpeech subItemOwner)
        {
            CheckDisposed();

            m_subItemOwner           = subItemOwner;   // May be null, which is fine.
            m_posList                = posList;
            m_launchedFromInsertMenu = launchedFromInsertMenu;
            m_mediator               = mediator;
            if (mediator != null)
            {
                // Reset window location.
                // Get location to the stored values, if any.
                object locWnd = m_mediator.PropertyTable.GetValue("masterCatListDlgLocation");
                object szWnd  = m_mediator.PropertyTable.GetValue("masterCatListDlgSize");
                if (locWnd != null && szWnd != null)
                {
                    Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd);
                    ScreenUtils.EnsureVisibleRect(ref rect);
                    DesktopBounds = rect;
                    StartPosition = FormStartPosition.Manual;
                }
            }
            Debug.Assert(posList != null);
            m_cache = posList.Cache;
            LoadMasterCategories(posList.ReallyReallyAllPossibilities);
        }
コード例 #7
0
            /// <summary>
            /// Executes in two distinct scenarios.
            ///
            /// 1. If disposing is true, the method has been called directly
            /// or indirectly by a user's code via the Dispose method.
            /// Both managed and unmanaged resources can be disposed.
            ///
            /// 2. If disposing is false, the method has been called by the
            /// runtime from inside the finalizer and you should not reference (access)
            /// other managed objects, as they already have been garbage collected.
            /// Only unmanaged resources can be disposed.
            /// </summary>
            /// <param name="disposing"></param>
            /// <remarks>
            /// If any exceptions are thrown, that is fine.
            /// If the method is being done in a finalizer, it will be ignored.
            /// If it is thrown by client code calling Dispose,
            /// it needs to be handled by fixing the bug.
            ///
            /// If subclasses override this method, they should call the base implementation.
            /// </remarks>
            protected virtual void Dispose(bool disposing)
            {
                //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
                // Must not be run more than once.
                if (m_isDisposed)
                {
                    return;
                }

                if (disposing)
                {
                    // Dispose managed resources here.
                    if (m_citations != null)
                    {
                        m_citations.Clear();
                    }
                }

                // Dispose unmanaged resources here, whether disposing is true or false.
                m_citations = null;
                m_pos       = null;
                m_id        = null;
                m_abbrev    = null;
                m_abbrevWs  = null;
                m_term      = null;
                m_termWs    = null;
                m_def       = null;
                m_defWs     = null;
                m_node      = null;

                m_isDisposed = true;
            }
コード例 #8
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            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_nodes != null)
                {
                    m_nodes.Clear();
                }
            }
            m_posList  = null;
            m_mediator = null;
            m_cache    = null;
            m_selPOS   = null;
            m_nodes    = null;

            base.Dispose(disposing);
        }
コード例 #9
0
        protected override void CreateTestData()
        {
            base.CreateTestData();
            IPartOfSpeech pos = Cache.ServiceLocator.GetInstance <IPartOfSpeechFactory>().Create();

            Cache.LanguageProject.PartsOfSpeechOA.PossibilitiesOS.Add(pos);
        }
コード例 #10
0
        private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph)
        {
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            CompareTss(sense.Gloss.GetAlternativeTss(Cache.DefaultAnalWs),
                       wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));

            // make sure the morph is linked to the lexicon sense, msa, and part of speech.
            IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0];

            Assert.AreEqual(sense.Hvo, morphBundle.SenseRAHvo);
            Assert.AreEqual(sense.MorphoSyntaxAnalysisRAHvo, morphBundle.MsaRAHvo);
            if (!fMatchMainPossibility)
            {
                // expect exact possibility
                Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo);
            }
            else
            {
                IPartOfSpeech posTarget = PartOfSpeech.CreateFromDBObject(Cache, hvoSbWordPos);
                Assert.AreEqual(posTarget.MainPossibility.Hvo, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA.MainPossibility.Hvo);
            }
            Assert.AreEqual(allomorph.Hvo, morphBundle.MorphRAHvo);
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo);
        }
コード例 #11
0
 public EmptyWwfInfo(IMoForm form, IMoMorphSynAnalysis msa, IPartOfSpeech pos, ILexSense sense)
 {
     Form  = form;
     Msa   = msa;
     Pos   = pos;
     Sense = sense;
 }
コード例 #12
0
ファイル: ReversalEntryPOS.cs プロジェクト: sillsdev/WorldPad
        public bool OnMoveReversalPOS(object cmd)
        {
            FdoCache cache = Cache;
            ObjectLabelCollection labels = new ObjectLabelCollection();

            foreach (IPartOfSpeech pos in MergeOrMoveCandidates)
            {
                labels.Add(ObjectLabel.CreateObjectLabelOnly(cache, pos.Hvo, "ShortNameTSS", "best analysis"));
            }
            using (SimpleListChooser dlg = new SimpleListChooser(cache, null, labels, 0,
                                                                 LexEdStrings.ksCategoryToMoveTo, null))
            {
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    IPartOfSpeech currentPOS = POS;
                    IPartOfSpeech newOwner   = PartOfSpeech.CreateFromDBObject(cache, dlg.ChosenOne.Hvo);
                    cache.BeginUndoTask(LexEdStrings.ksUndoMoveRevCategory,
                                        LexEdStrings.ksRedoMoveRevCategory);
                    ICmObject newOwningObj = newOwner.MoveIfNeeded(currentPOS);
                    newOwner.SubPossibilitiesOS.Append(currentPOS);
                    cache.EndUndoTask();
                    // Note: PropChanged should happen on the old owner and the new in the 'Add" method call.
                    // Have to jump to a main PartOfSpeech, as RecordClerk doesn't know anything about subcategories.
                    m_mediator.BroadcastMessageUntilHandled("JumpToRecord", newOwner.MainPossibility.Hvo);
                }
            }

            return(true);
        }
コード例 #13
0
ファイル: ReversalEntryPOS.cs プロジェクト: sillsdev/WorldPad
        public bool OnPromoteReversalSubPOS(object cmd)
        {
            Slice slice = m_dataEntryForm.CurrentSlice;

            Debug.Assert(slice != null, "No slice was current");
            if (slice != null)
            {
                FdoCache       cache       = m_dataEntryForm.Cache;
                ICmPossibility sliceObj    = slice.Object as ICmPossibility;
                int            hvoNewOwner = cache.GetOwnerOfObject(sliceObj.OwnerHVO);
                switch (cache.GetClassOfObject(hvoNewOwner))
                {
                default:
                    throw new ArgumentException("Illegal class.");

                case PartOfSpeech.kclsidPartOfSpeech:
                {
                    IPartOfSpeech pos = PartOfSpeech.CreateFromDBObject(cache, hvoNewOwner);
                    pos.SubPossibilitiesOS.Append(sliceObj);
                    break;
                }

                case CmPossibilityList.kclsidCmPossibilityList:
                {
                    ICmPossibilityList posList = CmPossibilityList.CreateFromDBObject(cache, hvoNewOwner);
                    posList.PossibilitiesOS.Append(sliceObj);
                    break;
                }
                }
            }
            return(true);
        }
コード例 #14
0
        public void Action_WithOneWellKnownItemButNoGuidInMongoGrammar_ShouldGetCorrectWellKnownGuidInFdo()
        {
            // Setup
            var          lfProj       = _lfProj;
            FdoCache     cache        = lfProj.FieldWorksProject.Cache;
            var          data         = new SampleData();
            BsonDocument grammarEntry = new BsonDocument();

            grammarEntry.Add("key", "subordconn");             // Standard abbreviation for "subordinating connector"
            grammarEntry.Add("value", "NotTheRightName");
            grammarEntry.Add("abbreviation", "NotTheRightAbbrev");
            data.bsonOptionListData["items"] = new BsonArray(new BsonDocument[] { grammarEntry });

            _conn.UpdateMockOptionList(data.bsonOptionListData);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            string        expectedGuid    = PartOfSpeechMasterList.FlatPosGuidsFromAbbrevs["subordconn"];
            string        expectedName    = PartOfSpeechMasterList.FlatPosNames[expectedGuid];
            string        expectedAbbrev  = PartOfSpeechMasterList.FlatPosAbbrevs[expectedGuid];
            IPartOfSpeech newlyCreatedPos = cache.LangProject.AllPartsOfSpeech.FirstOrDefault(pos =>
                                                                                              pos.Name.BestAnalysisVernacularAlternative.Text == expectedName
                                                                                              );

            Assert.That(newlyCreatedPos, Is.Not.Null);
            Assert.That(newlyCreatedPos.Guid, Is.Not.Null);
            Assert.That(newlyCreatedPos.Guid.ToString(), Is.EqualTo(expectedGuid));
            Assert.That(newlyCreatedPos.Name.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedName));
            Assert.That(newlyCreatedPos.Abbreviation.BestAnalysisVernacularAlternative.Text, Is.EqualTo(expectedAbbrev));
        }
コード例 #15
0
        public static IPartOfSpeech FromMSA(IMoMorphSynAnalysis msa, out IPartOfSpeech secondaryPos)
        {
            secondaryPos = null;
            switch (msa.ClassID)
            {
            case MoDerivAffMsaTags.kClassId:
                // FDO considers the "From" PoS to be the main one, and "To" to be the secondary one
                secondaryPos = ((IMoDerivAffMsa)msa).ToPartOfSpeechRA;
                return(((IMoDerivAffMsa)msa).FromPartOfSpeechRA);

            case MoDerivStepMsaTags.kClassId:
                return(((IMoDerivStepMsa)msa).PartOfSpeechRA);

            case MoInflAffMsaTags.kClassId:
                return(((IMoInflAffMsa)msa).PartOfSpeechRA);

            case MoStemMsaTags.kClassId:
                return(((IMoStemMsa)msa).PartOfSpeechRA);

            case MoUnclassifiedAffixMsaTags.kClassId:
                return(((IMoUnclassifiedAffixMsa)msa).PartOfSpeechRA);

            default:
                return(null);
            }
        }
コード例 #16
0
        private IMoMorphSynAnalysis GetMsaAndMoForm(ILexEntry entry, Guid slotType, IPartOfSpeech pos, FS inflFS, out IMoForm form)
        {
            IFsFeatStruc        fs = inflFS == null ? null : Cache.ServiceLocator.GetInstance <IFsFeatStrucFactory>().Create();
            IMoMorphSynAnalysis msa;

            if (slotType == MoMorphTypeTags.kguidMorphStem)
            {
                form = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create();
                var stemMsa = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create();
                msa = stemMsa;
                entry.MorphoSyntaxAnalysesOC.Add(msa);
                stemMsa.PartOfSpeechRA = pos;
                if (inflFS != null)
                {
                    stemMsa.MsFeaturesOA = fs;
                }
            }
            else
            {
                form = Cache.ServiceLocator.GetInstance <IMoAffixAllomorphFactory>().Create();
                var affixMsa = Cache.ServiceLocator.GetInstance <IMoInflAffMsaFactory>().Create();
                msa = affixMsa;
                entry.MorphoSyntaxAnalysesOC.Add(msa);
                affixMsa.PartOfSpeechRA = pos;
                if (inflFS != null)
                {
                    affixMsa.InflFeatsOA = fs;
                }
            }
            if (inflFS != null)
            {
                CreateFeatStruc(m_inflType, fs, inflFS);
            }
            return(msa);
        }
コード例 #17
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 (helpProvider != null)
                {
                    helpProvider.Dispose();
                }
            }
            m_cache      = null;
            m_fs         = null;
            m_highestPOS = null;
            m_poses      = null;
            m_mediator   = null;
            m_cache      = null;
            helpProvider = null;

            base.Dispose(disposing);
        }
コード例 #18
0
        private void ValidateSenseWithAnalysis(ILexSense sense, IWfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph)
        {
            IWfiAnalysis wfiAnalysis = wfiGloss.Owner as IWfiAnalysis;

            CompareTss(sense.Gloss.get_String(Cache.DefaultAnalWs),
                       wfiGloss.Form.get_String(Cache.DefaultAnalWs));

            // make sure the morph is linked to the lexicon sense, msa, and part of speech.
            IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0];

            Assert.AreEqual(sense, morphBundle.SenseRA);
            Assert.AreEqual(sense.MorphoSyntaxAnalysisRA, morphBundle.MsaRA);
            if (!fMatchMainPossibility)
            {
                // expect exact possibility
                Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Hvo);
            }
            else
            {
                IPartOfSpeech posTarget = Cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(hvoSbWordPos);
                Assert.AreEqual(posTarget.MainPossibility, (sense.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.MainPossibility);
            }
            Assert.AreEqual(allomorph, morphBundle.MorphRA);
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRA.Hvo);
        }
コード例 #19
0
        private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            if (!m_launchedFromInsertMenu)
            {
                XCore.XMessageBoxExManager.Trigger("CreateNewFromGrammaticalCategoryCatalog");
            }
            m_cache.BeginUndoTask(LexTextControls.ksUndoInsertCategory,
                                  LexTextControls.ksRedoInsertCategory);
            int flid;
            int newOwnerHvo;
            int insertLocation;

            if (m_subItemOwner != null)
            {
                newOwnerHvo    = m_subItemOwner.Hvo;
                insertLocation = m_subItemOwner.SubPossibilitiesOS.Count;
                flid           = (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities;
                m_selPOS       = (IPartOfSpeech)m_subItemOwner.SubPossibilitiesOS.Append(new PartOfSpeech());
            }
            else
            {
                newOwnerHvo    = m_posList.Hvo;
                insertLocation = m_posList.PossibilitiesOS.Count;
                flid           = (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities;
                m_selPOS       = (IPartOfSpeech)m_posList.PossibilitiesOS.Append(new PartOfSpeech());
            }
            m_cache.EndUndoTask();
            m_cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll,
                                                  newOwnerHvo, flid,
                                                  insertLocation, // This is the index of the first (and only) new object in the list.
                                                  1, 0);          // 1 object was added, 0 were deleted. (LT-3259)

            DialogResult = DialogResult.Yes;
            Close();
        }
コード例 #20
0
        private void DeterminePOSLocationInfo(LcmCache cache, IPartOfSpeech subItemOwner,
                                              MasterCategory parent, ICmPossibilityList posList,
                                              out int newOwningFlid, out int insertLocation)
        {
            // The XML node is from a file shipped with FieldWorks. It is quite likely multiple users
            // of a project could independently add the same items, so we create them with fixed guids
            // so merge will recognize them as the same objects.
            //// LT-14511 However, if the partOfSpeech is being added to a reversal index, a different guid needs to be used
            //// than the ones in the file shipped with FieldWorks. In this case if two users add the same POS to the
            //// reversal index at the same time and then do a Send/Receive operation, then a merge conflict report
            //// will probably be created for this. This scenario is not likely to occur very often at all so having
            //// a conflict report created for when this happens is something we can live with.
            var guid = posList.Owner is IReversalIndex?Guid.NewGuid() : new Guid(XmlUtils.GetAttributeValue(m_node, "guid"));

            var posFactory = cache.ServiceLocator.GetInstance <IPartOfSpeechFactory>();

            if (subItemOwner != null)
            {
                newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                insertLocation = subItemOwner.SubPossibilitiesOS.Count;
                POS            = posFactory.Create(guid, subItemOwner);
            }
            else if (parent?.POS != null)
            {
                newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                insertLocation = parent.POS.SubPossibilitiesOS.Count;
                POS            = posFactory.Create(guid, parent.POS);
            }
            else
            {
                newOwningFlid  = CmPossibilityListTags.kflidPossibilities;
                insertLocation = posList.PossibilitiesOS.Count;
                POS            = posFactory.Create(guid, posList);     // automatically adds to parent.
            }
        }
コード例 #21
0
            private int DeterminePOSLocationInfo(IPartOfSpeech subItemOwner, MasterCategory parent, ICmPossibilityList posList, out int newOwningFlid, out int insertLocation)
            {
                int newOwner;

                // This is the index of the new object in the list.  See LT-5608.
                if (subItemOwner != null)
                {
                    newOwner       = subItemOwner.Hvo;
                    newOwningFlid  = (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = subItemOwner.SubPossibilitiesOS.Count;
                    m_pos          = (IPartOfSpeech)subItemOwner.SubPossibilitiesOS.Append(new PartOfSpeech());
                }
                else if (parent != null && parent.m_pos != null)
                {
                    newOwner       = parent.m_pos.Hvo;
                    newOwningFlid  = (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = parent.m_pos.SubPossibilitiesOS.Count;
                    m_pos          = (IPartOfSpeech)parent.m_pos.SubPossibilitiesOS.Append(new PartOfSpeech());
                }
                else
                {
                    newOwner       = posList.Hvo;
                    newOwningFlid  = (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities;
                    insertLocation = posList.PossibilitiesOS.Count;
                    m_pos          = (IPartOfSpeech)posList.PossibilitiesOS.Append(new PartOfSpeech());
                }
                return(newOwner);
            }
コード例 #22
0
        /// <summary>
        /// Given a (potentially) owning object, and the flid in which is does/will own
        /// the feature structure, find the relevant POS.
        /// </summary>
        /// <param name="cobj"></param>
        /// <param name="owningFlid"></param>
        /// <returns></returns>
        private IPartOfSpeech GetPosFromCmObjectAndFlid(ICmObject cobj, int owningFlid)
        {
            IPartOfSpeech pos = null;

            switch (cobj.ClassID)
            {
            case MoInflAffMsa.kclsidMoInflAffMsa:
                IMoInflAffMsa infl = cobj as IMoInflAffMsa;
                if (infl != null)
                {
                    pos = infl.PartOfSpeechRA;
                }
                break;

            case MoDerivAffMsa.kclsidMoDerivAffMsa:
                IMoDerivAffMsa deriv = cobj as IMoDerivAffMsa;
                if (deriv != null)
                {
                    if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures)
                    {
                        pos = deriv.FromPartOfSpeechRA;
                    }
                    else if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToMsFeatures)
                    {
                        pos = deriv.ToPartOfSpeechRA;
                    }
                }
                break;

            case MoStemMsa.kclsidMoStemMsa:
                IMoStemMsa stem = cobj as IMoStemMsa;
                if (stem != null)
                {
                    pos = stem.PartOfSpeechRA;
                }
                break;

            case MoStemName.kclsidMoStemName:
                IMoStemName sn = cobj as IMoStemName;
                pos = PartOfSpeech.CreateFromDBObject(sn.Cache, sn.OwnerHVO);
                break;

            case MoAffixAllomorph.kclsidMoAffixAllomorph:
                // get entry of the allomorph and then get the msa of first sense and return its (from) POS
                ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, cobj.OwnerHVO);
                if (entry == null)
                {
                    return(pos);
                }
                ILexSense sense = entry.SensesOS.FirstItem;
                if (sense == null)
                {
                    return(pos);
                }
                IMoMorphSynAnalysis msa = sense.MorphoSyntaxAnalysisRA;
                pos = GetPosFromCmObjectAndFlid(msa, (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures);
                break;
            }
            return(pos);
        }
コード例 #23
0
        // ReSharper disable once InconsistentNaming
        public IMoMorphSynAnalysis CreateMSA(ILexEntry entry, IPartOfSpeech pos)
        {
            var msa = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create();

            entry.MorphoSyntaxAnalysesOC.Add(msa);
            msa.PartOfSpeechRA = pos;
            return(msa);
        }
コード例 #24
0
 private void AddSubPartsOfSpeech(IPartOfSpeech posRoot, List <IPartOfSpeech> rgpos)
 {
     foreach (IPartOfSpeech pos in posRoot.SubPossibilitiesOS)
     {
         rgpos.Add(pos);
         AddSubPartsOfSpeech(pos, rgpos);
     }
 }
コード例 #25
0
 private static void CheckPosHasOnlyEnglish(IPartOfSpeech pos)
 {
     CollectionAssert.AreEquivalent(s_wssOnlyEn, pos.Abbreviation.AvailableWritingSystemIds,
                                    $"Abbrev {pos.Abbreviation.BestAnalysisAlternative} should have only English");
     CollectionAssert.AreEquivalent(s_wssOnlyEn, pos.Name.AvailableWritingSystemIds,
                                    $"Name {pos.Name.BestAnalysisAlternative} should have only English");
     CollectionAssert.AreEquivalent(s_wssOnlyEn, pos.Description.AvailableWritingSystemIds,
                                    $"Def of {pos.Name.BestAnalysisAlternative} should have only English");
 }
コード例 #26
0
        protected ILexEntry AddLexeme(List <ICmObject> addList, string lexForm, string citationForm,
                                      IMoMorphType morphTypePoss, string gloss, IPartOfSpeech catPoss)
        {
            var ws = Cache.DefaultVernWs;
            var le = AddLexeme(addList, lexForm, morphTypePoss, gloss, catPoss);

            le.CitationForm.set_String(ws, citationForm);
            return(le);
        }
コード例 #27
0
ファイル: MSAGroupBox.cs プロジェクト: vkarthim/FieldWorks
        private void m_secPOSPopupTreeManager_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            m_selectedSecondaryPOS = null;
            var repo = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>();

            if (e.Node is HvoTreeNode)
            {
                repo.TryGetObject((e.Node as HvoTreeNode).Hvo, out m_selectedSecondaryPOS);
            }
        }
コード例 #28
0
ファイル: ParserTrace.cs プロジェクト: sillsdev/WorldPad
        /// <summary>
        /// Determine if a PartOfSpeech requires inflection.
        /// If it or any of its parent POSes have a template, it requires inflection.
        /// </summary>
        /// <param name="posHvo">hvo of the Part of Speech</param>
        /// <returns>true if it does, false otherwise</returns>
        protected bool RequiresInflection(int posHvo)
        {
            bool fResult = false;              // be pessimistic

            if (posHvo > 0)
            {
                IPartOfSpeech pos = PartOfSpeech.CreateFromDBObject(m_cache, posHvo);
                fResult = pos.RequiresInflection();
            }
            return(fResult);
        }
コード例 #29
0
        protected ILexSense AddSenseToEntry(List <ICmObject> addList, ILexEntry le, string gloss,
                                            IPartOfSpeech catPoss)
        {
            var msa = new SandboxGenericMSA();

            msa.MainPOS = catPoss;
            var sense = m_senseFact.Create(le, msa, gloss);

            addList.Add(sense);
            return(sense);
        }
コード例 #30
0
        //methods

        public override ObjectLabel Execute()
        {
            IMoInflAffixSlot slot = new MoInflAffixSlot();
            IPartOfSpeech    pos  = PartOfSpeech.CreateFromDBObject(m_cache, m_posHvo);

            pos.AffixSlotsOC.Add(slot);
            string sNewSlotName = m_mediator.StringTbl.GetString("NewSlotName", "Linguistics/Morphology/TemplateTable");

            slot.Name.AnalysisDefaultWritingSystem = sNewSlotName;
            slot.Optional = m_fOptional;
            return(ObjectLabel.CreateObjectLabel(m_cache, slot.Hvo, ""));
        }
コード例 #31
0
		protected override void CreateTestData()
		{
			base.CreateTestData();
			var servLoc = Cache.ServiceLocator;
			m_leFact = servLoc.GetInstance<ILexEntryFactory>();
			m_lerFact = servLoc.GetInstance<ILexEntryRefFactory>();
			//m_moFact = servLoc.GetInstance<IMoStemAllomorphFactory>();
			MockLauncher = new MockVectorReferenceLauncher();
			m_wsAnalysis = Cache.DefaultAnalWs;
			m_wsVern = Cache.DefaultVernWs;
			m_wsAnalStr = Cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(Cache.DefaultAnalWs);
			m_noun = GetNounPOS();
			m_stem = GetStemMorphType();
		}
コード例 #32
0
 // This class used to contain code for parsing the canonical part-of-speech data from GOLDEtic.xml and creating
 // new IPartOfSpeech objects from the canonical data if they were in Mongo but not in FDO. Most of that code has
 // been moved to the classes in the CanonicalSources namespace, and the "create new IPartOfSpeech" objects has
 // been moved to ConvertMongoToFdoOptionList (and made more generic). The only thing left in this class is the
 // static SetPartOfSpeech function, which deals with the complexities of MSAs.
 public static void SetPartOfSpeech(IMoMorphSynAnalysis msa, IPartOfSpeech pos, IPartOfSpeech secondaryPos = null, ILogger logger = null)
 {
     if (msa == null)
     {
         if (logger != null)
             logger.Debug("Trying to set part of speech \"{0}\" in MSA, but MSA was null", pos == null ? "(null)" : pos.AbbrAndName);
         return;
     }
     if (pos == null)
     {
         if (logger != null)
             logger.Debug("Trying to set a null part of speech in MSA \"{0}\" with GUID {1}", msa.GetGlossOfFirstSense(), msa.Guid);
         return;
     }
     switch (msa.ClassID)
     {
     case MoDerivAffMsaTags.kClassId:
         ((IMoDerivAffMsa)msa).FromPartOfSpeechRA = pos;
         // It's OK for secondaryPos to be null here; this represents *removing* the "To" part of speech link from this MSA
         ((IMoDerivAffMsa)msa).ToPartOfSpeechRA = secondaryPos;
         break;
     case MoDerivStepMsaTags.kClassId:
         ((IMoDerivStepMsa)msa).PartOfSpeechRA = pos;
         break;
     case MoInflAffMsaTags.kClassId:
         ((IMoInflAffMsa)msa).PartOfSpeechRA = pos;
         break;
     case MoStemMsaTags.kClassId:
         ((IMoStemMsa)msa).PartOfSpeechRA = pos;
         break;
     case MoUnclassifiedAffixMsaTags.kClassId:
         ((IMoUnclassifiedAffixMsa)msa).PartOfSpeechRA = pos;
         break;
     default:
         // We'll only reach here if new MSA types are added to FDO and we forget to update the switch statement above
         if (logger != null)
             logger.Debug("Got MSA of unknown type {0}", msa.GetType().Name);
         return;
     }
 }
コード例 #33
0
 public static IPartOfSpeech FromMSA(IMoMorphSynAnalysis msa, out IPartOfSpeech secondaryPos)
 {
     secondaryPos = null;
     switch (msa.ClassID)
     {
     case MoDerivAffMsaTags.kClassId:
         // FDO considers the "From" PoS to be the main one, and "To" to be the secondary one
         secondaryPos = ((IMoDerivAffMsa)msa).ToPartOfSpeechRA;
         return ((IMoDerivAffMsa)msa).FromPartOfSpeechRA;
     case MoDerivStepMsaTags.kClassId:
         return ((IMoDerivStepMsa)msa).PartOfSpeechRA;
     case MoInflAffMsaTags.kClassId:
         return ((IMoInflAffMsa)msa).PartOfSpeechRA;
     case MoStemMsaTags.kClassId:
         return ((IMoStemMsa)msa).PartOfSpeechRA;
     case MoUnclassifiedAffixMsaTags.kClassId:
         return ((IMoUnclassifiedAffixMsa)msa).PartOfSpeechRA;
     default:
         // TODO: Make this a log message, not Console.WriteLine
         Console.WriteLine("Got MSA of unknown type {0}", msa.GetType().Name);
         return null;
     }
 }
コード例 #34
0
			private int DeterminePOSLocationInfo(FdoCache cache, IPartOfSpeech subItemOwner, MasterCategory parent, ICmPossibilityList posList,
				out int newOwningFlid, out int insertLocation)
			{
				int newOwner;
				// The XML node is from a file shipped with FieldWorks. It is quite likely multiple users
				// of a project could independently add the same items, so we create them with fixed guids
				// so merge will recognize them as the same objects.
				//// LT-14511 However, if the partOfSpeech is being added to a reversal index, a different guid needs to be used
				//// than the ones in the file shipped with FieldWorks. In this case if two users add the same POS to the
				//// reversal index at the same time and then do a Send/Receive operation, then a merge conflict report
				//// will probably be created for this. This scenario is not likely to occur very often at all so having
				//// a conflict report created for when this happens is something we can live with.
				Guid guid;
				if (posList.Owner is IReversalIndex)
					guid = new Guid();
				else
					guid = new Guid(XmlUtils.GetAttributeValue(m_node, "guid"));
				var posFactory = cache.ServiceLocator.GetInstance<IPartOfSpeechFactory>();
				if (subItemOwner != null)
				{
					newOwner = subItemOwner.Hvo;
					newOwningFlid = CmPossibilityTags.kflidSubPossibilities;
					insertLocation = subItemOwner.SubPossibilitiesOS.Count;
					m_pos = posFactory.Create(guid, subItemOwner);
				}
				else if (parent != null && parent.m_pos != null)
				{
					newOwner = parent.m_pos.Hvo;
					newOwningFlid = CmPossibilityTags.kflidSubPossibilities;
					insertLocation = parent.m_pos.SubPossibilitiesOS.Count;
					m_pos = posFactory.Create(guid, parent.m_pos);
				}
				else
				{
					newOwner = posList.Hvo;
					newOwningFlid = CmPossibilityListTags.kflidPossibilities;
					insertLocation = posList.PossibilitiesOS.Count;
					m_pos = posFactory.Create(guid,posList); // automatically adds to parent.
				}
				return newOwner;
			}
コード例 #35
0
		/// <summary>
		/// Create element for one Gafaws PartOfSpeech object.
		/// </summary>
		private static XElement ExportPartOfSpeechGafaws(string elementName, IPartOfSpeech partOfSpeech)
		{
			return new XElement(elementName,
					   new XAttribute("Id", partOfSpeech.Hvo),
					   new XElement("AffixSlots",
						   from affixSlot in partOfSpeech.AffixSlotsOC where IsValidSlot(affixSlot)
						   select new XElement("MoInflAffixSlot",
							   new XAttribute("Id", affixSlot.Hvo))),
					   new XElement("AffixTemplates",
						   from template in partOfSpeech.AffixTemplatesOS where IsValidTemplate(template)
						   select new XElement("MoInflAffixTemplate",
							   new XAttribute("Id", template.Hvo),
							   from pfxslot in template.PrefixSlotsRS where IsValidSlot(pfxslot)
							   select ExportItemAsReference(pfxslot, template.PrefixSlotsRS.IndexOf(pfxslot), "PrefixSlots"),
							   from sfxslot in template.SuffixSlotsRS where IsValidSlot(sfxslot)
							   select ExportItemAsReference(sfxslot, template.PrefixSlotsRS.IndexOf(sfxslot), "SuffixSlots"))),
					   from IPartOfSpeech ownedPos in partOfSpeech.SubPossibilitiesOS
					   select ExportPartOfSpeechGafaws("poss", ownedPos));
		}
コード例 #36
0
		private void PopulateTreeFromPos(IPartOfSpeech pos)
		{
			if (pos != null && !m_poses.ContainsKey(pos.Hvo))
			{
				m_poses.Add(pos.Hvo, pos);
			}
			m_highestPOS = pos;
			while (pos != null)
			{
				m_tvMsaFeatureList.PopulateTreeFromInflectableFeats(pos.InflectableFeatsRC);
				var cobj = pos.Owner;
				m_highestPOS = pos;
				pos = cobj as IPartOfSpeech;
			}
		}
コード例 #37
0
		private static void WritePosXmlAttribute(XmlWriter writer, IPartOfSpeech pos, string sCat)
		{
			if (pos != null)
			{
				writer.WriteAttributeString(sCat, pos.Hvo.ToString(CultureInfo.InvariantCulture));
				string sPosAbbr = pos.Hvo > 0 ? pos.Abbreviation.BestAnalysisAlternative.Text : "??";
				writer.WriteAttributeString(sCat + "Abbr", sPosAbbr);
			}
			else
				writer.WriteAttributeString(sCat, "0");
		}
コード例 #38
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 (helpProvider != null)
					helpProvider.Dispose();
			}
			m_cache = null;
			m_fs = null;
			m_highestPOS = null;
			m_poses = null;
			m_mediator = null;
			m_cache = null;
			helpProvider = null;

			base.Dispose(disposing);
		}
コード例 #39
0
			private void UpdateSense(ILexSense sense, IPartOfSpeech pos)
			{
				CopyGlossesToSense(sense);
				var msa = (IMoStemMsa)sense.MorphoSyntaxAnalysisRA;
				var lexEntry = sense.Entry;
				if (msa.PartOfSpeechRA != pos)
				{
					// is there another MSA we can use?
					foreach (var msaOther in lexEntry.MorphoSyntaxAnalysesOC)
					{
						var stem = msaOther as IMoStemMsa;
						if (stem == null)
							continue;
						if (stem.PartOfSpeechRA == pos)
						{
							sense.MorphoSyntaxAnalysisRA = msaOther; // also updates WfiMorphBundle and deletes old obsolete MSA if obsolete.
							return;
						}
					}
					// Is this msa used elsewhere or can we modify it?
					if (lexEntry.SensesOS.Where(s => s != sense && s.MorphoSyntaxAnalysisRA == msa).Take(1).Count() > 0)
					{
						// Used; have to make a new one.
						msa = sense.Services.GetInstance<IMoStemMsaFactory>().Create();
						lexEntry.MorphoSyntaxAnalysesOC.Add(msa);
						sense.MorphoSyntaxAnalysisRA = msa;
					}
					msa.PartOfSpeechRA = pos;
				}
			}
コード例 #40
0
		/// <summary>
		/// If OK, then add relevant POSes to DB.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void MasterCategoryListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			switch (DialogResult)
			{
				default:
					m_selPOS = null;
					break;
				case DialogResult.OK:
				{
					// Closing with normal selection(s).
					foreach (TreeNode tn in m_nodes)
					{
						MasterCategory mc = tn.Tag as MasterCategory;
						Debug.Assert(mc != null);
						if ((tn.Checked || (tn == m_tvMasterList.SelectedNode))
							&& !mc.InDatabase)
						{
							// if this.m_subItemOwner != null, it indicates where to put the newly chosed POS
							mc.AddToDatabase(m_cache,
								m_posList,
								(tn.Parent == null) ? null : tn.Parent.Tag as MasterCategory,
								m_subItemOwner);
						}
					}
					MasterCategory mc2 = m_tvMasterList.SelectedNode.Tag as MasterCategory;
					Debug.Assert(mc2 != null);
					m_selPOS = mc2.POS;
					Debug.Assert(m_selPOS != null);
					break;
				}
				case DialogResult.Yes:
				{
					// Closing via the hotlink.
					// Do nothing special, except avoid setting m_selPOS to null, as in the default case.
					break;
				}
			}

			if (m_mediator != null)
			{
				m_mediator.PropertyTable.SetProperty("masterCatListDlgLocation", Location);
				m_mediator.PropertyTable.SetProperty("masterCatListDlgSize", Size);
			}
		}
コード例 #41
0
		partial void ToPartOfSpeechRASideEffects(IPartOfSpeech oldObjValue, IPartOfSpeech newObjValue)
		{
			if (oldObjValue != null && oldObjValue != newObjValue)
				CopyToAttributesIfValid(this);
		}
コード例 #42
0
		partial void PartOfSpeechRASideEffects(IPartOfSpeech oldObjValue, IPartOfSpeech newObjValue)
		{
			// When we change the part of speech to something different, we can't keep
			// the old InflectionClass since it is part of the original part of speech.
			// We try to allow any code (maybe copy operation) that wants to set the
			// inflection class before the part of speech.
			if (oldObjValue != null && oldObjValue != newObjValue)
				InflectionClassRA = null;
		}
コード例 #43
0
		/// <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;
		}
コード例 #44
0
		/// <summary>
		/// Removes all invalid feature specifications from the given feature
		/// structure.
		/// </summary>
		/// <param name="pos">the category to check for validity</param>
		/// <param name="fs">the field structure</param>
		protected void RemoveInvalidFeatureSpecs(IPartOfSpeech pos, IFsFeatStruc fs)
		{
			if (fs == null || pos == null)
				return;

			foreach (var spec in fs.FeatureSpecsOC)
			{
				if (!IsFeatureValid(pos, spec.FeatureRA))
				{
					fs.FeatureSpecsOC.Remove(spec);
				}
			}
		}
コード例 #45
0
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			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_nodes != null)
					m_nodes.Clear();
			}
			m_posList = null;
			m_mediator = null;
			m_cache = null;
			m_selPOS = null;
			m_nodes = null;

			base.Dispose( disposing );
		}
コード例 #46
0
ファイル: MSAGroupBox.cs プロジェクト: bbriggs/FieldWorks
		private void m_mainPOSPopupTreeManager_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			m_selectedMainPOS = null;
			var repo = m_cache.ServiceLocator.GetInstance<IPartOfSpeechRepository>();
			if (e.Node is HvoTreeNode)
				repo.TryGetObject((e.Node as HvoTreeNode).Hvo, out m_selectedMainPOS);

			// If this is an inflectional affix MSA,
			// then populate slot list (FwComboBox m_fwcbSlots).
			if (MSAType == MsaType.kInfl)
				ResetSlotCombo();
			if (m_tcMainPOS.Text != e.Node.Text)
				m_tcMainPOS.Text = e.Node.Text;
		}
コード例 #47
0
ファイル: MSAGroupBox.cs プロジェクト: bbriggs/FieldWorks
		private void m_secPOSPopupTreeManager_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			m_selectedSecondaryPOS = null;
			var repo = m_cache.ServiceLocator.GetInstance<IPartOfSpeechRepository>();
			if (e.Node is HvoTreeNode)
				repo.TryGetObject((e.Node as HvoTreeNode).Hvo, out m_selectedSecondaryPOS);
		}
コード例 #48
0
		/// <summary>
		///
		/// </summary>
		/// <param name="posList"></param>
		/// <param name="mediator"></param>
		/// <param name="launchedFromInsertMenu"></param>
		/// <param name="subItemOwner"></param>
		public void SetDlginfo(ICmPossibilityList posList, Mediator mediator, bool launchedFromInsertMenu, IPartOfSpeech subItemOwner)
		{
			CheckDisposed();

			m_subItemOwner = subItemOwner; // May be null, which is fine.
			m_posList = posList;
			m_launchedFromInsertMenu = launchedFromInsertMenu;
			m_mediator = mediator;
			if (mediator != null)
			{
				// Reset window location.
				// Get location to the stored values, if any.
				object locWnd = m_mediator.PropertyTable.GetValue("masterCatListDlgLocation");
				object szWnd = m_mediator.PropertyTable.GetValue("masterCatListDlgSize");
				if (locWnd != null && szWnd != null)
				{
					Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd);
					ScreenUtils.EnsureVisibleRect(ref rect);
					DesktopBounds = rect;
					StartPosition = FormStartPosition.Manual;
				}
				m_helpTopicProvider = m_mediator.HelpTopicProvider;
				if (m_helpTopicProvider != null)
				{
					helpProvider = new HelpProvider();
					helpProvider.HelpNamespace = m_helpTopicProvider.HelpFile;
					helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(s_helpTopic));
					helpProvider.SetHelpNavigator(this, HelpNavigator.Topic);
				}
			}
			m_bnHelp.Enabled = (m_helpTopicProvider != null);

			Debug.Assert(posList != null);
			m_cache = posList.Cache;
			var posSet = new Set<IPartOfSpeech>();
			foreach (IPartOfSpeech pos in posList.ReallyReallyAllPossibilities)
				posSet.Add(pos);
			LoadMasterCategories(posSet);
		}
コード例 #49
0
		private static void WriteRequiresInflectionXmlAttribute(XmlWriter writer, IPartOfSpeech pos)
		{
			writer.WriteAttributeString("requiresInfl", RequiresInflection(pos) ? "+" : "-");
		}
コード例 #50
0
		private IPartOfSpeech GetHighestPOS(IPartOfSpeech pos, out string sTopPOS)
		{
			IPartOfSpeech result = null;
			sTopPOS = MEStrings.ksQuestions;
			ICmObject obj = pos;
			while (obj.ClassID == PartOfSpeechTags.kClassId)
			{
				result = obj as IPartOfSpeech;
				sTopPOS = obj.ShortName;
				obj = obj.Owner;
			}
			return result;
		}
コード例 #51
0
		/// <summary>
		/// Determine if a PartOfSpeech requires inflection.
		/// If it or any of its parent POSes have a template, it requires inflection.
		/// If it is null we default to not requiring inflection.
		/// </summary>
		/// <param name="pos">the Part of Speech</param>
		/// <returns>true if it does, false otherwise</returns>
		private static bool RequiresInflection(IPartOfSpeech pos)
		{
			return pos != null && pos.RequiresInflection;
		}
コード例 #52
0
		IPartOfSpeech IPartOfSpeechFactory.Create(Guid guid, IPartOfSpeech owner)
		{
			if (owner == null) throw new ArgumentNullException("owner");

			int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo();

			var retval = new PartOfSpeech(m_cache, hvo, guid);
			owner.SubPossibilitiesOS.Add(retval);
			return retval;
		}
コード例 #53
0
		private static void ExportPartOfSpeech(IPartOfSpeech pos, ICollection<XElement> cats, Icu.UNormalizationMode mode)
		{
			// Add 'pos'.
			cats.Add(new XElement("PartOfSpeech",
								  new XAttribute("Id", pos.Hvo),
								CreateAttribute("DefaultInflectionClass", pos.DefaultInflectionClassRA),
								  ExportBestAnalysis(pos.Name, "Name", mode),
								  ExportBestAnalysis(pos.Description, "Description", mode),
								  ExportBestAnalysis(pos.Abbreviation, "Abbreviation", mode),
								  new XElement("NumberOfLexEntries", pos.NumberOfLexEntries),
								  new XElement("AffixSlots",
											   from affixSlot in pos.AffixSlotsOC
											   where IsValidSlot(affixSlot)
											   select new XElement("MoInflAffixSlot",
																	new XAttribute("Id", affixSlot.Hvo),
																	new XAttribute("Optional", affixSlot.Optional),
																	ExportBestAnalysis(affixSlot.Name, "Name", mode),
																	ExportBestAnalysis(affixSlot.Description, "Description", mode))),
				// Affix templates.
								  new XElement("AffixTemplates", from template in pos.AffixTemplatesOS where IsValidTemplate(template)
																  select ExportAffixtemplate(template, mode)),
				// Inflection classes.
								  new XElement("InflectionClasses", from inflectionClass in pos.InflectionClassesOC
																	 select ExportInflectionClass(inflectionClass, mode)),
				// Inflectable Features
								  new XElement("InflectableFeats", from inflectableFeature in pos.InflectableFeatsRC
																   select new XElement("InflectableFeature",
																	   CreateDstAttribute(inflectableFeature.Hvo))),
				// Stem names
								  new XElement("StemNames", from stemName in pos.StemNamesOC
															 select ExportStemName(stemName, mode)),
				// BearableFeatures
								  new XElement("BearableFeatures",
											   from bearableFeaature in pos.BearableFeaturesRC
												select new XElement("BearableFeature",
																	CreateDstAttribute(bearableFeaature.Hvo))),
								  from subpos in pos.SubPossibilitiesOS
								   select ExportItemAsReference(subpos, "SubPossibilities")));

			// Add owned parts of speech.
			foreach (IPartOfSpeech innerPos in pos.SubPossibilitiesOS)
				ExportPartOfSpeech(innerPos, cats, mode);
		}
コード例 #54
0
		private static void CheckPossibilityGuidAgainstGold(IPartOfSpeech pos,
																			 XmlDocument dom,
																			 Dictionary<IPartOfSpeech, string> itemsWithBadGuids)
		{
			if(!string.IsNullOrEmpty(pos.CatalogSourceId))
			{
				if(dom.SelectSingleNode(string.Format("//item[@id='{0}' and @guid='{1}']", pos.CatalogSourceId, pos.Guid.ToString())) == null)
				{
					var selectNodeWithoutGuid = dom.SelectSingleNode(string.Format("//item[@id='{0}']", pos.CatalogSourceId));

					itemsWithBadGuids[pos] = selectNodeWithoutGuid.Attributes["guid"].Value;
				}
			}
			if(pos.SubPossibilitiesOS != null)
			{
				foreach(IPartOfSpeech subPos in pos.SubPossibilitiesOS)
				{
					CheckPossibilityGuidAgainstGold(subPos, dom, itemsWithBadGuids);
				}
			}
		}
コード例 #55
0
		/// <summary>
		/// Init the dialog with a POS.
		/// If a new feature structure is created, it will currently be in the ReferenceForms of the POS.
		/// Eventually we want to make a new field for this purpose. (This is used by bulk edit
		/// to store previously used feature structures.)
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mediator"></param>
		/// <param name="pos"></param>
		public void SetDlgInfo(FdoCache cache, Mediator mediator, IPartOfSpeech pos)
		{
			SetDlgInfo(cache, mediator, pos, PartOfSpeechTags.kflidReferenceForms);
		}
コード例 #56
0
ファイル: LingOverrides.cs プロジェクト: sillsdev/WorldPad
		/// <summary>
		/// Get the hvo of the highest PartOfSpeech in the hierarchy
		/// </summary>
		/// <param name="ps">Beginning PartOfSpeech</param>
		/// <returns>Hvo of the highest PartOfSpeech in the hierarchy</returns>
		public int GetHvoOfHighestPartOfSpeech(IPartOfSpeech ps)
		{
			int iHvo = ps.Hvo;
			while (ps.ClassID == PartOfSpeech.kClassId)
			{
				ps = CmObject.CreateFromDBObject(m_cache, ps.OwnerHVO) as IPartOfSpeech;
				if (ps != null)
					iHvo = ps.Hvo;
				else
					break;
			}
			return iHvo;
		}
コード例 #57
0
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			// m_sda COM object block removed due to crash in Finializer thread LT-6124

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_sda != null)
					m_sda.RemoveNotification(this);

				if (m_tree != null && m_tree.Parent == null)
					m_tree.Dispose();

				if (m_pOSPopupTreeManager != null)
				{
					m_pOSPopupTreeManager.AfterSelect -= new TreeViewEventHandler(m_pOSPopupTreeManager_AfterSelect);
					m_pOSPopupTreeManager.Dispose();
				}
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_sda = null;
			m_cache = null;
			m_tree = null;
			m_pOSPopupTreeManager = null;
			m_persistProvider = null;
			m_pos = null;

			base.Dispose(disposing);
		}
コード例 #58
0
ファイル: MSAGroupBox.cs プロジェクト: bbriggs/FieldWorks
		/// <summary>
		/// Initialize the control.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mediator"></param>
		/// <param name="parentForm"></param>
		public void Initialize(FdoCache cache, Mediator mediator, Form parentForm, SandboxGenericMSA sandboxMSA)
		{
			CheckDisposed();

			m_parentForm = parentForm;
			m_mediator = mediator;
			m_tsf = cache.TsStrFactory;
			m_cache = cache;

			IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);
			int defUserWs = m_cache.ServiceLocator.WritingSystemManager.UserWs;
			IWritingSystem defAnalWs = m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem;
			string defAnalWsFont = defAnalWs.DefaultFontName;

			m_fwcbAffixTypes.WritingSystemFactory = m_cache.WritingSystemFactory;
			m_fwcbAffixTypes.WritingSystemCode = defAnalWs.Handle;
			m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksNotSure, defUserWs));
			m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksInflectional, defUserWs));
			m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksDerivational, defUserWs));
			m_fwcbAffixTypes.StyleSheet = stylesheet;
			m_fwcbAffixTypes.AdjustStringHeight = false;

			m_fwcbSlots.Font = new Font(defAnalWsFont, 10);
			m_fwcbSlots.WritingSystemFactory = m_cache.WritingSystemFactory;
			m_fwcbSlots.WritingSystemCode = defAnalWs.Handle;
			m_fwcbSlots.StyleSheet = stylesheet;
			m_fwcbSlots.AdjustStringHeight = false;

			m_tcMainPOS.Font = new Font(defAnalWsFont, 10);
			m_tcMainPOS.WritingSystemFactory = m_cache.WritingSystemFactory;
			m_tcMainPOS.WritingSystemCode = defAnalWs.Handle;
			m_tcMainPOS.StyleSheet = stylesheet;
			m_tcMainPOS.AdjustStringHeight = false;

			m_tcSecondaryPOS.Font = new Font(defAnalWsFont, 10);
			m_tcSecondaryPOS.WritingSystemFactory = m_cache.WritingSystemFactory;
			m_tcSecondaryPOS.WritingSystemCode = defAnalWs.Handle;
			m_tcSecondaryPOS.StyleSheet = stylesheet;
			m_tcSecondaryPOS.AdjustStringHeight = false;

			m_selectedMainPOS = sandboxMSA.MainPOS;
			m_fwcbAffixTypes.SelectedIndex = 0;
			m_fwcbAffixTypes.SelectedIndexChanged += HandleComboMSATypesChange;
			m_mainPOSPopupTreeManager = new POSPopupTreeManager(m_tcMainPOS, m_cache,
				m_cache.LanguageProject.PartsOfSpeechOA,
				defAnalWs.Handle, false, m_mediator,
				m_parentForm);
			m_mainPOSPopupTreeManager.NotSureIsAny = true;
			m_mainPOSPopupTreeManager.LoadPopupTree(m_selectedMainPOS != null ? m_selectedMainPOS.Hvo : 0);
			m_mainPOSPopupTreeManager.AfterSelect += m_mainPOSPopupTreeManager_AfterSelect;
			m_fwcbSlots.SelectedIndexChanged += HandleComboSlotChange;
			m_secPOSPopupTreeManager = new POSPopupTreeManager(m_tcSecondaryPOS, m_cache,
				m_cache.LanguageProject.PartsOfSpeechOA,
				defAnalWs.Handle, false, m_mediator,
				m_parentForm);
			m_secPOSPopupTreeManager.NotSureIsAny = true; // only used for affixes.
			m_selectedSecondaryPOS = sandboxMSA.SecondaryPOS;
			m_secPOSPopupTreeManager.LoadPopupTree(m_selectedSecondaryPOS != null ? m_selectedSecondaryPOS.Hvo : 0);
			m_secPOSPopupTreeManager.AfterSelect += m_secPOSPopupTreeManager_AfterSelect;

			// Relocate the m_tcSecondaryPOS control to overlay the m_fwcbSlots.
			// In the designer, they are offset to see them, and edit them.
			// In running code they are in the same spot, but only one is visible at a time.
			m_tcSecondaryPOS.Location = m_fwcbSlots.Location;

			if (m_selectedMainPOS != null && sandboxMSA.MsaType == MsaType.kInfl)
			{
				// This fixes LT-4677, LT-6048, and LT-6201.
				ResetSlotCombo();
			}
			MSAType = sandboxMSA.MsaType;
		}
コード例 #59
0
			public void AddToDatabase(FdoCache cache, ICmPossibilityList posList, MasterCategory parent, IPartOfSpeech subItemOwner)
			{
				if (m_pos != null)
					return; // It's already in the database, so nothing more can be done.

				UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateCategory, LexTextControls.ksRedoCreateCategory,
					cache.ServiceLocator.GetInstance<IActionHandler>(), () =>
				{
					int newOwningFlid;
					int insertLocation;
					int newOwner =
						DeterminePOSLocationInfo(cache, subItemOwner, parent, posList, out newOwningFlid, out insertLocation);
					ILgWritingSystemFactory wsf = cache.WritingSystemFactory;
					Debug.Assert(m_pos != null);

					int termWs = wsf.GetWsFromStr(m_termWs);
					int abbrevWs = wsf.GetWsFromStr(m_abbrevWs);
					int defWs = wsf.GetWsFromStr(m_defWs);
					ITsStrFactory tsf = cache.TsStrFactory;
					if (m_node == null)
					{ // should not happen, but just in case... we still get something useful
						m_pos.Name.set_String(termWs, tsf.MakeString(m_term, termWs));
						m_pos.Abbreviation.set_String(abbrevWs, tsf.MakeString(m_abbrev, abbrevWs));
						m_pos.Description.set_String(defWs, tsf.MakeString(m_def, defWs));
					}
					else
					{
						SetContentFromNode(cache, "abbrev", false, m_pos.Abbreviation);
						SetContentFromNode(cache, "term", true, m_pos.Name);
						SetContentFromNode(cache, "def", false, m_pos.Description);
					}

					m_pos.CatalogSourceId = m_id;
				});
			}
コード例 #60
0
		private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			if (!m_launchedFromInsertMenu)
				XCore.XMessageBoxExManager.Trigger("CreateNewFromGrammaticalCategoryCatalog");
			m_cache.DomainDataByFlid.BeginUndoTask(LexTextControls.ksUndoInsertCategory,
				LexTextControls.ksRedoInsertCategory);
			var posFactory = m_cache.ServiceLocator.GetInstance<IPartOfSpeechFactory>();
			if (m_subItemOwner != null)
			{
				m_selPOS = posFactory.Create();
				m_subItemOwner.SubPossibilitiesOS.Add(m_selPOS);
			}
			else
			{
				m_selPOS = posFactory.Create();
				m_posList.PossibilitiesOS.Add(m_selPOS);
			}
			m_cache.DomainDataByFlid.EndUndoTask();
			DialogResult = DialogResult.Yes;
			Close();
		}