Exemple #1
0
        //Returns the slices that appear before slice in the given coincidence
        //Also the slices that appear in the previous co, if exists and partial are added
        private List <string> getSlicesBeforeInCo(string slc, List <string> coes, int index, string pat, string id, int last_time)
        {
            List <string> befSlices   = new List <string>();
            List <string> prev_slices = new List <string>();

            if (index > 0 && CoincidenceManager.isPartialCo(coes[index - 1]))
            {
                prev_slices = CoincidenceManager.getSymPartOfSlices(CoincidenceManager.splitCoToSlices(coes[index - 1]));
            }
            List <string> cur_coes = new List <string>();

            for (int i = 0; i < index + 1; i++)
            {
                cur_coes.Add(coes[i]);
            }
            cur_coes[index] = "";
            fillSliceList(befSlices, prev_slices, cur_coes, pat, id, last_time);
            if (slc[0] == Constants.MEET_REP)
            {
                return(befSlices);
            }
            //Added slices that appears in the previous coincidence after the previous slice if exist
            string cur_slc = slc;

            if (slc[0] == Constants.MEET_REP)
            {
                cur_slc = cur_slc.Substring(1);
            }
            cur_coes[index] = CoincidenceManager.getPartBefore(coes[index], cur_slc);
            List <string> allSlices = CoincidenceManager.splitCoToSlices(cur_coes[index]);

            //List<string> allSlices = CoincidenceManager.getSymPartOfSlices(CoincidenceManager.splitCoToSlices(cur_coes[index]));
            fillSliceList(befSlices, allSlices, cur_coes, pat, id, last_time);
            return(befSlices);
        }
Exemple #2
0
        //Returns the slices that appears in the i-th co-occuring-checking period in the DB for the last slice
        private List <string> ithCo(string slice)
        {
            string slicetmp = slice[0] == Constants.CO_REP || slice[0] == Constants.MEET_REP ?
                              slice.Substring(1) : slice;
            Dictionary <string, int> ith_co = new Dictionary <string, int>();
            int app_counter = 0;

            foreach (KeyValuePair <string, List <string> > entry in trans_db)
            {
                List <string> seq_coes  = entry.Value; //Split entry to coincidences
                int           last_time = patterns[entry.Key].Item2;
                KeyValuePair <int, KeyValuePair <List <string>, string> > proj =
                    canProjectBy(slice, seq_coes, patterns[entry.Key].Item1, getID(entry.Key), 0, "", last_time);
                int           cpb = proj.Key;
                List <string> suspect;
                while (cpb >= 0)
                {
                    app_counter++;
                    string pref = "";
                    suspect = new List <string>();
                    if (CoincidenceManager.isPartialCo(seq_coes[cpb]))
                    {
                        pref = Constants.CO_REP + "";
                    }
                    else if (seq_coes[cpb].IndexOf(Constants.MEET_REP) >= 0 && (cpb == 0 ||
                                                                                (cpb == 1 && CoincidenceManager.isPartialCo(seq_coes[cpb - 1]))))
                    {
                        pref = Constants.MEET_REP + "";
                    }
                    List <string> toAdd = CoincidenceManager.getSymPartOfSlices
                                              (CoincidenceManager.splitCoToSlices(seq_coes[cpb]));
                    foreach (string s in toAdd)
                    {
                        string stmp = s[0] == Constants.CO_REP || s[0] == Constants.MEET_REP ?
                                      s.Substring(1) : s;
                        if (stmp.Equals(slicetmp))
                        {
                            break;
                        }
                        if (!suspect.Contains(pref + stmp))
                        {
                            suspect.Add(pref + stmp);
                        }
                    }
                    //suspect = getSlicesBeforeInCo(slice, seq_coes, cpb, patterns[entry.Key].Item1, getID(entry.Key), last_time);
                    //Add occurences of the slices that appeared in the current occurence of 'slice'
                    foreach (string sus in suspect)
                    {
                        if (ith_co.ContainsKey(sus))
                        {
                            ith_co[sus]++;
                        }
                        else
                        {
                            ith_co.Add(sus, 1);
                        }
                    }
                    proj = canProjectBy(slice, seq_coes, patterns[entry.Key].Item1, getID(entry.Key), proj.Key, proj.Value.Value, last_time);
                    cpb  = proj.Key;
                }
            }
            //Take those that always appear
            List <string> ic = new List <string>();

            foreach (KeyValuePair <string, int> entry in ith_co)
            {
                if (entry.Value == app_counter)
                {
                    string tmp = entry.Key[0] == Constants.MEET_REP || entry.Key[0] == Constants.CO_REP ?
                                 entry.Key.Substring(1) : entry.Key;
                    if (!ic.Contains(tmp))
                    {
                        ic.Add(tmp);
                    }
                }
            }
            return(ic);
        }
Exemple #3
0
        //Returns the slices that appears in the i-th before-checking period in the DB for the last slice
        private List <string> ithBefore(string slice)
        {
            Dictionary <string, int> ith_bef      = new Dictionary <string, int>();
            Dictionary <string, int> meet_ith_bef = new Dictionary <string, int>();
            int app_counter = 0;

            foreach (KeyValuePair <string, List <string> > entry in trans_db)
            {
                List <string> seq_coes  = entry.Value; //Split entry to coincidences
                int           last_time = patterns[entry.Key].Item2;
                KeyValuePair <int, KeyValuePair <List <string>, string> > proj =
                    canProjectBy(slice, seq_coes, patterns[entry.Key].Item1, getID(entry.Key), 0, "", last_time); //Returns co index and postfix
                int cpb = proj.Key;
                //bool skip_one;
                List <string> suspect;
                List <string> meet_suspect;
                while (cpb >= 0)
                {
                    //skip_one = (seq_coes.Count > 0 && seq_coes[0].IndexOf(Constants.CO_REP) >= 0);
                    suspect      = new List <string>();
                    meet_suspect = new List <string>();
                    app_counter++;
                    List <string> cur_coes = new List <string>();
                    for (int i = 0; i < cpb; i++)
                    {
                        cur_coes.Add("");
                    }
                    string pref;
                    for (int i = 0; i < cpb; i++)
                    {
                        /*if (skip_one)
                         * {
                         *  skip_one = false;
                         *  continue;
                         * }*/
                        pref = "";
                        if (i == 0)
                        {
                            if (CoincidenceManager.isPartialCo(seq_coes[i]))
                            {
                                pref = Constants.CO_REP + "";
                            }
                            else if (seq_coes[i].IndexOf(Constants.MEET_REP) >= 0)
                            {
                                pref = Constants.MEET_REP + "";
                            }
                        }
                        else if (i == 1)
                        {
                            if (seq_coes[i].IndexOf(Constants.MEET_REP) >= 0 &&
                                CoincidenceManager.isPartialCo(seq_coes[i - 1]))
                            {
                                pref = Constants.MEET_REP + "";
                            }
                        }
                        bool b1 = i == cpb - 1 && seq_coes[cpb].IndexOf(Constants.MEET_REP) >= 0;
                        bool b2 = slice[0] == Constants.MEET_REP;
                        if (b1 != b2)
                        {
                            List <string> toAdd1 = CoincidenceManager.getSymPartOfSlices
                                                       (CoincidenceManager.splitCoToSlices(seq_coes[i]));
                            List <string> conc_toAdd1 = CoincidenceManager.splitCoToSlices(seq_coes[i]);
                            int           ind1        = 0;
                            foreach (string s in toAdd1)
                            {
                                string stmp = s[0] == Constants.CO_REP || s[0] == Constants.MEET_REP ?
                                              s.Substring(1) : s;
                                string cs    = conc_toAdd1[ind1];
                                string cstmp = cs[0] == Constants.CO_REP || cs[0] == Constants.MEET_REP ?
                                               cs.Substring(1) : cs;
                                if (!meet_suspect.Contains(pref + stmp) &&
                                    (stmp.IndexOf(Constants.FIN_REP) >= 0 ||
                                     (maxGapHolds(getID(entry.Key), last_time, cstmp) &&
                                      maxGapHolds(getID(entry.Key), getInt(getID(entry.Key), cstmp).
                                                  st_time, proj.Value.Value))))
                                {
                                    meet_suspect.Add(pref + stmp);
                                }
                                ind1++;
                            }
                            continue;
                        }
                        List <string> toAdd = CoincidenceManager.getSymPartOfSlices
                                                  (CoincidenceManager.splitCoToSlices(seq_coes[i]));
                        List <string> conc_toAdd = CoincidenceManager.splitCoToSlices(seq_coes[i]);
                        int           ind        = 0;
                        foreach (string s in toAdd)
                        {
                            string stmp = s[0] == Constants.CO_REP || s[0] == Constants.MEET_REP ?
                                          s.Substring(1) : s;
                            string cs    = conc_toAdd[ind];
                            string cstmp = cs[0] == Constants.CO_REP || cs[0] == Constants.MEET_REP ?
                                           cs.Substring(1) : cs;
                            if (!suspect.Contains(pref + stmp) &&
                                (stmp.IndexOf(Constants.FIN_REP) >= 0 ||
                                 (maxGapHolds(getID(entry.Key), last_time, cstmp) &&
                                  maxGapHolds(getID(entry.Key), getInt(getID(entry.Key), cstmp).st_time,
                                              proj.Value.Value))))
                            {
                                suspect.Add(pref + stmp);
                            }
                            ind++;
                        }

                        /*
                         * List<string> toAdd = CoincidenceManager.getSymPartOfSlices
                         *  (CoincidenceManager.splitCoToSlices(seq_coes[i]));
                         * cur_coes[i] = seq_coes[i];
                         * fillSliceList(suspect, toAdd, cur_coes, patterns[entry.Key].Item1, getID(entry.Key), last_time);
                         */
                    }
                    //Add occurences of the slices that appeared in the current occurence of 'slice'
                    foreach (string sus in suspect)
                    {
                        if (ith_bef.ContainsKey(sus))
                        {
                            ith_bef[sus]++;
                        }
                        else
                        {
                            ith_bef.Add(sus, 1);
                        }
                    }
                    foreach (string sus in meet_suspect)
                    {
                        if (meet_ith_bef.ContainsKey(sus))
                        {
                            meet_ith_bef[sus]++;
                        }
                        else
                        {
                            meet_ith_bef.Add(sus, 1);
                        }
                    }
                    proj = canProjectBy(slice, seq_coes, patterns[entry.Key].Item1, getID(entry.Key), proj.Key, proj.Value.Value, last_time);
                    cpb  = proj.Key;
                }
            }
            //Take those that always appear
            List <string> ib = new List <string>();

            foreach (KeyValuePair <string, int> entry in ith_bef)
            {
                if (entry.Value == app_counter)
                {
                    string tmp = entry.Key[0] == Constants.MEET_REP || entry.Key[0] == Constants.CO_REP ?
                                 entry.Key.Substring(1) : entry.Key;
                    if (!ib.Contains(tmp))
                    {
                        ib.Add(tmp);
                    }
                }
            }
            foreach (KeyValuePair <string, int> entry in meet_ith_bef)
            {
                if (entry.Value == app_counter)
                {
                    string tmp = entry.Key[0] == Constants.MEET_REP || entry.Key[0] == Constants.CO_REP ?
                                 entry.Key.Substring(1) : entry.Key;
                    if (!ib.Contains(tmp))
                    {
                        ib.Add(tmp);
                    }
                }
            }
            return(ib);
        }