Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParseFiler"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="taskUpdateHandler">The task update handler.</param>
        /// <param name="idleQueue">The idle queue.</param>
        /// <param name="parserAgent">The parser agent.</param>
        public ParseFiler(FdoCache cache, Action <TaskReport> taskUpdateHandler, IdleQueue idleQueue, ICmAgent parserAgent)
        {
            Debug.Assert(cache != null);
            Debug.Assert(taskUpdateHandler != null);
            Debug.Assert(idleQueue != null);
            Debug.Assert(parserAgent != null);

            m_cache             = cache;
            m_taskUpdateHandler = taskUpdateHandler;
            m_idleQueue         = idleQueue;
            m_parserAgent       = parserAgent;
            m_resultQueue       = new Queue <ParseResult>();
            m_syncRoot          = new object();

            var servLoc = cache.ServiceLocator;

            m_wordformRepository       = servLoc.GetInstance <IWfiWordformRepository>();
            m_analysisFactory          = servLoc.GetInstance <IWfiAnalysisFactory>();
            m_mbFactory                = servLoc.GetInstance <IWfiMorphBundleFactory>();
            m_baseAnnotationRepository = servLoc.GetInstance <ICmBaseAnnotationRepository>();
            m_baseAnnotationFactory    = servLoc.GetInstance <ICmBaseAnnotationFactory>();
            m_moFormRepository         = servLoc.GetInstance <IMoFormRepository>();
            m_msaRepository            = servLoc.GetInstance <IMoMorphSynAnalysisRepository>();
            m_userAgent                = m_cache.LanguageProject.DefaultUserAgent;

            m_analysesWithOldEvaluation = new HashSet <IWfiAnalysis>(
                m_cache.ServiceLocator.GetInstance <IWfiAnalysisRepository>().AllInstances().Where(
                    analysis => analysis.GetAgentOpinion(m_parserAgent) != Opinions.noopinion));
        }
Example #2
0
        public void SetAgentOpinion()
        {
            ICmAgent     agent = Cache.LangProject.DefaultComputerAgent;
            IWfiWordform wf    = WfiWordformServices.FindOrCreateWordform(Cache,
                                                                          TsStringUtils.MakeTss("xxxyyyzzz12234", Cache.DefaultVernWs));
            IWfiAnalysis wa = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create();

            wf.AnalysesOC.Add(wa);
            Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));

            wa.SetAgentOpinion(agent, Opinions.approves);
            Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent));

            wa.SetAgentOpinion(agent, Opinions.disapproves);
            Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent));

            wa.SetAgentOpinion(agent, Opinions.noopinion);
            Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParseFiler"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="taskUpdateHandler">The task update handler.</param>
        /// <param name="idleQueue">The idle queue.</param>
        /// <param name="parserAgent">The parser agent.</param>
        public ParseFiler(LcmCache cache, Action <TaskReport> taskUpdateHandler, IdleQueue idleQueue, ICmAgent parserAgent)
        {
            Debug.Assert(cache != null);
            Debug.Assert(taskUpdateHandler != null);
            Debug.Assert(idleQueue != null);
            Debug.Assert(parserAgent != null);

            m_cache             = cache;
            m_taskUpdateHandler = taskUpdateHandler;
            m_idleQueue         = idleQueue;
            m_parserAgent       = parserAgent;
            m_workQueue         = new Queue <WordformUpdateWork>();
            m_syncRoot          = new object();

            ILcmServiceLocator servLoc = cache.ServiceLocator;

            m_analysisFactory          = servLoc.GetInstance <IWfiAnalysisFactory>();
            m_mbFactory                = servLoc.GetInstance <IWfiMorphBundleFactory>();
            m_baseAnnotationRepository = servLoc.GetInstance <ICmBaseAnnotationRepository>();
            m_baseAnnotationFactory    = servLoc.GetInstance <ICmBaseAnnotationFactory>();
            m_userAgent                = m_cache.LanguageProject.DefaultUserAgent;
        }
Example #4
0
        public void SetAgentOpinion()
        {
            ICmAgent     agent = m_fdoCache.LangProject.DefaultComputerAgent;
            IWfiWordform wf    = new WfiWordform(m_fdoCache, WfiWordform.FindOrCreateWordform(m_fdoCache, "xxxyyyzzz12234", m_fdoCache.DefaultVernWs, true));
            IWfiAnalysis wa    = new WfiAnalysis();

            wf.AnalysesOC.Add(wa);
            ICmObject target = wa;             // can pick anything as target for evaluation!

            m_fdoCache.BeginUndoTask("doit", "undoit");
            wa.SetAgentOpinion(agent, Opinions.approves);
            m_fdoCache.EndUndoTask();
            Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent));
            m_fdoCache.Undo();
            Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));
            m_fdoCache.Redo();
            Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent));

            m_fdoCache.BeginUndoTask("changeit", "unchangeit");
            wa.SetAgentOpinion(agent, Opinions.disapproves);
            m_fdoCache.EndUndoTask();
            Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent));
            m_fdoCache.Undo();
            Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent));
            m_fdoCache.Redo();
            Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent));

            m_fdoCache.BeginUndoTask("clearit", "unclearit");
            wa.SetAgentOpinion(agent, Opinions.noopinion);
            m_fdoCache.EndUndoTask();
            Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));
            m_fdoCache.Undo();
            Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent));
            m_fdoCache.Redo();
            Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent));
        }
Example #5
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 #6
0
		/// <summary>
		/// </summary>
		/// <param name="agent"></param>
		/// <param name="hvoEvaluation">will be zero if no evaluation was found</param>
		/// <param name="wasAccepted">false if no evaluation was found</param>
		protected void FindEvaluation(ICmAgent agent, out int hvoEvaluation, out bool wasAccepted)
		{
			IOleDbCommand odc = null;
			try
			{
				uint intSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(int));
				Debug.Assert(m_cache != null); // The cache must be set.
				m_cache.DatabaseAccessor.CreateCommand(out odc);
				uint uintSize = (uint)Marshal.SizeOf(typeof(uint));
				odc.SetParameter(1, (uint)DBPARAMFLAGSENUM.DBPARAMFLAGS_ISINPUT,
					null, (ushort)DBTYPEENUM.DBTYPE_I4, new uint[] { (uint)agent.Hvo }, intSize);
				odc.SetParameter(2, (uint)DBPARAMFLAGSENUM.DBPARAMFLAGS_ISINPUT,
					null, (ushort)DBTYPEENUM.DBTYPE_I4, new uint[] { (uint)Hvo }, intSize);
				// The SQL command must NOT modify the database contents!
				string sSql =
					"SELECT cae.id, cae.Accepted " +
					"FROM CmAgentEvaluation cae " +
					"JOIN CmObject co ON co.[Id] = cae.[Id] " +
					"AND co.[Owner$] = ? " +
					"WHERE cae.[Target] = ?";
				odc.ExecCommand(sSql, (int)SqlStmtType.knSqlStmtSelectWithOneRowset);
				bool fIsNull;
				bool fMoreRows;
				uint cbSpaceTaken;
				odc.GetRowset(0);
				odc.NextRow(out fMoreRows);
				if (fMoreRows)
				{
					using (ArrayPtr rgHvo = MarshalEx.ArrayToNative(1, typeof(uint)))
					{
						odc.GetColValue(1, rgHvo, rgHvo.Size,
							out cbSpaceTaken, out fIsNull, 0);
						uint[] uHvo = (uint[])MarshalEx.NativeToArray(rgHvo, 1, typeof(uint));
						hvoEvaluation = (int)uHvo[0];
						// Note, using bool or ushort instead of uint will randomly fail. Accepted is a bit in
						// SQL Server and comes across as 2 bytes with the top bytes having random data.
						using (ArrayPtr rgAccepted = MarshalEx.ArrayToNative(1, typeof(uint)))
						{
							odc.GetColValue(2, rgAccepted, rgAccepted.Size,
								out cbSpaceTaken, out fIsNull, 0);
							uint[] uAccepted = (uint[])MarshalEx.NativeToArray(rgAccepted, 1, typeof(uint));
							int nAccepted = (int)uAccepted[0];
							wasAccepted = (nAccepted & 0xFFFF) != 0;
						}
					}
				}
				else
				{
					hvoEvaluation = 0;
					wasAccepted = false;
				}
			}
			finally
			{
				DbOps.ShutdownODC(ref odc);
			}
		}
Example #7
0
		/// <summary>
		/// tells whether the given agent has approved or disapproved of this analysis, or has not given an opinion.
		/// </summary>
		/// <param name="agent"></param>
		/// <returns>one of the enumerated values in WfiAnalysis.Opinions.</returns>
		public Opinions GetAgentOpinion(ICmAgent agent)
		{
			int hvoEvaluation;
			bool wasAccepted;
			FindEvaluation(agent, out hvoEvaluation, out wasAccepted);

			if (0 ==hvoEvaluation)
				return Opinions.noopinion;
			else
				return wasAccepted ? Opinions.approves : Opinions.disapproves;
		}
 /// <summary>
 /// Get all the analyses approved by the specified agent.
 /// </summary>
 /// <param name="agent"></param>
 /// <returns></returns>
 private IEnumerable <IWfiAnalysis> GetAgentApprovedList(ICmAgent agent)
 {
     return(Cache.ServiceLocator.GetInstance <IWfiAnalysisRepository>().AllInstances().Where(
                analysis => analysis.GetAgentOpinion(agent) == Opinions.approves));
 }
Example #9
0
		/// <summary>
		/// Find the evaluation of this analysis by the specified agent. Specifically, find a CmAgentEvaluation
		/// whose owner is the agent in our Evaluations. If there is none return null.
		/// </summary>
		/// <param name="agent"></param>
		protected ICmAgentEvaluation FindEvaluation(ICmAgent agent)
		{
			return (from cae in EvaluationsRC where cae.Owner == agent select cae).FirstOrDefault();
		}
Example #10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get all annotations from a given agent which refer to the given object.
		/// </summary>
		/// <param name="cache">The cache to use.</param>
		/// <param name="hvoTarget">The object that may have annotations.</param>
		/// <param name="agent">The agent listed as the source of the annotation.</param>
		/// <returns>A set of annotations that refer to the given object.
		/// There may not be any.</returns>
		/// ------------------------------------------------------------------------------------
		public static FdoObjectSet<ICmBaseAnnotation> AnnotationsForObject(FdoCache cache, int hvoTarget, ICmAgent agent)
		{
			//enhance: this would be faster if we were allowed to give parameterized queries
			//	so that the server could cache execution plans.
			string qry = string.Format("select Id, Class$ from CmBaseAnnotation_ "
				+ "where BeginObject={0} and Source={1}",
				 hvoTarget, agent.Hvo) ;
			return new FdoObjectSet<ICmBaseAnnotation>(cache, qry, false);
		}
Example #11
0
		private IWfiAnalysis MakeCompleteAnalysis(IWfiWordform wf, out IPartOfSpeech pos, out ICmAgent human, out IWfiGloss wg)
		{
			var wa = MakeAnalysis(wf);
			var bundle = MakeCompleteBundle(wa);
			wg = MakeCompleteGloss(wa);
			pos = MakePartOfSpeech();
			wa.CategoryRA = pos;
			human = Cache.LangProject.DefaultUserAgent;
			wa.SetAgentOpinion(human, Opinions.approves);
			Assert.IsTrue(wa.IsComplete);
			return wa;
		}
Example #12
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ParseFiler"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="taskUpdateHandler">The task update handler.</param>
		/// <param name="idleQueue">The idle queue.</param>
		/// <param name="parserAgent">The parser agent.</param>
		public ParseFiler(FdoCache cache, Action<TaskReport> taskUpdateHandler, IdleQueue idleQueue, ICmAgent parserAgent)
		{
			Debug.Assert(cache != null);
			Debug.Assert(taskUpdateHandler != null);
			Debug.Assert(idleQueue != null);
			Debug.Assert(parserAgent != null);

			m_cache = cache;
			m_taskUpdateHandler = taskUpdateHandler;
			m_idleQueue = idleQueue;
			m_parserAgent = parserAgent;
			m_workQueue = new Queue<WordformUpdateWork>();
			m_syncRoot = new object();

			IFdoServiceLocator servLoc = cache.ServiceLocator;
			m_analysisFactory = servLoc.GetInstance<IWfiAnalysisFactory>();
			m_mbFactory = servLoc.GetInstance<IWfiMorphBundleFactory>();
			m_baseAnnotationRepository = servLoc.GetInstance<ICmBaseAnnotationRepository>();
			m_baseAnnotationFactory = servLoc.GetInstance<ICmBaseAnnotationFactory>();
			m_userAgent = m_cache.LanguageProject.DefaultUserAgent;
		}
Example #13
0
		/// <summary>
		/// Get the number of valid parses for the agent specified in hvoAgent
		/// <param name="agent">The ID of the agent that we are interested in.</param>
		/// </summary>
		public int AgentCount(ICmAgent agent)
		{
			var count = 0;
			foreach (var anal in AnalysesOC)
			{
				foreach (var eval in anal.EvaluationsRC)
				{
					if (eval.Approves && eval.Owner == agent)
						++count;
				}
			}
			return count;
		}
Example #14
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);
		}
Example #15
0
        private IWfiAnalysis MakeCompleteAnalysis(IWfiWordform wf, out IPartOfSpeech pos, out ICmAgent human, out IWfiGloss wg)
        {
            var wa     = MakeAnalysis(wf);
            var bundle = MakeCompleteBundle(wa);

            wg            = MakeCompleteGloss(wa);
            pos           = MakePartOfSpeech();
            wa.CategoryRA = pos;
            human         = Cache.LangProject.DefaultUserAgent;
            wa.SetAgentOpinion(human, Opinions.approves);
            Assert.IsTrue(wa.IsComplete);
            return(wa);
        }
Example #16
0
		private void CheckTheAgent(ICmAgent agent, int wsAme)
		{
			Assert.AreEqual(1, agent.Name.StringCount);
			int wsEn = m_cache.WritingSystemFactory.GetWsFromStr("en");
			Assert.AreEqual("default user", agent.Name.get_String(wsEn).Text);
			Assert.IsTrue(agent.Human);

			IWfiWordformRepository repoWfi = m_cache.ServiceLocator.GetInstance<IWfiWordformRepository>();
			IWfiWordform wfAn = repoWfi.GetMatchingWordform(wsAme, "an");
			IWfiAnalysis anal = wfAn.AnalysesOC.ToArray()[0];
			Assert.AreEqual(Opinions.approves, anal.GetAgentOpinion(agent));
		}
Example #17
0
 /// -----------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="ParserWorker"/> class.
 /// </summary>
 /// -----------------------------------------------------------------------------------
 protected ParserWorker(FdoCache cache, Action <TaskReport> taskUpdateHandler, IdleQueue idleQueue, ICmAgent agent)
 {
     m_cache             = cache;
     m_taskUpdateHandler = taskUpdateHandler;
     m_parseFiler        = new ParseFiler(cache, taskUpdateHandler, idleQueue, agent);
     m_projectName       = cache.ProjectId.Name;
     m_retriever         = new M3ParserModelRetriever(m_cache, m_taskUpdateHandler);
     Trace.WriteLineIf(m_tracingSwitch.TraceInfo, "ParserWorker(): CurrentThreadId = " + Win32.GetCurrentThreadId());
 }
Example #18
0
		/// <summary>
		/// tells whether the given agent has approved or disapproved of this analysis, or has not given an opinion.
		/// </summary>
		public Opinions GetAgentOpinion(ICmAgent agent)
		{
			var agentEvaluation = FindEvaluation(agent);

			if (null == agentEvaluation)
				return Opinions.noopinion;

			return agentEvaluation.Approves ? Opinions.approves : Opinions.disapproves;
		}