Example #1
0
        public void RootRegexTest()
        {
            var rg = new ConfigInitializer.RootRegex(@"./Config/ItemList.txt");
            RootParser rp = new RootParser(rg.ToString());

            string testCorpus = System.IO.File.ReadAllText(@"sampleCorpus.txt");
            var collection = rp.executeMatch(testCorpus);
            Assert.AreEqual(collection.Count, 1);
            var match = collection[0];
            Assert.AreEqual(match.Groups.Count, 25);

            Func<int, string, bool> checkMatch = (index, str) => { return match.Groups[index].Value == str; };

            Assert.IsTrue(checkMatch(1, @"10015678375"));
            Assert.IsTrue(checkMatch(5, @"7/10/2015 12:00:00 AM"));
            Assert.IsTrue(checkMatch(17, @"TASK \ 20150715 \ CLOSURE \ RM FOMENTO MERCANTIL \ B014G8UC \ SYNDICATED SEARCH \ BR"));
        }
Example #2
0
        static void Main(string[] args)
        {
            bool SKIP = false;
            // init resources and configs
            string[] flist = System.IO.Directory.GetFiles("./Corpus");

            var ZIM_TOKEN = System.IO.File.ReadAllText("./Config/dbconfig");

            var incidentTableEntity = new ConfigInitializer.IncidentTableEntity(@"./Config/IncidentItemList.txt", @"./Config/IncidentDataTypeList.txt");
            var chatlogTableEntity = new ConfigInitializer.ChatlogTableEntity(@"./Config/ChatlogItemList.txt", @"./Config/ChatlogDataTypeList.txt");
            var levelTableEntity = new ConfigInitializer.LevelTableEntity(@"./Config/LevelItemList.txt", @"./Config/LevelDataTypeList.txt");

            var rootRegex = new ConfigInitializer.RootRegex(@"./Config/IncidentItemList.txt");
            var caseRegex = new ConfigInitializer.CaseRegex();
            var levelRegex = new ConfigInitializer.LevelRegex();

            var rootParser = new RootParser(rootRegex.ToString());
            var caseParser = new CaseNoteParser(caseRegex.ToString());
            var levelParser = new LevelParser(levelRegex.ToString());

            var dbc = new DBController.DBController(ZIM_TOKEN);

            // start insert by file
            int incidentSuccessCount = 0;
            foreach (var fname in flist)
            {
                Console.WriteLine("[IncidentDB] Importing file : " + fname + "...");
                string lineCache = System.IO.File.ReadAllText(fname);
                var incidentCollections = rootParser.executeMatch(lineCache);

                // out parameter, saving dup incident id
                HashSet<string> dupIncidentList;
                // insert stem items
                incidentSuccessCount += dbc.BatchInsertIncidentCollections(incidentCollections, incidentTableEntity, out dupIncidentList, SKIP);
                Console.WriteLine("[IncidentDB] File imported...");
                // execute query to obtain Map(IncidentId_String, ID_Int)
                Console.WriteLine("[ChatlogDB] Start Feching ID...");
                var queryResult = dbc.ExecuteQuery(@"SELECT id, IncidentId FROM dbo.incidents");
                Dictionary<string, int> IncidentString_Id_Map = queryResult.ToDictionary(x => x[1], x => int.Parse(x[0]));
                Console.WriteLine("[ChatlogDB] Finish Feching ID!");

                // insert dialogs & case level
                int CASENOTES_INDEX = incidentCollections[0].Groups.Count - 1;
                int INCIDENT_INDEX = 1;
                foreach (Match incidentMatch in incidentCollections)
                {
                    var incidentString = incidentMatch.Groups[INCIDENT_INDEX].Value;
                    if (dupIncidentList.Contains(incidentString) || ! IncidentString_Id_Map.ContainsKey(incidentString))
                    {
                        Console.WriteLine($"skip incident: {incidentString} ...");
                        continue;
                    }

                    int incidentId = IncidentString_Id_Map[incidentString];
                    string caseNotesText = incidentMatch.Groups[CASENOTES_INDEX].Value;

                    var dialogCollections = caseParser.executeMatch(caseNotesText);
                    // insert chalogs' main function
                    dbc.BatchInsertDialogCollections(chatlogTableEntity, dialogCollections, incidentId, SKIP);
                    // insert level info's main funciton
                    var levelCollections = levelParser.executeMatch(caseNotesText);
                    if (levelCollections.Count == 5)
                    {
                        //assert.equal(levelCollections.groups.count, 5);
                        dbc.InsertIncidentLevel(levelTableEntity, levelCollections, incidentId);
                    }
                }
            }
            executeExitAction(incidentSuccessCount);
        }