Пример #1
0
        /// <summary>
        /// This patch removes all analyses from the DB that have no annotations from IText,
        /// and that have no human evaluations. Since some analyses can be approved by the parser that
        /// are duplicates (old IText bug), it also includes parser approved analyses.
        /// These will come back the next time the parser is run, if the grammar and lexicon allow such.
        /// </summary>
        protected void RemoveExtraAnalyses()
        {
            int count = 0;

            Console.WriteLine("");
            Console.WriteLine("RemoveExtraAnalyses()...");
            foreach (WfiWordform wf in m_cache.LangProj.WordformInventoryOA.WordformsOC)
            {
                ArrayList anals = new ArrayList();
                foreach (WfiAnalysis anal in wf.AnalysesOC)
                {
                    bool isHumanApproved = false;
                    bool hasAnnotation   = false;
                    foreach (LinkedObjectInfo loi in anal.LinkedObjects)
                    {
                        int relObjClass = loi.RelObjClass;
                        if (relObjClass == CmAnnotation.kclsidCmAnnotation)
                        {
                            hasAnnotation = true;
                            break;
                        }
                        else if (relObjClass == CmAgentEvaluation.kclsidCmAgentEvaluation)
                        {
                            // See if the evaluation is from a human.
                            CmAgentEvaluation eval  = CmAgentEvaluation.CreateFromDBObject(m_cache, loi.RelObjId);
                            CmAgent           agent = CmAgent.CreateFromDBObject(m_cache, eval.OwnerHVO);
                            if (agent.Human)
                            {
                                isHumanApproved = true;
                                break;
                            }
                        }
                    }
                    if (hasAnnotation || isHumanApproved)
                    {
                        continue;
                    }
                    anals.Add(anal);
                }
                if (anals.Count > 0)
                {
                    Console.WriteLine("Deleting {0} analyses from wordform: '{1}'.", anals.Count.ToString(), wf.Form.VernacularDefaultWritingSystem);
                    foreach (WfiAnalysis anal in anals)
                    {
                        ++count;
                        //m_cache.DatabaseAccessor.BeginTrans();
                        Debug.WriteLine(string.Format("Deleting analysis: {0}.", anal.Hvo));
                        anal.DeleteUnderlyingObject();
                        //m_cache.DatabaseAccessor.CommitTrans();
                    }
                }
            }
            Console.WriteLine("Deleted " + count.ToString() + " analyses.");
        }
Пример #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set an evaluation for the given object. This sets the time to the current time.
		/// Note that for no opinion (accepted = 2), the CmAgentEvaluation is removed from
		/// the database. Otherwise an item is created, if not already present, and the
		/// value set to 0 or 1.
		/// </summary>
		/// <param name="hvoTarget">The target id of the object we are evaluating</param>
		/// <param name="accepted">0 = not accepted, 1 = accepted, 2 = don't know</param>
		/// <param name="details">Details for the evaluation</param>
		/// ------------------------------------------------------------------------------------
		public void SetEvaluation(int hvoTarget, int accepted, string details)
		{
			CmAgentEvaluation cae = null;
			foreach (CmAgentEvaluation caeCandidate in EvaluationsOC)
			{
				if (caeCandidate.TargetRAHvo == hvoTarget)
				{
					cae = caeCandidate;
					if (accepted == 2)
					{
						cae.DeleteUnderlyingObject();
						return;
					}
					break;
				}
			}
			if (accepted == 2)
				return; // none found or wanted.
			if (cae == null)
			{
				cae = new CmAgentEvaluation();
				EvaluationsOC.Add(cae);
				cae.TargetRAHvo = hvoTarget;
			}
			cae.Accepted = (accepted == 1);
			cae.DateCreated = DateTime.Now;
			cae.Details = details;

			//IOleDbCommand odc = null;
			//try
			//{
			//    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)Hvo }, uintSize);
			//    odc.SetParameter(2, (uint)DBPARAMFLAGSENUM.DBPARAMFLAGS_ISINPUT, null,
			//        (ushort)DBTYPEENUM.DBTYPE_I4, new uint[] { (uint)hvoTarget }, uintSize);
			//    odc.SetParameter(3, (uint)DBPARAMFLAGSENUM.DBPARAMFLAGS_ISINPUT, null,
			//        (ushort)DBTYPEENUM.DBTYPE_I4, new uint[] { (uint)accepted }, uintSize);
			//    odc.SetStringParameter(4, (uint)DBPARAMFLAGSENUM.DBPARAMFLAGS_ISINPUT,
			//        null, details, (uint)details.Length);
			//    string sSql =
			//        "declare @date datetime set @date = getdate() " +
			//        "exec SetAgentEval ?, ?, ?, ?, @date";
			//    odc.ExecCommand(sSql, (int)SqlStmtType.knSqlStmtStoredProcedure);
			//}
			//finally
			//{
			//    DbOps.ShutdownODC(ref odc);
			//}
		}