/// <summary> /// check if the relation is transitive /// </summary> /// <param name="path">path so far</param> /// <param name="operatorID">Given operator</param> /// <param name="symbolID1">from symbol A</param> /// <param name="symbolID2">to symbol B</param> /// <param name="limitOfResults">Maximum capacity accepted for the result set</param> /// <returns>the symbols succession from A to B</returns> public List<SymbolID> IsTransitive(List<SymbolID> path, OperatorID operatorID, SymbolID symbolID1, SymbolID symbolID2, int limitOfResults) { System.Diagnostics.StackTrace stackTrace0 = new System.Diagnostics.StackTrace(); LoggingSystem.BranchName = stackTrace0.GetFrame(0).GetMethod().Name; List<SymbolID> LocalReturnList = new List<SymbolID>(); List<SymbolID> returnList = new List<SymbolID>(); bool solved = false; try { string commandString; if (false) // ($t1[0]=='?x') { commandString = "SELECT `ID`, `g`, `h` FROM `" + DB + "`.`s" + symbolID1.Location.A.ToString("") + "` WHERE `a` = " + symbolID1.Location.A + " AND `c` LIKE " + operatorID.Location.Var + " AND `e` = " + symbolID2.Location.A + " "; } else { commandString = "SELECT `ID`, `g`, `h` FROM `" + DB + "`.`s" + symbolID1.Location.A.ToString("") + "` WHERE `a` = " + symbolID1.Location.A + " AND `c` = " + operatorID.Location.Var + " AND `e` = " + symbolID2.Location.A + " "; } if (limitOfResults > 0) { commandString += " Limit " + limitOfResults; } MySql.Data.MySqlClient.MySqlCommand mySqlCommand = new MySqlCommand(commandString, mySQLConnection); MySqlDataReader myReader = mySqlCommand.ExecuteReader(); if (MySqlTrace) SQLView.Log(mySqlCommand.CommandText); if (myReader.HasRows) { solved = true; while (myReader.Read()) { if (!string.IsNullOrEmpty(myReader.GetString(0))) { int[] multipplicity = new int[] {0, 0 }; int.TryParse(myReader.GetString(1), out multipplicity[0]); int.TryParse(myReader.GetString(2), out multipplicity[1]); //if (multipplicity[0] != 0 || multipplicity[1] != 0) //{ // ReturnList.Add(symbID); //} SymbolID symbID = new SymbolID(); symbID.Location.A = symbolID1.Location.A; int.TryParse(myReader.GetString(0), out symbID.Location.A); int.TryParse(myReader.GetString(1), out symbID.Location.B); //int.TryParse(myReader.GetString(2), out symbID[3]); if (symbID.Exists) { returnList.Add(symbID); } } } myReader.Close(); } else { myReader.Close(); if (true) // ($t1[0]=='?x') { commandString = "SELECT `ID`, `e`, `f`, `g`, `h` FROM `" + DB + "`.`s" + symbolID1.Location.A.ToString("") + "` WHERE `a` = " + symbolID1.Location.A + " AND `c` = " + operatorID.Location.IR + " "; } else { commandString = "SELECT `ID`, `e`, `f`, `g`, `h` FROM `" + DB + "`.`s" + symbolID1.Location.A.ToString("") + "` WHERE `a` = " + symbolID1.Location.A + " AND `c`< 5000 "; } if (limitOfResults > 0) { commandString += " Limit " + limitOfResults; } MySql.Data.MySqlClient.MySqlCommand mySqlCommand2 = new MySqlCommand(commandString, mySQLConnection); MySqlDataReader myReader2 = mySqlCommand2.ExecuteReader(); if (MySqlTrace) SQLView.Log(mySqlCommand2.CommandText); List<SymbolID> toTry = new List<SymbolID>(); while (myReader2.Read()) { if (!string.IsNullOrEmpty(myReader2.GetString(0))) { SymbolID symbID = new SymbolID(); int.TryParse(myReader2.GetString(0), out symbID.Location.A); int.TryParse(myReader2.GetString(1), out symbID.Location.B); //int.TryParse(myReader2.GetString(2), out symbID[2]); if (symbID.Exists) { toTry.Add(symbID); } } } myReader2.Close(); for (int i = 0; i < toTry.Count; i++) { if (!solved) { foreach (SymbolID symbID in toTry) { if (symbID.Exists) { SymbolID newSymbolID = symbID; LocalReturnList = IsTransitive(LocalReturnList, operatorID, newSymbolID, symbolID2, limitOfResults); } if (LocalReturnList.Count > 0) { //int[] ToAdd = new int[] { a[0], symbID[0] }; //ReturnList.Add(new int[] { symbID[1], symbID[2] }); SymbolID newSymbolID = symbID; newSymbolID.Location.A = symbolID1.Location.A; newSymbolID.Location.B = symbID.Location.A; returnList.Add(newSymbolID); returnList.AddRange(LocalReturnList); solved = true; } } } } } } catch (MySqlException retrieveSymbolIndexException) { Console.WriteLine("Error: {0}", retrieveSymbolIndexException.ToString()); } if (MyResultsTrace) { string ResultLog = ""; foreach (SymbolID i in returnList) { ResultLog += " [" + i.Location.A + ":" + i.Location.B + "]"; } SQLView.LogResult(new string[] { ResultLog }); } #region LOG //=== CUSTOM LOGGER=================================================================================== ElementMethod thisMethod = new ElementMethod(); int logLevel = -1; if (logingOptions != null) logLevel = logingOptions.levelNumbers; if (logLevel >= 3) // code { System.Diagnostics.StackTrace stackTrace; System.Diagnostics.StackFrame fr; stackTrace = new System.Diagnostics.StackTrace(); fr = stackTrace.GetFrame(0); thisMethod.ElementNamespaceName = this.GetType().Namespace; thisMethod.ElementClassName = this.GetType().Name; string methodName = fr.GetMethod().ToString(); thisMethod.ElementName = fr.GetMethod().Name; thisMethod.ReturnType = methodName.Substring(0, methodName.IndexOf(" ")); } if (logLevel >= 2) // parameters { // , , int[] , int[] , int[] , int[] , int thisMethod.Parameters.Add(new string[] { "List<int[]> path", path.ToString() }); thisMethod.Parameters.Add(new string[] { "int[] relationID", operatorID.ToString() }); thisMethod.Parameters.Add(new string[] { "int[] symbolID1", symbolID1.ToString() }); thisMethod.Parameters.Add(new string[] { "int[] symbolID2", symbolID2.ToString() }); thisMethod.Parameters.Add(new string[] { "int limitOfResults", limitOfResults.ToString() }); } if (logLevel >= 1) // results { string result = string.Empty; foreach (SymbolID symbolItem in returnList) { result += "{" + symbolItem.ToString() + "}"; } thisMethod.Result = result; } LoggingSystem.LogMethod = thisMethod; //==================================================================================================== #endregion LOG return returnList; }
/// <summary> /// Get the names of the given operatorIDs /// </summary> /// <param name="operatorID">OperatorIDs to look for</param> /// <param name="limitOfResults">Maximum capacity accepted for the result set</param> /// <returns>ResultSet: A List of the given operator`s names</returns> public List<string> GetOperatorNamesByID(OperatorID operatorID, int limitOfResults = 10) { // Start logging System.Diagnostics.StackTrace stackTrace0 = new System.Diagnostics.StackTrace(); LoggingSystem.BranchName = stackTrace0.GetFrame(0).GetMethod().Name; // Prepare result set List<string> resultedOperatorNames = new List<string>(); try { string commandString; commandString = "SELECT `En` FROM `" + DB + "`.`srel` WHERE `IR` = " + operatorID.Location.IR + " AND `Var` = " + operatorID.Location.Var + " AND `IR2` = " + operatorID.Location.IR2 + " AND `Var2` = " + operatorID.Location.Var2 + " "; if (limitOfResults != 0) { commandString += " Limit " + limitOfResults + " "; } MySql.Data.MySqlClient.MySqlCommand mySqlCommand = new MySqlCommand(commandString, mySQLConnection); if (MySqlTrace) SQLView.Log(mySqlCommand.CommandText); MySqlDataReader myReader = mySqlCommand.ExecuteReader(); while (myReader.Read()) { if (!string.IsNullOrEmpty(myReader.GetString(0))) { string symbolName; symbolName = myReader.GetString(0).ToString(); if (!string.IsNullOrEmpty(symbolName)) { resultedOperatorNames.Add(symbolName); } } } myReader.Close(); } catch (MySqlException retrieveSymbolIndexException) { Console.WriteLine("Error: {0}", retrieveSymbolIndexException.ToString()); } if (MyResultsTrace) { string ResultLog = ""; foreach (string i in resultedOperatorNames) { ResultLog += "" + i + ""; } SQLView.LogResult(new string[] { ResultLog }); } #region LOG //=== CUSTOM LOGGER=================================================================================== ElementMethod thisMethod = new ElementMethod(); int logLevel = -1; if (logingOptions != null) logLevel = logingOptions.levelNumbers; if (logLevel >= 3) // code { System.Diagnostics.StackTrace stackTrace; System.Diagnostics.StackFrame fr; stackTrace = new System.Diagnostics.StackTrace(); fr = stackTrace.GetFrame(0); thisMethod.ElementNamespaceName = this.GetType().Namespace; thisMethod.ElementClassName = this.GetType().Name; string methodName = fr.GetMethod().ToString(); thisMethod.ElementName = fr.GetMethod().Name; thisMethod.ReturnType = methodName.Substring(0, methodName.IndexOf(" ")); } if (logLevel >= 2) // parameters { thisMethod.Parameters.Add(new string[] { "int[] operatorID", operatorID.ToString() }); thisMethod.Parameters.Add(new string[] { "int limitOfResults", limitOfResults.ToString() }); } if (logLevel >= 1) // results { string result = string.Empty; foreach (string symbolItem in resultedOperatorNames) { result += "{" + symbolItem.ToString() + "}"; } thisMethod.Result = result; } LoggingSystem.LogMethod = thisMethod; //==================================================================================================== #endregion LOG return resultedOperatorNames; }
/// <summary> /// Get the proprieties of a symbol restricted to a relation type if provided /// </summary> /// <param name="operatorID">The relation to restrict the resultset if provided</param> /// <param name="multiplicationOrder">the multiplication order requested if provided</param> /// <param name="symbolID">The symbolID to expore for properties</param> /// <param name="limitOfResults">>Maximum capacity accepted for the result set</param> /// <returns>ResultSet: The descriptopn of the given symbol restricted to the relation if provided</returns> public List<SymbolID> GetContent(OperatorID operatorID, SymbolID symbolID, int limitOfResults) { // TODO Use multiplicationOrder parameter // Start logging System.Diagnostics.StackTrace stackTrace0 = new System.Diagnostics.StackTrace(); LoggingSystem.BranchName = stackTrace0.GetFrame(0).GetMethod().Name; // Prepare result set List<SymbolID> resultedSymbolIDs = new List<SymbolID>(); try { string commandString = string.Empty; if (operatorID.hasMultiplicity) { commandString = "SELECT `e`, `f` FROM `" + DB + "`.`s" + symbolID.Location.A.ToString() + "` WHERE `a` = " + symbolID.Location.A + " AND `b` = " + symbolID.Location.B + " AND `c` = " + operatorID.Location.IR + " AND `d` = " + operatorID.Location.Var + " "; } else { commandString = "SELECT `e`, `f` FROM `" + DB + "`.`s" + symbolID.Location.A.ToString() + "` WHERE `a` = " + symbolID.Location.A + " AND `b` = " + symbolID.Location.B + " AND `c` = " + operatorID.Location.IR +" AND `d` = " + operatorID.Location.Var + " "; // commandString = "SELECT `e`, `f` FROM `" + DB + "`.`s" + symbolID.Location.A.ToString() + "` WHERE `a` = " + symbolID.Location.A + " AND `b` = " + symbolID.Location.B + " "; } if (limitOfResults != 0) { commandString += " Limit " + limitOfResults; } MySql.Data.MySqlClient.MySqlCommand mySqlCommand = new MySqlCommand(commandString, mySQLConnection); if (MySqlTrace) SQLView.Log(mySqlCommand.CommandText); MySqlDataReader myReader = mySqlCommand.ExecuteReader(); while (myReader.Read()) { if (!string.IsNullOrEmpty(myReader.GetString(0))) { SymbolID newSymbolID = new SymbolID(); int.TryParse(myReader.GetString(0), out newSymbolID.Location.A); try { int.TryParse(myReader.GetString(1), out newSymbolID.Location.B); } catch { } //int.TryParse(myReader.GetString(2), out symbID[2]); //int.TryParse(myReader.GetString(3), out symbID[3]); if (newSymbolID.Exists) { resultedSymbolIDs.Add(newSymbolID); } } } myReader.Close(); } catch (MySqlException retrieveSymbolIndexException) { Console.WriteLine("Error: {0}", retrieveSymbolIndexException.ToString()); } if (MyResultsTrace) { string ResultLog = ""; foreach (SymbolID itemSymbolID in resultedSymbolIDs) { ResultLog += " [" + itemSymbolID.Location.A + ":" + itemSymbolID.Location.B + "]"; } SQLView.LogResult(new string[] { ResultLog }); } #region LOG //=== CUSTOM LOGGER=================================================================================== ElementMethod thisMethod = new ElementMethod(); int logLevel = -1; if (logingOptions != null) logLevel = logingOptions.levelNumbers; if (logLevel >= 3) // code { System.Diagnostics.StackTrace stackTrace; System.Diagnostics.StackFrame fr; stackTrace = new System.Diagnostics.StackTrace(); fr = stackTrace.GetFrame(0); thisMethod.ElementNamespaceName = this.GetType().Namespace; thisMethod.ElementClassName = this.GetType().Name; string methodName = fr.GetMethod().ToString(); thisMethod.ElementName = fr.GetMethod().Name; thisMethod.ReturnType = methodName.Substring(0, methodName.IndexOf(" ")); } if (logLevel >= 2) // parameters { thisMethod.Parameters.Add(new string[] { "int[] relationID", operatorID.ToString() }); thisMethod.Parameters.Add(new string[] { "int[] symbolID", symbolID.ToString() }); thisMethod.Parameters.Add(new string[] { "int limitOfResults", limitOfResults.ToString() }); } if (logLevel >= 1) // results { string result = string.Empty; foreach (SymbolID itemSymbolID in resultedSymbolIDs) { result += "{" + itemSymbolID.ToString() + "}"; } thisMethod.Result = result; } LoggingSystem.LogMethod = thisMethod; //==================================================================================================== #endregion LOG return resultedSymbolIDs; }
/// <summary> /// Create new relation /// </summary> /// <param name="operatorID">relation type</param> /// <param name="symbolID1">preoperand symbol</param> /// <param name="symbolID2">postoperand symbol</param> /// <returns>ResultSet: The new created relation</returns> public List<SymbolID> CreateRelation(OperatorID operatorID, SymbolID symbolID1, SymbolID symbolID2) { System.Diagnostics.StackTrace stackTrace0 = new System.Diagnostics.StackTrace(); LoggingSystem.BranchName = stackTrace0.GetFrame(0).GetMethod().Name; List<SymbolID> relationPositions = new List<SymbolID>(); SymbolID relationPosition = new SymbolID(); try { string commandString = commandString = "INSERT INTO `" + DB + "`.`s" + symbolID2.Location.A.ToString("") + "` (`a`, `b`, `c`, `d`, `e`, `f`) VALUES (" + symbolID2.Location.A + ", " + symbolID2.Location.B + "," + operatorID.Location.IR2 + ", " + operatorID.Location.Var2 + "," + symbolID1.Location.A + ", " + symbolID1.Location.A + ", " + operatorID.Location.IR2 + ", " + operatorID.Location.Var2 + " ) ;"; //string commandString = commandString = "INSERT INTO `" + DB + "`.`s" + symbolID2[0].ToString() + "` (`a`, `b`, `c`, `d`, `e`, `f`, `g`, `h`) VALUES (" + symbolID2[0] + ", " + symbolID2[1] + "," + relationID[4] + ", " + relationID[5] + "," + symbolID1[0] + ", " + symbolID1[1] + ", " + relationID[2] + ", " + relationID[3] + " ) ;"; MySql.Data.MySqlClient.MySqlCommand mySqlCommand = new MySqlCommand(commandString, mySQLConnection); //if (mySQLConnection. mySqlCommand.ExecuteNonQuery(); if (MySqlTrace) SQLView.Log(mySqlCommand.CommandText); commandString = commandString = "INSERT INTO `" + DB + "`.`s" + symbolID1.Location.A.ToString("") + "` (`a`, `b`, `c`, `d`, `e`, `f`) VALUES (" + symbolID1.Location.A + ", " + symbolID1.Location.B + ", " + operatorID.Location.IR + ", " + operatorID.Location.Var + ", " + symbolID2.Location.A + ", " + symbolID2.Location.B + ", " + operatorID.Location.IR2 + ", " + operatorID.Location.Var2 + " ) ;"; //commandString = commandString = "INSERT INTO `" + DB + "`.`s" + symbolID1[0].ToString() + "` (`a`, `b`, `c`, `d`, `e`, `f`, `g`, `h`) VALUES (" + symbolID1[0] + ", " + symbolID1[1] + ", " + relationID[0] + ", " + relationID[1] + ", " + symbolID2[0] + ", " + symbolID2[1] + ", " + relationID[2] + ", " + relationID[3] + " ) ;"; mySqlCommand = new MySqlCommand(commandString, mySQLConnection); mySqlCommand.ExecuteNonQuery(); if (MySqlTrace) SQLView.Log(mySqlCommand.CommandText); if (mySqlCommand.LastInsertedId > 0) { relationPosition.Location.A = symbolID1.Location.A; relationPosition.Location.B = (int)mySqlCommand.LastInsertedId; } } catch (MySqlException retrieveRelationIndexException) { Console.WriteLine("Error: {0}", retrieveRelationIndexException.ToString()); } if (MyResultsTrace) SQLView.LogResult(relationPosition.ToString()); relationPositions.Add(relationPosition); #region LOG //=== CUSTOM LOGGER=================================================================================== ElementMethod thisMethod = new ElementMethod(); int logLevel = -1; if (logingOptions != null) logLevel = logingOptions.levelNumbers; if (logLevel >= 3) // code { System.Diagnostics.StackTrace stackTrace; System.Diagnostics.StackFrame fr; stackTrace = new System.Diagnostics.StackTrace(); fr = stackTrace.GetFrame(0); thisMethod.ElementNamespaceName = this.GetType().Namespace; thisMethod.ElementClassName = this.GetType().Name; string methodName = fr.GetMethod().ToString(); thisMethod.ElementName = fr.GetMethod().Name; thisMethod.ReturnType = methodName.Substring(0, methodName.IndexOf(" ")); } if (logLevel >= 2) // parameters { thisMethod.Parameters.Add(new string[] { "int[] relationID", operatorID.ToString() }); // thisMethod.Parameters.Add(new string[] { "int[] multiplicityA", ArrayToString(multiplicityA) }); thisMethod.Parameters.Add(new string[] { "int[] symbolID1", symbolID1.ToString() }); // thisMethod.Parameters.Add(new string[] { "int[] multiplicityB", ArrayToString(multiplicityB) }); thisMethod.Parameters.Add(new string[] { "int[] symbolID2", symbolID2.ToString() }); } if (logLevel >= 1) // results { string result = string.Empty; foreach (SymbolID symbolItem in relationPositions) { result += "{" + symbolItem.Location.ToString() + "}"; } thisMethod.Result = result; } LoggingSystem.LogMethod = thisMethod; //==================================================================================================== #endregion LOG return relationPositions; }