Class ThoughtNode

java.lang.Object
com.tnsai.reasoning.ThoughtNode
All Implemented Interfaces:
Evaluable

public final class ThoughtNode extends Object implements Evaluable
Represents a node in a Tree of Thoughts exploration.

Each node contains a thought (reasoning step), its evaluation score, and references to parent and child nodes.

  • Method Details

    • root

      public static ThoughtNode root(String thought)
      Creates a root node.
    • addChild

      public ThoughtNode addChild(String id, String thought)
      Creates a child node.
    • getId

      public String getId()
      Gets the node identifier.
      Specified by:
      getId in interface Evaluable
    • getThought

      public String getThought()
      Gets the thought content at this node.
      Specified by:
      getThought in interface Evaluable
    • getDepth

      public int getDepth()
      Gets the depth of this node (root = 0).
      Specified by:
      getDepth in interface Evaluable
    • getParent

      public Optional<ThoughtNode> getParent()
      Gets the parent node, if any.
    • getChildren

      public List<ThoughtNode> getChildren()
      Gets the child nodes.
    • getScore

      public double getScore()
      Gets the evaluation score.
    • setScore

      public void setScore(double score)
      Sets the evaluation score.
    • isEvaluated

      public boolean isEvaluated()
      Returns true if this node has been evaluated.
    • isLeaf

      public boolean isLeaf()
      Returns true if this is a leaf node.
    • isRoot

      public boolean isRoot()
      Returns true if this is the root node.
    • isPruned

      public boolean isPruned()
      Returns true if this node has been pruned.
    • prune

      public void prune()
      Marks this node as pruned.
    • getFinalAnswer

      public String getFinalAnswer()
      Gets the final answer generated for this leaf node.
    • setFinalAnswer

      public void setFinalAnswer(String finalAnswer)
      Sets the final answer for this leaf node.
    • hasFinalAnswer

      public boolean hasFinalAnswer()
      Returns true if this node has a final answer.
    • getPath

      public List<ThoughtNode> getPath()
      Gets the path from root to this node.
    • getThoughtChain

      public String getThoughtChain()
      Gets the combined thought chain from root to this node.
      Specified by:
      getThoughtChain in interface Evaluable
    • getCumulativeScore

      public double getCumulativeScore()
      Gets the cumulative score along the path to this node.
    • getAverageScore

      public double getAverageScore()
      Gets the average score along the path to this node.
    • builder

      public static ThoughtNode.Builder builder()
      Creates a new builder for ThoughtNode.
    • toString

      public String toString()
      Overrides:
      toString in class Object