|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.stanford.nlp.ling.tokensregex.BasicSequenceMatchResult<T>
edu.stanford.nlp.ling.tokensregex.SequenceMatcher<T>
public class SequenceMatcher<T>
Generic sequence matcher
Similar to Java's Matcher except it matches sequences over an arbitrary type T
instead of characters
For a type T to be matchable, it has to have a corresponding NodePattern that indicates
whether a node is matched or not
A matcher is created as follows:
SequencePattern p = SequencePattern.compile("...");
SequencePattern m = p.getMatcher(List sequence);
Functions for searching
boolean matches()
boolean find()
boolean find(int start)
Functions for retrieving matched patterns
int groupCount()
List groupNodes(), List groupNodes(int g)
String group(), String group(int g)
int start(), int start(int g), int end(), int end(int g)
Functions for defining the region of the sequence to search over
(default region is entire sequence)
void region(int start, int end)
int regionStart()
int regionEnd()
NOTE: When find is used, matches are attempted starting from the specified start index of the sequence The match with the earliest starting index is returned.
| Nested Class Summary | |
|---|---|
static class |
SequenceMatcher.BasicMatchReplacement<T>
Replacement item is a sequence of items |
static class |
SequenceMatcher.FindType
Type of search to perform FIND_NONOVERLAPPING - Find nonoverlapping matches (default) FIND_ALL - Find all potential matches Greedy/reluctant quantifiers are not enforced (perhaps should add syntax where some of them are enforced...) |
static class |
SequenceMatcher.GroupMatchReplacement<T>
Replacement item is a matched group specified with a group id |
static interface |
SequenceMatcher.MatchReplacement<T>
Interface that specifies what to replace a matched pattern with |
static class |
SequenceMatcher.NamedGroupMatchReplacement<T>
Replacement item is a matched group specified with a group name |
| Nested classes/interfaces inherited from class edu.stanford.nlp.ling.tokensregex.BasicSequenceMatchResult |
|---|
BasicSequenceMatchResult.MatchedGroup |
| Nested classes/interfaces inherited from interface edu.stanford.nlp.ling.tokensregex.SequenceMatchResult |
|---|
SequenceMatchResult.GroupToIntervalFunc<MR extends java.util.regex.MatchResult>, SequenceMatchResult.MatchedGroupInfo<T> |
| Field Summary |
|---|
| Fields inherited from interface edu.stanford.nlp.ling.tokensregex.SequenceMatchResult |
|---|
DEFAULT_COMPARATOR, GROUP_AFTER_MATCH, GROUP_BEFORE_MATCH, LENGTH_COMPARATOR, OFFSET_COMPARATOR, ORDER_COMPARATOR, SCORE_COMPARATOR, SCORE_LENGTH_ORDER_OFFSET_COMPARATOR, TO_INTERVAL |
| Fields inherited from interface edu.stanford.nlp.util.HasInterval |
|---|
CONTAINS_FIRST_ENDPOINTS_COMPARATOR, ENDPOINTS_COMPARATOR, NESTED_FIRST_ENDPOINTS_COMPARATOR |
| Constructor Summary | |
|---|---|
protected |
SequenceMatcher(SequencePattern pattern,
java.util.List<? extends T> elements)
|
| Method Summary | |
|---|---|
int |
end(int group)
|
boolean |
find()
Searches for the next occurrence of the pattern |
boolean |
find(int start)
Reset the matcher and then searches for pattern at the specified start index |
protected boolean |
find(int start,
boolean matchStart)
|
java.lang.Iterable<SequenceMatchResult<T>> |
findAllNonOverlapping()
|
protected boolean |
findMatchStart(int start,
boolean matchAllTokens)
|
protected boolean |
findMatchStartBacktracking(int start,
boolean matchAllTokens)
|
protected boolean |
findMatchStartNoBacktracking(int start,
boolean matchAllTokens)
|
T |
get(int i)
Returns the ith element |
SequenceMatcher.FindType |
getFindType()
|
SequenceMatchResult.MatchedGroupInfo<T> |
groupInfo(int group)
|
java.lang.Object |
groupMatchResult(int group,
int index)
Returns an Object representing the result for the match for a particular node in a group. |
java.util.List<java.lang.Object> |
groupMatchResults(int group)
Returns a list of Objects representing the match results for the nodes in the group. |
java.util.List<? extends T> |
groupNodes(int group)
Returns the matched group as a list. |
java.lang.Object |
groupValue(int group)
|
boolean |
isMatchWithResult()
|
boolean |
matches()
Checks if the pattern matches the entire sequence |
java.lang.Object |
nodeMatchResult(int index)
Returns an Object representing the result for the match for a particular node. |
void |
region(int start,
int end)
Set region to search in |
int |
regionEnd()
|
int |
regionStart()
|
java.util.List<T> |
replaceAll(java.util.List<T> replacement)
Replaces all occurrences of the pattern with the specified list. |
java.util.List<T> |
replaceAllExtended(java.util.List<SequenceMatcher.MatchReplacement<T>> replacement)
Replaces all occurrences of the pattern with the specified list of replacement items (can include matched groups). |
java.util.List<T> |
replaceFirst(java.util.List<T> replacement)
Replaces the first occurrence of the pattern with the specified list. |
java.util.List<T> |
replaceFirstExtended(java.util.List<SequenceMatcher.MatchReplacement<T>> replacement)
Replaces the first occurrence of the pattern with the specified list of replacement items (can include matched groups). |
void |
reset()
Clears matcher - Clears matched groups, reset region to be entire sequence |
void |
setFindType(SequenceMatcher.FindType findType)
|
void |
setMatchWithResult(boolean matchWithResult)
|
int |
start(int group)
|
BasicSequenceMatchResult<T> |
toBasicSequenceMatchResult()
|
| Methods inherited from class edu.stanford.nlp.ling.tokensregex.BasicSequenceMatchResult |
|---|
copy, elements, end, end, getInterval, getOrder, group, group, group, groupCount, groupInfo, groupInfo, groupMatchResult, groupMatchResults, groupMatchResults, groupNodes, groupNodes, groupValue, groupValue, pattern, score, setOrder, start, start |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected SequenceMatcher(SequencePattern pattern,
java.util.List<? extends T> elements)
| Method Detail |
|---|
public java.util.List<T> replaceAllExtended(java.util.List<SequenceMatcher.MatchReplacement<T>> replacement)
replacement - What to replace the matched sequence with
replaceFirst(java.util.List),
replaceFirstExtended(java.util.List),
replaceAllExtended(java.util.List)public java.util.List<T> replaceFirstExtended(java.util.List<SequenceMatcher.MatchReplacement<T>> replacement)
replacement - What to replace the matched sequence with
replaceFirst(java.util.List),
replaceAll(java.util.List),
replaceAllExtended(java.util.List)public java.util.List<T> replaceAll(java.util.List<T> replacement)
replaceAllExtended(java.util.List) to replace with matched groups.
replacement - What to replace the matched sequence with
replaceAllExtended(java.util.List),
replaceFirst(java.util.List),
replaceFirstExtended(java.util.List)public java.util.List<T> replaceFirst(java.util.List<T> replacement)
replaceFirstExtended(java.util.List) to replace with matched groups.
replacement - What to replace the matched sequence with
replaceAll(java.util.List),
replaceAllExtended(java.util.List),
replaceFirstExtended(java.util.List)public SequenceMatcher.FindType getFindType()
public void setFindType(SequenceMatcher.FindType findType)
public boolean isMatchWithResult()
public void setMatchWithResult(boolean matchWithResult)
public boolean find(int start)
start - - Index at which to start the search
java.lang.IndexOutOfBoundsException - if start is < 0 or larger then the size of the sequencefind()
protected boolean find(int start,
boolean matchStart)
public java.lang.Iterable<SequenceMatchResult<T>> findAllNonOverlapping()
public boolean find()
find(int)
protected boolean findMatchStart(int start,
boolean matchAllTokens)
protected boolean findMatchStartNoBacktracking(int start,
boolean matchAllTokens)
protected boolean findMatchStartBacktracking(int start,
boolean matchAllTokens)
public boolean matches()
find()
public void region(int start,
int end)
start - - start indexend - - end index (exclusive)public int regionEnd()
public int regionStart()
public BasicSequenceMatchResult<T> toBasicSequenceMatchResult()
toBasicSequenceMatchResult in interface SequenceMatchResult<T>toBasicSequenceMatchResult in class BasicSequenceMatchResult<T>public int start(int group)
start in interface java.util.regex.MatchResultstart in class BasicSequenceMatchResult<T>public int end(int group)
end in interface java.util.regex.MatchResultend in class BasicSequenceMatchResult<T>public java.util.List<? extends T> groupNodes(int group)
SequenceMatchResult
groupNodes in interface SequenceMatchResult<T>groupNodes in class BasicSequenceMatchResult<T>group - The index of a capturing group in this matcher's pattern
public java.lang.Object groupValue(int group)
groupValue in interface SequenceMatchResult<T>groupValue in class BasicSequenceMatchResult<T>public SequenceMatchResult.MatchedGroupInfo<T> groupInfo(int group)
groupInfo in interface SequenceMatchResult<T>groupInfo in class BasicSequenceMatchResult<T>public java.util.List<java.lang.Object> groupMatchResults(int group)
SequenceMatchResult
groupMatchResults in interface SequenceMatchResult<T>groupMatchResults in class BasicSequenceMatchResult<T>group - The index of a capturing group in this matcher's pattern
public java.lang.Object groupMatchResult(int group,
int index)
SequenceMatchResult
groupMatchResult in interface SequenceMatchResult<T>groupMatchResult in class BasicSequenceMatchResult<T>group - The index of a capturing group in this matcher's patternindex - The index of the element in the captured subsequence.
public java.lang.Object nodeMatchResult(int index)
SequenceMatchResult
nodeMatchResult in interface SequenceMatchResult<T>nodeMatchResult in class BasicSequenceMatchResult<T>index - The index of the element in the original sequence.
public void reset()
public T get(int i)
i - - index
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||