Esempio n. 1
0
 //Adds start/finish (by type) tieps for the symbols in an endtime object
 private static void getTiepsForSyms(Coincidence co, List<STI> syms, int time, char type, string entity){
     foreach (STI s in syms){
         Tiep t = new Tiep(type, time, s, co);
         co.tieps.Add(t);
         TiepsHandler.addTiepOccurrence(t.premitive_rep, entity, t);
     }
 }
Esempio n. 2
0
        //Get the postfix of the projection
        //@ is meet
        public static KeyValuePair <Coincidence, bool> getCoRest(Tiep occ, string tiep,
                                                                 CoincidenceSequence coseq, Coincidence c, PatternInstance pi, bool is_meet)
        {
            Coincidence curr = coseq.partial != null && coseq.partial.index == c.index ? coseq.partial : c;

            return(getCoRest(tiep, curr, occ, pi));
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        //Collect special tieps from special coincidences
        private void handle_meet_co(Coincidence curr, string ent_id, int tuple_index,
                                    Dictionary <string, TiepProjector> tieps_instances)
        {
            List <Tiep> tieps = curr.tieps;

            if (curr.isCo)
            {
                for (int i = 0; i < tieps.Count; i++)
                {
                    string tiep = Constants.CO_REP + "" + tieps[i].premitive_rep;
                    Tiep   tmp  = tieps[i].orig;
                    add_to_instances(tiep, ent_id, tuple_index, tieps_instances, tmp.ms_index);
                }
                if (curr.next != null && curr.next.isMeet)
                {
                    curr  = curr.next;
                    tieps = curr.tieps;
                    for (int i = 0; i < tieps.Count; i++)
                    {
                        string tiep = Constants.MEET_REP + "" + tieps[i].premitive_rep;
                        add_to_instances(tiep, ent_id, tuple_index, tieps_instances, tieps[i].ms_index);
                    }
                }
            }
            else if (curr.isMeet)
            {
                for (int i = 0; i < tieps.Count; i++)
                {
                    string tiep = Constants.MEET_REP + "" + tieps[i].premitive_rep;
                    add_to_instances(tiep, ent_id, tuple_index, tieps_instances, tieps[i].ms_index);
                }
            }
        }
Esempio n. 5
0
 //Add a new tiep to the index
 public static void addTiepOccurrence(string t, string entity, Tiep s)
 {
     if (!master_tieps.ContainsKey(t))
     {
         master_tieps.Add(t, new MasterTiep());
     }
     master_tieps[t].addOccurrence(entity, s);
 }
Esempio n. 6
0
 //Add a tiep's occurrence to the master tiep
 public void addOccurrence(string entity, Tiep t)
 {
     if (!tiep_occurrences.ContainsKey(entity))
     {
         tiep_occurrences.Add(entity, new List <Tiep>());
         supporting_entities.Add(entity);
     }
     t.ms_index = tiep_occurrences[entity].Count;
     tiep_occurrences[entity].Add(t);
 }
Esempio 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;
 }
Esempio 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;
 }
Esempio n. 9
0
        /*private Dictionary<string, TiepProjector> tiepsFreq_alt(string tiep)
         * {
         *  int count = 0;
         *  Dictionary<string, TiepProjector> tieps_instances = new Dictionary<string, TiepProjector>();
         *  foreach (KeyValuePair<string, MasterTiep> mtiep in TiepsHandler.master_tieps)
         *  {
         *      if (mtiep.Value.supporting_entities.Count < Constants.MINSUP)
         *      {
         *          continue;
         *      }
         *      bool finish = mtiep.Key[mtiep.Key.Length - 1] == Constants.FIN_REP;
         *      if (finish)
         *      {
         *          if (tiep.Equals(mtiep.Key.Replace(Constants.FIN_REP, Constants.ST_REP)))
         *          {
         *              int tup_ind = 0;
         *              foreach (Tuple<CoincidenceSequence, PatternInstance> entry in trans_db)
         *              {
         *                  string ent_id = entry.Item1.entity;
         *                  int index = entry.Item2.tieps[0].ms_index;
         *                  add_to_instances(mtiep.Key, ent_id, tup_ind, tieps_instances, index);
         *                  tup_ind++;
         *              }
         *          }
         *          continue;
         *      }
         *      int tuple_index = 0;
         *      foreach (Tuple<CoincidenceSequence, PatternInstance> entry in trans_db)
         *      {
         *          string ent_id = entry.Item1.entity;
         *          Coincidence curr = entry.Item1.coes;
         *          if (curr == null)
         *          {
         *              tuple_index++;
         *              continue;
         *          }
         *          if (count == 0)
         *          {
         *              handle_meet_co(curr, ent_id, tuple_index, tieps_instances);
         *          }
         *          if (!mtiep.Value.supporting_entities.Contains(ent_id))
         *          {
         *              tuple_index++;
         *              continue;
         *          }
         *          if (curr.isCo)
         *          {
         *              curr = curr.next;
         *              if (curr == null)
         *              {
         *                  tuple_index++;
         *                  continue;
         *              }
         *          }
         *          if (curr.isMeet)
         *          {
         *              curr = curr.next;
         *              if (curr == null)
         *              {
         *                  tuple_index++;
         *                  continue;
         *              }
         *          }
         *          int time = entry.Item2.last;
         *          int start_co_index = curr.index;
         *          int prev_start_index = 0;
         *          List<Tiep> ms_entity = mtiep.Value.tiep_occurrences[ent_id];
         *          for (int i = prev_start_index; i < ms_entity.Count; i++)
         *          {
         *              if (!maxGapHolds(time, ms_entity[i]))
         *              {
         *                  break;
         *              }
         *              int co_index = ms_entity[i].c.index;
         *              if (co_index >= start_co_index)
         *              {
         *                  add_to_instances(mtiep.Key, ent_id, tuple_index, tieps_instances, i);
         *                  break;
         *              }
         *          }
         *          tuple_index++;
         *      }
         *      count++;
         *  }
         *  if (count == 0)
         *  {
         *      int tuple_index = 0;
         *      foreach (Tuple<CoincidenceSequence, PatternInstance> entry in trans_db)
         *      {
         *          string ent_id = entry.Item1.entity;
         *          Coincidence curr = entry.Item1.coes;
         *          if (curr == null)
         *          {
         *              tuple_index++;
         *              continue;
         *          }
         *          handle_meet_co(curr, ent_id, tuple_index, tieps_instances);
         *          tuple_index++;
         *      }
         *  }
         *  return tieps_instances;
         * }*/
        //Collect special tieps from special coincidences
        private void handle_meet_co(Coincidence curr, string ent_id, int tuple_index,
                                    Dictionary <string, TiepProjector> tieps_instances, PatternInstance pi)
        {
            List <Tiep> tieps = curr.tieps;

            if (curr.isCo)
            {
                bool fin = curr.tieps[0].type == Constants.FIN_REP;
                for (int i = 0; i < tieps.Count; i++)
                {
                    string tiep = Constants.CO_REP + "" + tieps[i].premitive_rep;
                    Tiep   tmp  = tieps[i].orig;

                    /*if (!TiepsHandler.master_tieps.ContainsKey(tmp.premitive_rep))
                     * {
                     *  continue;
                     * }*/
                    if (fin && !pi.pre_matched.Contains(tmp.e))
                    {
                        continue;
                    }
                    add_to_instances(tiep, ent_id, tuple_index, tieps_instances, tmp.ms_index);
                }
                if (curr.next != null && curr.next.isMeet)
                {
                    curr  = curr.next;
                    tieps = curr.tieps;
                    for (int i = 0; i < tieps.Count; i++)
                    {
                        string tiep = Constants.MEET_REP + "" + tieps[i].premitive_rep;

                        /*if (!TiepsHandler.master_tieps.ContainsKey(tieps[i].premitive_rep))
                         * {
                         *  continue;
                         * }*/
                        add_to_instances(tiep, ent_id, tuple_index, tieps_instances, tieps[i].ms_index);
                    }
                }
            }
            else if (curr.isMeet)
            {
                for (int i = 0; i < tieps.Count; i++)
                {
                    string tiep = Constants.MEET_REP + "" + tieps[i].premitive_rep;

                    /*if (!TiepsHandler.master_tieps.ContainsKey(tieps[i].premitive_rep))
                     * {
                     *  continue;
                     * }*/
                    add_to_instances(tiep, ent_id, tuple_index, tieps_instances, tieps[i].ms_index);
                }
            }
        }
Esempio n. 10
0
        //Project the coincidence by the tiep
        public static CoincidenceSequence projectBy(Tiep occ, string tiep,
                                                    CoincidenceSequence coseq, Coincidence c, PatternInstance pi, bool is_meet)
        {
            KeyValuePair <Coincidence, bool> ret = getCoRest(occ, tiep, coseq, c, pi, is_meet);

            if (ret.Value == false)
            {
                return(null);
            }
            CoincidenceSequence cs = new CoincidenceSequence();

            cs.coes    = ret.Key;
            cs.entity  = coseq.entity;
            cs.partial = ret.Key != null && ret.Key.index == c.index ? ret.Key : null;
            return(cs);
        }
Esempio n. 11
0
        //Get the postfix of the projection
        public static KeyValuePair <Coincidence, bool> getCoRest(string srep, Coincidence curr, Tiep occ, PatternInstance pi)
        {
            Tiep        app;
            Coincidence rest          = null;
            List <Tiep> fullCo_slices = curr.tieps;

            for (int i = 0; i < fullCo_slices.Count; i++)
            {
                bool pred = srep[0] == Constants.CO_REP ? occ == fullCo_slices[i].orig :
                            fullCo_slices[i] == occ;
                if (pred)
                {
                    app = fullCo_slices[i];
                    if (app.type == Constants.FIN_REP && !checkNoEndBeforeStart(app, pi))
                    {
                        return(new KeyValuePair <Coincidence, bool>(null, false));
                    }
                    rest       = new Coincidence();
                    rest.index = curr.index;
                    rest.isCo  = true;
                    if (i < fullCo_slices.Count - 1)
                    {
                        for (int k = i + 1; k < fullCo_slices.Count; k++)
                        {
                            Tiep toAdd = null;
                            if (curr.isCo)
                            {
                                toAdd = fullCo_slices[k];
                            }
                            else
                            {
                                toAdd = new Tiep(fullCo_slices[k]);
                            }
                            rest.tieps.Add(toAdd);
                        }
                    }
                    rest.next = curr.next;
                    if (rest.tieps.Count == 0)
                    {
                        rest = rest.next;
                    }
                    return(new KeyValuePair <Coincidence, bool>(rest, true));
                }
            }
            return(new KeyValuePair <Coincidence, bool>(null, false));
        }
Esempio n. 12
0
        /*private Dictionary<string, TiepProjector> tiepsFreq_alt(string slice)
         * {
         *  int count = 0;
         *  Dictionary<string, TiepProjector> tieps_instances = new Dictionary<string, TiepProjector>();
         *  foreach (KeyValuePair<string, MasterTiep> mslc in TiepsHandler.master_tieps)
         *  {
         *      if (mslc.Value.supporting_entities.Count < Constants.MINSUP)
         *      {
         *          continue;
         *      }
         *      bool finish = mslc.Key[mslc.Key.Length - 1] == Constants.FIN_REP;
         *      if (finish)
         *      {
         *          if (slice.Equals(mslc.Key.Replace(Constants.FIN_REP, Constants.ST_REP)))
         *          {
         *              int tup_ind = 0;
         *              foreach (Tuple<CoincidenceSequence, PatternInstance> entry in trans_db)
         *              {
         *                  string ent_id = entry.Item1.entity;
         *                  int index = entry.Item2.tieps[0].ms_index;
         *                  add_to_instances(mslc.Key, ent_id, tup_ind, tieps_instances, index);
         *                  tup_ind++;
         *              }
         *          }
         *          continue;
         *      }
         *      int tuple_index = 0;
         *      foreach (Tuple<CoincidenceSequence, PatternInstance> entry in trans_db)
         *      {
         *          string ent_id = entry.Item1.entity;
         *          Coincidence curr = entry.Item1.coes;
         *          if (curr == null)
         *          {
         *              tuple_index++;
         *              continue;
         *          }
         *          if (count == 0)
         *          {
         *              handle_meet_co(curr, ent_id, tuple_index, tieps_instances);
         *          }
         *          if (!mslc.Value.supporting_entities.Contains(ent_id))
         *          {
         *              tuple_index++;
         *              continue;
         *          }
         *          if (curr.isCo)
         *          {
         *              curr = curr.next;
         *              if (curr == null)
         *              {
         *                  tuple_index++;
         *                  continue;
         *              }
         *          }
         *          if (curr.isMeet)
         *          {
         *              curr = curr.next;
         *              if (curr == null)
         *              {
         *                  tuple_index++;
         *                  continue;
         *              }
         *          }
         *          int time = entry.Item2.last;
         *          int start_co_index = curr.index;
         *          int prev_start_index = 0;
         *          List<Tiep> ms_entity = mslc.Value.tiep_occurrences[ent_id];
         *          for (int i = prev_start_index; i < ms_entity.Count; i++)
         *          {
         *              if (!maxGapHolds(time, ms_entity[i]))
         *              {
         *                  break;
         *              }
         *              int co_index = ms_entity[i].c.index;
         *              if (co_index >= start_co_index)
         *              {
         *                  add_to_instances(mslc.Key, ent_id, tuple_index, tieps_instances, i);
         *                  break;
         *              }
         *          }
         *          tuple_index++;
         *      }
         *      count++;
         *  }
         *  if (count == 0)
         *  {
         *      int tuple_index = 0;
         *      foreach (Tuple<CoincidenceSequence, PatternInstance> entry in trans_db)
         *      {
         *          string ent_id = entry.Item1.entity;
         *          Coincidence curr = entry.Item1.coes;
         *          if (curr == null)
         *          {
         *              tuple_index++;
         *              continue;
         *          }
         *          handle_meet_co(curr, ent_id, tuple_index, tieps_instances);
         *          tuple_index++;
         *      }
         *  }
         *  return tieps_instances;
         * }*/
        //Collect special tieps from special coincidences
        private void handle_meet_co(Coincidence curr, string ent_id, int tuple_index,
                                    Dictionary <string, TiepProjector> tieps_instances)
        {
            List <Tiep> slices = curr.tieps;

            if (curr.isCo)
            {
                for (int i = 0; i < slices.Count; i++)
                {
                    string slc = Constants.CO_REP + "" + slices[i].premitive_rep;
                    Tiep   tmp = slices[i].orig;
                    if (!TiepsHandler.master_tieps.ContainsKey(tmp.premitive_rep))
                    {
                        continue;
                    }
                    add_to_instances(slc, ent_id, tuple_index, tieps_instances, tmp.ms_index);
                }
                if (curr.next != null && curr.next.isMeet)
                {
                    curr   = curr.next;
                    slices = curr.tieps;
                    for (int i = 0; i < slices.Count; i++)
                    {
                        string slc = Constants.MEET_REP + "" + slices[i].premitive_rep;
                        if (!TiepsHandler.master_tieps.ContainsKey(slices[i].premitive_rep))
                        {
                            continue;
                        }
                        add_to_instances(slc, ent_id, tuple_index, tieps_instances, slices[i].ms_index);
                    }
                }
            }
            else if (curr.isMeet)
            {
                for (int i = 0; i < slices.Count; i++)
                {
                    string slc = Constants.MEET_REP + "" + slices[i].premitive_rep;
                    if (!TiepsHandler.master_tieps.ContainsKey(slices[i].premitive_rep))
                    {
                        continue;
                    }
                    add_to_instances(slc, ent_id, tuple_index, tieps_instances, slices[i].ms_index);
                }
            }
        }
Esempio n. 13
0
 //Extend by a new tiep
 public void extendPatternInstance(Tiep s)
 {
     tieps.Add(s);
     if (pre_matched.Contains(s.e))
     {
         pre_matched.Remove(s.e);
         ptime = pre_matched.Count == 0 ? int.MaxValue : pre_matched.Min(elem => elem.fin_time);
     }
     else
     {
         int sym = s.sym;
         if (sym_mss.ContainsKey(sym))
         {
             sym_mss[sym] = s.ms_index;
         }
         else
         {
             sym_mss.Add(sym, s.ms_index);
         }
         pre_matched.Add(s.e);
         ptime = Math.Min(ptime, s.e.fin_time);
     }
 }
Esempio n. 14
0
        //Project the DB for the first time
        public SequenceDB first_projectDB(string alpha, List <string> tieps_instances)
        {
            CoincidenceSequence proj;
            //New db records
            List <Tuple <CoincidenceSequence, PatternInstance> > projDB =
                new List <Tuple <CoincidenceSequence, PatternInstance> >();
            //New Pattern Instance
            PatternInstance newpi = null;
            MasterTiep      ms    = TiepsHandler.master_tieps[alpha];

            //For each co sequence in db
            foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
            {
                string ent_id = entry.Item1.entity;
                if (!tieps_instances.Contains(ent_id))
                {
                    continue;
                }
                List <Tiep> ms_entity          = ms.tiep_occurrences[ent_id];
                int         cur_co_start_index = entry.Item1.coes.index;
                for (int i = 0; i < ms_entity.Count; i++)
                {
                    Tiep occ = ms_entity[i];
                    proj = projectBy(occ, alpha, entry.Item1, occ.c, entry.Item2);
                    if (proj != null)
                    {
                        newpi = new PatternInstance();
                        newpi.extendPatternInstance(occ);
                        int updated = occ.e.fin_time;
                        newpi.last = updated;
                        projDB.Add(new Tuple <CoincidenceSequence, PatternInstance>(proj, newpi));
                    }
                }
            }
            return(new SequenceDB(projDB, null, ms.supporting_entities.Count));
        }
Esempio n. 15
0
 //Perform closure checking
 public bool back_scan(ref Dictionary <string, List <BETiep> > f_acc)
 {
     //For each i
     for (int i = 0; i < trans_db[0].Item2.tieps.Count; i++)
     {
         Dictionary <string, BETiep> acc = null;
         Dictionary <string, BETiep> rem = null;
         int counter    = 0;
         int entity_idx = -1;
         foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
         {
             PatternInstance pi   = entry.Item2;
             Tiep            occ  = pi.tieps[i];
             Coincidence     curr = pi.nexts[i];
             if (counter == 0 || !entry.Item1.entity.Equals(trans_db[counter - 1].Item1.entity))
             {
                 entity_idx++;
                 acc = rem;
                 if (acc != null && acc.Count == 0)
                 {
                     break;
                 }
                 rem = new Dictionary <string, BETiep>();
             }
             string p = curr.isCo ? Constants.CO_REP + "" : (curr.isMeet ? Constants.MEET_REP + "" : "*");
             string tmp;
             //For ith before detection
             while (curr.index != occ.c.index)
             {
                 bool meet = curr.index == occ.c.index - 1 && occ.c.isMeet;
                 if (meet)
                 {
                     foreach (Tiep s in curr.tieps)
                     {
                         tmp = p + Constants.MEET_REP + s.premitive_rep;
                         if (entity_idx == 0 || acc.ContainsKey(tmp))
                         {
                             if (!rem.ContainsKey(tmp))
                             {
                                 if (entity_idx == 0)
                                 {
                                     rem.Add(tmp, new BETiep());
                                 }
                                 else
                                 {
                                     rem.Add(tmp, acc[tmp]);
                                 }
                             }
                             rem[tmp].addOcc(counter, s.e);
                         }
                     }
                 }
                 else
                 {
                     foreach (Tiep s in curr.tieps)
                     {
                         tmp = p + "*" + s.premitive_rep;
                         if ((entity_idx == 0 || acc.ContainsKey(tmp)) && maxGapHolds(s.e.fin_time, occ))
                         {
                             if (!rem.ContainsKey(tmp))
                             {
                                 if (entity_idx == 0)
                                 {
                                     rem.Add(tmp, new BETiep());
                                 }
                                 else
                                 {
                                     rem.Add(tmp, acc[tmp]);
                                 }
                             }
                             rem[tmp].addOcc(counter, s.e);
                         }
                     }
                 }
                 p    = curr.isCo && curr.next.isMeet ? Constants.MEET_REP + "" : "*";
                 curr = curr.next;
             }
             //For ith co detection
             foreach (Tiep s in curr.tieps)
             {
                 if (s.Equals(occ) || occ.Equals(s.orig))
                 {
                     break;
                 }
                 tmp = p + Constants.CO_REP + s.premitive_rep;
                 if (entity_idx == 0 || acc.ContainsKey(tmp))
                 {
                     if (!rem.ContainsKey(tmp))
                     {
                         if (entity_idx == 0)
                         {
                             rem.Add(tmp, new BETiep());
                         }
                         else
                         {
                             rem.Add(tmp, acc[tmp]);
                         }
                     }
                     rem[tmp].addOcc(counter, s.e);
                 }
             }
             counter++;
         }
         acc = rem;
         if (acc.Count == 0)
         {
             continue;
         }
         //Fill the backward extension tieps
         foreach (KeyValuePair <string, BETiep> t in acc)
         {
             string tiep = t.Key.Substring(2);
             if (tiep[tiep.Length - 1] == Constants.ST_REP)
             {
                 if (!f_acc.ContainsKey(tiep))
                 {
                     f_acc.Add(tiep, new List <BETiep>());
                 }
                 f_acc[tiep].Add(t.Value);
             }
         }
         //Look for a finish one whose start one is also there
         foreach (KeyValuePair <string, BETiep> t in acc)
         {
             string tiep = t.Key.Substring(2);
             if (tiep[tiep.Length - 1] == Constants.FIN_REP)
             {
                 tiep = tiep.Replace(Constants.FIN_REP, Constants.ST_REP);
                 if (f_acc.ContainsKey(tiep) && checkStFinMatch(f_acc[tiep], t.Value))
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Esempio n. 16
0
        //Extend tiep projectors for the first time
        public Dictionary <string, TiepProjector> tiepsFreq(string s)
        {
            Dictionary <string, TiepProjector> tieps_instances = new Dictionary <string, TiepProjector>();
            //For each record's postfix in the current db
            int entry_index = 0;

            foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
            {
                bool        found_complement = false;
                bool        beyond_gap       = false;
                string      ent_id           = entry.Item1.entity;
                int         time             = entry.Item2.last;
                Coincidence curr             = entry.Item1.coes;
                while (curr != null)
                {
                    if (beyond_gap && found_complement)
                    {
                        break;
                    }
                    List <Tiep> tieps = curr.tieps;
                    //For each tiep
                    bool co     = curr.isCo;
                    bool finish = tieps[0].type == Constants.FIN_REP;
                    if ((found_complement && finish) || (beyond_gap && !finish))
                    {
                        curr = curr.next;
                        continue;
                    }
                    for (int i = 0; i < tieps.Count; i++)
                    {
                        if (finish)
                        {
                            if (s.Equals(tieps[i].premitive_rep.Replace(Constants.FIN_REP, Constants.ST_REP)))
                            {
                                int index = tieps[i].ms_index;//entry.Item2.tieps[0].ms_index;
                                add_to_instances(tieps[i].premitive_rep, ent_id, entry_index, tieps_instances, index);
                                found_complement = true;
                                break;
                            }
                            continue;
                        }
                        if (s.Equals(tieps[i].premitive_rep))
                        {
                            continue;
                        }
                        if (!maxGapHolds(time, tieps[i]))
                        {
                            beyond_gap = true;
                            break;
                        }
                        string tiep = co ? Constants.CO_REP + "" : "";
                        tiep += tieps[i].premitive_rep;
                        Tiep tmp = tieps[i].orig == null ? tieps[i] : tieps[i].orig;
                        if (!tieps_instances.ContainsKey(tiep))
                        {
                            /*if (!TiepsHandler.master_tieps.ContainsKey(tmp.premitive_rep))
                             * {
                             *  continue;
                             * }*/
                            tieps_instances.Add(tiep, new TiepProjector());
                            tieps_instances[tiep].sup_entities.Add(ent_id);
                        }
                        else
                        {
                            if (!tieps_instances[tiep].sup_entities.Contains(ent_id))
                            {
                                tieps_instances[tiep].sup_entities.Add(ent_id);
                            }
                        }
                        if (!tieps_instances[tiep].co_starts.ContainsKey(entry_index))
                        {
                            tieps_instances[tiep].co_starts.Add(entry_index, tmp.ms_index);
                        }
                    }
                    curr = curr.next;
                }
                entry_index++;
            }
            return(tieps_instances);
        }
Esempio n. 17
0
        //Extend tiep projectors for the first time
        public Dictionary <string, TiepProjector> tiepsFreq(string s)
        {
            Dictionary <string, TiepProjector> tieps_instances = new Dictionary <string, TiepProjector>();
            //For each record's postfix in the current db
            int entry_index = 0;

            foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
            {
                string      ent_id = entry.Item1.entity;
                int         time   = entry.Item2.last;
                Coincidence curr   = entry.Item1.coes;
                while (curr != null)
                {
                    List <Tiep> tieps = curr.tieps;
                    //For each tiep
                    bool co = curr.isCo;
                    for (int i = 0; i < tieps.Count; i++)
                    {
                        bool finish = tieps[i].type == Constants.FIN_REP;
                        //Removed for closed TIRPs discovery

                        /*if (finish)
                         * {
                         *  if (s.Equals(tieps[i].premitive_rep.Replace(Constants.FIN_REP, Constants.ST_REP)))
                         *  {
                         *      int index = entry.Item2.tieps[0].ms_index;
                         *      add_to_instances(tieps[i].premitive_rep, ent_id, entry_index, tieps_instances, index);
                         *  }
                         *  continue;
                         * }*/
                        if (!finish && !maxGapHolds(time, tieps[i]))
                        {
                            break;
                        }
                        string slc = "";
                        slc += co ? Constants.CO_REP + "" : "";
                        slc += tieps[i].premitive_rep;
                        Tiep tmp = tieps[i].orig == null ? tieps[i] : tieps[i].orig;
                        if (tieps_instances.ContainsKey(slc))
                        {
                            //Not the first time we meet the tiep
                            if (!tieps_instances[slc].sup_entities.Contains(ent_id))
                            {
                                tieps_instances[slc].sup_entities.Add(ent_id);
                            }
                        }
                        else
                        {
                            if (!TiepsHandler.master_tieps.ContainsKey(tmp.premitive_rep))
                            {
                                continue;
                            }
                            //First time we see the tiep
                            tieps_instances.Add(slc, new TiepProjector());
                            tieps_instances[slc].sup_entities.Add(ent_id);
                        }
                        if (!tieps_instances[slc].co_starts.ContainsKey(entry_index))
                        {
                            tieps_instances[slc].co_starts.Add(entry_index, tmp.ms_index);
                        }
                    }
                    curr = curr.next;
                }
                entry_index++;
            }
            return(tieps_instances);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
 //Returns true iff the last added finishing slice has a concrete starting one before
 public static bool checkNoEndBeforeStart(Tiep t, PatternInstance prev_pattern)
 {
     return(prev_pattern.pre_matched.Contains(t.e));
 }
Esempio n. 20
0
        //Project the DB for the first time
        public SequenceDB first_projectDB(string alpha, List <string> tieps_instances, ref bool is_closed, ref Dictionary <string, List <BETiep> > f_acc)
        {
            Dictionary <string, BETiep> acc = null;
            Dictionary <string, BETiep> rem;
            CoincidenceSequence         proj;
            //New db records
            List <Tuple <CoincidenceSequence, PatternInstance> > projDB =
                new List <Tuple <CoincidenceSequence, PatternInstance> >();
            //New Pattern Instance
            PatternInstance newpi = null;
            //Corresponding Master Slice
            bool       is_meet    = false;
            MasterTiep ms         = TiepsHandler.master_tieps[alpha];
            int        counter    = 0;
            int        entity_idx = 0;

            //For each co sequence in db
            foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
            {
                string ent_id = entry.Item1.entity;
                if (!tieps_instances.Contains(ent_id))
                {
                    continue;
                }
                List <Tiep> ms_entity          = ms.tiep_occurrences[ent_id];
                int         cur_co_start_index = entry.Item1.coes.index;
                rem = new Dictionary <string, BETiep>();
                for (int i = 0; i < ms_entity.Count; i++)
                {
                    Tiep occ = ms_entity[i];
                    proj = projectBy(occ, alpha, entry.Item1, occ.c, entry.Item2, is_meet);
                    if (proj != null)
                    {
                        newpi = new PatternInstance(entry.Item1.coes);
                        newpi.extendPatternInstance(occ, proj.coes);
                        int updated = occ.e.fin_time;
                        newpi.last = updated;
                        projDB.Add(new Tuple <CoincidenceSequence, PatternInstance>(proj, newpi));
                        //For ith before detection
                        Coincidence curr = i == 0 ? entry.Item1.coes : ms_entity[i - 1].c;
                        if (i > 0)
                        {
                            foreach (KeyValuePair <string, BETiep> kvp in rem)
                            {
                                if (kvp.Key[0] != Constants.CO_REP && kvp.Key[0] != Constants.MEET_REP)
                                {
                                    if (!kvp.Value.indexes.ContainsKey(counter - 1))
                                    {
                                        continue;
                                    }
                                    foreach (STI sti in kvp.Value.indexes[counter - 1])
                                    {
                                        if (maxGapHolds(sti.fin_time, occ))
                                        {
                                            rem[kvp.Key].addOcc(counter, sti);
                                        }
                                    }
                                }
                            }
                        }
                        string tmp;
                        while (curr.index != occ.c.index)
                        {
                            bool meet = curr.index == occ.c.index - 1 && occ.c.isMeet;
                            if (meet)
                            {
                                foreach (Tiep s in curr.tieps)
                                {
                                    tmp = Constants.MEET_REP + s.premitive_rep;
                                    if (entity_idx == 0 || acc.ContainsKey(tmp))
                                    {
                                        if (!rem.ContainsKey(tmp))
                                        {
                                            if (entity_idx == 0)
                                            {
                                                rem.Add(tmp, new BETiep());
                                            }
                                            else
                                            {
                                                rem.Add(tmp, acc[tmp]);
                                            }
                                        }
                                        rem[tmp].addOcc(counter, s.e);
                                    }
                                }
                            }
                            else
                            {
                                foreach (Tiep s in curr.tieps)
                                {
                                    tmp = "*" + s.premitive_rep;
                                    if ((entity_idx == 0 || acc.ContainsKey(tmp)) && maxGapHolds(s.e.fin_time, occ))
                                    {
                                        if (!rem.ContainsKey(tmp))
                                        {
                                            if (entity_idx == 0)
                                            {
                                                rem.Add(tmp, new BETiep());
                                            }
                                            else
                                            {
                                                rem.Add(tmp, acc[tmp]);
                                            }
                                        }
                                        rem[tmp].addOcc(counter, s.e);
                                    }
                                }
                            }
                            curr = curr.next;
                        }
                        //For ith co detection
                        foreach (Tiep s in curr.tieps)
                        {
                            if (s.Equals(occ))
                            {
                                break;
                            }
                            tmp = Constants.CO_REP + s.premitive_rep;
                            if (entity_idx == 0 || acc.ContainsKey(tmp))
                            {
                                if (!rem.ContainsKey(tmp))
                                {
                                    if (entity_idx == 0)
                                    {
                                        rem.Add(tmp, new BETiep());
                                    }
                                    else
                                    {
                                        rem.Add(tmp, acc[tmp]);
                                    }
                                }
                                rem[tmp].addOcc(counter, s.e);
                            }
                        }
                        counter++;
                    }
                }
                acc = rem;
                entity_idx++;
            }
            //Fill the backward extension tieps and look for a finish tiep whose existence is equivalent to being surely unclosed
            foreach (KeyValuePair <string, BETiep> t in acc)
            {
                string tiep = t.Key.Substring(1);
                if (tiep[tiep.Length - 1] == Constants.ST_REP)
                {
                    if (!f_acc.ContainsKey(tiep))
                    {
                        f_acc.Add(tiep, new List <BETiep>());
                    }
                    f_acc[tiep].Add(t.Value);
                }
                else
                {
                    is_closed = false;
                    break;
                }
            }
            List <string> prem = new List <string>();

            prem.Add(alpha.Replace(Constants.ST_REP, Constants.FIN_REP));
            return(new SequenceDB(projDB, null, ms.supporting_entities.Count, prem));
        }