コード例 #1
0
 private void Serialize_Recursive(StringBuilder sb, TextIdMapper classToClassId, TextIdMapper wordToWordId, int depth)
 {
     // If is is a leaf node, ...
     if (TrueBranch == null && FalseBranch == null)
     {
         string path = GetPath(wordToWordId);
         sb.AppendFormat("{0} {1}", path, FeatureVectors.Count);
         double[] distribution = GetDistributionByClass();
         for (int i = 0; i < distribution.Length; i++)
         {
             sb.AppendFormat(" {0} {1}", classToClassId[i], distribution[i]);
         }
         sb.AppendLine();
     }
     // If it is not a leaf node, ...
     else
     {
         if (FalseBranch != null)
         {
             FalseBranch.Serialize_Recursive(sb, classToClassId, wordToWordId, depth + 1);
         }
         if (TrueBranch != null)
         {
             TrueBranch.Serialize_Recursive(sb, classToClassId, wordToWordId, depth + 1);
         }
     }
 }
コード例 #2
0
ファイル: If.cs プロジェクト: thomasio101/Yolol
        public override string ToString()
        {
            var builder = new StringBuilder();

            builder.Append("if ");
            builder.Append(Condition);
            builder.Append(" then");

            var ts = TrueBranch.ToString();

            if (!string.IsNullOrWhiteSpace(ts))
            {
                builder.Append(" ");
                builder.Append(ts);
            }

            var fs = FalseBranch.ToString();

            if (!string.IsNullOrWhiteSpace(fs))
            {
                builder.Append(" else ");
                builder.Append(fs);
            }

            builder.Append(" end");

            return(builder.ToString());
        }
コード例 #3
0
 /**
  * This is where the decision tree algorithm is located: it
  * recursively walks down the tree until it reaches the final
  * item to return (which is an action).
  */
 public virtual IDecisionTreeNode <T> MakeDecision()
 {
     // Choose a branch based on the getBranch method
     if (GetBranch())
     {
         // Make sure its not null before recursing.
         if (TrueBranch == null)
         {
             return(null);
         }
         else
         {
             return(TrueBranch.MakeDecision());
         }
     }
     else
     {
         // Make sure its not null before recursing.
         if (FalseBranch == null)
         {
             return(null);
         }
         else
         {
             return(FalseBranch.MakeDecision());
         }
     }
 }
コード例 #4
0
 public override string AST(int depth = 0)
 {
     return($"{Spaces(depth)}[{Name}\n" +
            $"{Expression.AST(depth + 1)}" +
            $"{TrueBranch.AST(depth + 1)}" +
            (FalseBranch is NoOpNode ? "" : $"{FalseBranch.AST(depth + 1)}") +
            $"{Spaces(depth)}]\n");
 }
コード例 #5
0
 public override int GetHashCode()
 {
     return(unchecked (
                Condition.GetHashCode()
                * TrueBranch.GetHashCode()
                * FalseBranch.GetHashCode()
                ));
 }
コード例 #6
0
 public override Node Clone()
 {
     return(new BasicBlock()
     {
         TrueBranch = TrueBranch?.Clone() as BasicBlock,
         FalseBranch = FalseBranch?.Clone() as BasicBlock,
         TerminatingBlock = TerminatingBlock,
         Instructions = Instructions?.Clone() as Instructions,
     });
 }
コード例 #7
0
ファイル: Node.cs プロジェクト: twakeham/csharplang
        public override DataType staticTypeCheck()
        {
            if (Predicate.staticTypeCheck() != DataType.BooleanType)
            {
                Log.Error("Type mismatch - predicate must evaluate to boolean", Filename, Line, Position);
            }
            TrueBranch.staticTypeCheck();
            FalseBranch?.staticTypeCheck();

            return(DataType.NoneType);
        }
コード例 #8
0
 internal DecisionTreeNode FindLeaf(FeatureVector vector)
 {
     // TODO: Make this less binary dependent.
     if (vector.Features[f_i] > 0 && TrueBranch != null)
     {
         return(TrueBranch.FindLeaf(vector));
     }
     else if (FalseBranch != null)
     {
         return(FalseBranch.FindLeaf(vector));
     }
     else
     {
         return(this);
     }
 }
コード例 #9
0
        public override string ToString()
        {
            var builder = new StringBuilder();

            builder.Append("if(").Append(Condition.ToString()).Append(") {").Append(Environment.NewLine);
            builder.Append(TrueBranch.ToString()).Append(Environment.NewLine);
            builder.Append("}");

            if (FalseBranch != null)
            {
                builder.Append(" else {").Append(Environment.NewLine);
                builder.Append(FalseBranch.ToString()).Append(Environment.NewLine);
                builder.Append("}");
            }

            return(builder.ToString());
        }
コード例 #10
0
 /// <summary>
 /// Converts to string.
 /// </summary>
 /// <returns>
 /// A <see cref="string" /> that represents this instance.
 /// </returns>
 public override string ToString() => $@"PRUNE ({Condition}, {
     TrueBranch.ToString()}) [{Location}];";
コード例 #11
0
        public Value Evaluate(Dictionary <string, IExpression> env)
        {
            var test = Test.Evaluate(env) as Value <bool>;

            return(test.Raw ? TrueBranch.Evaluate(env) : ElseBranch.Evaluate(env));
        }
コード例 #12
0
ファイル: CILBranch.cs プロジェクト: traplol/langlanglang
 public void AddTrueBranchStmt(CILNode node)
 {
     TrueBranch.Add(node);
 }
コード例 #13
0
ファイル: Node.cs プロジェクト: twakeham/csharplang
 public override string toSyntaxGraph()
 {
     return(String.Format("[IF [CONDITION {0}] [THEN {1}] [ELSE {2}]]", Predicate.toSyntaxGraph(), TrueBranch.toSyntaxGraph(), FalseBranch?.toSyntaxGraph() ?? "NULL"));
 }
 public override string GenerateCode(ICodeGenerationContext context)
 {
     return($"{Condition.GenerateCode(context)} ? {TrueBranch.GenerateCode(context)} : {FalseBranch.GenerateCode(context)}");
 }