Pep 0.4 API Documentation

edu.osu.ling.pep
Class Chart

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

public class Chart
extends Object

A chart produced by an Earley parser.

Charts contain sets of edges mapped to the string indices where they originate. Since the edge sets are sets, an edge can only be added at a given index once (as sets do not permit duplicate members). Edge sets are not guaranteed to maintain edges in their order of insertion.

Version:
$LastChangedRevision: 2070 $
Author:
Scott Martin

Constructor Summary
Chart()
          Creates a new chart, initializing its internal data structure.
Chart(Chart chart)
          Creates a new chart based on the specified chart.
 
Method Summary
 boolean addEdge(Integer index, Edge edge)
          Adds an edge to this chart at the given index.
 void clear()
          Removes all edges from this map at all indices (if any are present).
 boolean contains(Edge edge)
          Tests whether this chart contains the specified edge.
 boolean containsEdges(Integer index)
          Tests whether this chart contains any edges at a given string index.
 int countEdges()
          Counts the total number of edges contained in this chart, at any index.
 boolean equals(Object obj)
          Tests whether this chart is equal to another by comparing their internal data structures.
 Integer firstIndex()
          Gets the first index in this chart that contains edges.
 Set<Edge> getEdges(Integer index)
          Gets the edges in this chart at a given index.
 int hashCode()
          Computes a hash code for this chart based on its internal data structure.
 Chart headChart(Integer to)
          Gets a head chart of this chart (a chart containing only the indices from 0 to to).
 Integer indexOf(Edge edge)
          Gets the index of the specified edge in this chart.
 Set<Integer> indices()
          Gets the set of indices at which this chart contains edges.
 boolean isEmpty()
          Tests whether this chart contains any edges at any index.
 Integer lastIndex()
          Gets the last index in this chart that contains edges.
 Chart subChart(Integer from, Integer to)
          Gets a sub chart of this chart.
 Chart tailChart(Integer from)
          Gets a tail chart of this chart (a chart containing only the indices from from to the size of its indices()).
 String toString()
          Gets a string representation of this chart.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Chart

public Chart()
Creates a new chart, initializing its internal data structure.


Chart

public Chart(Chart chart)
Creates a new chart based on the specified chart. The newly created chart contains all the edges as the specified chart at all the same indices.

Parameters:
chart - The chart to base the newly created chart upon.
Since:
0.4
Method Detail

addEdge

public boolean addEdge(Integer index,
                       Edge edge)
Adds an edge to this chart at the given index. If no other edges exist in this chart at the same index, a new edge set is created before adding the edge.

Parameters:
index - The index for edge.
edge - The edge to add.
Returns:
true iff this chart did not already contain edge at the given index.
Throws:
IndexOutOfBoundsException - If index < 0.
NullPointerException - If index or edge is null.

clear

public void clear()
Removes all edges from this map at all indices (if any are present).

Since:
0.4

contains

public boolean contains(Edge edge)
Tests whether this chart contains the specified edge.

Parameters:
edge - The edge to test whether this chart contains.
Returns:
true iff this chart contains the specified edge at some index.
Since:
0.2
See Also:
indexOf(Edge)

containsEdges

public boolean containsEdges(Integer index)
Tests whether this chart contains any edges at a given string index.

Parameters:
index - The string index to check for edges.
Returns:
true iff this chart contains an edge set at index.

countEdges

public int countEdges()
Counts the total number of edges contained in this chart, at any index.

Returns:
The total number of edges contained.

equals

public boolean equals(Object obj)
Tests whether this chart is equal to another by comparing their internal data structures.

Overrides:
equals in class Object
Returns:
true iff the specified object is an instance of Chart and it contains the same edges at the same indices as this chart.

firstIndex

public Integer firstIndex()
Gets the first index in this chart that contains edges.

Returns:
The minimal member of indices(). In most cases, this will return 0 (unless this chart is a subchart of another chart).
Since:
0.2

getEdges

public Set<Edge> getEdges(Integer index)
Gets the edges in this chart at a given index.

Parameters:
index - The index to return edges for.
Returns:
The set of edges this chart contains at index, or null if no edge set exists in this chart for the given index. The edge set returned by this method is not guaranteed to contain the edges in the order in which they were added. This method returns a set of edges that is not modifiable.
Throws:
NullPointerException - If index is null.
See Also:
Collections.unmodifiableSet(Set)

hashCode

public int hashCode()
Computes a hash code for this chart based on its internal data structure.

Overrides:
hashCode in class Object

headChart

public Chart headChart(Integer to)
Gets a head chart of this chart (a chart containing only the indices from 0 to to).

Parameters:
to - The high endpoint (exclusive) of the new chart.
Returns:
A chart containing all the indices strictly less than to.
Since:
0.4
See Also:
SortedMap.headMap(Object)

indexOf

public Integer indexOf(Edge edge)
Gets the index of the specified edge in this chart.

Parameters:
edge - The edge to find the index of.
Returns:
The index of the specified edge, or -1 if the specified edge is null or is not contained in this chart.
Since:
0.2

indices

public Set<Integer> indices()
Gets the set of indices at which this chart contains edges. For any member of this set, getEdges(Integer) will return a non-empty set of edges.

Returns:
A set containing every index in this chart where edges have been added, sorted in ascending order (0 ... n).

isEmpty

public boolean isEmpty()
Tests whether this chart contains any edges at any index.

Returns:
true if an edge is present at some index, false otherwise.
Since:
0.4

lastIndex

public Integer lastIndex()
Gets the last index in this chart that contains edges.

Returns:
The maximal member of indices().
Since:
0.2

subChart

public Chart subChart(Integer from,
                      Integer to)
Gets a sub chart of this chart.

Parameters:
from - The low endpoint (inclusive) of the sub chart.
to - The high endpoint (exclusive) of the subchart.
Returns:
A new chart containing only the edge sets in this chart where from <= index < to.
Throws:
NullPointerException - If either from or to is null.
Since:
0.2
See Also:
SortedMap.subMap(Object, Object)

tailChart

public Chart tailChart(Integer from)
Gets a tail chart of this chart (a chart containing only the indices from from to the size of its indices()).

Parameters:
from - The low endpoint (inclusive) of the new chart.
Returns:
A chart containing all the indices greater than or equal to from.
Since:
0.4
See Also:
SortedMap.tailMap(Object)

toString

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

Overrides:
toString in class Object

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.