Class Match<E>
- java.lang.Object
-
- edu.washington.cs.knowitall.regex.Match<E>
-
- Type Parameters:
E-
- Direct Known Subclasses:
Match.FinalMatch,Match.IntermediateMatch
public abstract class Match<E> extends java.lang.ObjectA class to represent a match. Each part of the regular expression is matched to a sequence of tokens. A match also stores information about the range of tokens matched and the matching groups in the match.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classMatch.FinalMatch<E>A match representation that has efficient method calls but is immutable.static classMatch.Group<E>A captured group in a matched expression.protected static classMatch.IntermediateMatch<E>A match representation that is mutable but many method calls compute values instead of returning stored values.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Match.Group<E>>pairs
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(Expression<E> expr, E token, int pos)Convenience method for add(new Group(expr, token, pos)). booleanadd(Match.Group<E> pair)booleanaddAll(java.util.Collection<Match.Group<E>> pairs)abstract intendIndex()Match.Group<E>group(java.lang.String name)Retrieve a group by name.abstract java.util.List<Match.Group<E>>groups()booleanisEmpty()True iff this match contains no pairs.intlength()java.util.List<Match.Group<E>>pairs()Pairs differ from the matching groups in that each regular expression element has a pair to associate the element with the text matched.abstract intstartIndex()abstract java.util.List<E>tokens()java.lang.StringtoMultilineString()java.lang.StringtoString()
-
-
-
Field Detail
-
pairs
protected java.util.List<Match.Group<E>> pairs
-
-
Method Detail
-
add
public boolean add(Match.Group<E> pair)
-
addAll
public boolean addAll(java.util.Collection<Match.Group<E>> pairs)
-
add
public boolean add(Expression<E> expr, E token, int pos)
Convenience method for add(new Group(expr, token, pos)). - Parameters:
expr-token-pos-- Returns:
-
isEmpty
public boolean isEmpty()
True iff this match contains no pairs. This should only happen on an IntermediateMatch that has not had any pairs added to it yet.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toMultilineString
public java.lang.String toMultilineString()
-
startIndex
public abstract int startIndex()
- Returns:
- the index of the first token matched (inclusive start).
-
endIndex
public abstract int endIndex()
- Returns:
- the index one past of the last token matched (exclusive end).
-
pairs
public java.util.List<Match.Group<E>> pairs()
Pairs differ from the matching groups in that each regular expression element has a pair to associate the element with the text matched. For example, 'a*' might be associated with 'a a a a'.- Returns:
- all pairs in this match.
-
groups
public abstract java.util.List<Match.Group<E>> groups()
- Returns:
- all matching groups (named and unnamed).
-
tokens
public abstract java.util.List<E> tokens()
- Returns:
- all matched tokens.
-
length
public int length()
- Returns:
- the number of tokens in the match.
-
group
public Match.Group<E> group(java.lang.String name)
Retrieve a group by name.- Parameters:
name- the name of the group to retrieve.- Returns:
- the associated group.
-
-