1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* LanguageTool, a natural language style checker
* Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package de.danielnaber.languagetool;
/**
* A word (or punctuation, or whitespace) and its part-of-speech tag.
*
* @author Daniel Naber
*/
public class AnalyzedToken {
private final String token;
private final String posTag;
private final String lemma;
/**
* used only for matching with Elements
*/
private final String tokenInflected;
private boolean isWhitespaceBefore;
public AnalyzedToken(final String token, final String posTag, final String lemma) {
if (token == null) {
throw new NullPointerException("Token cannot be null!");
}
this.token = token;
this.posTag = posTag;
this.lemma = lemma;
if (lemma == null) {
tokenInflected = token;
} else {
tokenInflected = lemma;
}
}
public final String getToken() {
return token;
}
public final String getPOSTag() {
return posTag;
}
public final String getLemma() {
return lemma;
}
public final String getTokenInflected() {
return tokenInflected;
}
public final void setWhitespaceBefore(final boolean isWhite) {
isWhitespaceBefore = isWhite;
}
public final boolean isWhitespaceBefore() {
return isWhitespaceBefore;
}
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(tokenInflected);
sb.append('/');
sb.append(posTag);
return sb.toString();
}
@Override
public final int hashCode() {
// TODO: use Apache Commons Lang HashCodeBuilder
final int prime = 31;
int result = 1;
result = prime * result + (isWhitespaceBefore ? 1231 : 1237);
result = prime * result + ((lemma == null) ? 0 : lemma.hashCode());
result = prime * result + ((posTag == null) ? 0 : posTag.hashCode());
result = prime * result + ((token == null) ? 0 : token.hashCode());
return result;
}
@Override
public final boolean equals(final Object obj) {
// TODO: use Apache Commons Lang EqualsBuilder
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final AnalyzedToken other = (AnalyzedToken) obj;
if (isWhitespaceBefore != other.isWhitespaceBefore) {
return false;
}
if (lemma == null) {
if (other.lemma != null) {
return false;
}
} else if (!lemma.equals(other.lemma)) {
return false;
}
if (posTag == null) {
if (other.posTag != null) {
return false;
}
} else if (!posTag.equals(other.posTag)) {
return false;
}
if (token == null) {
if (other.token != null) {
return false;
}
} else if (!token.equals(other.token)) {
return false;
}
return true;
}
}
|