public abstract class AbstractTextAnnotation extends Object implements Serializable
This class stores the raw text, the tokens and the list of views available for the text and provides methods for adding new views.
TextAnnotation
,
Sentence
,
Serialized FormModifier and Type | Field and Description |
---|---|
String |
text
The raw text
|
protected IntPair[] |
tokenCharacterOffsets
The character offsets of the tokens.
|
protected String |
tokenizedText
The tokenized text
|
protected String[] |
tokens
The list of tokens in the text.
|
protected Map<String,List<View>> |
views
The list of views
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractTextAnnotation() |
Modifier and Type | Method and Description |
---|---|
void |
addTopKView(String viewName,
List<View> view)
Adds a new view identified by
viewName and sets the top K values for this view. |
void |
addView(String viewName,
View view)
Adds the top scoring value for the view identified by
viewName . |
void |
addViews(String[] viewNames,
View[] views) |
Set<String> |
getAvailableViews()
Gets the set of views that are available
|
String |
getText()
Gets the raw text
|
String |
getToken(int position)
Get the token at position from this text
|
IntPair |
getTokenCharacterOffset(int position)
Get the character offset of the token at position in the raw text.
|
String |
getTokenizedText()
Gets the tokenized text.
|
String[] |
getTokens()
Gets the tokens in this text.
|
String[] |
getTokensInSpan(int start,
int end)
Gets the tokens in the span.
|
List<View> |
getTopKViews(String viewName)
Get all the values available for a given view, identified by
viewName |
View |
getView(String viewName)
Gets the highest scoring value for the view identified by
viewName . |
boolean |
hasView(String viewName)
Checks if this text annotation has a view identified by
viewName |
void |
removeAllViews() |
void |
removeView(String viewName)
Remove a given view
|
IQueryable<Constituent> |
select(String viewName)
Gets a queryable list of all constituents from the view, represented by
viewName . |
void |
setTokens(String[] tokens,
IntPair[] tokenCharacterOffsets)
Deprecated.
There is now a TOKENS view that should be used to access the tokens
|
int |
size()
Get the number of tokens in this text.
|
public String text
protected String[] tokens
protected IntPair[] tokenCharacterOffsets
protected String tokenizedText
public void addTopKView(String viewName, List<View> view)
viewName
and sets the top K values for this view.viewName
- The name of the new view to be added.view
- The top K viewspublic void addView(String viewName, View view)
viewName
.public void removeView(String viewName)
public void removeAllViews()
public Set<String> getAvailableViews()
Set<String>
of views that are available for this text annotation.public View getView(String viewName)
viewName
.public List<View> getTopKViews(String viewName)
viewName
public String getText()
public String getTokenizedText()
public String[] getTokens()
public String getToken(int position)
public IntPair getTokenCharacterOffset(int position)
IntPair
representing the pair
(start, end+1)public String[] getTokensInSpan(int start, int end)
start
- The start of the spanend
- The end of the spanpublic boolean hasView(String viewName)
viewName
true
if the text annotation contains a view called viewName
and
false
otherwisepublic void setTokens(String[] tokens, IntPair[] tokenCharacterOffsets)
NOTE: This function should not be called by any method that is not a Tokenizer
and will throw an exception if tokens are set more than once. So do not call this function
unless you know what you are doing.
tokens
- An array of tokenstokenCharacterOffsets
- An array, whose length is the same as tokens
. Each
element indicates the character offset of this token in the raw text.IllegalArgumentException
- if the tokens are set more than once.public int size()
public IQueryable<Constituent> select(String viewName)
viewName
.
This function can be used for SQL-like queries on the text.
Examples: In all the examples that follow, we assume that text
is a variable of type
AbstractTextAnnotation
.
srlConstituent
from the SRL_VERB view, find all constituents
in the parse view that cover exactly this constituent.
List<Constituent> parseConstituent = text.select(ViewNames.PARSE).where( Queries.sameSpanAsConstituent(srlConstituent));
QueryableList
,
ViewNames
Copyright © 2017. All rights reserved.