Changeset 15900 for branches/2911_TSQLSymbolicExpressionFormatter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/TSQLExpressionFormatter.cs
- Timestamp:
- 04/13/18 10:25:22 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2911_TSQLSymbolicExpressionFormatter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/TSQLExpressionFormatter.cs
r15881 r15900 83 83 84 84 //Generate comment and instructions 85 strBuilder.Append( $"-- generated. created function can be used like 'SELECT dbo.REGRESSIONMODEL(");85 strBuilder.Append("-- generated. created function can be used like 'SELECT dbo.REGRESSIONMODEL("); 86 86 strBuilder.Append(string.Join(", ", sortedVarcharIdentifiers)); 87 87 if (varcharVarNames.Any() && floatVarNames.Any()) … … 89 89 strBuilder.Append(string.Join(", ", sortedFloatIdentifiers)); 90 90 strBuilder.AppendLine(")'"); 91 strBuilder.AppendLine( $"-- use the expression after the RETURN statement if you want to incorporate the model in a query without creating a function.");91 strBuilder.AppendLine("-- use the expression after the RETURN statement if you want to incorporate the model in a query without creating a function."); 92 92 93 93 //Generate function header 94 strBuilder.Append( $"CREATE FUNCTION dbo.REGRESSIONMODEL(");95 strBuilder.Append(string.Join(", ", sortedVarcharIdentifiers.Select(n => $"{n} NVARCHAR(max)")));94 strBuilder.Append("CREATE FUNCTION dbo.REGRESSIONMODEL("); 95 strBuilder.Append(string.Join(", ", sortedVarcharIdentifiers.Select(n => String.Format("{0} NVARCHAR(max)",n)))); 96 96 if (varcharVarNames.Any() && floatVarNames.Any()) 97 97 strBuilder.Append(","); 98 strBuilder.Append(string.Join(", ", sortedFloatIdentifiers.Select(n => $"{n} FLOAT")));98 strBuilder.Append(string.Join(", ", sortedFloatIdentifiers.Select(n => String.Format("{0} FLOAT",n)))); 99 99 strBuilder.AppendLine(")"); 100 100 … … 104 104 105 105 //add variable declaration for convenience 106 strBuilder.AppendLineIndented(1, $"-- added variable declaration for convenience");106 strBuilder.AppendLineIndented(1, "-- added variable declaration for convenience"); 107 107 foreach (var name in sortedVarcharIdentifiers) 108 strBuilder.AppendLineIndented(1, $"-- DECLARE {name} NVARCHAR(max) = ''");108 strBuilder.AppendLineIndented(1, String.Format("-- DECLARE {0} NVARCHAR(max) = ''", name)); 109 109 foreach (var name in sortedFloatIdentifiers) 110 strBuilder.AppendLineIndented(1, $"-- DECLARE {name} FLOAT = 0.0");111 strBuilder.AppendLineIndented(1, $"-- SELECT");110 strBuilder.AppendLineIndented(1, String.Format("-- DECLARE {0} FLOAT = 0.0", name)); 111 strBuilder.AppendLineIndented(1, "-- SELECT"); 112 112 strBuilder.AppendLine("RETURN "); 113 113 } … … 142 142 FormatOperator(level, node, "OR", strBuilder); 143 143 } else if (node.Symbol is Xor) { 144 throw new NotSupportedException( $"Symbol {node.Symbol.GetType().Name} not yet supported.");144 throw new NotSupportedException(String.Format("Symbol {0} not yet supported.", node.Symbol.GetType().Name)); 145 145 } else if (node.Symbol is Sine) { 146 146 FormatFunction(level, node, "SIN", strBuilder); … … 172 172 } else if (node.Symbol is BinaryFactorVariable) { 173 173 var binFactorNode = node as BinaryFactorVariableTreeNode; 174 throw new NotSupportedException( $"Symbol {node.Symbol.GetType().Name} not yet supported.");174 throw new NotSupportedException(String.Format("Symbol {0} not yet supported.", node.Symbol.GetType().Name)); 175 175 } else { 176 176 throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for TSQL symbolic expression tree formatter."); … … 199 199 strBuilder.Append(" + "); 200 200 } 201 strBuilder.Append ($") / {node.Subtrees.Count()}");201 strBuilder.AppendFormat(") / {0}", node.Subtrees.Count()); 202 202 } 203 203 204 204 private string VariableName2Identifier(string variableName) { 205 return $"@{variableName.Replace(' ', '_')}";205 return "@"+variableName.Replace(' ', '_'); 206 206 } 207 207 208 208 private void GenerateFooter(StringBuilder strBuilder) { 209 strBuilder.AppendLine($"{Environment.NewLine}END"); 209 strBuilder.Append(Environment.NewLine); 210 strBuilder.AppendLine("END"); 210 211 } 211 212 … … 265 266 266 267 private void FormatFactor(int level, FactorVariableTreeNode node, StringBuilder strBuilder) { 267 strBuilder.AppendLine( $"( ");268 strBuilder.AppendLineIndented(level + 1, $"CASE {VariableName2Identifier(node.VariableName)}");268 strBuilder.AppendLine("( "); 269 strBuilder.AppendLineIndented(level + 1, String.Format("CASE {0}", VariableName2Identifier(node.VariableName))); 269 270 foreach (var name in node.Symbol.GetVariableValues(node.VariableName)) { 270 strBuilder.AppendLineIndented(level + 2, $"WHEN '{name}' THEN {node.GetValue(name).ToString(CultureInfo.InvariantCulture)}");271 strBuilder.AppendLineIndented(level + 2, String.Format("WHEN '{0}' THEN {1}", name, node.GetValue(name).ToString(CultureInfo.InvariantCulture))); 271 272 } 272 273 strBuilder.AppendLineIndented(level + 1, "ELSE NULL END");
Note: See TracChangeset
for help on using the changeset viewer.