示例#1
0
        public static void Test_FindDate_03(FindDateManager_v1 findDateManager, string file)
        {
            file = zPath.Combine(GetDirectoryDate(), file);
            int year = Date.Today.Year;
            findDateManager.DateRegexList.Add("year", new RegexValues("year", "year", string.Format(@"(?:^|[_\s])({0}|{1}|{2})(?:$|[_\s])", year - 1, year, year + 1), "IgnoreCase", "year", compileRegex: true));

            string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out");
            Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, findDateManager.DateRegexList.Count);
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_FindDate_03", WriteToFile.Create(traceFile, FileOption.RazFile).Write);

            try
            {
                DateTime dt = DateTime.Now;
                TraceRegexValuesList(findDateManager.DateRegexList);
                Trace.WriteLine();

                string bsonFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_bson");
                zmongo.BsonRead<TestText>(file).zFindDate(findDateManager).zSave(bsonFile);
                zmongo.BsonRead<TestFindDate>(bsonFile).zTraceFindDate();
                Trace.WriteLine("test duration {0}", DateTime.Now - dt);
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_03");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
示例#2
0
        public static void Test_FindDate_02(FindDateManager_v1 findDateManager, string file)
        {
            file = zPath.Combine(GetDirectoryDate(), file);
            int year = Date.Today.Year;
            findDateManager.DateRegexList.Add("year", new RegexValues("year", "year", string.Format(@"(?:^|[_\s])({0}|{1}|{2})(?:$|[_\s])", year - 1, year, year + 1), "IgnoreCase", "year", compileRegex: true));
            string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out");
            Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, findDateManager.DateRegexList.Count);
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_FindDate_02", WriteToFile.Create(traceFile, FileOption.RazFile).Write);
            try
            {
                DateTime dt = DateTime.Now;
                TraceRegexValuesList(findDateManager.DateRegexList);
                Trace.WriteLine();
                int nb = 0;
                int nbDateFound = 0;
                foreach (BsonDocument document in zmongo.BsonRead<BsonDocument>(file))
                {
                    string text = document["text"].AsString;

                    //FindDate_old findDate = FindDate(findDateManager, text);
                    FindDate findDate = FindDate(findDateManager, text);

                    if (findDate.Found)
                        nbDateFound++;

                    nb++;
                }
                Trace.WriteLine();
                Trace.WriteLine();
                Trace.WriteLine("search date in {0} text", nb);
                Trace.WriteLine("found date in {0} text", nbDateFound);
                Trace.WriteLine("test duration {0}", DateTime.Now - dt);
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_02");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
示例#3
0
        //public static FindDate_old FindDate(FindDateManager findDateManager, string text)
        public static FindDate FindDate(FindDateManager_v1 findDateManager, string text)
        {
            //FindDate_old findDate = findDateManager.Find_old(text);
            FindDate findDate = findDateManager.Find(text);

            Trace.WriteLine("search date in  : \"{0}\"", text);
            if (findDate.Found)
            {
                //Trace.WriteLine("    found date  : \"{0}\"", findDate.regexValues.MatchValue_old);
                Trace.WriteLine("    found date  : \"{0}\"", findDate.matchValues.Match.Value);
                //Trace.WriteLine("    remain text : \"{0}\"", findDate.regexValues.MatchReplace_old("_"));
                Trace.WriteLine("    remain text : \"{0}\"", findDate.matchValues.Replace("_"));

                Trace.WriteLine("    date        : {0:dd-MM-yyyy} type {1}", findDate.Date, findDate.DateType);
                //Trace.Write("not found ");

                Trace.Write("    values      : ");
                //findDate.regexValues.GetValues_old().zTrace();
                findDate.matchValues.GetValues().zTrace();
                Trace.WriteLine();
                //nbDateFound++;
            }
            else
                Trace.WriteLine("    date not found ");
            Trace.WriteLine();
            return findDate;
        }
示例#4
0
 public static IEnumerable<TestFindDate> zFindDate(this IEnumerable<TestText> textList, FindDateManager_v1 findDateManager)
 {
     foreach (TestText text in textList)
     {
         //FindDate_old findDate = findDateManager.Find_old(text.text);
         FindDate findDate = findDateManager.Find(text.text);
         TestFindDate testFindDate = new TestFindDate();
         testFindDate.text = text.text;
         testFindDate.foundDate = findDate.Found;
         if (findDate.Found)
         {
             //testFindDate.dateFound = findDate.regexValues.MatchValue_old.Value;
             testFindDate.dateFound = findDate.matchValues.Match.Value;
             testFindDate.date = findDate.Date;
             testFindDate.dateType = findDate.DateType;
             //testFindDate.remainText = findDate.regexValues.MatchReplace_old("_");
             testFindDate.remainText = findDate.matchValues.Replace("_");
             //testFindDate.namedValues = findDate.regexValues.GetValues_old();
             testFindDate.namedValues = findDate.matchValues.GetValues();
         }
         yield return testFindDate;
     }
 }