Pep 0.4 API Documentation

edu.osu.ling.pep
Class Parse

java.lang.Object
  extended by edu.osu.ling.pep.Parse

public class Parse
extends Object

Represents a parse completed by an Earley parser.

A parse contains the string (list of tokens) parsed, the seed category and completed chart. The status of the completed parse can also be determined.

Parse trees can be retrieved for any Category in the parse at a given string index and origin position. Parses allow the fully derived parse trees for the seed category to be obtained using getParseTrees(). For a parse of a string using a grammar that permits structural or lexical ambiguity, the methods for fetching parse trees will return sets that contain more than one element.

Version:
$LastChangedRevision: 2070 $
Author:
Scott Martin
See Also:
EarleyParser, Chart

Method Summary
 boolean equals(Object obj)
          Tests whether this parse equals another by comparing their tokens, seed categories, and completed charts.
 Chart getChart()
          Gets the completed chart for this parse.
 ParseTree getParseTreeFor(Edge edge)
          Gets a parse tree corresponding to the given edge.
 Set<ParseTree> getParseTrees()
          Gets completed parse trees for the seed category spanning the entire input string.
 Set<ParseTree> getParseTreesFor(Category category, int origin, int index)
          Gets the parse trees derived during this parse with the specified category as their parent's left side.
 Category getSeed()
          Gets the seed category for this parse.
 Status getStatus()
          Gets the status of this parse.
 List<String> getTokens()
          Gets the tokens parsed.
 int hashCode()
          Computes a hash code for this parse based on its tokens, seed category, and chart.
 String toString()
          Gets a string representation of this parse.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

equals

public boolean equals(Object obj)
Tests whether this parse equals another by comparing their tokens, seed categories, and completed charts.

Overrides:
equals in class Object
Returns:
true iff the given object is an instance of Parse and its tokens, seed category, and chart are equal to those of this parse.

getChart

public Chart getChart()
Gets the completed chart for this parse.


getParseTreeFor

public ParseTree getParseTreeFor(Edge edge)
Gets a parse tree corresponding to the given edge.

Parameters:
edge - The edge to find a parse tree for.
Returns:
The parse tree corresponding to the specified edge. If the edge is not contained in this parse's chart, returns null. The parse tree returned will be the same as calling
ParseTree.newParseTree(edge);
Throws:
NullPointerException - If edge is null.
Since:
0.2
See Also:
ParseTree.newParseTree(Edge), Chart.contains(Edge)

getParseTrees

public Set<ParseTree> getParseTrees()
Gets completed parse trees for the seed category spanning the entire input string. This method returns valid derivations (if any) that the parse found for the seed category.

Returns:
A set of parse trees for the seed category spanning the entire string, or the empty set if none were derivable. In the case that the grammar used in this parse permits ambiguity for the string parsed, this set will contain more than one member. If this parse's status is Status.ERROR, the empty set is returned.
Since:
0.2
See Also:
getParseTreesFor(Category, int, int)

getParseTreesFor

public Set<ParseTree> getParseTreesFor(Category category,
                                       int origin,
                                       int index)
Gets the parse trees derived during this parse with the specified category as their parent's left side. This parse's chart must contain a completed edge at the specified index that starts at the specified origin with the correct category as its left side.

For example, the string Mary saw her duck parsed using the tiny grammar included in samples will produce a parse that contains two subtrees for the category VP at origin position 1 and index 4. This is because the derived VP categories for saw her duck both start at 1 and end at 4. To retrieve these subtrees from the parse, use

Parse.getParseTreesFor(VP, 1, 4)
where VP represents an instance of Category whose name is "VP".

Parameters:
category - The category of the parse tree's parent. This is the left side of the edge's dotted rule.
origin - The origin position of the edge to find parse trees for.
index - The string index position of the edge to find parse trees for. This is the end position of the subtree.
Returns:
A set of parse trees for the given category at the given origin and string index position, or the empty set if no edges match.
Throws:
NullPointerException - If category is null.
Since:
0.2

getSeed

public Category getSeed()
Gets the seed category for this parse.


getStatus

public Status getStatus()
Gets the status of this parse. A parse accepts a string when its completed chart contains an edge where the following conditions hold:
  1. its index is the last index in the chart,
  2. it is passive,
  3. its origin is the beginning of the string (position 0), and
  4. the left side of its dotted rule is the same as the start category that seeded the parse.

Returns:
Status.ACCEPT for accepted strings, Status.REJECT for rejected ones. The status Status.ERROR is returned if an error occurred during the parse.

getTokens

public List<String> getTokens()
Gets the tokens parsed.


hashCode

public int hashCode()
Computes a hash code for this parse based on its tokens, seed category, and chart.

Overrides:
hashCode in class Object
See Also:
List.hashCode(), Category.hashCode(), Chart.hashCode()

toString

public String toString()
Gets a string representation of this parse.

Overrides:
toString in class Object
Returns:
"ACCEPT: S -> [the, boy, left] (1)" for an accepted parse of "the boy left" with seed category S and one possible parse tree.

Pep: Pep is an Earley parser

Pep API Documentation, Copyright © 2007 Scott Martin

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the overview file.