/// <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(Karma 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.karma.GetVerticalSupportOfSymbolToSymbolRelation(t1Idx, symbol2.SymbolINDEX, rel) >= k.getMinVerSup()) { //Print the 2-sized TIRP to file TIRP twoSzdTIRP = k.GetTwoSizedTirpForSymbolsAndRel(symbolID, symbol2.symbolID, rel); Lego lego = new Lego(k); twoSzdTIRP.WriteTIRPtoFile(outFile, k.getEntitiesVec(), relStyle); //Extend it recursively lego.DoLego(outFile, twoSzdTIRP, relStyle); lego = null; } } } } } }
//Execute the algorithm public static void run_algorithm(int num_entities, double min_support, int maximal_gap, string file_path) { int index = Dharma_Index; int method = METHOD_KL; //set directory, input & output files string inputFile = file_path + ".csv"; //set variables bool setHS1 = false; int epsilon = 0; long dt1 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; string rt = ""; string outFile = file_path + "-support-" + min_support + "-maxgap-" + maximal_gap + ".txt"; File.Delete(outFile); //Select whether to use KarmaLego or the LL algorithm if (method == METHOD_KL) { //Build either the karma or dharma index according to the index flag if (index == Karma_Index) { Karma k = new Karma(epsilon, maximal_gap, min_support, inputFile, setHS1); Lego.RunLego(k, outFile, KLC.KL_TRANS_YES, k.getRelStyle()); } else { Dharma d = new Dharma(int.MaxValue, true, KLC.dharma_relVecSymVecSymDic, true, KLC.forwardMining, KLC.RELSTYLE_ALLEN7, epsilon, maximal_gap, min_support, inputFile, true, setHS1, 1, ref rt); DLego.RunLego(d, outFile, KLC.KL_TRANS_YES, d.getRelStyle()); } } Console.WriteLine("---------------"); Console.WriteLine("---------------"); Console.WriteLine("---------------"); long dt2 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; long diff = dt2 - dt1; Console.WriteLine(diff); Thread.Sleep(2000); //Write running stats to file string[] to_write = new string[1]; to_write[0] = diff + ""; System.IO.File.WriteAllLines(outFile + "-stats.txt", to_write); //outputConverter(outfile); }
public Lego(Karma setKarma) { karma = setKarma; }