@ccmaymay/concrete 4.15.0 → 4.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ActiveLearnerClientService.js +249 -249
- package/ActiveLearnerServerService.js +642 -642
- package/AnnotateCommunicationService.js +696 -696
- package/AnnotateWithContextService.js +298 -298
- package/FeedbackService.js +750 -750
- package/FetchCommunicationService.js +709 -709
- package/README.md +125 -0
- package/ResultsServerService.js +2138 -2138
- package/SearchProxyService.js +962 -962
- package/SearchService.js +685 -685
- package/Service.js +373 -373
- package/StoreCommunicationService.js +255 -255
- package/SummarizationService.js +479 -479
- package/access_types.js +168 -168
- package/annotate_types.js +26 -26
- package/audio_types.js +110 -110
- package/cluster_types.js +398 -398
- package/communication_fu.js +432 -432
- package/communication_types.js +845 -845
- package/concrete.js +64 -64
- package/context_types.js +65 -65
- package/email_types.js +477 -477
- package/entities_types.js +658 -658
- package/ex_types.js +82 -82
- package/language_types.js +123 -123
- package/learn_types.js +207 -207
- package/linking_types.js +286 -286
- package/metadata_types.js +926 -926
- package/nitf_types.js +1005 -1005
- package/package.json +26 -5
- package/results_types.js +18 -18
- package/search_types.js +661 -661
- package/services_types.js +384 -384
- package/situations_types.js +1268 -1268
- package/spans_types.js +151 -151
- package/structure_types.js +2311 -2311
- package/summarization_types.js +433 -433
- package/tokenization_fu.js +33 -33
- package/tokentagging_fu.js +241 -241
- package/twitter_types.js +1553 -1553
- package/util.js +117 -117
- package/uuid_types.js +67 -67
package/communication_fu.js
CHANGED
@@ -1,432 +1,432 @@
|
|
1
|
-
/**
|
2
|
-
* @class Communication
|
3
|
-
* @classdesc concrete.js extensions to the Communication class
|
4
|
-
*/
|
5
|
-
const Communication = module.exports = require('./communication_types').Communication;
|
6
|
-
|
7
|
-
const thrift = require('thrift');
|
8
|
-
const Thrift = thrift.Thrift;
|
9
|
-
|
10
|
-
/**
|
11
|
-
* Adds internal references between data structures contained in Communication
|
12
|
-
*
|
13
|
-
* Specifically, adds:
|
14
|
-
* - to each concrete.Section, a section.communication reference to the enclosing Communication
|
15
|
-
* - to each concrete.Sentence, a sentence.section reference to the enclosing Section
|
16
|
-
* - to each concrete.Tokenization, a tokenization.sentence reference to the enclosing Sentence
|
17
|
-
*/
|
18
|
-
Communication.prototype.addInternalReferences = function() {
|
19
|
-
if (this.sectionList) {
|
20
|
-
for (var sectionIndex in this.sectionList) {
|
21
|
-
var section = this.sectionList[sectionIndex];
|
22
|
-
// We add both a 'comm' and 'communication' field to each section. We
|
23
|
-
// originally only added 'comm', but 'communication' is arguably more
|
24
|
-
// consistent. We keep both variable names to avoid breaking existing code.
|
25
|
-
section.comm = this;
|
26
|
-
section.communication = this;
|
27
|
-
|
28
|
-
if (section.sentenceList) {
|
29
|
-
for (var sentenceIndex in section.sentenceList) {
|
30
|
-
var sentence = section.sentenceList[sentenceIndex];
|
31
|
-
sentence.section = section;
|
32
|
-
if (sentence.tokenization) {
|
33
|
-
sentence.tokenization.sentence = sentence;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
};
|
40
|
-
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Return the Entity (or null) that has an EntityMention with the specified UUID
|
44
|
-
*
|
45
|
-
* @param {UUID} uuid
|
46
|
-
* @returns {Entity|null}
|
47
|
-
*/
|
48
|
-
Communication.prototype.getEntityForEntityMentionUUID = function(uuid) {
|
49
|
-
if (!uuid || !uuid.uuidString) {
|
50
|
-
console.error("ERROR: getEntityForEntityMentionUUID() was not passed a valid UUID");
|
51
|
-
return null;
|
52
|
-
}
|
53
|
-
|
54
|
-
if (this.entitySetList) {
|
55
|
-
for (var entitySetIndex in this.entitySetList) {
|
56
|
-
var entityList = this.entitySetList[entitySetIndex].entityList;
|
57
|
-
for (var entityIndex in entityList) {
|
58
|
-
var entity = entityList[entityIndex];
|
59
|
-
for (var entityMentionIndex in entity.mentionIdList) {
|
60
|
-
if (entity.mentionIdList[entityMentionIndex].uuidString === uuid.uuidString) {
|
61
|
-
return entity;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
67
|
-
// TODO: Error handling if no matching UUID could be found
|
68
|
-
console.error("ERROR: No Entity found for EntityMention with UUID " + uuid.uuidString);
|
69
|
-
return null;
|
70
|
-
};
|
71
|
-
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Return the EntityMentionSet in the Communication with the specified toolname
|
75
|
-
*
|
76
|
-
* @param {String} toolname
|
77
|
-
* @returns {EntityMentionSet|null}
|
78
|
-
*/
|
79
|
-
Communication.prototype.getEntityMentionSetWithToolname = function(toolname) {
|
80
|
-
if (this.entityMentionSetList && this.entityMentionSetList.length > 0) {
|
81
|
-
for (var i = 0; i < this.entityMentionSetList.length; i++) {
|
82
|
-
if (this.entityMentionSetList[i].metadata.tool === toolname) {
|
83
|
-
return this.entityMentionSetList[i];
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
return null;
|
88
|
-
};
|
89
|
-
|
90
|
-
|
91
|
-
/**
|
92
|
-
* Return the EntityMention (or null) with the specified UUID
|
93
|
-
*
|
94
|
-
* @param {UUID} uuid
|
95
|
-
* @returns {EntityMention|null}
|
96
|
-
*/
|
97
|
-
Communication.prototype.getEntityMentionWithUUID = function(uuid) {
|
98
|
-
if (!uuid || !uuid.uuidString) {
|
99
|
-
console.error("ERROR: getEntityMentionWithUUID() was not passed a valid UUID");
|
100
|
-
return null;
|
101
|
-
}
|
102
|
-
|
103
|
-
if (this.entityMentionSetList) {
|
104
|
-
for (var entityMentionSetIndex in this.entityMentionSetList) {
|
105
|
-
if (this.entityMentionSetList[entityMentionSetIndex].mentionList) {
|
106
|
-
for (var mentionListIndex in this.entityMentionSetList[entityMentionSetIndex].mentionList) {
|
107
|
-
var entityMention = this.entityMentionSetList[entityMentionSetIndex].mentionList[mentionListIndex];
|
108
|
-
if (entityMention.uuid.uuidString == uuid.uuidString) {
|
109
|
-
return entityMention;
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}
|
115
|
-
// TODO: Error handling if no matching UUID could be found
|
116
|
-
console.error("ERROR: No EntityMention found with UUID " + uuid.uuidString);
|
117
|
-
return null;
|
118
|
-
};
|
119
|
-
|
120
|
-
|
121
|
-
/**
|
122
|
-
* Return the Entity (or null) that has the specified Entity ID
|
123
|
-
*
|
124
|
-
* @param {String} entityId
|
125
|
-
* @returns {Entity|null}
|
126
|
-
*/
|
127
|
-
Communication.prototype.getEntityWithEntityId = function(entityId) {
|
128
|
-
if (!entityId) {
|
129
|
-
console.error("ERROR: getEntityWithEntityId() was not passed a valid entityId");
|
130
|
-
return null;
|
131
|
-
}
|
132
|
-
|
133
|
-
if (this.entitySetList) {
|
134
|
-
for (var entitySetIndex in this.entitySetList) {
|
135
|
-
var entityList = this.entitySetList[entitySetIndex].entityList;
|
136
|
-
for (var entityIndex in entityList) {
|
137
|
-
var entity = entityList[entityIndex];
|
138
|
-
if (entity.id === entityId) {
|
139
|
-
return entity;
|
140
|
-
}
|
141
|
-
}
|
142
|
-
}
|
143
|
-
}
|
144
|
-
// TODO: Error handling if no matching entityId could be found
|
145
|
-
console.error("ERROR: No Entity found for entityId " + entityId);
|
146
|
-
return null;
|
147
|
-
};
|
148
|
-
|
149
|
-
|
150
|
-
/**
|
151
|
-
* Return the first Sentence in a Communication if it exists, or null
|
152
|
-
*
|
153
|
-
* @returns {Sentence|null}
|
154
|
-
*/
|
155
|
-
Communication.prototype.getFirstSentence = function() {
|
156
|
-
// The first few Sections may be empty, so we need to iterate over Sections
|
157
|
-
if (this.sectionList && this.sectionList.length) {
|
158
|
-
for (var i = 0; i < this.sectionList.length; i++) {
|
159
|
-
if (this.sectionList[i].sentenceList && this.sectionList[i].sentenceList.length) {
|
160
|
-
return this.sectionList[i].sentenceList[0];
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
164
|
-
return null;
|
165
|
-
};
|
166
|
-
|
167
|
-
|
168
|
-
/**
|
169
|
-
* Return the first Tokenization in a Communication if it exists, or null
|
170
|
-
*
|
171
|
-
* @returns {Tokenization|null}
|
172
|
-
*/
|
173
|
-
Communication.prototype.getFirstTokenization = function() {
|
174
|
-
var firstSentence = this.getFirstSentence();
|
175
|
-
if (firstSentence) {
|
176
|
-
return firstSentence.tokenization;
|
177
|
-
}
|
178
|
-
else {
|
179
|
-
return null;
|
180
|
-
}
|
181
|
-
};
|
182
|
-
|
183
|
-
|
184
|
-
/**
|
185
|
-
* Return the Sentence (or null) with the specified UUID
|
186
|
-
*
|
187
|
-
* @param {UUID} uuid
|
188
|
-
* @returns {Sentence|null}
|
189
|
-
*/
|
190
|
-
Communication.prototype.getSentenceWithUUID = function(uuid) {
|
191
|
-
if (!uuid || !uuid.uuidString) {
|
192
|
-
console.error("ERROR: getSentenceWithUUID() was not passed a valid UUID");
|
193
|
-
return null;
|
194
|
-
}
|
195
|
-
|
196
|
-
if (this.sectionList) {
|
197
|
-
for (var sectionListIndex in this.sectionList) {
|
198
|
-
var section = this.sectionList[sectionListIndex];
|
199
|
-
if (section.sentenceList) {
|
200
|
-
for (var sentenceIndex in section.sentenceList) {
|
201
|
-
var sentence = section.sentenceList[sentenceIndex];
|
202
|
-
if (sentence.uuid.uuidString == uuid.uuidString) {
|
203
|
-
return sentence;
|
204
|
-
}
|
205
|
-
}
|
206
|
-
}
|
207
|
-
}
|
208
|
-
}
|
209
|
-
// TODO: Error handling if no matching UUID could be found
|
210
|
-
console.error("ERROR: No Sentence found with UUID " + uuid.uuidString);
|
211
|
-
return null;
|
212
|
-
};
|
213
|
-
|
214
|
-
|
215
|
-
/**
|
216
|
-
* Return the SituationMention (or null) with the specified UUID
|
217
|
-
*
|
218
|
-
* @param {UUID} uuid
|
219
|
-
* @returns {SituationMention|null}
|
220
|
-
*/
|
221
|
-
Communication.prototype.getSituationMentionWithUUID = function(uuid) {
|
222
|
-
if (!uuid || !uuid.uuidString) {
|
223
|
-
console.error("ERROR: getSituationMentionWithUUID() was not passed a valid UUID");
|
224
|
-
return null;
|
225
|
-
}
|
226
|
-
|
227
|
-
if (this.situationMentionSetList) {
|
228
|
-
for (var situationMentionSetIndex in this.situationMentionSetList) {
|
229
|
-
var situationMentionSet = this.situationMentionSetList[situationMentionSetIndex];
|
230
|
-
for (var mentionListIndex in situationMentionSet.mentionList) {
|
231
|
-
var mention = situationMentionSet.mentionList[mentionListIndex];
|
232
|
-
if (mention.uuid.uuidString === uuid.uuidString) {
|
233
|
-
return mention;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
}
|
237
|
-
}
|
238
|
-
// TODO: Error handling if no matching UUID could be found
|
239
|
-
console.error("ERROR: No SituationMention found with UUID " + uuid.uuidString);
|
240
|
-
return null;
|
241
|
-
};
|
242
|
-
|
243
|
-
|
244
|
-
/**
|
245
|
-
* Return all Sections in a Communication as a (flat) list
|
246
|
-
*
|
247
|
-
* @returns {List}
|
248
|
-
*/
|
249
|
-
Communication.prototype.getSectionsAsList = function() {
|
250
|
-
var sections = [];
|
251
|
-
|
252
|
-
if (this.sectionList && this.sectionList.length) {
|
253
|
-
for (var i = 0; i < this.sectionList.length; i++) {
|
254
|
-
sections.push(this.sectionList[i]);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
|
258
|
-
return sections;
|
259
|
-
};
|
260
|
-
|
261
|
-
|
262
|
-
/**
|
263
|
-
* Return all Sentences in a Communication as a (flat) list
|
264
|
-
*
|
265
|
-
* @returns {List}
|
266
|
-
*/
|
267
|
-
Communication.prototype.getSentencesAsList = function() {
|
268
|
-
var sentences = [];
|
269
|
-
|
270
|
-
if (this.sectionList && this.sectionList.length) {
|
271
|
-
for (var i = 0; i < this.sectionList.length; i++) {
|
272
|
-
if (this.sectionList[i].sentenceList && this.sectionList[i].sentenceList.length) {
|
273
|
-
for (var j = 0; j < this.sectionList[i].sentenceList.length; j++) {
|
274
|
-
sentences.push(this.sectionList[i].sentenceList[j]);
|
275
|
-
}
|
276
|
-
}
|
277
|
-
}
|
278
|
-
}
|
279
|
-
|
280
|
-
return sentences;
|
281
|
-
};
|
282
|
-
|
283
|
-
|
284
|
-
/**
|
285
|
-
* Return all Tokenizations in a Communication as a (flat) list
|
286
|
-
*
|
287
|
-
* @returns {List}
|
288
|
-
*/
|
289
|
-
Communication.prototype.getTokenizationsAsList = function() {
|
290
|
-
var tokenizations = [];
|
291
|
-
|
292
|
-
if (this.sectionList && this.sectionList.length) {
|
293
|
-
for (var i = 0; i < this.sectionList.length; i++) {
|
294
|
-
if (this.sectionList[i].sentenceList && this.sectionList[i].sentenceList.length) {
|
295
|
-
for (var j = 0; j < this.sectionList[i].sentenceList.length; j++) {
|
296
|
-
if (this.sectionList[i].sentenceList[j].tokenization) {
|
297
|
-
tokenizations.push(this.sectionList[i].sentenceList[j].tokenization);
|
298
|
-
}
|
299
|
-
}
|
300
|
-
}
|
301
|
-
}
|
302
|
-
}
|
303
|
-
|
304
|
-
return tokenizations;
|
305
|
-
};
|
306
|
-
|
307
|
-
/**
|
308
|
-
* Return the Tokenization (or null) with the specified UUID
|
309
|
-
*
|
310
|
-
* @param {UUID} uuid
|
311
|
-
* @returns {Tokenization|null}
|
312
|
-
*/
|
313
|
-
Communication.prototype.getTokenizationWithUUID = function(uuid) {
|
314
|
-
if (!uuid || !uuid.uuidString) {
|
315
|
-
console.error("ERROR: getTokenizationWithUUID() was not passed a valid UUID");
|
316
|
-
return null;
|
317
|
-
}
|
318
|
-
|
319
|
-
if (this.sectionList) {
|
320
|
-
for (var sectionListIndex in this.sectionList) {
|
321
|
-
var section = this.sectionList[sectionListIndex];
|
322
|
-
if (section.sentenceList) {
|
323
|
-
for (var sentenceIndex in section.sentenceList) {
|
324
|
-
var sentence = section.sentenceList[sentenceIndex];
|
325
|
-
if (sentence.tokenization && sentence.tokenization.uuid.uuidString == uuid.uuidString) {
|
326
|
-
return sentence.tokenization;
|
327
|
-
}
|
328
|
-
}
|
329
|
-
}
|
330
|
-
}
|
331
|
-
}
|
332
|
-
// TODO: Error handling if no matching UUID could be found
|
333
|
-
console.error("ERROR: No Tokenization found with UUID " + uuid.uuidString);
|
334
|
-
return null;
|
335
|
-
};
|
336
|
-
|
337
|
-
|
338
|
-
/**
|
339
|
-
* Get list of token text strings for the EntityMention specified by the UUID
|
340
|
-
*
|
341
|
-
* @param {UUID} mentionId
|
342
|
-
* @returns {Array} An array of token text strings
|
343
|
-
*/
|
344
|
-
Communication.prototype.getTokensForEntityMentionID = function(mentionId) {
|
345
|
-
var entityMention = this.getEntityMentionWithUUID(mentionId);
|
346
|
-
var tokenization = this.getTokenizationWithUUID(entityMention.tokens.tokenizationId);
|
347
|
-
|
348
|
-
var tokens = [];
|
349
|
-
|
350
|
-
for (var tokenIndex in entityMention.tokens.tokenIndexList) {
|
351
|
-
tokens.push(tokenization.tokenList.tokenList[entityMention.tokens.tokenIndexList[tokenIndex]].text);
|
352
|
-
}
|
353
|
-
return tokens;
|
354
|
-
};
|
355
|
-
|
356
|
-
|
357
|
-
/**
|
358
|
-
* Initialize Communication from a TJSONProtocol object created from a Communication.
|
359
|
-
*
|
360
|
-
* Thrift's TJSONProtocol is used to serialize objects to JSON. The objects look
|
361
|
-
* something like this:
|
362
|
-
*
|
363
|
-
* {
|
364
|
-
* "1":{"str":"tests/testdata/serif_dog-bites-man.xml"},
|
365
|
-
* "2":{"rec":{"1":{"str":"a90d397a-560f-44a0-baae-c82a34e4be09"}}},
|
366
|
-
* "3":{"str":"CommunicationType.OTHER"},
|
367
|
-
* ...
|
368
|
-
* }
|
369
|
-
*
|
370
|
-
* @param {Object} commJSONObject - An object created from a Communication using TJSONProtocol
|
371
|
-
* @returns {Communication} - This Communication
|
372
|
-
*/
|
373
|
-
Communication.prototype.initFromTJSONProtocolObject = function(commJSONObject) {
|
374
|
-
// We convert the JSON object to a JSON string, and then
|
375
|
-
// initFromTJSONProtocol converts the JSON string back to a JSON
|
376
|
-
// object. This is done deliberately. We create a copy of the
|
377
|
-
// original JSON object, and this copy is then destructively
|
378
|
-
// modified by Communication.read().
|
379
|
-
return this.initFromTJSONProtocolString(JSON.stringify(commJSONObject));
|
380
|
-
};
|
381
|
-
|
382
|
-
|
383
|
-
/**
|
384
|
-
* Initialize Communication from a TJSONProtocol string created from a Communication
|
385
|
-
*
|
386
|
-
* @param {String} commJSONString - A JSON string created from a Communication using TJSONProtocol
|
387
|
-
* @returns {Communication} - This Communication
|
388
|
-
*/
|
389
|
-
Communication.prototype.initFromTJSONProtocolString = function(commJSONString) {
|
390
|
-
var commJSONObject = JSON.parse(commJSONString);
|
391
|
-
var transport = new Thrift.Transport();
|
392
|
-
var protocol = new Thrift.TJSONProtocol(transport);
|
393
|
-
|
394
|
-
// The values for these protocol object fields was determined by
|
395
|
-
// mucking around with the JavaScript debugger to figure out how
|
396
|
-
// Thrift RPC calls used TJSONProtocol objects.
|
397
|
-
protocol.rpos = [];
|
398
|
-
|
399
|
-
// The object stored in protocol.rstack[] is destructively modified
|
400
|
-
// by Communication.read()
|
401
|
-
protocol.rstack = [commJSONObject];
|
402
|
-
|
403
|
-
this.read(protocol);
|
404
|
-
|
405
|
-
return this;
|
406
|
-
};
|
407
|
-
|
408
|
-
|
409
|
-
/**
|
410
|
-
* Returns JSON object for Communication serialized using TJSONProtocol
|
411
|
-
*
|
412
|
-
* @returns {Object}
|
413
|
-
*/
|
414
|
-
Communication.prototype.toTJSONProtocolObject = function() {
|
415
|
-
return JSON.parse(this.toTJSONProtocolString());
|
416
|
-
};
|
417
|
-
|
418
|
-
|
419
|
-
/**
|
420
|
-
* Returns JSON string for Communication serialized using TJSONProtocol
|
421
|
-
*
|
422
|
-
* @returns {String}
|
423
|
-
*/
|
424
|
-
Communication.prototype.toTJSONProtocolString = function() {
|
425
|
-
var transport = new Thrift.Transport();
|
426
|
-
var protocol = new Thrift.TJSONProtocol(transport);
|
427
|
-
protocol.tpos = [];
|
428
|
-
protocol.tstack = [];
|
429
|
-
this.write(protocol);
|
430
|
-
|
431
|
-
return protocol.tstack[0];
|
432
|
-
};
|
1
|
+
/**
|
2
|
+
* @class Communication
|
3
|
+
* @classdesc concrete.js extensions to the Communication class
|
4
|
+
*/
|
5
|
+
const Communication = module.exports = require('./communication_types').Communication;
|
6
|
+
|
7
|
+
const thrift = require('thrift');
|
8
|
+
const Thrift = thrift.Thrift;
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Adds internal references between data structures contained in Communication
|
12
|
+
*
|
13
|
+
* Specifically, adds:
|
14
|
+
* - to each concrete.Section, a section.communication reference to the enclosing Communication
|
15
|
+
* - to each concrete.Sentence, a sentence.section reference to the enclosing Section
|
16
|
+
* - to each concrete.Tokenization, a tokenization.sentence reference to the enclosing Sentence
|
17
|
+
*/
|
18
|
+
Communication.prototype.addInternalReferences = function() {
|
19
|
+
if (this.sectionList) {
|
20
|
+
for (var sectionIndex in this.sectionList) {
|
21
|
+
var section = this.sectionList[sectionIndex];
|
22
|
+
// We add both a 'comm' and 'communication' field to each section. We
|
23
|
+
// originally only added 'comm', but 'communication' is arguably more
|
24
|
+
// consistent. We keep both variable names to avoid breaking existing code.
|
25
|
+
section.comm = this;
|
26
|
+
section.communication = this;
|
27
|
+
|
28
|
+
if (section.sentenceList) {
|
29
|
+
for (var sentenceIndex in section.sentenceList) {
|
30
|
+
var sentence = section.sentenceList[sentenceIndex];
|
31
|
+
sentence.section = section;
|
32
|
+
if (sentence.tokenization) {
|
33
|
+
sentence.tokenization.sentence = sentence;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Return the Entity (or null) that has an EntityMention with the specified UUID
|
44
|
+
*
|
45
|
+
* @param {UUID} uuid
|
46
|
+
* @returns {Entity|null}
|
47
|
+
*/
|
48
|
+
Communication.prototype.getEntityForEntityMentionUUID = function(uuid) {
|
49
|
+
if (!uuid || !uuid.uuidString) {
|
50
|
+
console.error("ERROR: getEntityForEntityMentionUUID() was not passed a valid UUID");
|
51
|
+
return null;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (this.entitySetList) {
|
55
|
+
for (var entitySetIndex in this.entitySetList) {
|
56
|
+
var entityList = this.entitySetList[entitySetIndex].entityList;
|
57
|
+
for (var entityIndex in entityList) {
|
58
|
+
var entity = entityList[entityIndex];
|
59
|
+
for (var entityMentionIndex in entity.mentionIdList) {
|
60
|
+
if (entity.mentionIdList[entityMentionIndex].uuidString === uuid.uuidString) {
|
61
|
+
return entity;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
// TODO: Error handling if no matching UUID could be found
|
68
|
+
console.error("ERROR: No Entity found for EntityMention with UUID " + uuid.uuidString);
|
69
|
+
return null;
|
70
|
+
};
|
71
|
+
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Return the EntityMentionSet in the Communication with the specified toolname
|
75
|
+
*
|
76
|
+
* @param {String} toolname
|
77
|
+
* @returns {EntityMentionSet|null}
|
78
|
+
*/
|
79
|
+
Communication.prototype.getEntityMentionSetWithToolname = function(toolname) {
|
80
|
+
if (this.entityMentionSetList && this.entityMentionSetList.length > 0) {
|
81
|
+
for (var i = 0; i < this.entityMentionSetList.length; i++) {
|
82
|
+
if (this.entityMentionSetList[i].metadata.tool === toolname) {
|
83
|
+
return this.entityMentionSetList[i];
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return null;
|
88
|
+
};
|
89
|
+
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Return the EntityMention (or null) with the specified UUID
|
93
|
+
*
|
94
|
+
* @param {UUID} uuid
|
95
|
+
* @returns {EntityMention|null}
|
96
|
+
*/
|
97
|
+
Communication.prototype.getEntityMentionWithUUID = function(uuid) {
|
98
|
+
if (!uuid || !uuid.uuidString) {
|
99
|
+
console.error("ERROR: getEntityMentionWithUUID() was not passed a valid UUID");
|
100
|
+
return null;
|
101
|
+
}
|
102
|
+
|
103
|
+
if (this.entityMentionSetList) {
|
104
|
+
for (var entityMentionSetIndex in this.entityMentionSetList) {
|
105
|
+
if (this.entityMentionSetList[entityMentionSetIndex].mentionList) {
|
106
|
+
for (var mentionListIndex in this.entityMentionSetList[entityMentionSetIndex].mentionList) {
|
107
|
+
var entityMention = this.entityMentionSetList[entityMentionSetIndex].mentionList[mentionListIndex];
|
108
|
+
if (entityMention.uuid.uuidString == uuid.uuidString) {
|
109
|
+
return entityMention;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
// TODO: Error handling if no matching UUID could be found
|
116
|
+
console.error("ERROR: No EntityMention found with UUID " + uuid.uuidString);
|
117
|
+
return null;
|
118
|
+
};
|
119
|
+
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Return the Entity (or null) that has the specified Entity ID
|
123
|
+
*
|
124
|
+
* @param {String} entityId
|
125
|
+
* @returns {Entity|null}
|
126
|
+
*/
|
127
|
+
Communication.prototype.getEntityWithEntityId = function(entityId) {
|
128
|
+
if (!entityId) {
|
129
|
+
console.error("ERROR: getEntityWithEntityId() was not passed a valid entityId");
|
130
|
+
return null;
|
131
|
+
}
|
132
|
+
|
133
|
+
if (this.entitySetList) {
|
134
|
+
for (var entitySetIndex in this.entitySetList) {
|
135
|
+
var entityList = this.entitySetList[entitySetIndex].entityList;
|
136
|
+
for (var entityIndex in entityList) {
|
137
|
+
var entity = entityList[entityIndex];
|
138
|
+
if (entity.id === entityId) {
|
139
|
+
return entity;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
// TODO: Error handling if no matching entityId could be found
|
145
|
+
console.error("ERROR: No Entity found for entityId " + entityId);
|
146
|
+
return null;
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Return the first Sentence in a Communication if it exists, or null
|
152
|
+
*
|
153
|
+
* @returns {Sentence|null}
|
154
|
+
*/
|
155
|
+
Communication.prototype.getFirstSentence = function() {
|
156
|
+
// The first few Sections may be empty, so we need to iterate over Sections
|
157
|
+
if (this.sectionList && this.sectionList.length) {
|
158
|
+
for (var i = 0; i < this.sectionList.length; i++) {
|
159
|
+
if (this.sectionList[i].sentenceList && this.sectionList[i].sentenceList.length) {
|
160
|
+
return this.sectionList[i].sentenceList[0];
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
return null;
|
165
|
+
};
|
166
|
+
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Return the first Tokenization in a Communication if it exists, or null
|
170
|
+
*
|
171
|
+
* @returns {Tokenization|null}
|
172
|
+
*/
|
173
|
+
Communication.prototype.getFirstTokenization = function() {
|
174
|
+
var firstSentence = this.getFirstSentence();
|
175
|
+
if (firstSentence) {
|
176
|
+
return firstSentence.tokenization;
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
return null;
|
180
|
+
}
|
181
|
+
};
|
182
|
+
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Return the Sentence (or null) with the specified UUID
|
186
|
+
*
|
187
|
+
* @param {UUID} uuid
|
188
|
+
* @returns {Sentence|null}
|
189
|
+
*/
|
190
|
+
Communication.prototype.getSentenceWithUUID = function(uuid) {
|
191
|
+
if (!uuid || !uuid.uuidString) {
|
192
|
+
console.error("ERROR: getSentenceWithUUID() was not passed a valid UUID");
|
193
|
+
return null;
|
194
|
+
}
|
195
|
+
|
196
|
+
if (this.sectionList) {
|
197
|
+
for (var sectionListIndex in this.sectionList) {
|
198
|
+
var section = this.sectionList[sectionListIndex];
|
199
|
+
if (section.sentenceList) {
|
200
|
+
for (var sentenceIndex in section.sentenceList) {
|
201
|
+
var sentence = section.sentenceList[sentenceIndex];
|
202
|
+
if (sentence.uuid.uuidString == uuid.uuidString) {
|
203
|
+
return sentence;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
// TODO: Error handling if no matching UUID could be found
|
210
|
+
console.error("ERROR: No Sentence found with UUID " + uuid.uuidString);
|
211
|
+
return null;
|
212
|
+
};
|
213
|
+
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Return the SituationMention (or null) with the specified UUID
|
217
|
+
*
|
218
|
+
* @param {UUID} uuid
|
219
|
+
* @returns {SituationMention|null}
|
220
|
+
*/
|
221
|
+
Communication.prototype.getSituationMentionWithUUID = function(uuid) {
|
222
|
+
if (!uuid || !uuid.uuidString) {
|
223
|
+
console.error("ERROR: getSituationMentionWithUUID() was not passed a valid UUID");
|
224
|
+
return null;
|
225
|
+
}
|
226
|
+
|
227
|
+
if (this.situationMentionSetList) {
|
228
|
+
for (var situationMentionSetIndex in this.situationMentionSetList) {
|
229
|
+
var situationMentionSet = this.situationMentionSetList[situationMentionSetIndex];
|
230
|
+
for (var mentionListIndex in situationMentionSet.mentionList) {
|
231
|
+
var mention = situationMentionSet.mentionList[mentionListIndex];
|
232
|
+
if (mention.uuid.uuidString === uuid.uuidString) {
|
233
|
+
return mention;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
// TODO: Error handling if no matching UUID could be found
|
239
|
+
console.error("ERROR: No SituationMention found with UUID " + uuid.uuidString);
|
240
|
+
return null;
|
241
|
+
};
|
242
|
+
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Return all Sections in a Communication as a (flat) list
|
246
|
+
*
|
247
|
+
* @returns {List}
|
248
|
+
*/
|
249
|
+
Communication.prototype.getSectionsAsList = function() {
|
250
|
+
var sections = [];
|
251
|
+
|
252
|
+
if (this.sectionList && this.sectionList.length) {
|
253
|
+
for (var i = 0; i < this.sectionList.length; i++) {
|
254
|
+
sections.push(this.sectionList[i]);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
return sections;
|
259
|
+
};
|
260
|
+
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Return all Sentences in a Communication as a (flat) list
|
264
|
+
*
|
265
|
+
* @returns {List}
|
266
|
+
*/
|
267
|
+
Communication.prototype.getSentencesAsList = function() {
|
268
|
+
var sentences = [];
|
269
|
+
|
270
|
+
if (this.sectionList && this.sectionList.length) {
|
271
|
+
for (var i = 0; i < this.sectionList.length; i++) {
|
272
|
+
if (this.sectionList[i].sentenceList && this.sectionList[i].sentenceList.length) {
|
273
|
+
for (var j = 0; j < this.sectionList[i].sentenceList.length; j++) {
|
274
|
+
sentences.push(this.sectionList[i].sentenceList[j]);
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
return sentences;
|
281
|
+
};
|
282
|
+
|
283
|
+
|
284
|
+
/**
|
285
|
+
* Return all Tokenizations in a Communication as a (flat) list
|
286
|
+
*
|
287
|
+
* @returns {List}
|
288
|
+
*/
|
289
|
+
Communication.prototype.getTokenizationsAsList = function() {
|
290
|
+
var tokenizations = [];
|
291
|
+
|
292
|
+
if (this.sectionList && this.sectionList.length) {
|
293
|
+
for (var i = 0; i < this.sectionList.length; i++) {
|
294
|
+
if (this.sectionList[i].sentenceList && this.sectionList[i].sentenceList.length) {
|
295
|
+
for (var j = 0; j < this.sectionList[i].sentenceList.length; j++) {
|
296
|
+
if (this.sectionList[i].sentenceList[j].tokenization) {
|
297
|
+
tokenizations.push(this.sectionList[i].sentenceList[j].tokenization);
|
298
|
+
}
|
299
|
+
}
|
300
|
+
}
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
return tokenizations;
|
305
|
+
};
|
306
|
+
|
307
|
+
/**
|
308
|
+
* Return the Tokenization (or null) with the specified UUID
|
309
|
+
*
|
310
|
+
* @param {UUID} uuid
|
311
|
+
* @returns {Tokenization|null}
|
312
|
+
*/
|
313
|
+
Communication.prototype.getTokenizationWithUUID = function(uuid) {
|
314
|
+
if (!uuid || !uuid.uuidString) {
|
315
|
+
console.error("ERROR: getTokenizationWithUUID() was not passed a valid UUID");
|
316
|
+
return null;
|
317
|
+
}
|
318
|
+
|
319
|
+
if (this.sectionList) {
|
320
|
+
for (var sectionListIndex in this.sectionList) {
|
321
|
+
var section = this.sectionList[sectionListIndex];
|
322
|
+
if (section.sentenceList) {
|
323
|
+
for (var sentenceIndex in section.sentenceList) {
|
324
|
+
var sentence = section.sentenceList[sentenceIndex];
|
325
|
+
if (sentence.tokenization && sentence.tokenization.uuid.uuidString == uuid.uuidString) {
|
326
|
+
return sentence.tokenization;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
}
|
330
|
+
}
|
331
|
+
}
|
332
|
+
// TODO: Error handling if no matching UUID could be found
|
333
|
+
console.error("ERROR: No Tokenization found with UUID " + uuid.uuidString);
|
334
|
+
return null;
|
335
|
+
};
|
336
|
+
|
337
|
+
|
338
|
+
/**
|
339
|
+
* Get list of token text strings for the EntityMention specified by the UUID
|
340
|
+
*
|
341
|
+
* @param {UUID} mentionId
|
342
|
+
* @returns {Array} An array of token text strings
|
343
|
+
*/
|
344
|
+
Communication.prototype.getTokensForEntityMentionID = function(mentionId) {
|
345
|
+
var entityMention = this.getEntityMentionWithUUID(mentionId);
|
346
|
+
var tokenization = this.getTokenizationWithUUID(entityMention.tokens.tokenizationId);
|
347
|
+
|
348
|
+
var tokens = [];
|
349
|
+
|
350
|
+
for (var tokenIndex in entityMention.tokens.tokenIndexList) {
|
351
|
+
tokens.push(tokenization.tokenList.tokenList[entityMention.tokens.tokenIndexList[tokenIndex]].text);
|
352
|
+
}
|
353
|
+
return tokens;
|
354
|
+
};
|
355
|
+
|
356
|
+
|
357
|
+
/**
|
358
|
+
* Initialize Communication from a TJSONProtocol object created from a Communication.
|
359
|
+
*
|
360
|
+
* Thrift's TJSONProtocol is used to serialize objects to JSON. The objects look
|
361
|
+
* something like this:
|
362
|
+
*
|
363
|
+
* {
|
364
|
+
* "1":{"str":"tests/testdata/serif_dog-bites-man.xml"},
|
365
|
+
* "2":{"rec":{"1":{"str":"a90d397a-560f-44a0-baae-c82a34e4be09"}}},
|
366
|
+
* "3":{"str":"CommunicationType.OTHER"},
|
367
|
+
* ...
|
368
|
+
* }
|
369
|
+
*
|
370
|
+
* @param {Object} commJSONObject - An object created from a Communication using TJSONProtocol
|
371
|
+
* @returns {Communication} - This Communication
|
372
|
+
*/
|
373
|
+
Communication.prototype.initFromTJSONProtocolObject = function(commJSONObject) {
|
374
|
+
// We convert the JSON object to a JSON string, and then
|
375
|
+
// initFromTJSONProtocol converts the JSON string back to a JSON
|
376
|
+
// object. This is done deliberately. We create a copy of the
|
377
|
+
// original JSON object, and this copy is then destructively
|
378
|
+
// modified by Communication.read().
|
379
|
+
return this.initFromTJSONProtocolString(JSON.stringify(commJSONObject));
|
380
|
+
};
|
381
|
+
|
382
|
+
|
383
|
+
/**
|
384
|
+
* Initialize Communication from a TJSONProtocol string created from a Communication
|
385
|
+
*
|
386
|
+
* @param {String} commJSONString - A JSON string created from a Communication using TJSONProtocol
|
387
|
+
* @returns {Communication} - This Communication
|
388
|
+
*/
|
389
|
+
Communication.prototype.initFromTJSONProtocolString = function(commJSONString) {
|
390
|
+
var commJSONObject = JSON.parse(commJSONString);
|
391
|
+
var transport = new Thrift.Transport();
|
392
|
+
var protocol = new Thrift.TJSONProtocol(transport);
|
393
|
+
|
394
|
+
// The values for these protocol object fields was determined by
|
395
|
+
// mucking around with the JavaScript debugger to figure out how
|
396
|
+
// Thrift RPC calls used TJSONProtocol objects.
|
397
|
+
protocol.rpos = [];
|
398
|
+
|
399
|
+
// The object stored in protocol.rstack[] is destructively modified
|
400
|
+
// by Communication.read()
|
401
|
+
protocol.rstack = [commJSONObject];
|
402
|
+
|
403
|
+
this.read(protocol);
|
404
|
+
|
405
|
+
return this;
|
406
|
+
};
|
407
|
+
|
408
|
+
|
409
|
+
/**
|
410
|
+
* Returns JSON object for Communication serialized using TJSONProtocol
|
411
|
+
*
|
412
|
+
* @returns {Object}
|
413
|
+
*/
|
414
|
+
Communication.prototype.toTJSONProtocolObject = function() {
|
415
|
+
return JSON.parse(this.toTJSONProtocolString());
|
416
|
+
};
|
417
|
+
|
418
|
+
|
419
|
+
/**
|
420
|
+
* Returns JSON string for Communication serialized using TJSONProtocol
|
421
|
+
*
|
422
|
+
* @returns {String}
|
423
|
+
*/
|
424
|
+
Communication.prototype.toTJSONProtocolString = function() {
|
425
|
+
var transport = new Thrift.Transport();
|
426
|
+
var protocol = new Thrift.TJSONProtocol(transport);
|
427
|
+
protocol.tpos = [];
|
428
|
+
protocol.tstack = [];
|
429
|
+
this.write(protocol);
|
430
|
+
|
431
|
+
return protocol.tstack[0];
|
432
|
+
};
|