Example #1
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));
        }
Example #2
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);
     }
 }
Example #3
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);
                }
            }
        }
Example #4
0
 public Coincidence()
 {
     isMeet = false;
     tieps  = new List <Tiep>();
     index  = -1;
     next   = null;
     isCo   = false;
 }
Example #5
0
 public PatternInstance(Coincidence c)
 {
     tieps       = new List <Tiep>();
     sym_mss     = new Dictionary <int, int>();
     pre_matched = new List <STI>();
     nexts       = new List <Coincidence>();
     nexts.Add(c);
     last  = -1;
     ptime = int.MaxValue;
 }
Example #6
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;
 }
Example #7
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;
 }
Example #8
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);
                }
            }
        }
Example #9
0
 public void filterInfrequentTiepsFromInitialSDB()
 {
     foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
     {
         Coincidence current  = entry.Item1.coes;
         Coincidence previous = null;
         int         removed_co_tieps;
         int         removed_coincidences = 0;
         bool        removed_recent       = false;
         while (current != null)
         {
             List <Tiep> tieps = current.tieps;
             removed_co_tieps = 0;
             for (int i = 0; i < tieps.Count + removed_co_tieps; i++)
             {
                 if (!TiepsHandler.master_tieps.ContainsKey(tieps[i - removed_co_tieps].premitive_rep))
                 {
                     tieps.Remove(tieps[i - removed_co_tieps]);
                     removed_co_tieps++;
                 }
             }
             if (tieps.Count == 0)
             {
                 removed_coincidences++;
                 removed_recent = true;
                 if (previous != null)
                 {
                     previous.next = current.next;
                 }
             }
             else
             {
                 current.index -= removed_coincidences;
                 if (removed_recent)
                 {
                     current.isMeet = false;
                 }
                 if (previous == null)
                 {
                     entry.Item1.coes = current;
                 }
                 removed_recent = false;
                 previous       = current;
             }
             current = current.next;
         }
     }
 }
Example #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);
        }
Example #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));
        }
Example #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);
                }
            }
        }
Example #13
0
        //Converts the entity's stis into time points based tieps sequential rep.
        public static CoincidenceSequence eventSeqToCoincidenceSeq(string entity)
        {
            co_index = 0;
            Coincidence         curr = null;
            CoincidenceSequence cs   = new CoincidenceSequence();
            //The previous element in the end time list
            EndTime     last_endtime = null;
            bool        isMeet       = false;
            Coincidence coincidence;

            foreach (EndTime t in endtime_list)
            {
                isMeet            = false;
                coincidence       = new Coincidence();
                coincidence.index = co_index;
                if (t.type == Constants.START)
                {
                    //Start tiep
                    if (last_endtime != null && last_endtime.time == t.time)
                    {
                        isMeet = true;
                    }
                    getSlicesForSyms(coincidence, t.symbols, t.time, Constants.ST_REP, entity);
                }
                else
                {
                    //Finish tieps
                    getSlicesForSyms(coincidence, t.symbols, t.time, Constants.FIN_REP, entity);
                }
                if (co_index == 0)
                {
                    cs.coes = coincidence;
                }
                else
                {
                    curr.next = coincidence;
                }
                coincidence.isMeet = isMeet;
                co_index++;
                curr         = coincidence;
                last_endtime = t;
            }
            return(cs);
        }
Example #14
0
 //Extend by a new tiep
 public void extendPatternInstance(Tiep s, Coincidence n)
 {
     tieps.Add(s);
     nexts.Add(n);
     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);
     }
 }
Example #15
0
        //Extend tiep projectors
        public Dictionary <string, TiepProjector> tiepsFreq_alt(string last_t, Dictionary <string, TiepProjector> sf)
        {
            if (sf == null)
            {
                return(tiepsFreq(last_t));
            }
            if (last_t[0] == Constants.CO_REP || last_t[0] == Constants.MEET_REP)
            {
                last_t = last_t.Substring(1);
            }
            Dictionary <string, TiepProjector> tieps_instances = new Dictionary <string, TiepProjector>();
            //For each tiep projector
            int spare = trans_db.Count - Constants.MINSUP;

            foreach (KeyValuePair <string, TiepProjector> slc_entry in sf)
            {
                //If it is frequent and not special
                if (slc_entry.Value.sup_entities.Count < Constants.MINSUP)
                {
                    continue;
                }
                if (slc_entry.Key[0] == Constants.CO_REP || slc_entry.Key[0] == Constants.MEET_REP)
                {
                    continue;
                }
                bool finish = slc_entry.Key[slc_entry.Key.Length - 1] == Constants.FIN_REP;
                if (finish && last_t.Equals(slc_entry.Key))
                {
                    continue;
                }
                bool       pre         = !finish;
                int        tuple_index = 0;
                MasterTiep ms          = TiepsHandler.master_tieps[slc_entry.Key];
                //For each entry in the sequence DB
                int lack = 0;
                foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
                {
                    if (lack > spare)
                    {
                        break;
                    }
                    //Take the first non special coincidence
                    string      ent_id = entry.Item1.entity;
                    Coincidence curr   = entry.Item1.coes;
                    if (curr == null)
                    {
                        lack++;
                        tuple_index++;
                        continue;
                    }
                    if (curr.isCo)
                    {
                        curr = curr.next;
                        if (curr == null)
                        {
                            lack++;
                            tuple_index++;
                            continue;
                        }
                    }
                    if (curr.isMeet)
                    {
                        curr = curr.next;
                        if (curr == null)
                        {
                            lack++;
                            tuple_index++;
                            continue;
                        }
                    }
                    int start_co_index = curr.index;
                    int sp_index       = entries_prev_indexes[tuple_index];
                    //If the entry is in the tiep projector
                    if (!slc_entry.Value.co_starts.ContainsKey(sp_index))
                    {
                        lack++;
                        tuple_index++;
                        continue;
                    }
                    List <Tiep> ms_entity = ms.tiep_occurrences[ent_id];
                    //If it is of type finish, check if the postfix contains the specific instance corresponding to the start tiep in the
                    //pattern instance
                    //Removed for closed TIRPs discovery

                    /*if (!pre)
                     * {
                     *  int index = entry.Item2.sym_mss[ms_entity[0].sym];
                     *  if (ms_entity[index].c.index >= start_co_index)
                     *  {
                     *      add_to_instances(slc_entry.Key, ent_id, tuple_index, tieps_instances, index);
                     *  }
                     *  else
                     *  {
                     *      lack++;
                     *  }
                     *  tuple_index++;
                     *  continue;
                     * }*/
                    //For start tiep, look for the first instance in the postfix if exist
                    int  time             = entry.Item2.last;
                    int  prev_start_index = slc_entry.Value.co_starts[sp_index];
                    bool s = false;
                    for (int i = prev_start_index; i < ms_entity.Count; i++)
                    {
                        if (pre && !maxGapHolds(time, ms_entity[i]))
                        {
                            break;
                        }
                        int co_index = ms_entity[i].c.index;
                        if (co_index >= start_co_index)
                        {
                            add_to_instances(slc_entry.Key, ent_id, tuple_index, tieps_instances, i);
                            s = true;
                            break;
                        }
                    }
                    if (!s)
                    {
                        lack++;
                    }
                    tuple_index++;
                }
            }
            //If the last tiep was start, we need to consider its finish tiep
            if (last_t[last_t.Length - 1] == Constants.ST_REP)
            {
                string     fin_slc     = last_t.Replace(Constants.ST_REP, Constants.FIN_REP);
                int        tuple_index = 0;
                int        lack        = 0;
                MasterTiep ms          = TiepsHandler.master_tieps[fin_slc];
                //For each entry in the sequence DB
                foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
                {
                    if (lack > spare)
                    {
                        break;
                    }
                    //Get the first non special coincidence
                    string      ent_id = entry.Item1.entity;
                    Coincidence curr   = entry.Item1.coes;
                    if (curr == null)
                    {
                        lack++;
                        tuple_index++;
                        continue;
                    }
                    if (curr.isCo)
                    {
                        curr = curr.next;
                        if (curr == null)
                        {
                            lack++;
                            tuple_index++;
                            continue;
                        }
                    }
                    //Add the specific corresponding finish tiep for the recently added start tiep for each record
                    int         start_co_index = curr.index;
                    List <Tiep> ms_entity      = ms.tiep_occurrences[ent_id];
                    bool        s = false;
                    for (int i = 0; i < ms_entity.Count; i++)
                    {
                        int co_index = ms_entity[i].c.index;
                        if (co_index >= start_co_index)
                        {
                            add_to_instances(fin_slc, ent_id, tuple_index, tieps_instances, i);
                            s = true;
                            break;
                        }
                    }
                    if (!s)
                    {
                        lack++;
                    }
                    //Removed for closed TIRPs discovery

                    /*int index = entry.Item2.sym_mss[ms_entity[0].sym];
                     * if (ms_entity[index].c.index >= start_co_index)
                     * {
                     *  add_to_instances(fin_slc, ent_id, tuple_index, tieps_instances, index);
                     * }
                     * else
                     * {
                     *  lack++;
                     * }*/
                    tuple_index++;
                }
            }
            //If we still did not handle the special ones we do it now
            int tup_index = 0;

            foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db)
            {
                string      ent_id = entry.Item1.entity;
                Coincidence curr   = entry.Item1.coes;
                if (curr == null)
                {
                    tup_index++;
                    continue;
                }
                handle_meet_co(curr, ent_id, tup_index, tieps_instances);
                tup_index++;
            }
            return(tieps_instances);
        }
Example #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);
        }
Example #17
0
 public CoincidenceSequence()
 {
     partial = null;
 }
Example #18
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);
        }
Example #19
0
 //True iff curr is meet and it is the first of coes or it is the second of coes when the first is partial
 private static bool mayMeet(Coincidence curr, Coincidence coes)
 {
     return(curr.isMeet &&
            ((curr == coes && !curr.isCo) || (coes.isCo && curr == coes.next)));
 }
Example #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));
        }
Example #21
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);
 }