protected override void readResults(int taskID, long allObjectsCount, object taskDescription, out GeneratingStruct generation, out HypothesisStruct[] result) { generation = common.GetGeneratingStruct(taskID); List<HypothesisStruct> hypothesesResult = new List<HypothesisStruct>(); HypothesisStruct hypothesisStruct; AbstractQuantifierSetting quantifierSetting; DataTable hypothesis = common.ExecuteSelectQuery("SELECT * FROM tiHypothesisCF WHERE TaskID=" + taskID); LiteralStruct[] literals = common.GetCategorialLiterals(TaskTypeEnum.CF, taskID, taskDescription); foreach (DataRow hypothese in hypothesis.Rows) { int hypothesisID = Convert.ToInt32(hypothese["HypothesisID"]); hypothesisStruct = new HypothesisStruct(); hypothesisStruct.booleanLiterals = common.GetBooleanLiterals(taskID, hypothesisID); int rowLiteralId = common.CategorialLiteral[Convert.ToInt32(hypothese["CFLiteralDID"])]; LiteralStruct rowLiteral = new LiteralStruct(); foreach (LiteralStruct literal in literals) { if (literal.cedentType == CedentEnum.Antecedent && literal.literalIdentifier == rowLiteralId) rowLiteral = literal; } hypothesisStruct.literals = new LiteralStruct[] { rowLiteral }; quantifierSetting = new AbstractQuantifierSetting(); quantifierSetting.firstContingencyTableRows = common.GetContingecyTable(this.taskType, taskID, hypothesisID, rowLiteral.literalIdentifier, rowLiteral.literalIdentifier); quantifierSetting.secondContingencyTableRows = new int[0][]; quantifierSetting.allObjectsCount = allObjectsCount; hypothesisStruct.quantifierSetting = quantifierSetting; hypothesesResult.Add(hypothesisStruct); } result = hypothesesResult.ToArray(); }
protected override void readResults(int taskID, long allObjectsCount, object taskDescription, out GeneratingStruct generation, out HypothesisStruct[] result) { generation = common.GetGeneratingStruct(taskID); List<HypothesisStruct> hypothesesResult = new List<HypothesisStruct>(); HypothesisStruct hypothesisStruct; AbstractQuantifierSetting quantifierSetting; DataTable hypothesis = common.ExecuteSelectQuery("SELECT * FROM tiHypothesisDF WHERE TaskID=" + taskID); foreach (DataRow hypothese in hypothesis.Rows) { hypothesisStruct = new HypothesisStruct(); hypothesisStruct.booleanLiterals = common.GetBooleanLiterals(taskID, Convert.ToInt32(hypothese["HypothesisID"])); hypothesisStruct.literals = new LiteralStruct[0]; quantifierSetting = new AbstractQuantifierSetting(); quantifierSetting.firstContingencyTableRows = new int[2][]; quantifierSetting.firstContingencyTableRows[0] = new int[2] { Convert.ToInt32(hypothese["FirstFreqA"]), Convert.ToInt32(hypothese["FirstFreqB"]) }; quantifierSetting.firstContingencyTableRows[1] = new int[2] { Convert.ToInt32(hypothese["FirstFreqC"]), Convert.ToInt32(hypothese["FirstFreqD"]) }; quantifierSetting.secondContingencyTableRows = new int[2][]; quantifierSetting.secondContingencyTableRows[0] = new int[2] { Convert.ToInt32(hypothese["SecondFreqA"]), Convert.ToInt32(hypothese["SecondFreqB"]) }; quantifierSetting.secondContingencyTableRows[1] = new int[2] { Convert.ToInt32(hypothese["SecondFreqC"]), Convert.ToInt32(hypothese["SecondFreqD"]) }; quantifierSetting.allObjectsCount = allObjectsCount; hypothesisStruct.quantifierSetting = quantifierSetting; hypothesesResult.Add(hypothesisStruct); } result = hypothesesResult.ToArray(); }
public void RunTask(object taskDescription, string boxIdentity, out GeneratingStruct generation, out HypothesisStruct[] result) { this.boxIdentity = boxIdentity; this.Prepare(); int taskID = saveTask(taskDescription, boxIdentity); long allObjectsCount; remap(taskDescription, boxIdentity, taskID, out allObjectsCount); /* * /DSN "<data-source-name>" ... data source name of metabase * /TaskID <TaskID> ... TaskID of selected task * /Quiet ... errors reported to _AppLog.dat instead on screen * /NoProgress ... no progress dialog is displayed * /TimeOut <sec> ... optional: time-out in seconds (approx.) after result * (exluding initialisation) is automatically interrupted * /ODBCConnectionString="ODBC;<odbc-data-source-connection-string>" * */ this.metabase.Connection.Close(); System.Diagnostics.ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.Arguments = " /ODBCConnectionString=\"ODBC;" + this.metabase.Connection.ConnectionString + "\"" + " /TaskID " + taskID + " /Quiet "; processStartInfo.FileName = Path.Combine( exeDirectoryName, exeFileName ); processStartInfo.WindowStyle = ProcessWindowStyle.Normal; Debug.WriteLine("*Gen process start at: " + DateTime.Now.ToString()); Process genProcess = Process.Start(processStartInfo); do { if (!genProcess.HasExited) { if (genProcess.Responding) Debug.WriteLine("Status = Running"); else Debug.WriteLine("Status = Not Responding"); } } while (!genProcess.WaitForExit(250)); int genProcessExitCode = genProcess.ExitCode; if (genProcessExitCode != 0) { throw Ferda.Modules.Exceptions.BoxRuntimeError(null, boxIdentity, "Process \"" + processStartInfo.FileName + " " + processStartInfo.Arguments + "\" exited with code " + genProcessExitCode.ToString()); } Debug.WriteLine("*Gen process exit at: " + DateTime.Now.ToString() + ", witch exit code: " + genProcessExitCode.ToString()); this.metabase.Connection.Open(); Debug.WriteLine("Reading of result start at: " + DateTime.Now.ToString()); readResults(taskID, allObjectsCount, taskDescription, out generation, out result); Debug.WriteLine("Reading of result finished at: " + DateTime.Now.ToString()); this.metabase.Connection.Close(); //this.FinalizeMe(); }
public HypothesesTI(HypothesisStruct[] hypothesisStructSeq) { this.hypothesesValue = hypothesisStructSeq; }
/// <summary> /// Drawing first contingency table to chart /// </summary> /// <param name="hypothese">Hypothese to take contingency table from</param> /// <param name="chart">Chart to draw bars into</param> private void DrawBarsFromSecondTable(HypothesisStruct hypothese, Steema.TeeChart.TChart chart) { chart.Series.Clear(); Random random = new Random(); bool fft = false; this.ContingencyTableChart.Header.Text = this.resManager.GetString("SecondContingencyTable"); //for miners with boolean antecedents and succedents - for now only 4ft foreach (BooleanLiteralStruct booleanLiteral in hypothese.booleanLiterals) { if ((booleanLiteral.cedentType == CedentEnum.Antecedent) || (booleanLiteral.cedentType == CedentEnum.Succedent)) { fft = true; break; } } // int i = 0; int j = 0; int[][] transpondedTable = FerdaResultBrowserControl.Transpose(hypothese.quantifierSetting.secondContingencyTableRows); for (int k = transpondedTable.GetUpperBound(0); k >=0; k--) { Steema.TeeChart.Styles.Bar barSeries = new Steema.TeeChart.Styles.Bar(); barSeries.Color = System.Drawing.Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)); barSeries.MultiBar = Steema.TeeChart.Styles.MultiBars.None; foreach (int number in transpondedTable[k]) { if ((fft) && (j == 0)) { barSeries.Add(number, this.resManager.GetString("ColumnAntecedent")); } else { if ((fft) && (j == 1)) { barSeries.Add(number, '\u00AC' + this.resManager.GetString("ColumnAntecedent")); } else { string seriesTitle = String.Empty; foreach (LiteralStruct literal in hypothese.literals) { if (literal.cedentType == CedentEnum.Antecedent) { if (literal.categoriesNames.Length > j) { seriesTitle = literal.categoriesNames[j]; } } } barSeries.Add(number, seriesTitle); } } j++; } if (this.CheckBoxShowLabels.Checked) { barSeries.Marks.Visible = true; } else { barSeries.Marks.Visible = false; } barSeries.Marks.Style = Steema.TeeChart.Styles.MarksStyles.LabelValue; if (fft) { if (k == 0) { barSeries.Title = this.resManager.GetString("ColumnSuccedent"); } else { barSeries.Title = '\u00AC' + this.resManager.GetString("ColumnSuccedent"); } } else { string seriesTitle = String.Empty; foreach (LiteralStruct literal in hypothese.literals) { if (literal.cedentType == CedentEnum.Succedent) { if (literal.categoriesNames.Length > k) { seriesTitle = literal.categoriesNames[k]; } break; } } if (seriesTitle == String.Empty) { foreach (LiteralStruct literal in hypothese.literals) { if (literal.cedentType == CedentEnum.Antecedent) { if (literal.categoriesNames.Length > k) { seriesTitle = literal.categoriesNames[k]; } } } } barSeries.Title = seriesTitle; } chart.Series.Add(barSeries); // i++; j = 0; } }
protected abstract void readResults(int taskID, long allObjectsCount, object taskDescription, out GeneratingStruct generation, out HypothesisStruct[] result);
/// <summary> /// Class constructor /// </summary> /// <param name="localePrefs">Localeprefs</param> /// <param name="hypotheses">Hypotheses to display</param> /// <param name="used_quantifiers">Used quantifiers</param> /// <param name="Displayer">Propertygrid</param> /// <param name="statisticsProxies">Statistics proxies</param> public FerdaResultBrowserControl(string[] localePrefs, HypothesisStruct[] hypotheses, QuantifierProvider[] used_quantifiers, IOtherObjectDisplayer Displayer, List<Ferda.Statistics.StatisticsProviderPrx> statisticsProxies, string taskType, IOwnerOfAddIn ownerOfAddIn) { //setting the ResManager resource manager and localization string string locale; try { locale = localePrefs[0]; localizationString = locale; locale = "Ferda.FrontEnd.AddIns.ResultBrowser.Localization_" + locale; resManager = new ResourceManager(locale, Assembly.GetExecutingAssembly()); } catch { resManager = new ResourceManager("Ferda.FrontEnd.AddIns.ResultBrowser.Localization_en-US", Assembly.GetExecutingAssembly()); localizationString = "en-US"; } this.ownerOfAddIn = ownerOfAddIn; columnSorter.column = 0; InitializeComponent(); InitializeGraph(); this.hypothesesCount = hypotheses.Length; this.taskType = taskType; resultBrowser = new FerdaResult(resManager); resultBrowser.IceTicked += new LongRunTick(resultBrowser_IceTicked); resultBrowser.IceComplete += new LongRunCompleted(resultBrowser_IceComplete); //setting locale this.ChangeLocale(this.resManager); this.displayer = Displayer; this.displayer.Reset(); this.PreloadDisable(); resultBrowser.Initialize(hypotheses, used_quantifiers, statisticsProxies); if ((this.taskType == "LISpMinerTasks.KLTask") || (this.taskType == "LISpMinerTasks.CFTask") || (this.taskType == "LISpMinerTasks.FFTTask")) { RadioFirstTable.Visible = false; RadioSecondTable.Visible = false; } }
/// <summary> /// Method to initialize the ResultBrowser structure /// </summary> /// <param name="hypotheses"></param> public void Initialize(HypothesisStruct[] hypotheses, QuantifierProvider[] used_quantifiers, List<Ferda.Statistics.StatisticsProviderPrx> statisticsProxies) { this.Hypotheses = hypotheses; this.statisticsProxies = statisticsProxies; //working with quantifiers - need to obtain all quantifier, for now working only with used ones this.UsedQuantifiers = used_quantifiers; this.SelectedQuantifiers = new int[this.UsedQuantifiers.Length]; for (int i = 0; i < this.SelectedQuantifiers.Length; i++) { this.SelectedQuantifiers[i] = 0; } proxy = new AbstractQuantifierFunctionsPrx[this.UsedQuantifiers.Length]; for (int i = 0; i < this.UsedQuantifiers.Length; i++) { this.proxy[i] = this.UsedQuantifiers[i].functions; } #region Caching //caching statistics names this.cachedStatisticsNames = this.GetStatisticsNames(); //initializing hypotheses cache this.cachedHypotheses = new CachedHypothesis[this.Hypotheses.Length]; Thread IceCommunicationThread = new Thread(new ThreadStart(IceCommunication)); IceCommunicationThread.Start(); #endregion }
/// <summary> /// Sets the hypotheses. /// </summary> /// <param name="boxModule">The box module.</param> /// <param name="value">The value.</param> public static void SetHypotheses(BoxModuleI boxModule, HypothesisStruct[] value) { HypothesesTI newValue = new HypothesesTI(value); boxModule.setProperty("Hypotheses", newValue); }
/// <summary> /// Method which applies all quantifiers on the hypothese contingency table /// </summary> /// <param name="hypothese"></param> /// <returns>Arraylist of values</returns> public List<double> AllQuantifierValues(HypothesisStruct hypothese) { return this.CountAllQuantifiers(hypothese); }
/// <summary> /// Method to get hypothesis contingency table /// </summary> /// <param name="hypothese">Hypothese to take the table from</param> /// <returns>Formatted string containing contingency table</returns> public String GetHypothesisTable(HypothesisStruct hypothese) { StringBuilder returnString = new StringBuilder(); foreach (int[] arr in hypothese.quantifierSetting.firstContingencyTableRows) { foreach (int value in arr) { returnString.Append(value.ToString() + "\t"); } returnString.Append("\n"); } foreach (int[] arr in hypothese.quantifierSetting.secondContingencyTableRows) { foreach (int value in arr) { returnString.Append(value.ToString() + "\t"); } returnString.Append("\n"); } return returnString.ToString(); }
/// <summary> /// Method to decide whether the hypothesis is of 4-ft miner /// </summary> /// <param name="hypothesis">Hypothesis to check</param> /// <returns>True if hypothesis is from 4ft</returns> public static bool IsFFT(HypothesisStruct hypothesis) { foreach (BooleanLiteralStruct booleanLiteral in hypothesis.booleanLiterals) { if ((booleanLiteral.cedentType == CedentEnum.Antecedent) || (booleanLiteral.cedentType == CedentEnum.Succedent)) { return true; } } return false; }
/// <summary> /// Function to get a string value for succedent /// </summary> /// <param name="hypothese">Hypothese to extract value from</param> /// <returns>String value with succedent</returns> public static String GetSuccedentString(HypothesisStruct hypothese) { StringBuilder returnString = new StringBuilder(); bool firstRun = true; bool boolCedent = false; if (hypothese.literals.Length > 0) { foreach (LiteralStruct literal in hypothese.literals) { if (literal.cedentType == CedentEnum.Succedent) { returnString.Append(literal.literalName); } } } else { boolCedent = true; foreach (BooleanLiteralStruct literal in hypothese.booleanLiterals) { if (literal.cedentType == CedentEnum.Succedent) { if (!firstRun) { returnString.Append(") & "); } if (literal.negation) { returnString.Append('\u00AC' + literal.literalName + "("); } else { returnString.Append(literal.literalName + "("); } foreach (String category in literal.categoriesNames) { returnString.Append(category.ToString()); } firstRun = false; } } } if (returnString.Length == 0) { return String.Empty; } else { if (boolCedent) returnString.Append(")"); return returnString.ToString(); } }
/// <summary> /// Method to compose hypothesis name /// </summary> /// <param name="hypothese">Hypothese </param> /// <returns></returns> public static String GetHypothesisName(HypothesisStruct hypothesis) { StringBuilder returnString = new StringBuilder(); if (hypothesis.literals.Length > 0) { string temp, temp1; temp = temp1 = String.Empty; temp = FerdaResult.GetAntecedentString(hypothesis); temp1 = FerdaResult.GetSuccedentString(hypothesis); if (temp != String.Empty) { if (temp1 != String.Empty) { returnString.Append(temp + " " + '\u00D7' + " " + temp1); } else { returnString.Append(temp); } } else { if (temp1 != String.Empty) { returnString.Append(temp1); } else { returnString.Append(String.Empty); } } } else { returnString.Append(FerdaResult.GetAntecedentString(hypothesis) + '\u2022' + '\u2022' + FerdaResult.GetSuccedentString(hypothesis)); } if (!FerdaResult.GetConditionString(hypothesis).Equals("")) { returnString.Append(" \\ " + FerdaResult.GetConditionString(hypothesis)); } return returnString.ToString(); }
/// <summary> /// Method which check whether the given hypothesis matches current filter settings /// </summary> /// <param name="hypothesis">Hypothesis to check</param> /// <returns>True if hypothesis matches</returns> private bool HypothesisIsValid(HypothesisStruct hypothesis) { LiteralFilter filter; //initialize structure List<string> antecedentLiteralsList = new List<string>(); List<string> succedentLiteralsList = new List<string>(); List<string> conditionLiteralsList = new List<string>(); foreach (BooleanLiteralStruct booleanLiteral in hypothesis.booleanLiterals) { switch (booleanLiteral.cedentType) { case CedentEnum.Antecedent: if (!antecedentLiteralsList.Contains(booleanLiteral.literalName)) { antecedentLiteralsList.Add(booleanLiteral.literalName); } break; case CedentEnum.Succedent: if (!succedentLiteralsList.Contains(booleanLiteral.literalName)) { succedentLiteralsList.Add(booleanLiteral.literalName); } break; case CedentEnum.Condition: if (!conditionLiteralsList.Contains(booleanLiteral.literalName)) { conditionLiteralsList.Add(booleanLiteral.literalName); } break; default: break; } } foreach (LiteralStruct literal in hypothesis.literals) { switch (literal.cedentType) { case CedentEnum.Antecedent: if (!antecedentLiteralsList.Contains(literal.literalName)) { antecedentLiteralsList.Add(literal.literalName); } break; case CedentEnum.Succedent: if (!succedentLiteralsList.Contains(literal.literalName)) { succedentLiteralsList.Add(literal.literalName); } break; case CedentEnum.Condition: if (!conditionLiteralsList.Contains(literal.literalName)) { conditionLiteralsList.Add(literal.literalName); } break; default: break; } } //check antecedent foreach (string literal in antecedentLiteralsList) { if (antecedentFilter.TryGetValue(literal, out filter)) { if (!filter.Selected) { return false; } } } //check succedent foreach (string literal in succedentLiteralsList) { if (succedentFilter.TryGetValue(literal, out filter)) { if (!filter.Selected) { return false; } } } //check condition foreach (string literal in conditionLiteralsList) { if (conditionFilter.TryGetValue(literal, out filter)) { if (!filter.Selected) { return false; } } } return true; }
/// <summary> /// Method which applies all quantifiers on the contingency table data. /// </summary> /// <param name="hypothese">Hypothese to take tables from</param> /// <returns>List of values for each quantifier</returns> private List<double> CountAllQuantifiers(HypothesisStruct hypothese) { List<double> returnList = new List<double>(); for (int i = 0; i < this.UsedQuantifiers.Length; i++) { returnList.Add(this.proxy[i].Value(hypothese.quantifierSetting)); } return returnList; }