示例#1
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));
        }
示例#2
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);
        }
示例#3
0
        //Project the DB after the first time
        public SequenceDB projectDB(string alpha, TiepProjector tiep_instances)
        {
            CoincidenceSequence proj;
            //New db records
            List <Tuple <CoincidenceSequence, PatternInstance> > projDB =
                new List <Tuple <CoincidenceSequence, PatternInstance> >();
            List <int> proj_indexes = new List <int>();
            //New Pattern Instance
            PatternInstance newpi = null;
            //Corresponding Master Slice
            string temp_alpha = alpha;
            bool   is_meet = false, is_co = false;

            if (temp_alpha[0] == Constants.MEET_REP)
            {
                is_meet    = true;
                temp_alpha = temp_alpha.Substring(1);
            }
            else if (temp_alpha[0] == Constants.CO_REP)
            {
                is_co      = true;
                temp_alpha = temp_alpha.Substring(1);
            }
            MasterTiep ms = TiepsHandler.master_tieps[temp_alpha];
            //For each co sequence in db
            bool          st = temp_alpha[temp_alpha.Length - 1] == Constants.ST_REP;
            Tiep          occ;
            List <string> sup_ents = new List <string>();

            foreach (KeyValuePair <int, int> sp_entry in tiep_instances.co_starts)
            {
                Tuple <CoincidenceSequence, PatternInstance> entry = trans_db[sp_entry.Key];
                string      ent_id    = entry.Item1.entity;
                List <Tiep> ms_entity = ms.tiep_occurrences[ent_id];
                int         last_time = entry.Item2.last;
                for (int i = sp_entry.Value; i < ms_entity.Count; i++)
                {
                    if (ms_entity[i].time > entry.Item2.ptime)
                    {
                        continue;
                    }
                    if (st && !maxGapHolds(last_time, ms_entity[i]))
                    {
                        break;
                    }
                    occ  = ms_entity[i];
                    proj = projectBy(occ, alpha, entry.Item1, occ.c, entry.Item2, is_meet);
                    if (proj != null)
                    {
                        if (!sup_ents.Contains(ent_id))
                        {
                            sup_ents.Add(ent_id);
                        }
                        newpi = new PatternInstance();
                        newpi.copyPatternToExtend(entry.Item2);
                        newpi.extendPatternInstance(occ, proj.coes);
                        int updated = getUpdatedEndTime(last_time, occ);
                        newpi.last = updated;
                        projDB.Add(new Tuple <CoincidenceSequence, PatternInstance>(proj, newpi));
                        proj_indexes.Add(sp_entry.Key);
                    }
                    if (is_co || is_meet || !st)
                    {
                        break;
                    }
                }
            }
            List <string> prem = new List <string>(pre_matched);

            if (temp_alpha[temp_alpha.Length - 1] == Constants.ST_REP)
            {
                prem.Add(temp_alpha.Replace(Constants.ST_REP, Constants.FIN_REP));
            }
            else
            {
                prem.Remove(temp_alpha);
            }
            return(new SequenceDB(projDB, proj_indexes, sup_ents.Count, prem));
        }
示例#4
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));
        }