com.johnsnowlabs.nlp.annotators
Add one character string to rip off from tokens, such as parenthesis or question marks.
Add one character string to rip off from tokens, such as parenthesis or question marks. Ignored if using prefix, infix or suffix patterns.
Add a single exception
Add a single exception
Add an extension pattern regex with groups to the top of thsetExceptionse rules (will target first, from more specific to the more general).
Add an extension pattern regex with groups to the top of thsetExceptionse rules (will target first, from more specific to the more general).
One character string to split tokens inside, such as hyphens.
One character string to split tokens inside, such as hyphens. Ignored if using infix, prefix or suffix patterns.
Build rule factory which combines all defined parameters to build regex that is applied to tokens
Build rule factory which combines all defined parameters to build regex that is applied to tokens
Whether to care for case sensitiveness in exceptions (Default: true
)
Whether to care for case sensitiveness in exceptions (Default: true
)
Character list used to separate from token boundaries
(Default: Array(".", ",", ";", ":", "!", "?", "*", "-", "(", ")", "\"", "'")
)
Character list used to separate from token boundaries
(Default: Array(".", ",", ";", ":", "!", "?", "*", "-", "(", ")", "\"", "'")
)
Annotator that identifies points of analysis in a useful manner
Annotator that identifies points of analysis in a useful manner
Words that won't be affected by tokenization rules
Words that won't be affected by tokenization rules
Path to file containing list of exceptions
Path to file containing list of exceptions
Whether to follow case sensitiveness for matching exceptions in text
Whether to follow case sensitiveness for matching exceptions in text
List of 1 character string to rip off from tokens, such as parenthesis or question marks.
List of 1 character string to rip off from tokens, such as parenthesis or question marks. Ignored if using prefix, infix or suffix patterns.
Add an extension pattern regex with groups to the top of the rules (will target first, from more specific to the more general).
Add an extension pattern regex with groups to the top of the rules (will target first, from more specific to the more general).
input annotations columns currently used
Get the maximum allowed length for each token
Get the maximum allowed length for each token
Get the minimum allowed length for each token
Get the minimum allowed length for each token
Gets annotation column name going to generate
Gets annotation column name going to generate
Regex to identify subtokens that come in the beginning of the token.
Regex to identify subtokens that come in the beginning of the token. Regex has to start with \\A and must contain groups (). Each group will become a separate token within the prefix. Defaults to non-letter characters. e.g. quotes or parenthesis
List of 1 character string to split tokens inside, such as hyphens.
List of 1 character string to split tokens inside, such as hyphens. Ignored if using infix, prefix or suffix patterns.
List of 1 character string to split tokens inside, such as hyphens.
List of 1 character string to split tokens inside, such as hyphens. Ignored if using infix, prefix or suffix patterns.
Regex to identify subtokens that are in the end of the token.
Regex to identify subtokens that are in the end of the token. Regex has to end with \\z and must contain groups (). Each group will become a separate token within the prefix. Defaults to non-letter characters. e.g. quotes or parenthesis
Basic regex rule to identify a candidate for tokenization.
Basic regex rule to identify a candidate for tokenization. Defaults to \\S+ which means anything not a space
Regex patterns that match tokens within a single target.
Regex patterns that match tokens within a single target. groups identify different sub-tokens. multiple defaults
Infix patterns must use regex group. Notice each group will result in separate token
Example:
import org.apache.spark.ml.Pipeline import com.johnsnowlabs.nlp.annotators.Tokenizer import com.johnsnowlabs.nlp.DocumentAssembler val textDf = sqlContext.sparkContext.parallelize(Array("l'une d'un l'un, des l'extrême des l'extreme")).toDF("text") val documentAssembler = new DocumentAssembler().setInputCol("text").setOutputCol("sentences") val tokenizer = new Tokenizer().setInputCols("sentences").setOutputCol("tokens").setInfixPatterns(Array("([\\p{L}\\w]+'{1})([\\p{L}\\w]+)")) new Pipeline().setStages(Array(documentAssembler, tokenizer)).fit(textDf).transform(textDf).select("tokens.result").show(false)
This will yield: l', une, d', un, l', un, , , des, l', extrême, des, l', extreme
Input Annotator Type : CHUNK
Input Annotator Type : CHUNK
columns that contain annotations necessary to run this annotator AnnotatorType is used both as input and output columns if not specified
columns that contain annotations necessary to run this annotator AnnotatorType is used both as input and output columns if not specified
Set the maximum allowed length for each token
Set the maximum allowed length for each token
Set the minimum allowed length for each token
Set the minimum allowed length for each token
Output Annotator Type : TOKEN
Output Annotator Type : TOKEN
Regex with groups and begins with \\A to match target prefix.
Regex with groups and begins with \\A to match target prefix. Overrides contextCharacters Param
Whether to follow case sensitiveness for matching exceptions in text
Whether to follow case sensitiveness for matching exceptions in text
List of 1 character string to rip off from tokens, such as parenthesis or question marks.
List of 1 character string to rip off from tokens, such as parenthesis or question marks. Ignored if using prefix, infix or suffix patterns.
List of tokens to not alter at all.
List of tokens to not alter at all. Allows composite tokens like two worded tokens that the user may not want to split.
Path to txt file with list of token exceptions
Path to txt file with list of token exceptions
Set a list of Regex patterns that match tokens within a single target.
Set a list of Regex patterns that match tokens within a single target. Groups identify different sub-tokens. multiple defaults
Overrides required annotators column if different than default
Overrides required annotators column if different than default
Get the maximum allowed length for each token
Get the maximum allowed length for each token
Set the minimum allowed length for each token
Set the minimum allowed length for each token
Overrides annotation column name when transforming
Overrides annotation column name when transforming
Regex to identify subtokens that come in the beginning of the token.
Regex to identify subtokens that come in the beginning of the token. Regex has to start with \\A and must contain groups (). Each group will become a separate token within the prefix. Defaults to non-letter characters. e.g. quotes or parenthesis
List of 1 character string to split tokens inside, such as hyphens.
List of 1 character string to split tokens inside, such as hyphens. Ignored if using infix, prefix or suffix patterns.
Regex pattern to separate from the inside of tokens.
Regex pattern to separate from the inside of tokens. Takes priority over splitChars.
Regex to identify subtokens that are in the end of the token.
Regex to identify subtokens that are in the end of the token. Regex has to end with \\z and must contain groups (). Each group will become a separate token within the prefix. Defaults to non-letter characters. e.g. quotes or parenthesis
Set a basic regex rule to identify token candidates in text.
Set a basic regex rule to identify token candidates in text.
Character list used to separate from the inside of tokens
Character list used to separate from the inside of tokens
Pattern to separate from the inside of tokens.
Pattern to separate from the inside of tokens. takes priority over splitChars.
This pattern will be applied to the tokens which where extracted with the target pattern previously
Example:
import org.apache.spark.ml.Pipeline import com.johnsnowlabs.nlp.annotators.Tokenizer import com.johnsnowlabs.nlp.DocumentAssembler val textDf = sqlContext.sparkContext.parallelize(Array("Tokens in this-text will#be#split on hashtags-and#dashes")).toDF("text") val documentAssembler = new DocumentAssembler().setInputCol("text").setOutputCol("sentences") val tokenizer = new Tokenizer().setInputCols("sentences").setOutputCol("tokens").setSplitPattern("-|#") new Pipeline().setStages(Array(documentAssembler, tokenizer)).fit(textDf).transform(textDf).select("tokens.result").show(false)
This will yield: Tokens, in, this, text, will, be, split, on, hashtags, and, dashes
Regex with groups and ends with \\z to match target suffix.
Regex with groups and ends with \\z to match target suffix. Overrides contextCharacters Param
Pattern to grab from text as token candidates.
Pattern to grab from text as token candidates. (Default: "\\S+"
)
Defaults to: "\\S+" which means anything not a space will be matched and considered as a token candidate, This will cause text to be split on on white spaces to yield token candidates.
This rule will be added to the BREAK_PATTERN varaible, which is used to yield token candidates.
import org.apache.spark.ml.Pipeline import com.johnsnowlabs.nlp.annotators.Tokenizer import com.johnsnowlabs.nlp.DocumentAssembler val textDf = sqlContext.sparkContext.parallelize(Array("I only consider lowercase characters and NOT UPPERCASED and only the numbers 0,1, to 7 as tokens but not 8 or 9")).toDF("text") val documentAssembler = new DocumentAssembler().setInputCol("text").setOutputCol("sentences") val tokenizer = new Tokenizer().setInputCols("sentences").setOutputCol("tokens").setTargetPattern("a-z-0-7") new Pipeline().setStages(Array(documentAssembler, tokenizer)).fit(textDf).transform(textDf).select("tokens.result").show(false)
This will yield: only, consider, lowercase, characters, and, and, only, the, numbers, 0, 1, to, 7, as, tokens, but, not, or
Clears out rules and constructs a new rule for every combination of rules provided .
Clears out rules and constructs a new rule for every combination of rules provided . The strategy is to catch one token per regex group. User may add its own groups if needs targets to be tokenized separately from the rest
requirement for pipeline transformation validation.
requirement for pipeline transformation validation. It is called on fit()
required internal uid for saving annotator
required internal uid for saving annotator
takes a Dataset and checks to see if all the required annotation types are present.
takes a Dataset and checks to see if all the required annotation types are present.
to be validated
True if all the required types are present, else false
A list of (hyper-)parameter keys this annotator can take. Users can set and get the parameter values through setters and getters, respectively.
Required input and expected output annotator types
Tokenizes and flattens extracted NER chunks.
The ChunkTokenizer will split the extracted NER
CHUNK
type Annotations and will createTOKEN
type Annotations. The result is then flattened, resulting in a single array.For extended examples of usage, see the ChunkTokenizerTestSpec.
Example