de.danielnaber.languagetool.rules.patterns
Class Element

Object
  extended by Element

public class Element
extends Object

A part of a pattern.

Author:
Daniel Naber

Constructor Summary
Element(String token, boolean caseSensitive, boolean regExp, boolean inflected)
          Creates Element that is used to match tokens in the text.
 
Method Summary
 void addMemberAndGroup(AnalyzedToken token)
          Enables testing multiple conditions specified by different elements.
 boolean checkAndGroup(boolean previousValue)
           
 void compile(AnalyzedTokenReadings token, Synthesizer synth)
          Prepare Element for matching by formatting its string token and POS (if the Element is supposed to refer to some other token).
 List<Element> getAndGroup()
          Returns the group of elements linked with AND operator.
 boolean getCaseSensitive()
          Whether the element matches case sensitively.
 List<Element> getExceptionList()
          Since 1.0.0
 Match getMatch()
           
 boolean getNegation()
          see setNegation(boolean)
 String getPhraseName()
          Gets the phrase the element is in.
 boolean getPOSNegation()
          Tests whether the POS is negated.
 String getPOStag()
           
 int getSkipNext()
          Gets the exception scope length.
 String getString()
           
 String getUniFeature()
           
 String getUniType()
           
 boolean hasAndGroup()
          Checks if this element has an AND group associated with it.
 boolean hasPreviousException()
          Checks if the element has an exception for a previous token.
 boolean isAndExceptionGroupMatched(AnalyzedToken token)
          Enables testing multiple conditions specified by multiple element exceptions.
 boolean isExceptionMatched(AnalyzedToken token)
          Checks whether an exception matches.
 boolean isExceptionMatchedCompletely(AnalyzedToken token)
          This method checks exceptions both in AND-group and the token.
 boolean isInflected()
          Whether the token is inflected.
 boolean isMatched(AnalyzedToken token)
          Checks whether the rule element matches the token given as a parameter.
 boolean isMatchedByPreviousException(AnalyzedToken token)
          Checks whether an exception for a previous token matches (in case the exception had scope == "previous").
 boolean isMatchedByPreviousException(AnalyzedTokenReadings prevToken)
          Checks whether an exception for a previous token matches all readings of a given token (in case the exception had scope == "previous").
 boolean isMatchedByScopeNextException(AnalyzedToken token)
          Checks whether a previously set exception matches (in case the exception had scope == "next").
 boolean isPartOfPhrase()
          Checks if the Element is in any phrase.
 boolean isReferenceElement()
           
 boolean isRegularExpression()
          Tests whether the element matches a regular expression.
 boolean isSentStart()
          Checks if the token is a SENT_START.
 boolean isUnified()
           
 boolean isUniNegated()
           
 boolean isWhitespaceBefore(AnalyzedToken token)
           
 void setAndGroupElement(Element andToken)
           
 void setExceptionSpaceBefore(boolean isWhite)
           
 void setMatch(Match match)
          Sets the reference to another token.
 void setNegation(boolean negation)
          Negates the meaning of match().
 void setPhraseName(String s)
          Sets the phrase the element is in.
 void setPosElement(String posToken, boolean regExp, boolean negation)
           
 void setPosException(String posToken, boolean regExp, boolean negation, boolean scopeNext, boolean scopePrevious)
          Sets a POS-type exception for matching string tokens.
 void setSkipNext(int i)
          Sets the exception scope length.
 void setStringElement(String token)
           
 void setStringException(String token, boolean regExp, boolean inflected, boolean negation, boolean scopeNext, boolean scopePrevious)
          Sets a string-type exception for matching string tokens.
 void setUnification(String feature, String type)
           
 void setUniNegation()
           
 void setupAndGroup()
           
 void setWhitespaceBefore(boolean isWhite)
           
 String toString()
           
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Element

public Element(String token,
               boolean caseSensitive,
               boolean regExp,
               boolean inflected)
Creates Element that is used to match tokens in the text.

Parameters:
token - String to be matched
caseSensitive - True if the check is case-sensitive.
regExp - True if the check uses regular expressions.
inflected - True if the check refers to base forms (lemmas).
Method Detail

isMatched

public final boolean isMatched(AnalyzedToken token)
Checks whether the rule element matches the token given as a parameter.

Parameters:
token -
Returns:
True if token matches, false otherwise.

isExceptionMatched

public final boolean isExceptionMatched(AnalyzedToken token)
Checks whether an exception matches.

Parameters:
token -
Returns:
True if any of the exceptions matches (logical disjunction).

addMemberAndGroup

public final void addMemberAndGroup(AnalyzedToken token)
Enables testing multiple conditions specified by different elements. Doesn't test exceptions. Works as logical AND operator only if preceded with setupAndGroup(), and followed by checkAndGroup(boolean).

Parameters:
token - AnalyzedToken - the token checked.

setupAndGroup

public final void setupAndGroup()

checkAndGroup

public final boolean checkAndGroup(boolean previousValue)

isAndExceptionGroupMatched

public final boolean isAndExceptionGroupMatched(AnalyzedToken token)
Enables testing multiple conditions specified by multiple element exceptions. Works as logical AND operator.

Parameters:
token - AnalyzedToken - the token checked for exceptions.
Returns:
true if all conditions are met, false otherwise.

isExceptionMatchedCompletely

public final boolean isExceptionMatchedCompletely(AnalyzedToken token)
This method checks exceptions both in AND-group and the token. Introduced to for clarity.

Parameters:
token - Token to match
Returns:
True if matched.

setAndGroupElement

public final void setAndGroupElement(Element andToken)

hasAndGroup

public final boolean hasAndGroup()
Checks if this element has an AND group associated with it.

Returns:
true if the element has a group of elements that all should match.

getAndGroup

public final List<Element> getAndGroup()
Returns the group of elements linked with AND operator.

Returns:
List of Elements.

isMatchedByScopeNextException

public final boolean isMatchedByScopeNextException(AnalyzedToken token)
Checks whether a previously set exception matches (in case the exception had scope == "next").

Parameters:
token -
Returns:
True if any of the exceptions matches.

isMatchedByPreviousException

public final boolean isMatchedByPreviousException(AnalyzedToken token)
Checks whether an exception for a previous token matches (in case the exception had scope == "previous").

Parameters:
token - AnalyzedToken to check matching against.
Returns:
True if any of the exceptions matches.

isMatchedByPreviousException

public final boolean isMatchedByPreviousException(AnalyzedTokenReadings prevToken)
Checks whether an exception for a previous token matches all readings of a given token (in case the exception had scope == "previous").

Parameters:
token - AnalyzedTokenReadings to check matching against.
Returns:
true if any of the exceptions matches.

isSentStart

public final boolean isSentStart()
Checks if the token is a SENT_START.

Returns:
True if the element starts the sentence and the element hasn't been set to have negated POS token.

toString

public final String toString()
Overrides:
toString in class Object

setPosElement

public final void setPosElement(String posToken,
                                boolean regExp,
                                boolean negation)

getString

public final String getString()

setStringElement

public final void setStringElement(String token)

setPosException

public final void setPosException(String posToken,
                                  boolean regExp,
                                  boolean negation,
                                  boolean scopeNext,
                                  boolean scopePrevious)
Sets a POS-type exception for matching string tokens.

Parameters:
posToken - The part of the speech tag in the exception.
regExp - True if the POS is specified as a regular expression.
negation - True if the exception is negated.
scopeNext - True if the exception scope is next tokens.
scopePrevious - True if the exception should match only a single previous token.

setStringException

public final void setStringException(String token,
                                     boolean regExp,
                                     boolean inflected,
                                     boolean negation,
                                     boolean scopeNext,
                                     boolean scopePrevious)
Sets a string-type exception for matching string tokens.

Parameters:
token - The string in the exception.
regExp - True if the string is specified as a regular expression.
inflected - True if the string is a base form (lemma).
negation - True if the exception is negated.
scopeNext - True if the exception scope is next tokens.
scopePrevious - True if the exception should match only a single previous token.

getSkipNext

public final int getSkipNext()
Gets the exception scope length.

Returns:
Scope length.

setSkipNext

public final void setSkipNext(int i)
Sets the exception scope length.

Parameters:
i - Exception scope length.

hasPreviousException

public final boolean hasPreviousException()
Checks if the element has an exception for a previous token.

Returns:
True if the element has a previous token matching exception.

setNegation

public final void setNegation(boolean negation)
Negates the meaning of match().

Parameters:
negation - - true if the meaning of match() is to be negated.

getNegation

public final boolean getNegation()
see setNegation(boolean)

Since:
0.9.3

isReferenceElement

public final boolean isReferenceElement()
Returns:
true when this element refers to another token.

setMatch

public final void setMatch(Match match)
Sets the reference to another token.

Parameters:
match - Formatting object for the token reference.

getMatch

public final Match getMatch()

compile

public final void compile(AnalyzedTokenReadings token,
                          Synthesizer synth)
                   throws IOException
Prepare Element for matching by formatting its string token and POS (if the Element is supposed to refer to some other token).

Parameters:
token - the token specified as #AnalyzedTokenReadings
synth - the language synthesizer (#Syntesizer)
Throws:
IOException

setPhraseName

public final void setPhraseName(String s)
Sets the phrase the element is in.

Parameters:
s - ID of the phrase.

isPartOfPhrase

public final boolean isPartOfPhrase()
Checks if the Element is in any phrase.

Returns:
True if the Element is contained in the phrase.

getCaseSensitive

public final boolean getCaseSensitive()
Whether the element matches case sensitively.

Since:
0.9.3

isRegularExpression

public final boolean isRegularExpression()
Tests whether the element matches a regular expression.

Since:
0.9.6

getPOStag

public final String getPOStag()
Returns:
the POS of the Element
Since:
0.9.6

getPOSNegation

public final boolean getPOSNegation()
Tests whether the POS is negated.

Returns:
true if so.

isInflected

public final boolean isInflected()
Whether the token is inflected.

Returns:
True if so.

getPhraseName

public final String getPhraseName()
Gets the phrase the element is in.

Returns:
String The name of the phrase.

isUnified

public final boolean isUnified()

setUnification

public final void setUnification(String feature,
                                 String type)

getUniFeature

public final String getUniFeature()

getUniType

public final String getUniType()

setUniNegation

public final void setUniNegation()

isUniNegated

public final boolean isUniNegated()

setWhitespaceBefore

public final void setWhitespaceBefore(boolean isWhite)

setExceptionSpaceBefore

public final void setExceptionSpaceBefore(boolean isWhite)

isWhitespaceBefore

public final boolean isWhitespaceBefore(AnalyzedToken token)

getExceptionList

public final List<Element> getExceptionList()
Since 1.0.0

Returns:
A List of Exceptions. Used for testing.


Copyright © 2005-2009 Daniel Naber