Example #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));
        }
Example #2
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));
        }
Example #3
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));
        }