Exemplo n.º 1
0
 //Returns Allen's suitable relation for the two intervals
 private static char getRelation(STI ei1, STI ei2)
 {
     if (ei1.fin_time < ei2.st_time)
     {
         return(Constants.ALLEN_BEFORE);
     }
     if (ei1.fin_time == ei2.st_time)
     {
         return(Constants.ALLEN_MEET);
     }
     if (ei1.st_time == ei2.st_time && ei1.fin_time == ei2.fin_time)
     {
         return(Constants.ALLEN_EQUAL);
     }
     if (ei1.st_time < ei2.st_time && ei1.fin_time > ei2.fin_time)
     {
         return(Constants.ALLEN_CONTAIN);
     }
     if (ei1.st_time == ei2.st_time && ei1.fin_time < ei2.fin_time)
     {
         return(Constants.ALLEN_STARTS);
     }
     if (ei1.st_time < ei2.st_time && ei1.fin_time == ei2.fin_time)
     {
         return(Constants.ALLEN_FINISHBY);
     }
     return(Constants.ALLEN_OVERLAP);
 }
Exemplo n.º 2
0
        //Get updated last time for a given pattern
        private int getUpdatedEndTime(int last_time, Tiep t)
        {
            STI ei2  = t.e;
            int time = ei2.fin_time;

            return(last_time < 0 ? time : Math.Min(last_time, time));
        }
Exemplo n.º 3
0
 public EndTime(STI symbol, int time_point, bool entry_type)
 {
     symbols = new List <STI>();
     symbols.Add(symbol);
     time = time_point;
     type = entry_type;
 }
Exemplo n.º 4
0
        public static string getTIRP(SequenceDB pp)
        {
            int support = pp.sup;
            int length  = pp.trans_db[0].Item2.tieps.Count / 2;

            STI[] ints  = new STI[length];
            int   index = 0;

            foreach (Tiep t in pp.trans_db[0].Item2.tieps)
            {
                if (t.type == Constants.ST_REP)
                {
                    ints[index] = t.e;
                    index++;
                }
            }
            Array.Sort(ints);
            string res = "";

            res += length + " ";
            for (int i = 0; i < length; i++)
            {
                res = res + ints[i].sym + "-";
            }
            res += " ";
            if (length == 1)
            {
                res += "-.";
            }
            else
            {
                for (int i = 0; i < length; i++)
                {
                    for (int j = i + 1; j < length; j++)
                    {
                        res += getRelation(ints[i], ints[j]) + ".";
                    }
                }
            }
            res += " ";
            res += support + " ";
            res += (length == 1 ? support : Math.Round((double)pp.trans_db.Count / support, 2)) + " ";
            res += pp.trans_db[0].Item1.entity + " " + printIntervals(ints) + " ";
            for (int i = 1; i < pp.trans_db.Count; i++)
            {
                index = 0;
                foreach (Tiep t in pp.trans_db[i].Item2.tieps)
                {
                    if (t.type == Constants.ST_REP)
                    {
                        ints[index] = t.e;
                        index++;
                    }
                }
                Array.Sort(ints);
                res += pp.trans_db[i].Item1.entity + " " + printIntervals(ints) + " ";
            }
            return(res);
        }
Exemplo n.º 5
0
        //Add a new sti to the end time list
        public static void addIntervalToEndTimes(STI ei)
        {
            EndTime st_et  = new EndTime(ei, ei.st_time, Constants.START);
            EndTime fin_et = new EndTime(ei, ei.fin_time, Constants.FINISH);

            addPointToEndTimes(st_et);
            addPointToEndTimes(fin_et);
        }
Exemplo n.º 6
0
 //Add an instace of the tiep in some record
 public void addOcc(int rec, STI sti)
 {
     if (!indexes.ContainsKey(rec))
     {
         indexes.Add(rec, new List <STI>());
     }
     indexes[rec].Add(sti);
 }
Exemplo n.º 7
0
 public Tiep(char t, int ti, STI ei, Coincidence coi)
 {
     c             = coi;
     e             = ei;
     time          = ti;
     sym           = ei.sym;
     type          = t;
     premitive_rep = sym + "" + t;
     orig          = null;
 }
Exemplo n.º 8
0
 public Tiep(Tiep s)
 {
     c             = s.c;
     e             = s.e;
     time          = s.time;
     sym           = s.sym;
     type          = s.type;
     premitive_rep = s.premitive_rep;
     ms_index      = s.ms_index;
     orig          = s;
 }
Exemplo n.º 9
0
        //Compare two stis
        public int CompareTo(object otherTimeInterval)
        {
            STI other  = otherTimeInterval as STI;
            int st_dif = st_time - other.st_time;

            if (st_dif != 0)
            {
                return(st_dif);
            }
            int fin_dif = fin_time - other.fin_time;

            if (fin_dif != 0)
            {
                return(fin_dif);
            }
            return(sym - other.sym);
        }
Exemplo n.º 10
0
        //Input transformation
        public static SequenceDB createSequencesKLF(string filePath)
        {
            TextReader tr       = new StreamReader(filePath);
            string     readLine = tr.ReadLine();

            //Move on until the significant start
            while (readLine != null && !readLine.StartsWith(Constants.FILE_START))
            {
                readLine = tr.ReadLine();
            }
            if (!(readLine == Constants.FILE_START &&
                  tr.ReadLine().StartsWith(Constants.FILE_NUM)))
            {
                throw new InvalidOperationException(Constants.FILE_FORMAT_ERR);
            }
            //Start reading the entities
            List <Tuple <CoincidenceSequence, PatternInstance> > trans_db =
                new List <Tuple <CoincidenceSequence, PatternInstance> >();

            while (tr.Peek() >= 0)
            {
                sequenceTransformer.emptyEndTimes();
                readLine = tr.ReadLine();
                string[] mainDelimited = readLine.Split(';');
                string   entityID      = mainDelimited[0].Split(',')[0];
                readLine      = tr.ReadLine();
                mainDelimited = readLine.Split(';');
                for (int i = 0; i < mainDelimited.Length - 1; i++)
                {
                    string[] tisDelimited = mainDelimited[i].Split(',');
                    int      symbol       = int.Parse(tisDelimited[2]);
                    STI      ei           = new STI(symbol, int.Parse(tisDelimited[0]), int.Parse(tisDelimited[1]));
                    sequenceTransformer.addIntervalToEndTimes(ei);
                }
                CoincidenceSequence cs = sequenceTransformer.eventSeqToCoincidenceSeq(entityID);
                PatternInstance     pi = new PatternInstance();
                cs.entity = entityID;
                trans_db.Add(new Tuple <CoincidenceSequence, PatternInstance>(cs, pi));
            }
            tr.Close();
            return(new SequenceDB(trans_db, null, 0, new List <string>()));
        }
Exemplo n.º 11
0
        //Adds a new symbol to the symbols in the entry
        public void addSymToSyms(STI new_symbol)
        {
            //symbols.Add(new_symbol);
            int min = 0;
            int max = symbols.Count - 1;
            int mid = 0, cmp = 0;

            while (min <= max)
            {
                mid = (min + max) / 2;
                cmp = new_symbol.sym - symbols[mid].sym;
                if (cmp < 0)
                {
                    max = mid - 1;
                }
                else
                {
                    min = mid + 1;
                }
            }
            symbols.Insert(min, new_symbol);
        }
Exemplo n.º 12
0
        //Returns true if the max gap constraint holds
        public static bool maxGapHolds(int time, Tiep t)
        {
            STI ei2 = t.e;

            return(Constants.MAX_GAP > ei2.st_time - time);
        }
Exemplo n.º 13
0
 //Adds the event interval to the list
 public void addInterval(STI ei)
 {
     intervals.Add(ei);
 }