Example #1
0
        private void FinishWordForm(IWfiWordform wordform)
        {
            // the following is a port of the SP RemoveUnusedAnalyses

            // Delete stale evaluations on analyses. The only non-stale analyses are new, positive ones, so this
            // makes all analyses that are not known to be correct no-opinion. Later any of them that survive at all
            // will be changed to failed (if there was no error in parsing the wordform).
            var analysesNotUpdated = from analysis in wordform.AnalysesOC where m_analysesWithOldEvaluation.Contains(analysis) select analysis;

            foreach (var analysis in analysesNotUpdated)
            {
                analysis.SetAgentOpinion(m_parserAgent, Opinions.noopinion);
            }

            // Make sure all analyses have human evaluations, if they,
            // or glosses they own, are referred to by an ISegment.
            //var annLookup = m_baseAnnotationRepository.AllInstances()
            //	.Where(ann => ann.AnnotationTypeRA != null && ann.AnnotationTypeRA.Guid == CmAnnotationDefnTags.kguidAnnWordformInContext)
            //	.ToLookup(ann => ann.InstanceOfRA);
            var segmentAnalyses = new HashSet <IAnalysis>();

            foreach (var seg in wordform.OccurrencesBag)
            {
                segmentAnalyses.UnionWith(seg.AnalysesRS.ToArray());
            }
            var analyses = from anal in wordform.AnalysesOC
                           where segmentAnalyses.Contains(anal) || anal.MeaningsOC.Any(segmentAnalyses.Contains)
                           select anal;

            foreach (var analysis in analyses)
            {
                m_userAgent.SetEvaluation(analysis, Opinions.approves);
            }

            // Delete orphan analyses, which have no evaluations (Review JohnT: should we also check for no owned WfiGlosses?)
            var orphanedAnalyses = from anal in wordform.AnalysesOC
                                   where anal.EvaluationsRC.Count == 0
                                   select anal;

            foreach (var analysis in orphanedAnalyses)
            {
                m_cache.DomainDataByFlid.DeleteObj(analysis.Hvo);
            }
        }
Example #2
0
		/// <summary>
		/// Tells whether the giving agent has approved or disapproved of this analysis, or has not given an opinion.
		/// </summary>
		/// <param name="agent"></param>
		/// <param name="opinion"></param>
		/// <returns>one of the enumerated values in Opinions.</returns>
		public void SetAgentOpinion(ICmAgent agent, Opinions opinion)
		{
			int wasAccepted = 0;
			//now set the opinion to what it should be
			switch(opinion)
			{
				case Opinions.approves:
					wasAccepted = 1;
					break;
				case Opinions.disapproves:
					wasAccepted = 0;
					break;
				case Opinions.noopinion:
					wasAccepted = 2;
					break;
			}

			agent.SetEvaluation(Hvo, wasAccepted, "");
		}
Example #3
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);
            }
        }
Example #4
0
		/// <summary>
		/// Tells whether the giving agent has approved or disapproved of this analysis, or has not given an opinion.
		/// </summary>
		/// <param name="agent"></param>
		/// <param name="opinion"></param>
		/// <returns>one of the enumerated values in Opinions.</returns>
		public void SetAgentOpinion(ICmAgent agent, Opinions opinion)
		{
			//int wasAccepted = 0;
			////now set the opinion to what it should be
			//switch (opinion)
			//{
			//    case Opinions.approves:
			//        wasAccepted = 1;
			//        break;
			//    case Opinions.disapproves:
			//        wasAccepted = 0;
			//        break;
			//    case Opinions.noopinion:
			//        wasAccepted = 2;
			//        break;
			//}

			agent.SetEvaluation(this, opinion);
		}