Class ParseForest

java.lang.Object
org.nineml.coffeegrinder.parser.ParseForest
Direct Known Subclasses:
ParseForestGLL

public class ParseForest extends Object
An SPPF is a shared packed parse forest.

The SPPF is a graph representation of all the (possibly infinite) parses that can be used to recognize the input sequence as a sentence in the grammar.

  • Field Details

  • Constructor Details

  • Method Details

    • isAmbiguous

      public boolean isAmbiguous()
      Is the grammar represented by this graph ambiguous?

      A grammar is ambiguous if there are more than two parses that will recognize the input.

      Returns:
      true if the grammar is ambiguous
    • isInfinitelyAmbiguous

      public boolean isInfinitelyAmbiguous()
      Is the grammar represented by this graph infinitely ambiguous?

      If the answer is "true", then the graph is infinitely ambiguous. If the graph is ambiguous and the anwer is "false", then all that can be said is the single parse explored to check ambiguity did not encounter infinite ambiguity. It is not an assertion that no unexplored part of the graph contains a loop.

      Returns:
      true if the parse forest is known to be infinitely ambiguous
    • getParseTreeCount

      public int getParseTreeCount()
      How many parse trees are there in this forest?

      In an infinitely ambiguous graph, there are an infinite number of parse trees. However, CoffeeGrinder will never follow the same edge twice when constructing a tree, it won't loop. So the number of available trees is always a finite number.

      Returns:
      the parse tree count
    • getAmbiguousNodes

      public List<ForestNode> getAmbiguousNodes()
    • size

      public int size()
      How big is the graph?
      Returns:
      the number of nodes in the graph
    • getNodes

      public List<ForestNode> getNodes()
      Get the nodes in the graph.
      Returns:
      the nodes in the graph.
    • getRoot

      public ForestNode getRoot()
    • getOptions

      public ParserOptions getOptions()
      Get the options for this forest.
      Returns:
      the options.
    • serialize

      public String serialize()
      Serialize the graph as XML.
      Returns:
      an XML serialization as a string
    • serialize

      public void serialize(PrintStream stream)
      Serialize the graph as XML.
      Parameters:
      stream - the stream on which to write the XML serialization
    • serialize

      public void serialize(String filename)
      Serialize the graph as XML.

      This method attempts to write the XML to a file.

      Parameters:
      filename - the name of the file
      Throws:
      ForestException - if a error occurs attempt to write to the file