예제 #1
0
        /// <summary>
        /// Runs the Lego algorithm on every 2 sized TIRP with enough vertical support and prints every extended TIRP with enough vertical support to file
        /// </summary>
        /// <param name="tirp"></param>
        /// <param name="tw"></param>
        /// <param name="relStyle"></param>
        private void DoLego(string outFile, TIRP tirp, int relStyle)
        {
            List <int[]> candidates = null;

            foreach (Symbol symbol in karma.getSymbolicTimeIntervals())                                                                                                                               // for every symbol...
            {
                for (int seedRelation = 0; seedRelation < relStyle; seedRelation++)                                                                                                                   // ... and every relation
                {
                    if (karma.getIndex().GetVerticalSupportOfSymbolToSymbolRelation(karma.getSymbolIndexByID(tirp.symbols[tirp.size - 1]), symbol.SymbolINDEX, seedRelation) >= karma.getMinVerSup()) // if vertical support is high enough
                    {
                        candidates = CandidatesGeneration(tirp, seedRelation);                                                                                                                        // Generate candidate and extend the TIRP
                        for (int cand = 0; cand < candidates.Count; cand++)
                        {
                            TIRP tirpNew            = new TIRP(tirp, symbol.symbolID, seedRelation, candidates.ElementAt(cand));
                            bool seedRelCnndtsEmpty = SearchSupportingInstances(ref tirpNew, tirp.tinstancesList); // Also sets the TIRP supportingEntities field
                            if (tirpNew.supprtingEntities.Count >= karma.getMinVerSup())                           // If the TIRPs vertical support is big enough, write the TIRP and attempt to further extend it
                            {
                                tirpNew.WriteTIRPtoFile(outFile, karma.getEntitiesVec(), relStyle);
                                DoLego(outFile, tirpNew, relStyle);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Runs lego and prints output to file
        /// </summary>
        /// <param name="k"></param>
        /// <param name="outFile"></param>
        /// <param name="seTrans"></param>
        /// <param name="relStyle"></param>
        public static void RunLego(Dharma k, string outFile, bool seTrans, int relStyle)
        {
            int counter = 1;

            Dictionary <int, Symbol> .ValueCollection dic = k.getSymbolicTimeIntervals();
            int symbCount = dic.Count;

            //For each symbol
            foreach (Symbol symbol1 in dic)
            {
                Console.WriteLine(counter + "/" + symbCount + ", symbol: " + symbol1.symbolID);
                counter++;
                //long t = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                //If it is frequent
                if (k.getSymbolByIDVerticalSupport(symbol1.symbolID) >= k.getMinVerSup())
                {
                    int symbolID = symbol1.symbolID;
                    int t1Idx    = symbol1.SymbolINDEX;
                    using (FileStream fileStream = new FileStream(outFile, FileMode.Append, FileAccess.Write))
                    {
                        //Print one-sized TIRP to file
                        #region initial output formatting
                        TextWriter tw        = new StreamWriter(fileStream);
                        string     instances = " ";
                        for (int i = 0; i < k.getSymbolByIDVerticalSupport(symbolID); i++)
                        {
                            KeyValuePair <int, List <SymbolicTimeInterval> > userInstances = k.getSymbolByID(symbolID).getTonceptHorizontalDic().ElementAt(i);
                            for (int j = 0; j < userInstances.Value.Count; j++)
                            {
                                instances += k.getEntityByIdx(userInstances.Key) + " [" + userInstances.Value.ElementAt(j).startTime + "-" + userInstances.Value.ElementAt(j).endTime + "] ";
                            }
                        }
                        tw.WriteLine("1 " + symbolID + "- -. " + k.getSymbolByIDVerticalSupport(symbolID) + " " + Math.Round((double)k.getSymbolByIDVerticalSupport(symbolID), 2) + instances);
                        #endregion
                    }
                    //For each second symbol
                    foreach (Symbol symbol2 in k.getSymbolicTimeIntervals())
                    {
                        //And for each relation
                        for (int rel = 0; rel < relStyle; rel++)
                        {
                            //If the <symbol1,symbol2,relation> entry in the index is frequent
                            if (k.getIndex().GetVerticalSupportOfSymbolToSymbolRelation(t1Idx, symbol2.SymbolINDEX, rel) >= k.getMinVerSup())
                            {
                                //Print the 2-sized TIRP to file
                                TIRP  twoSzdTIRP = k.GetTwoSizedTirpForSymbolsAndRel(symbolID, symbol2.symbolID, rel);
                                DLego lego       = new DLego(k);
                                twoSzdTIRP.WriteTIRPtoFile(outFile, k.getEntitiesVec(), relStyle);
                                //Extend it recursively
                                lego.DoLego(outFile, twoSzdTIRP, relStyle);
                                lego = null;
                            }
                        }
                    }
                }
            }
        }