Skip to content

Commit

Permalink
small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaber committed Mar 16, 2015
1 parent 9c2e437 commit 52b0a1d
Showing 1 changed file with 20 additions and 28 deletions.
Expand Up @@ -83,8 +83,8 @@ public class Element implements Cloneable {
private int minOccurrence = 1; private int minOccurrence = 1;
private int maxOccurrence = 1; private int maxOccurrence = 1;


private Pattern p; private Pattern pattern;
private Pattern pPos; private Pattern posPattern;


/** The reference to another element in the pattern. **/ /** The reference to another element in the pattern. **/
private Match tokenReference; private Match tokenReference;
Expand All @@ -109,9 +109,7 @@ public class Element implements Cloneable {
private Map<String, List<String>> unificationFeatures; private Map<String, List<String>> unificationFeatures;
private boolean posUnknown; private boolean posUnknown;


/** /** Set to true on tokens that close the unification block. */
* Set to true on tokens that close the unification block.
*/
private boolean isLastUnified; private boolean isLastUnified;


/** /**
Expand Down Expand Up @@ -145,11 +143,11 @@ public final boolean isMatched(final AnalyzedToken token) {
} }
final boolean matched; final boolean matched;
if (testString) { if (testString) {
matched = isStringTokenMatched(token) ^ negation matched = isStringTokenMatched(token) ^ negation &&
&& isPosTokenMatched(token) ^ posNegation; isPosTokenMatched(token) ^ posNegation;
} else { } else {
matched = !negation matched = !negation &&
&& isPosTokenMatched(token) ^ posNegation; isPosTokenMatched(token) ^ posNegation;
} }
return matched; return matched;
} }
Expand Down Expand Up @@ -329,21 +327,19 @@ public final void setPosElement(final String posToken, final boolean regExp,
this.posNegation = negation; this.posNegation = negation;
posRegExp = regExp; posRegExp = regExp;
if (posRegExp) { if (posRegExp) {
pPos = Pattern.compile(posToken); posPattern = Pattern.compile(posToken);
final Matcher mPos = pPos.matcher(UNKNOWN_TAG); posUnknown = posPattern.matcher(UNKNOWN_TAG).matches();
posUnknown = mPos.matches();
} else { } else {
posUnknown = UNKNOWN_TAG.equals(posToken); posUnknown = UNKNOWN_TAG.equals(posToken);
} }
} }


/** /** @since 2.3 */
* @since 2.3
*/
public final void setChunkElement(final ChunkTag chunkTag) { public final void setChunkElement(final ChunkTag chunkTag) {
this.chunkToken = chunkTag; this.chunkToken = chunkTag;
} }


@Nullable
public final String getString() { public final String getString() {
return stringToken; return stringToken;
} }
Expand All @@ -361,7 +357,7 @@ public final void setStringElement(final String token) {
regToken = CASE_INSENSITIVE + stringToken; regToken = CASE_INSENSITIVE + stringToken;
} }
if (!"\\0".equals(token)) { if (!"\\0".equals(token)) {
p = Pattern.compile(regToken); pattern = Pattern.compile(regToken);
} }
} }
} }
Expand All @@ -385,7 +381,6 @@ public final void setStringPosException(
final String token, final boolean regExp, final boolean inflected, final String token, final boolean regExp, final boolean inflected,
final boolean negation, final boolean scopeNext, final boolean scopePrevious, final boolean negation, final boolean scopeNext, final boolean scopePrevious,
final String posToken, final boolean posRegExp, final boolean posNegation, final Boolean caseSensitivity) { final String posToken, final boolean posRegExp, final boolean posNegation, final Boolean caseSensitivity) {

final Element exception = new Element(token, caseSensitivity == null ? caseSensitive : caseSensitivity, regExp, inflected); final Element exception = new Element(token, caseSensitivity == null ? caseSensitive : caseSensitivity, regExp, inflected);
exception.setNegation(negation); exception.setNegation(negation);
exception.setPosElement(posToken, posRegExp, posNegation); exception.setPosElement(posToken, posRegExp, posNegation);
Expand Down Expand Up @@ -413,7 +408,6 @@ public final void setStringPosException(
setStringPosException(token, regExp, inflected, negation, scopeNext, scopePrevious, posToken, posRegExp, posNegation, Boolean.valueOf(caseSensitivity)); setStringPosException(token, regExp, inflected, negation, scopeNext, scopePrevious, posToken, posRegExp, posNegation, Boolean.valueOf(caseSensitivity));
} }



private void setException(final Element elem, final boolean scopePrevious) { private void setException(final Element elem, final boolean scopePrevious) {
exceptionValidPrevious |= scopePrevious; exceptionValidPrevious |= scopePrevious;
if (exceptionList == null && !scopePrevious) { if (exceptionList == null && !scopePrevious) {
Expand Down Expand Up @@ -471,7 +465,7 @@ private boolean isPosTokenMatched(final AnalyzedToken token) {
} }
boolean match; boolean match;
if (posRegExp) { if (posRegExp) {
final Matcher mPos = pPos.matcher(token.getPOSTag()); final Matcher mPos = posPattern.matcher(token.getPOSTag());
match = mPos.matches(); match = mPos.matches();
} else { } else {
match = posToken.equals(token.getPOSTag()); match = posToken.equals(token.getPOSTag());
Expand All @@ -490,7 +484,7 @@ private boolean isPosTokenMatched(final AnalyzedToken token) {
boolean isStringTokenMatched(final AnalyzedToken token) { boolean isStringTokenMatched(final AnalyzedToken token) {
final String testToken = getTestToken(token); final String testToken = getTestToken(token);
if (stringRegExp) { if (stringRegExp) {
final Matcher m = p.matcher(testToken); final Matcher m = pattern.matcher(testToken);
return m.matches(); return m.matches();
} }
if (caseSensitive) { if (caseSensitive) {
Expand Down Expand Up @@ -631,7 +625,7 @@ public final Element compile(final AnalyzedTokenReadings token, final Synthesize
} }


void doCompile(final AnalyzedTokenReadings token, final Synthesizer synth) throws IOException { void doCompile(final AnalyzedTokenReadings token, final Synthesizer synth) throws IOException {
p = null; pattern = null;
final MatchState matchState = tokenReference.createState(synth, token); final MatchState matchState = tokenReference.createState(synth, token);


if (StringTools.isEmpty(referenceString)) { if (StringTools.isEmpty(referenceString)) {
Expand All @@ -652,10 +646,10 @@ void doCompile(final AnalyzedTokenReadings token, final Synthesizer synth) throw


/** /**
* Sets the phrase the element is in. * Sets the phrase the element is in.
* @param s ID of the phrase. * @param id ID of the phrase.
*/ */
public final void setPhraseName(final String s) { public final void setPhraseName(final String id) {
phraseName = s; phraseName = id;
} }


/** /**
Expand Down Expand Up @@ -736,16 +730,14 @@ public final boolean isUnified() {
return unified; return unified;
} }




public final void setUnification(final Map<String, List<String>> uniFeatures) { public final void setUnification(final Map<String, List<String>> uniFeatures) {
unificationFeatures = uniFeatures; unificationFeatures = uniFeatures;
unified = true; unified = true;
} }


/** /**
* Get unification features and types. * Get unification features and types.
* @return A map from features to a list of types. * @return A map from features to a list of types or {@code null}
* @since 1.0.1 * @since 1.0.1
*/ */
@Nullable @Nullable
Expand Down Expand Up @@ -774,7 +766,7 @@ public final void setLastInUnification() {
* and simply added. * and simply added.
* @return True when the element is not included in unifying. * @return True when the element is not included in unifying.
* @since 2.5 * @since 2.5
**/ */
public boolean isUnificationNeutral() { public boolean isUnificationNeutral() {
return unificationNeutral; return unificationNeutral;
} }
Expand Down

0 comments on commit 52b0a1d

Please sign in to comment.