Pep 0.4 API Documentation

edu.osu.ling.pep
Class DottedRule

java.lang.Object
  extended by edu.osu.ling.pep.Rule
      extended by edu.osu.ling.pep.DottedRule

public class DottedRule
extends Rule

Extension of Rule that maintains a dot position within the rule.

Dotted rules are used by Earley parsers to keep track of how far within a rule processing has succeeded. In a dotted rule, the active category is the first category after the dot position, and is null when processing has fully covered the underlying rule. Edges test the active category of dotted rules to determine when an edge is active or passive.

Version:
$LastChangedRevision: 1796 $
Author:
Scott Martin
See Also:
Rule, Edge

Constructor Summary
DottedRule(Rule rule)
          Creates a new dotted rule for the given rule, with a dot position at the beginning of the rule's right side (position 0).
DottedRule(Rule rule, int position)
          Creates a dotted rule maintaining the dot position within the right side category sequence of the underlying rule.
 
Method Summary
static DottedRule advanceDot(DottedRule dottedRule)
          Creates and returns a new dotted rule exactly like the one provided except that its dot position is advanced by 1.
 boolean equals(Object obj)
          Tests whether this dotted rule is equal to another dotted rule by comparing their underlying rules and dot positions.
 Category getActiveCategory()
          Gets the active category in the underlying rule, if any.
 int getPosition()
          Gets the dot position within the underlying rule's right side category sequence.
 int hashCode()
          Computes a hash code for this dotted rule based on its underlying rule and dot position.
static DottedRule startRule(Category seed)
          Creates a new start rule for a given seed category.
 String toString()
          Gets a string representation of this dotted rule.
 
Methods inherited from class edu.osu.ling.pep.Rule
getLeft, getRight, isPreterminal, isSingletonPreterminal
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DottedRule

public DottedRule(Rule rule)
Creates a new dotted rule for the given rule, with a dot position at the beginning of the rule's right side (position 0).

See Also:
DottedRule(Rule, int)

DottedRule

public DottedRule(Rule rule,
                  int position)
Creates a dotted rule maintaining the dot position within the right side category sequence of the underlying rule.

Parameters:
rule - The underlying rule.
position - The zero-based position within rule right side categories where this dotted rule's dot is maintained.
Throws:
IndexOutOfBoundsException - If position < 0 or position is greater than the length of the right side sequence in rule.
Method Detail

advanceDot

public static DottedRule advanceDot(DottedRule dottedRule)
Creates and returns a new dotted rule exactly like the one provided except that its dot position is advanced by 1.

Parameters:
dottedRule - The dotted rule whose dot position should be advanced.
Returns:
A new dotted rule wrapping this rule with its position incremented.
Throws:
IndexOutOfBoundsException - If thw dotted rule's dot position is already at the end of its right side.
Since:
0.2
See Also:
DottedRule(Rule, int)

equals

public boolean equals(Object obj)
Tests whether this dotted rule is equal to another dotted rule by comparing their underlying rules and dot positions.

Overrides:
equals in class Rule
Returns:
true iff the specified object is an instance of DottedRule and its underlying rule and position are equal to this dotted rule's rule and position.
See Also:
Rule.equals(Object)

getActiveCategory

public Category getActiveCategory()
Gets the active category in the underlying rule, if any.

Returns:
The category at this dotted rule's dot position in the underlying rule's right side category sequence. If this rule's dot position is already at the end of the right side category sequence, returns null.

getPosition

public int getPosition()
Gets the dot position within the underlying rule's right side category sequence.

Returns:
The dot position that was specified for this dotted rule when it was created.

hashCode

public int hashCode()
Computes a hash code for this dotted rule based on its underlying rule and dot position.

Overrides:
hashCode in class Rule
See Also:
Rule.hashCode()

startRule

public static DottedRule startRule(Category seed)
Creates a new start rule for a given seed category.

Parameters:
seed - The seed category to use.
Returns:
A dotted rule that has the special start rule on the left and the specified seed on the right. This method is used by Earley parsers for seeding.
Throws:
NullPointerException - If the seed category is null.
IllegalArgumentException - If the seed category is a terminal.
See Also:
Category.START, EarleyParser.parse(Iterable, Category)

toString

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

Overrides:
toString in class Rule
Returns:
"S -> NP * VP" for a dotted rule with an underlying rule S -> NP VP and a dot position 1.
See Also:
Rule.toString()

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.