Class EarleyTrace

java.lang.Object
org.libxmq.imp.ixml.earley.EarleyTrace

public final class EarleyTrace extends Object
Record what the Earley parser did: as a trace document (toXml), the same as xmq --traceixml=file records, or (write) in the same line format as the C parser (xmq --debug=ixml.), so that OpenMike/parse-trace.ixml and OpenMike/render-trace.xslq can visualize it, see OpenMike/debug-ixml-java.sh. The lines are written from the finished chart and the chosen tree: (ixml.gr) S → S '+' M a production of the grammar (ixml.pa.step) @2 (d5,2-2) none/8 M → · T an item in set 2 (ixml.pa.token) @2 '2' the code point at position 2 (ixml.pa.view) @2 READ '2' the parser reads it (ixml.bt.step) adding (d12,2-3) M → T a node added to the tree An item is written as (dN,from-to) where dN numbers the dotted rule, the production with the dot, in the order they first appear. Then the kind: none (nothing matched yet, a prediction), part (partly matched) or full (complete), and n, the number of tokens. Like in C the input ends with an extra token ω (end of input), so n is the input length plus one. The generated rules /1, /2, ... are written |1, |2, ... like in C.
  • Method Details

    • write

      public static void write(PrintStream out, Grammar grammar, Chart chart, Tree tree, List<TreeBuilder.Step> steps)
      Write the trace.
      Parameters:
      out - the stream, eg stderr
      grammar - the grammar
      chart - the chart from EarleyParser.recognize
      tree - the chosen tree, or null if the input was rejected
      steps - the nodes in the order they were added to the tree
    • toXml

      public static XmlDocument toXml(Grammar grammar, Chart chart, List<TreeBuilder.Step> tree_steps)
      The trace as a document, the same as the C version records (xmq --traceixml=file):
       trace(engine=earley) {
           grammar { rule(name=S rhs="S '+' M") ... }
           input { token(pos=0) = 1 ... token(pos=7) = ω }
           steps { item(id from to state rule matched expected) ... read(pos=0) ... }
           tree { node(step parent id from to rule rhs chosen cost tree-parent) ... } }
       
      where state is predicted, partial or complete. The items of set k+1 follow read(pos=k). The tree nodes are in the order they were added, step 1, 2, ..., and parent is the step of the parent node, 0 for the root. chosen is yes for the nodes of the final tree, the others lost on cost. cost is the cost of the node with its children. tree-parent is the step of the parent in the final tree, a node is composed once and can be used by another parent than the one it was composed for.
      Parameters:
      grammar - the grammar
      chart - the chart from EarleyParser.recognize
      tree_steps - the nodes in the order they were added to the tree, empty if the input was rejected
      Returns:
      the trace document