edu.stanford.nlp.ling.tokensregex.SequenceMatchResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-parser Show documentation
Show all versions of stanford-parser Show documentation
Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.
The newest version!
package edu.stanford.nlp.ling.tokensregex;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.ToDoubleFunction;
import java.util.regex.MatchResult;
import edu.stanford.nlp.util.Comparators;
import edu.stanford.nlp.util.HasInterval;
import edu.stanford.nlp.util.Interval;
/**
* 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
int GROUP_BEFORE_MATCH = Integer.MIN_VALUE; // Special match groups (before match)
int GROUP_AFTER_MATCH = Integer.MIN_VALUE + 1; // Special match groups (after match)
double score();
double priority();
/**
* Returns the original sequence the match was performed on.
*
* @return The list that the match was performed on
*/
List extends T> elements();
/**
* Returns pattern used to create this sequence match result
*
* @return the SequencePattern against which this sequence match result was matched
*/
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
*/
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
*/
List extends T> groupNodes(int group);
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 {@code 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
*/
List extends T> groupNodes(String groupVar);
/**
* Returns the {@code String} representing the matched group.
*
* @param groupVar The name of the capturing group in this matcher's pattern
* @return the matched group as a {@code String}
* or {@code 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
*/
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 {@code -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
*/
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 {@code -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
*/
int end(String groupVar);
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
*/
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
*/
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
*/
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
*/
List