shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package com.walker.semantics;
 
/**
 * 描述:词元对象定义
 * @author 时克英
 * @date 2020年11月10日 上午11:23:10
 */
 
public class WordMeta {
 
    private String text;
    private SpeechPart speechPart = null;
    
    private int index = 0;    // 单词所在句子中的索引值,从0开始
    
    // 是否重复数据,最初考虑句子中的词是不重复的,但考虑太单纯,
    // 在分析时间范围过程中,就出现多个月份,但还不能删掉,所以设置此字段表示已经重复的词。
    private boolean duplication = false;
    
    /**
     * 返回是否已经是重复的词
     * @return
     */
    public boolean isDuplication() {
        return duplication;
    }
 
    public void setDuplication(boolean duplication) {
        this.duplication = duplication;
    }
 
    public int getIndex() {
        return index;
    }
 
    public void setIndex(int index) {
        this.index = index;
    }
 
    public WordMeta(String text, SpeechPart speechPart){
        if(text == null || text.equals("") || speechPart == null){
            throw new IllegalArgumentException("缺少参数:text | speechPart");
        }
        this.text = text;
        this.speechPart = speechPart;
    }
    
    public String getText(){
        return this.text;
    }
    
    public SpeechPart getSpeechPart(){
        return this.speechPart;
    }
    
    /**
     * 是否系统规定的名词,不包括:道路和建筑
     * @return
     * @date 2021-09-01
     */
    public boolean isMyName(){
        if(this.speechPart == SpeechPart.MY_N){
            return true;
        }
        return false;
    }
    
    /**
     * 是否系统定义的建筑,如:中原饭店。</p>
     * 该关键词会提交到系统以及语音系统中
     * @return
     * @date 2021-09-01
     */
    public boolean isMyPlace(){
        if(this.speechPart == SpeechPart.MY_PLACE){
            return true;
        }
        return false;
    }
    
    /**
     * 是否系统定义的道路,如:文化路。</p>
     * 该关键词会提交到系统以及语音系统中
     * @return
     * @date 2021-09-01
     */
    public boolean isMyRoad(){
        if(this.speechPart == SpeechPart.MY_ROAD){
            return true;
        }
        return false;
    }
    
    /**
     * 是否是地点词
     * @return
     */
    public boolean isPlace(){
        if(this.speechPart == SpeechPart.MY_PLACE 
                || this.speechPart == SpeechPart.NS_PLACENAME 
                || this.speechPart == SpeechPart.S_PLACE){
            return true;
        }
        return false;
    }
    
    /**
     * 是否已经是自定义指令词。</p>
     * 指令词不管动词、名词,系统自定义一律使用 SpeechPart.MY_V 类型
     * @return
     */
    public boolean isInstruction(){
        if(this.speechPart == SpeechPart.MY_V){
            return true;
        }
        return false;
    }
    
    /**
     * 是否指令辅助词,如:显示...(分布)
     * @return
     */
    public boolean isInstructionAuxiliary(){
        if(this.speechPart == SpeechPart.MY_V_AUX){
            return true;
        }
        return false;
    }
    
    public boolean isResource(){
//        if(this.speechPart == SpeechPart.MY_N){
        // 2021-09-01 修改:把建筑、道路词性,单独区分开了
        if(this.speechPart == SpeechPart.MY_N 
                || this.isMyPlace() || this.isMyRoad()){
            return true;
        }
        return false;
    }
    
    /**
     * 可当指令使用的词性
     * @return
     */
    public boolean isAvailableInstruction(){
        if(this.speechPart == SpeechPart.V_VERB 
                || this.speechPart == SpeechPart.VN_VERBNAME 
                || this.speechPart == SpeechPart.N_NAME
                
                // 注意:在测试中发现【哪里】这个词性是rys,这个很特殊
                // 在定位中使用了
                || this.speechPart == SpeechPart.RYS){
            return true;
        }
        return false;
    }
    
    /**
     * 是否动词
     * @return
     */
    public boolean isVerbs(){
        if(this.speechPart == SpeechPart.V_VERB 
                || this.speechPart == SpeechPart.VN_VERBNAME){
            return true;
        }
        return false;
    }
    
    /**
     * 是否介词</p>
     * <li>该方法目前在解析时间中判断,如:[从...] 至 使用
     * @return
     */
    public boolean isPreposition(){
        if(this.speechPart == SpeechPart.P_PREPOSITION){
            return true;
        }
        return false;
    }
    
    /**
     * 是否方位词</p>
     * <li>该方法目前在解析时间中判断,如:...之间
     * @return
     */
    public boolean isF_Position(){
        if(this.speechPart == SpeechPart.F_POSITION){
            return true;
        }
        return false;
    }
    
    /**
     * 是否时间词</p>
     * <li>该方法目前在解析时间中判断,如:最近
     * @return
     */
    public boolean isTime(){
        if(this.speechPart == SpeechPart.T_TIME){
            return true;
        }
        return false;
    }
    
    /**
     * 是否数值
     * @return
     */
    public boolean isNumber(){
        if(this.speechPart == SpeechPart.M_NUMBER){
            return true;
        }
        return false;
    }
    
    /**
     * 是否数值+单位(数值可能是中文,如:一天、一个月等)
     * @return
     */
    public boolean isMQ(){
        if(this.speechPart == SpeechPart.MQ_NUMBER_UNIT){
            return true;
        }
        return false;
    }
    
    /**
     * 是否单位,如:个,双等
     * @return
     */
    public boolean isQ(){
        if(this.speechPart == SpeechPart.Q_QUANTIFIER || this.speechPart == SpeechPart.QV){
            return true;
        }
        return false;
    }
    
    /**
     * 是否数量,因为情况复杂,发现词性:m和mq是混合存在的,根据句子不同是不确定的,所以这里<br>
     * 返回的是只要包含数量词相关的情况都返回True,如:
     * <pre>
     * m: 五十,3个,三个,五十六个,120个,2万,2万个,两万,两万个
     * mq:二十二公里,两只,一双,4500人
     * </pre>
     * @return
     */
    public boolean isQuantity(){
        if(this.speechPart == SpeechPart.M_NUMBER || this.speechPart == SpeechPart.MQ_NUMBER_UNIT){
            return true;
        }
        return false;
    }
    
    /**
     * 数词,如:几、12345等,有些很特殊,如:一个月(一个mq),而两个月、三个月就分开了
     * @return
     */
    @Deprecated
    public boolean isM(){
        if(this.speechPart == SpeechPart.M_NUMBER){
            return true;
        }
        return false;
    }
    
    /**
     * 是否形容词
     * @return
     */
    public boolean isAdjective(){
        if(this.speechPart == SpeechPart.A_ADJECTIVE){
            return true;
        }
        return false;
    }
    
    /**
     * 是否名词(或动名词)
     * @return
     */
    public boolean isName(){
        if(this.speechPart == SpeechPart.N_NAME || this.speechPart == SpeechPart.VN_VERBNAME){
            return true;
        }
        return false;
    }
    
    @Override
    public boolean equals(Object obj){
        if(obj == null){
            return false;
        }
        if(obj instanceof WordMeta){
            WordMeta wm = (WordMeta)obj;
            if(wm.text.equals(this.text)){
                return true;
            }
        }
        return false;
    }
    
    @Override
    public int hashCode(){
        return this.text.hashCode();
    }
    
    @Override
    public String toString(){
        return new StringBuilder().append("[text=").append(this.text)
                .append(", speechPart=").append(this.speechPart)
                .append("]").toString();
    }
}