//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)); }
//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); }
//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); }
//Input transformation public static SequenceDB createSequencesKLF(string filePath) { TextReader tr = new StreamReader(filePath); string readLine = tr.ReadLine(); //Move on until the significant start while (readLine != null && !readLine.StartsWith(Constants.FILE_START)) { readLine = tr.ReadLine(); } if (!(readLine == Constants.FILE_START && tr.ReadLine().StartsWith(Constants.FILE_NUM))) { throw new InvalidOperationException(Constants.FILE_FORMAT_ERR); } //Start reading the entities List <Tuple <CoincidenceSequence, PatternInstance> > trans_db = new List <Tuple <CoincidenceSequence, PatternInstance> >(); while (tr.Peek() >= 0) { sequenceTransformer.emptyEndTimes(); readLine = tr.ReadLine(); string[] mainDelimited = readLine.Split(';'); string entityID = mainDelimited[0].Split(',')[0]; readLine = tr.ReadLine(); mainDelimited = readLine.Split(';'); for (int i = 0; i < mainDelimited.Length - 1; i++) { string[] tisDelimited = mainDelimited[i].Split(','); int symbol = int.Parse(tisDelimited[2]); STI ei = new STI(symbol, int.Parse(tisDelimited[0]), int.Parse(tisDelimited[1])); sequenceTransformer.addIntervalToEndTimes(ei); } CoincidenceSequence cs = sequenceTransformer.eventSeqToCoincidenceSeq(entityID); PatternInstance pi = new PatternInstance(); cs.entity = entityID; trans_db.Add(new Tuple <CoincidenceSequence, PatternInstance>(cs, pi)); } tr.Close(); return(new SequenceDB(trans_db, null, 0, new List <string>())); }