edu.stanford.nlp.ling.tokensregex.SequenceMatchResult Maven / Gradle / Ivy
Show all versions of stanford-parser Show documentation
package edu.stanford.nlp.ling.tokensregex;
import edu.stanford.nlp.util.Comparators;
import java.util.function.Function;
import edu.stanford.nlp.util.HasInterval;
import edu.stanford.nlp.util.Interval;
import java.util.Comparator;
import java.util.List;
import java.util.regex.MatchResult;
/**
* The result of a match against a sequence.
*
* Similar to Java's {@link MatchResult} except it is for sequences
* over arbitrary types T instead of just characters.
*
* This interface contains query methods used to determine the
* results of a match against a regular expression against an sequence.
* The match boundaries, groups and group boundaries can be seen
* but not modified through a {@link SequenceMatchResult}.
*
* @author Angel Chang
* @see SequenceMatcher
*/
public interface SequenceMatchResult extends MatchResult, HasInterval {
// TODO: Need to be careful with GROUP_BEFORE_MATCH/GROUP_AFTER_MATCH
public static int GROUP_BEFORE_MATCH = Integer.MIN_VALUE; // Special match groups (before match)
public static int GROUP_AFTER_MATCH = Integer.MIN_VALUE+1; // Special match groups (after match)
public double score();
public double priority();
/**
* Returns the original sequence the match was performed on.
* @return The list that the match was performed on
*/
public List extends T> elements();
/**
* Returns pattern used to create this sequence match result
* @return the SequencePattern against which this sequence match result was matched
*/
public SequencePattern pattern();
/**
* Returns the entire matched subsequence as a list.
* @return the matched subsequence as a list
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
*/
public List extends T> groupNodes();
/**
* Returns the matched group as a list.
* @param group
* The index of a capturing group in this matcher's pattern
* @return the matched group as a list
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
*
* @throws IndexOutOfBoundsException
* If there is no capturing group in the pattern
* with the given index
*/
public List extends T> groupNodes(int group);
public BasicSequenceMatchResult toBasicSequenceMatchResult();
// String lookup versions using variables
/**
* Returns the matched group as a list.
* @param groupVar
* The name of the capturing group in this matcher's pattern
* @return the matched group as a list
* or null if there is no capturing group in the pattern
* with the given name
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
*/
public List extends T> groupNodes(String groupVar);
/**
* Returns the String
representing the matched group.
* @param groupVar
* The name of the capturing group in this matcher's pattern
* @return the matched group as a String
* or null if there is no capturing group in the pattern
* with the given name
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
*/
public String group(String groupVar);
/**
* Returns the start index of the subsequence captured by the given group
* during this match.
* @param groupVar
* The name of the capturing group in this matcher's pattern
* @return the index of the first element captured by the group,
* or -1 if the match was successful but the group
* itself did not match anything
* or if there is no capturing group in the pattern
* with the given name
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
*/
public int start(String groupVar);
/**
* Returns the index of the next element after the subsequence captured by the given group
* during this match.
* @param groupVar
* The name of the capturing group in this matcher's pattern
* @return the index of the next element after the subsequence captured by the group,
* or -1 if the match was successful but the group
* itself did not match anything
* or if there is no capturing group in the pattern
* with the given name
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
*/
public int end(String groupVar);
public int getOrder();
/**
* Returns an Object representing the result for the match for a particular node.
* (actual Object returned depends on the type T of the nodes. For instance,
* for a CoreMap, the match result is returned as a {@code Map}, while
* for String, the match result is typically a MatchResult.
*
* @param index The index of the element in the original sequence.
* @return The match result associated with the node at the given index.
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
* @throws IndexOutOfBoundsException
* If the index is out of range
*/
public Object nodeMatchResult(int index);
/**
* Returns an Object representing the result for the match for a particular node in a group.
* (actual Object returned depends on the type T of the nodes. For instance,
* for a CoreMap, the match result is returned as a {@code Map}, while
* for String, the match result is typically a MatchResult.
*
* @param groupid The index of a capturing group in this matcher's pattern
* @param index The index of the element in the captured subsequence.
* @return the match result associated with the node
* at the given index for the captured group.
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
* @throws IndexOutOfBoundsException
* If there is no capturing group in the pattern
* with the given groupid or if the index is out of range
*/
public Object groupMatchResult(int groupid, int index);
/**
* Returns an Object representing the result for the match for a particular node in a group.
* (actual Object returned depends on the type T of the nodes. For instance,
* for a CoreMap, the match result is returned as a {@code Map}, while
* for String, the match result is typically a MatchResult.
*
* @param groupVar The name of the capturing group in this matcher's pattern
* @param index The index of the element in the captured subsequence.
* @return the match result associated with the node
* at the given index for the captured group.
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
* @throws IndexOutOfBoundsException
* if the index is out of range
*/
public Object groupMatchResult(String groupVar, int index);
/**
* Returns a list of Objects representing the match results for the entire sequence.
*
* @return the list of match results associated with the entire sequence
* @throws IllegalStateException
* If no match has yet been attempted,
* or if the previous match operation failed
*/
public List