Beispiel #1
0
        private void GlossParagraph(IStTxtPara paraToParse)
        {
            var ich     = 0;
            var wsForm  = Cache.DefaultVernWs;
            var wsGloss = Cache.DefaultAnalWs;

            foreach (var seg in paraToParse.SegmentsOS)
            {
                for (var i = 0; i < seg.AnalysesRS.Count; i++)
                {
                    var xform = seg.AnalysesRS[i];
                    var word  = xform.GetForm(wsForm).Text;
                    ich += word.Length;
                    if (!xform.HasWordform)
                    {
                        continue;
                    }
                    var wordform = xform.Wordform;
                    var analysis = m_wAnalysisFact.Create(wordform, m_wGlossFact);
                    ich++;                     // past space or dot
                    var tssString = m_tsf.MakeString(word + "Gloss" + ich, wsGloss);
                    var gloss     = analysis.MeaningsOC.FirstOrDefault();
                    gloss.Form.set_String(wsGloss, tssString);
                    seg.AnalysesRS[i] = gloss;
                }
            }
        }
Beispiel #2
0
        private static void CreateAnalysisForWord(string word, ISegment segment, int ws,
                                                  bool fCreateGlosses)
        {
            FdoCache               cache              = segment.Cache;
            IWfiWordformFactory    wfFactory          = cache.ServiceLocator.GetInstance <IWfiWordformFactory>();
            IWfiWordformRepository wfRepo             = cache.ServiceLocator.GetInstance <IWfiWordformRepository>();
            IWfiGlossFactory       glossFactory       = cache.ServiceLocator.GetInstance <IWfiGlossFactory>();
            IWfiAnalysisFactory    wfiAnalysisFactory = cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>();

            ITsString    tssForm = cache.TsStrFactory.MakeString(word, cache.DefaultVernWs);
            IWfiWordform form;
            IAnalysis    analysis;

            if (wfRepo.TryGetObject(tssForm, out form))
            {
                analysis = (fCreateGlosses) ? (IAnalysis)form.AnalysesOC.First().MeaningsOC.First() : form;
            }
            else
            {
                analysis = form = wfFactory.Create(tssForm);
                IWfiAnalysis actualWfiAnalysis = wfiAnalysisFactory.Create();
                form.AnalysesOC.Add(actualWfiAnalysis);
                if (fCreateGlosses)
                {
                    IWfiGloss gloss = glossFactory.Create();
                    actualWfiAnalysis.MeaningsOC.Add(gloss);
                    gloss.Form.set_String(ws, "G" + word + "g");
                    analysis = gloss;
                }
            }
            segment.AnalysesRS.Add(analysis);
        }
Beispiel #3
0
        private void SetUpGlosses(ISegment seg, params string[] glosses)
        {
            var servloc = Cache.ServiceLocator;
            IWfiAnalysisFactory analFactory  = servloc.GetInstance <IWfiAnalysisFactory>();
            IWfiGlossFactory    glossFactory = servloc.GetInstance <IWfiGlossFactory>();

            UndoableUnitOfWorkHelper.Do("Undo add glosses", "Redo add glosses", Cache.ActionHandlerAccessor,
                                        () =>
            {
                for (int i = 0; i < glosses.Length; i++)
                {
                    if (glosses[i] == null)
                    {
                        continue;
                    }
                    IWfiWordform wfiWordform = (IWfiWordform)seg.AnalysesRS[i];
                    IWfiAnalysis analysis    = analFactory.Create(wfiWordform, glossFactory);
                    IWfiGloss gloss          = analysis.MeaningsOC.First();
                    seg.AnalysesRS[i]        = gloss;
                    gloss.Form.SetAnalysisDefaultWritingSystem(glosses[i]);
                }
            });
        }
Beispiel #4
0
        /// <summary>
        /// Process an analysis.
        /// </summary>
        /// <remarks>
        /// This method contains the port of the UpdWfiAnalysisAndEval$ SP.
        /// The SP was about 220 lines of code (not counting a commetned out section).
        /// The C# version is about 60 lines long.
        /// </remarks>
        private void ProcessAnalysis(IWfiWordform wordform, ParseAnalysis analysis)
        {
            /*
             *      Try to find matching analysis(analyses) that already exist.
             *      A "match" is one in which:
             *      (1) the number of morph bundles equal the number of the MoForm and
             *              MorphoSyntaxAnanlysis (MSA) IDs passed in to the stored procedure, and
             *      (2) The objects of each MSA+Form pair match those of the corresponding WfiMorphBundle.
             */
            // Find matching analysis/analyses, if any exist.
            var matches = new HashSet <IWfiAnalysis>();

            foreach (var anal in wordform.AnalysesOC)
            {
                if (anal.MorphBundlesOS.Count == analysis.Morphs.Count)
                {
                    // Meets match condition (1), above.
                    var mbMatch = false;                     //Start pessimistically.
                    var i       = 0;
                    foreach (var mb in anal.MorphBundlesOS)
                    {
                        var current = analysis.Morphs[i++];
                        if (mb.MorphRA == current.Form && mb.MsaRA == current.Msa && mb.InflTypeRA == current.InflType)
                        {
                            // Possibly matches condition (2), above.
                            mbMatch = true;
                        }
                        else
                        {
                            // Fails condition (2), above.
                            mbMatch = false;
                            break;                             // No sense in continuing.
                        }
                    }
                    if (mbMatch)
                    {
                        // Meets matching condition (2), above.
                        matches.Add(anal);
                    }
                }
            }
            if (matches.Count == 0)
            {
                // Create a new analysis, since there are no matches.
                var newAnal = m_analysisFactory.Create();
                wordform.AnalysesOC.Add(newAnal);
                // Make WfiMorphBundle(s).
                foreach (var morph in analysis.Morphs)
                {
                    var mb = m_mbFactory.Create();
                    newAnal.MorphBundlesOS.Add(mb);
                    mb.MorphRA = morph.Form;
                    mb.MsaRA   = morph.Msa;
                    if (morph.InflType != null)
                    {
                        mb.InflTypeRA = morph.InflType;
                    }
                }
                matches.Add(newAnal);
            }
            // (Re)set evaluations.
            foreach (var matchingAnal in matches)
            {
                m_parserAgent.SetEvaluation(matchingAnal,
                                            Opinions.approves);
                m_analysesWithOldEvaluation.Remove(matchingAnal);
            }
        }