Exemplo n.º 1
0
        /// <summary>
        /// Initilize the gui control.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="mediator"></param>
        /// <param name="configurationNode">NB: In this case it is the main 'window' element node,
        /// se we have to drill down to find the control definition node(s).</param>
        /// <param name="sourceObject"></param>
        public void Init(Mediator mediator, XmlNode configurationNode, ICmObject sourceObject)
        {
            CheckDisposed();

            Debug.Assert(mediator != null);
            Debug.Assert(configurationNode != null);
            Debug.Assert(sourceObject != null && (sourceObject is IWfiWordform || sourceObject is IWfiAnalysis || sourceObject is IWfiGloss));

            m_cache             = sourceObject.Cache;
            m_mediator          = mediator;
            m_configurationNode = configurationNode;
            m_sourceObject      = sourceObject;
            if (sourceObject is IWfiWordform)
            {
                m_wordform = sourceObject as IWfiWordform;
            }
            else
            {
                IWfiAnalysis anal = null;
                if (sourceObject is IWfiAnalysis)
                {
                    anal = sourceObject as IWfiAnalysis;
                }
                else
                {
                    anal = WfiAnalysis.CreateFromDBObject(m_cache, sourceObject.OwnerHVO);
                }
                m_wordform = WfiWordform.CreateFromDBObject(m_cache, anal.OwnerHVO);
            }

            m_mediator.PropertyTable.SetProperty("IgnoreStatusPanel", true);
            m_mediator.PropertyTable.SetPropertyPersistence("IgnoreStatusPanel", false);
            m_progAdvInd = new ProgressReporting(m_toolStripProgressBar);

            // Gather up the nodes.
            string  xpathBase  = "/window/controls/parameters[@id='guicontrols']/guicontrol[@id='{0}']/parameters[@id='{1}']";
            string  xpath      = String.Format(xpathBase, "WordformConcordanceBrowseView", "WordformInTwficsOccurrenceList");
            XmlNode configNode = m_configurationNode.SelectSingleNode(xpath);
            // And create the RecordClerks.
            RecordClerk clerk = RecordClerkFactory.CreateClerk(m_mediator, configNode);

            clerk.ProgressReporter = m_progAdvInd;
            m_recordClerks[WfiWordform.kclsidWfiWordform]       = clerk;
            m_configurationNodes[WfiWordform.kclsidWfiWordform] = configNode;

            xpath                  = String.Format(xpathBase, "AnalysisConcordanceBrowseView", "AnalysisInTwficsOccurrenceList");
            configNode             = m_configurationNode.SelectSingleNode(xpath);
            clerk                  = RecordClerkFactory.CreateClerk(m_mediator, configNode);
            clerk.ProgressReporter = m_progAdvInd;
            m_recordClerks[WfiAnalysis.kclsidWfiAnalysis]       = clerk;
            m_configurationNodes[WfiAnalysis.kclsidWfiAnalysis] = configNode;

            xpath                  = String.Format(xpathBase, "GlossConcordanceBrowseView", "GlossInTwficsOccurrenceList");
            configNode             = m_configurationNode.SelectSingleNode(xpath);
            clerk                  = RecordClerkFactory.CreateClerk(m_mediator, configNode);
            clerk.ProgressReporter = m_progAdvInd;
            m_recordClerks[WfiGloss.kclsidWfiGloss]       = clerk;
            m_configurationNodes[WfiGloss.kclsidWfiGloss] = configNode;

            int concordOnHvo = sourceObject.Hvo;

            Debug.Assert(m_wordform != null);
            Debug.Assert(concordOnHvo > 0);

            tvSource.Font = new Font("Arial", 9);
            tvTarget.Font = new Font("Arial", 9);

            TreeNode srcTnWf = new TreeNode();
            TreeNode tarTnWf = new TreeNode();

            StringUtils.InitIcuDataDir();               // used for normalizing strings to NFC
            tarTnWf.Text = srcTnWf.Text = StringUtils.NormalizeToNFC(MEStrings.ksNoAnalysis);
            tarTnWf.Tag  = srcTnWf.Tag = m_wordform.Hvo;
            tvSource.Nodes.Add(srcTnWf);
            tvTarget.Nodes.Add(tarTnWf);
            if ((int)srcTnWf.Tag == concordOnHvo)
            {
                tvSource.SelectedNode = srcTnWf;
            }
            int cnt = 0;

            // Note: the left side source tree only has human approved analyses,
            // since only those can have instances from text-land pointing at them.
            foreach (int humanApprovedAnalId in m_wordform.HumanApprovedAnalyses)
            {
                IWfiAnalysis anal      = WfiAnalysis.CreateFromDBObject(m_wordform.Cache, humanApprovedAnalId);
                TreeNode     srcTnAnal = new TreeNode();
                TreeNode     tarTnAnal = new TreeNode();
                tarTnAnal.Text = srcTnAnal.Text = StringUtils.NormalizeToNFC(
                    String.Format(MEStrings.ksAnalysisX, (++cnt).ToString()));
                tarTnAnal.Tag = srcTnAnal.Tag = anal.Hvo;
                srcTnWf.Nodes.Add(srcTnAnal);
                tarTnWf.Nodes.Add(tarTnAnal);
                if ((int)srcTnAnal.Tag == concordOnHvo)
                {
                    tvSource.SelectedNode = srcTnAnal;
                }
                foreach (WfiGloss gloss in anal.MeaningsOC)
                {
                    TreeNode     srcTnGloss = new TreeNode();
                    TreeNode     tarTnGloss = new TreeNode();
                    ITsString    tss        = gloss.Form.BestAnalysisAlternative;
                    ITsTextProps props      = tss.get_PropertiesAt(0);
                    int          nVar;
                    int          ws       = props.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar);
                    string       fontname = m_wordform.Cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(ws).DefaultMonospace;
                    tarTnGloss.NodeFont = new Font(fontname, 9);
                    srcTnGloss.NodeFont = new Font(fontname, 9);
                    tarTnGloss.Text     = srcTnGloss.Text = StringUtils.NormalizeToNFC(tss.Text);
                    tarTnGloss.Tag      = srcTnGloss.Tag = gloss.Hvo;
                    srcTnAnal.Nodes.Add(srcTnGloss);
                    tarTnAnal.Nodes.Add(tarTnGloss);
                    if ((int)srcTnGloss.Tag == concordOnHvo)
                    {
                        tvSource.SelectedNode = srcTnGloss;
                    }
                }
            }
            tvSource.ExpandAll();
            tvSource.SelectedNode.EnsureVisible();
            tvTarget.ExpandAll();
        }
Exemplo n.º 2
0
            protected override void ValidateSegForms(object expectedSegForm, object actualSegForm, string segFormContext)
            {
                string msg = "Mismatched {0} in {1}.";
                // Get the paragraph string corresponding to the annotation.
                ICmBaseAnnotation cbaExpected = CmBaseAnnotation.CreateFromDBObject(m_cache, (int)expectedSegForm);

                // first make sure we have a txt item.
                if (IsLineEnabled(InterlinLineChoices.kflidWord))
                {
                    ITsString tssExpectedForm = m_para.Contents.UnderlyingTsString.GetSubstring(cbaExpected.BeginOffset, cbaExpected.EndOffset);
                    string    lang            = "xkal";
                    // Review: get WsLabel from tssExpectedForm.
                    string actualForm = "";
                    if (cbaExpected.AnnotationTypeRAHvo == TwficAnnotationType)
                    {
                        actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "txt", lang);
                    }
                    else if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
                    {
                        actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "punct", lang);
                    }
                    Assert.AreEqual(tssExpectedForm.Text, actualForm,
                                    String.Format(msg, "word", segFormContext));
                }
                // if WordGloss is enabled, verify it.
                if (IsLineEnabled(InterlinLineChoices.kflidWordGloss))
                {
                    string lang            = "en";
                    string actualWordGloss = m_reader.GetItemInnerText(actualSegForm as XmlNode, "gls", lang);
                    if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
                    {
                        // must be a punctuation (non-wfic)
                        Assert.AreEqual("", actualWordGloss);
                    }
                    else
                    {
                        WfiGloss expectedGloss = null;
                        int      clsId         = m_cache.GetClassOfObject(cbaExpected.InstanceOfRAHvo);
                        if (clsId == WfiGloss.kclsidWfiGloss)
                        {
                            expectedGloss = new WfiGloss(m_cache, cbaExpected.InstanceOfRAHvo);
                        }
                        else if (clsId == WfiWordform.kclsidWfiWordform)
                        {
                            // should be a twfic so get its guess.
                            StTxtPara.TwficInfo cbaInfo = new StTxtPara.TwficInfo(m_cache, cbaExpected.Hvo);
                            int hvoExpectedGloss        = cbaInfo.GetGuess();
                            if (hvoExpectedGloss != 0)
                            {
                                expectedGloss = new WfiGloss(m_cache, hvoExpectedGloss);
                            }
                        }
                        // TODO: There are cases for other classes (e.g. WfiAnalysis) but
                        // the tests do not generate those right now, so we won't worry about them right now.
                        if (expectedGloss != null)
                        {
                            Assert.AreEqual(expectedGloss.Form.AnalysisDefaultWritingSystem, actualWordGloss);
                        }
                        else
                        {
                            Assert.AreEqual("", actualWordGloss);
                        }
                    }
                }
                // validate morph bundle lines.
                if (IsLineEnabled(InterlinLineChoices.kflidMorphemes) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexEntries) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexGloss) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexPos))
                {
                    // compare exported document to the LexEntries information in the WfiAnalysis
                    int hvoWfiAnalysis = 0;
                    if (cbaExpected.AnnotationTypeRAHvo != PunctuationAnnotationType)
                    {
                        hvoWfiAnalysis = WfiAnalysis.GetWfiAnalysisFromInstanceOf(m_cache, cbaExpected.Hvo);
                    }
                    List <XmlNode> morphNodes = m_reader.GetMorphNodes(actualSegForm as XmlNode);
                    if (hvoWfiAnalysis == 0)
                    {
                        // make sure we don't have any morphs.
                        Assert.IsEmpty(morphNodes);
                    }
                    else
                    {
                        IWfiAnalysis wfiAnalysis = WfiAnalysis.CreateFromDBObject(m_cache, hvoWfiAnalysis);
                        foreach (WfiMorphBundle morphBundle in wfiAnalysis.MorphBundlesOS)
                        {
                            int     iMorph          = morphBundle.OwnOrd - 1;
                            string  morphContext    = segFormContext + "/Morph(" + iMorph + ")";
                            XmlNode actualMorphNode = iMorph < morphNodes.Count ? morphNodes[iMorph] : null;
                            if (actualMorphNode == null)
                            {
                                Assert.Fail(String.Format(msg, "missing morph", morphContext));
                            }
                            ITsString tssLexEntry = null;
                            int       hvoMorph    = morphBundle.MorphRAHvo;
                            if (hvoMorph != 0)
                            {
                                // first test the morph form
                                if (IsLineEnabled(InterlinLineChoices.kflidMorphemes))
                                {
                                    string actualMorphForm = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "txt", "xkal");
                                    Assert.AreEqual(morphBundle.MorphRA.Form.VernacularDefaultWritingSystem,
                                                    actualMorphForm,
                                                    String.Format(msg, "morph/txt", morphContext));
                                }

                                // next test the lex entry
                                if (IsLineEnabled(InterlinLineChoices.kflidLexEntries))
                                {
                                    string actualLexEntry     = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "cf", "xkal");
                                    string actualHomograph    = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "hn", "en");
                                    string actualVariantTypes = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "variantTypes", "en");
                                    tssLexEntry = InterlinDocChild.GetLexEntryTss(m_cache, morphBundle, m_cache.DefaultVernWs);
                                    Assert.AreEqual(tssLexEntry.Text, actualLexEntry + actualHomograph + actualVariantTypes,
                                                    String.Format(msg, "morph/cf[hn|variantTypes]", morphContext));
                                }

                                if (IsLineEnabled(InterlinLineChoices.kflidLexGloss))
                                {
                                    string actualLexGloss = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "gls", "en");
                                    string expectedGloss  = "";
                                    if (morphBundle.SenseRA != null && morphBundle.SenseRA.Gloss != null)
                                    {
                                        expectedGloss = morphBundle.SenseRA.Gloss.AnalysisDefaultWritingSystem;
                                    }
                                    Assert.AreEqual(expectedGloss, actualLexGloss,
                                                    String.Format(msg, "morph/gls", morphContext));
                                }
                                if (IsLineEnabled(InterlinLineChoices.kflidLexPos))
                                {
                                    string actualLexMsa = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "msa", "en");
                                    string expectedMsa  = "";
                                    if (morphBundle.SenseRA != null && morphBundle.SenseRA.MorphoSyntaxAnalysisRA != null)
                                    {
                                        expectedMsa = morphBundle.SenseRA.MorphoSyntaxAnalysisRA.InterlinearAbbr;
                                    }
                                    Assert.AreEqual(expectedMsa, actualLexMsa,
                                                    String.Format(msg, "morph/msa", morphContext));
                                }
                            }
                        }
                        Assert.AreEqual(wfiAnalysis.MorphBundlesOS.Count, morphNodes.Count);
                    }
                }
            }