示例#1
0
        //Sets the inervals
        private void setIntervalsAndRelations()
        {
            relations = new Dictionary <int, Dictionary <int, string> >();
            TemporalDB db = CCMiner.mainDB;

            sequences = new List <EventSequence>();
            for (int k = 0; k < actual_ids.Count; k++)
            {
                string t_id = TransformedDB.getID(actual_ids[k]);
                ids.Add(k, t_id);
                string        id       = t_id;
                EventSequence seq      = new EventSequence();
                List <string> seq_syms = CoincidenceManager.
                                         getPatternSymbols(pDB.patterns[actual_ids[k]].Item1);
                foreach (string sym in seq_syms)
                {
                    seq.ints.Add(db.seqs[id].getInterval(sym));
                }
                sequences.Add(seq);
                if (k == 0)
                {
                    for (int i = 0; i < length; i++)
                    {
                        relations.Add(i, new Dictionary <int, string>());
                        for (int j = i + 1; j < length; j++)
                        {
                            EventInterval ei1 = seq.ints[i];
                            EventInterval ei2 = seq.ints[j];
                            string        rel = getRelation(ei1, ei2);
                            relations[i].Add(j, rel);
                        }
                    }
                }
            }
        }
示例#2
0
        public static EventInterval getInt(string id, string slc)
        {
            EventSequence es       = CCMiner.mainDB.seqs[id];
            string        tosearch = slc.Substring(0, slc.Length - 1);
            EventInterval ei2      = es.intsdic[tosearch];

            return(ei2);
        }
示例#3
0
 //Reads the instances in the DB to extract a sorted event sequence for each sequence id ---------> KarmaLego Format
 public void createSequencesKLF(string filePath)
 {
     try
     {
         TextReader tr       = new StreamReader(filePath);
         string     readLine = tr.ReadLine();
         //Move on until significant start
         while (readLine != null && !readLine.StartsWith(Constants.FILE_START))
         {
             readLine = tr.ReadLine();
         }
         if (!(readLine == Constants.FILE_START && tr.Peek() >= 0 && tr.ReadLine().StartsWith(Constants.FILE_NUM)))
         {
             throw new InvalidOperationException(Constants.FILE_FORMAT_ERR);
         }
         //Start reading the entities
         Dictionary <string, int> syms_counter = new Dictionary <string, int>();
         EventSequence            es           = null;
         while (tr.Peek() >= 0)
         {
             readLine = tr.ReadLine();
             string[] mainDelimited = readLine.Split(';');
             string   entityID      = mainDelimited[0].Split(',')[0];
             readLine      = tr.ReadLine();
             mainDelimited = readLine.Split(';');
             es            = new EventSequence();
             seqs.Add(entityID, es);
             syms_counter.Clear();
             for (int i = 0; i < mainDelimited.Length - 1; i++)
             {
                 string[] tisDelimited = mainDelimited[i].Split(',');
                 string   symbol       = tisDelimited[2];
                 if (syms_counter.ContainsKey(symbol))
                 {
                     syms_counter[symbol]++;
                 }
                 else
                 {
                     syms_counter.Add(symbol, 1);
                 }
                 //For a symbol x, 'x#num_of_x_occurrences_in_entity_till_now' (e.g. x#1, x#2 etc.) is added as a new event interval
                 string symbol_with_index = symbol + Constants.DUP_SYM + (syms_counter[symbol] + "");
                 es.addIntervalBinary(new EventInterval(symbol_with_index, int.Parse(tisDelimited[0]), int.Parse(tisDelimited[1])));
             }
         }
         tr.Close();
     }
     catch (Exception e)
     {
         Console.WriteLine("The reading process has failed: {0}", e.ToString());
     }
 }
示例#4
0
        //Intializes endtime_list according to the event sequence q
        public static void fillEndTimeList(EventSequence q)
        {
            EndTime et = null;

            foreach (EventInterval ei in q.ints)
            {
                et = new EndTime(ei.sym, ei.st_time, Constants.START);
                endTimeInsert(et);
                et = new EndTime(ei.sym, ei.fin_time, Constants.FINISH);
                endTimeInsert(et);
            }
            sortAndMergeEndTimeList();
        }
示例#5
0
        //Converts the event sequence to a string that represents them in coincidence rep.
        public static List <string> eventSeqToCoincidenceSeq(EventSequence q)
        {
            endtime_list = new List <EndTime>();
            //the coincidence sequence we build
            List <string> coseq = new List <string>();
            //the previous element in the end time list
            EndTime last_endtime = null;

            //fills the endtime list with the values derived from the given sequence
            fillEndTimeList(q);
            //the end time list is now full, we need to traverse it entry by entry
            List <string> coincidence;
            bool          isMeet = false;
            string        pre    = "";

            foreach (EndTime t in endtime_list)
            {
                isMeet      = false;
                pre         = "";
                coincidence = new List <string>();
                if (t.type == Constants.START)
                {
                    getSlicesForSyms(coincidence, t.syms, Constants.ST_REP);
                    if (last_endtime != null && last_endtime.time == t.time)
                    {    //meet slice insertion
                        isMeet = true;
                        pre   += Constants.MEET_REP;
                    }
                }
                else
                {
                    getSlicesForSyms(coincidence, t.syms, Constants.FIN_REP);
                }
                //Check for a need to add '(' ')'
                string coincidence_str = coincidence.Aggregate("", (acc, x) => acc + x);
                if (slices_in_co > 1 && isMeet)
                {
                    coincidence_str = "(" + coincidence_str + ")";
                }
                string toAdd = pre + coincidence_str;
                if (toAdd.Length > 0)
                {
                    coseq.Add(toAdd);
                }
                //and now, update the previous entry to be the one we've just looked at
                last_endtime = t;
            }
            return(coseq);
        }
示例#6
0
        //Returns true if the max gap constraint holds
        public static bool maxGapHolds(string id, int time, string slc)
        {
            if (time < 0)
            {
                return(true);
            }
            if (slc[0] == Constants.MEET_REP)
            {
                slc = slc.Substring(1);
            }
            EventSequence es = CCMiner.mainDB.seqs[id];

            if (slc[0] == Constants.CO_REP)
            {
                slc = slc.Substring(1);
            }
            string        tosearch = slc.Substring(0, slc.Length - 1);
            EventInterval ei2      = es.intsdic[tosearch];

            return(Constants.MAX_GAP > ei2.st_time - time);
        }
示例#7
0
        //
        private int getUpdatedEndTime(string id, int last_time, string slc)
        {
            EventSequence es = CCMiner.mainDB.seqs[id];

            if (slc[0] == Constants.MEET_REP)
            {
                slc = slc.Substring(1);
            }
            if (slc[0] == Constants.CO_REP)
            {
                slc = slc.Substring(1);
            }
            string        tosearch = slc.Substring(0, slc.Length - 1);
            EventInterval ei2      = es.intsdic[tosearch];
            int           time     = ei2.fin_time;

            if (last_time < 0 || last_time > time)
            {
                return(time);
            }
            return(last_time);
        }