natural 0.5.6 → 0.6.3
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/.dockerignore +2 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/natural.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +511 -0
- package/.travis.yml +8 -1
- package/README.md +331 -40
- package/bayes_classifier.json +1 -1
- package/classifier.json +418 -0
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +8 -9
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tester.js +5 -5
- package/lib/natural/brill_pos_tagger/lib/Brill_POS_Trainer.js +10 -6
- package/lib/natural/brill_pos_tagger/lib/Corpus.js +21 -16
- package/lib/natural/brill_pos_tagger/lib/Lexicon.js +22 -13
- package/lib/natural/brill_pos_tagger/lib/Predicate.js +2 -2
- package/lib/natural/brill_pos_tagger/lib/RuleTemplate.js +2 -2
- package/lib/natural/brill_pos_tagger/lib/RuleTemplates.js +132 -146
- package/lib/natural/brill_pos_tagger/lib/Sentence.js +41 -0
- package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +10 -11
- package/lib/natural/classifiers/classifier.js +5 -3
- package/lib/natural/classifiers/maxent/Classifier.js +125 -0
- package/lib/natural/classifiers/maxent/Context.js +33 -0
- package/lib/natural/classifiers/maxent/Distribution.js +145 -0
- package/lib/natural/classifiers/maxent/Element.js +34 -0
- package/lib/natural/classifiers/maxent/Feature.js +88 -0
- package/lib/natural/classifiers/maxent/FeatureSet.js +67 -0
- package/lib/natural/classifiers/maxent/GISScaler.js +148 -0
- package/lib/natural/classifiers/maxent/POS/ME_Corpus.js +56 -0
- package/lib/natural/classifiers/maxent/POS/ME_Sentence.js +73 -0
- package/lib/natural/classifiers/maxent/POS/POS_Element.js +172 -0
- package/lib/natural/classifiers/maxent/Sample.js +141 -0
- package/lib/natural/classifiers/maxent/SimpleExample/SE_Element.js +49 -0
- package/lib/natural/distance/hamming_distance.js +52 -0
- package/lib/natural/distance/jaro-winkler_distance.js +16 -6
- package/lib/natural/distance/levenshtein_distance.js +2 -2
- package/lib/natural/index.js +21 -2
- package/lib/natural/inflectors/noun_inflector.js +5 -3
- package/lib/natural/ngrams/ngrams.js +83 -25
- package/lib/natural/sentiment/Basque/senticon_eu.json +21557 -0
- package/lib/natural/sentiment/Catalan/senticon_ca.json +36352 -0
- package/lib/natural/sentiment/Dutch/negations_du.json +3 -0
- package/lib/natural/sentiment/Dutch/pattern-sentiment-nl.json +39650 -0
- package/lib/natural/sentiment/English/negations_en.json +3 -0
- package/lib/natural/sentiment/English/pattern-sentiment-en.json +16024 -0
- package/lib/natural/sentiment/English/senticon_en.json +124197 -0
- package/lib/natural/sentiment/French/pattern-sentiment-fr.json +40906 -0
- package/lib/natural/sentiment/Galician/senticon_gl.json +24427 -0
- package/lib/natural/sentiment/Italian/pattern-sentiment-it.json +24522 -0
- package/lib/natural/sentiment/SentimentAnalyzer.js +116 -0
- package/lib/natural/sentiment/Spanish/afinnShortSortedSpanish.json +1655 -0
- package/lib/natural/sentiment/Spanish/negations_es.json +3 -0
- package/lib/natural/sentiment/Spanish/senticon_es.json +56722 -0
- package/lib/natural/sentiment/tools/README.md +31 -0
- package/lib/natural/sentiment/tools/XmlParser4PatternData.js +31 -0
- package/lib/natural/sentiment/tools/sentimentXmlParser.js +30 -0
- package/lib/natural/stemmers/indonesian/data/kata-dasar.json +29935 -0
- package/lib/natural/stemmers/indonesian/prefix_rules.js +10 -9
- package/lib/natural/stemmers/indonesian/stemmer_id.js +16 -15
- package/lib/natural/stemmers/indonesian/suffix_rules.js +2 -2
- package/lib/natural/stemmers/porter_stemmer_es.js +265 -199
- package/lib/natural/stemmers/porter_stemmer_fr.js +1 -1
- package/lib/natural/stemmers/porter_stemmer_nl.js +362 -0
- package/lib/natural/stemmers/stemmer_es.js +18 -12
- package/lib/natural/stemmers/stemmer_nl.js +64 -0
- package/lib/natural/tfidf/tfidf.js +27 -4
- package/lib/natural/tokenizers/aggressive_tokenizer_sv.js +1 -1
- package/lib/natural/tokenizers/aggressive_tokenizer_vi.js +37 -0
- package/lib/natural/tokenizers/orthography_matchers.js +33 -0
- package/lib/natural/tokenizers/regexp_tokenizer.js +24 -4
- package/lib/natural/tokenizers/sentence_tokenizer.js +1 -1
- package/lib/natural/wordnet/wordnet_file.js +7 -1
- package/lr_classifier.json +1 -1
- package/package.json +35 -23
- package/.npmignore +0 -4
- package/.vscode/temp.sql +0 -0
- package/Makefile +0 -38
- package/data/kata-dasar.txt +0 -29933
- package/package-lock.json +0 -79
- package/tests/stemmer_id_test.js +0 -361
|
@@ -261,54 +261,40 @@ var ruleTemplates = {
|
|
|
261
261
|
// ==================================
|
|
262
262
|
// Predicates that start with words
|
|
263
263
|
// ==================================
|
|
264
|
-
function next_word_is_cap(tagged_sentence, i, parameter) {
|
|
265
|
-
if (i < tagged_sentence.length - 1) {
|
|
266
|
-
var next_word = tagged_sentence[i+1][0];
|
|
267
|
-
return(next_word[0] === next_word[0].toUpperCase());
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
return(false);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/*
|
|
275
264
|
function next_word_is_cap(sentence, i, parameter) {
|
|
276
|
-
if (i < sentence.length - 1) {
|
|
277
|
-
var next_word =
|
|
265
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
266
|
+
var next_word = sentence.taggedWords[i+1].token;
|
|
278
267
|
return(next_word[0] === next_word[0].toUpperCase());
|
|
279
268
|
}
|
|
280
|
-
|
|
281
|
-
return(false);
|
|
282
|
-
}
|
|
269
|
+
return(false);
|
|
283
270
|
}
|
|
284
|
-
*/
|
|
285
271
|
|
|
286
|
-
function next_word_is(
|
|
287
|
-
if (i <
|
|
288
|
-
return(
|
|
272
|
+
function next_word_is(sentence, i, parameter) {
|
|
273
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
274
|
+
return(sentence.taggedWords[i + 1].token === parameter);
|
|
289
275
|
}
|
|
290
276
|
}
|
|
291
277
|
|
|
292
278
|
function nextWordParameterValues(sentence, i) {
|
|
293
|
-
if (i < sentence.length - 1) {
|
|
294
|
-
return [sentence[i + 1].token];
|
|
279
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
280
|
+
return [sentence.taggedWords[i + 1].token];
|
|
295
281
|
}
|
|
296
282
|
else {
|
|
297
283
|
return [];
|
|
298
284
|
}
|
|
299
285
|
}
|
|
300
286
|
|
|
301
|
-
function prev_word_is_cap(
|
|
287
|
+
function prev_word_is_cap(sentence, i, parameter) {
|
|
302
288
|
var prev_word = null;
|
|
303
289
|
if (i > 0) {
|
|
304
|
-
prev_word =
|
|
290
|
+
prev_word = sentence.taggedWords[i-1].token;
|
|
305
291
|
return(prev_word[0] === prev_word[0].toUpperCase());
|
|
306
292
|
}
|
|
307
293
|
return(false);
|
|
308
294
|
}
|
|
309
295
|
|
|
310
|
-
function current_word_is_cap(
|
|
311
|
-
var current_word =
|
|
296
|
+
function current_word_is_cap(sentence, i, parameter) {
|
|
297
|
+
var current_word = sentence.taggedWords[i].token;
|
|
312
298
|
return(current_word[0] === current_word[0].toUpperCase());
|
|
313
299
|
}
|
|
314
300
|
|
|
@@ -316,40 +302,40 @@ function currentWordParameterValues(sentence, i) {
|
|
|
316
302
|
return [sentence[i].token];
|
|
317
303
|
}
|
|
318
304
|
|
|
319
|
-
function current_word_is(
|
|
320
|
-
return(
|
|
305
|
+
function current_word_is(sentence, i, parameter) {
|
|
306
|
+
return(sentence.taggedWords[i].token === parameter);
|
|
321
307
|
}
|
|
322
308
|
|
|
323
309
|
function isNumeric(num) {
|
|
324
310
|
return (!isNaN(num));
|
|
325
311
|
}
|
|
326
312
|
|
|
327
|
-
function current_word_is_number(
|
|
328
|
-
var is_number = isNumeric(
|
|
313
|
+
function current_word_is_number(sentence, i, parameter) {
|
|
314
|
+
var is_number = isNumeric(sentence.taggedWords[i].token);
|
|
329
315
|
// Attempt to parse it as a float
|
|
330
316
|
if (!is_number) {
|
|
331
|
-
is_number = parseFloat(
|
|
317
|
+
is_number = parseFloat(sentence.taggedWords[i].token);
|
|
332
318
|
}
|
|
333
319
|
return((parameter === "YES") ? is_number : !is_number);
|
|
334
320
|
}
|
|
335
321
|
|
|
336
322
|
// Checks if the current word is a url
|
|
337
323
|
// Adapted from the original Javascript Brill tagger
|
|
338
|
-
function current_word_is_url(
|
|
324
|
+
function current_word_is_url(sentence, i, parameter) {
|
|
339
325
|
var is_url = false;
|
|
340
|
-
if (
|
|
326
|
+
if (sentence.taggedWords[i].token.indexOf(".") > -1) {
|
|
341
327
|
// url if there are two contiguous alpha characters
|
|
342
|
-
if (/[a-zA-Z]{2}/.test(
|
|
328
|
+
if (/[a-zA-Z]{2}/.test(sentence.taggedWords[i].token)) {
|
|
343
329
|
is_url = true;
|
|
344
330
|
}
|
|
345
331
|
}
|
|
346
332
|
return((parameter === "YES") ? is_url : !is_url);
|
|
347
333
|
}
|
|
348
334
|
|
|
349
|
-
function current_word_and_2_tag_after_are(
|
|
350
|
-
if (i <
|
|
351
|
-
if (
|
|
352
|
-
return(
|
|
335
|
+
function current_word_and_2_tag_after_are(sentence, i, parameter1, parameter2) {
|
|
336
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
337
|
+
if (sentence.taggedWords[i + 2][1] === parameter2) {
|
|
338
|
+
return(sentence.taggedWords[i].token === parameter1);
|
|
353
339
|
}
|
|
354
340
|
else {
|
|
355
341
|
return(false);
|
|
@@ -361,69 +347,69 @@ function current_word_and_2_tag_after_are(tagged_sentence, i, parameter1, parame
|
|
|
361
347
|
}
|
|
362
348
|
|
|
363
349
|
function twoTagAfterParameterValues(sentence, i) {
|
|
364
|
-
if (i < sentence.length - 2) {
|
|
365
|
-
return [sentence[i + 2].tag];
|
|
350
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
351
|
+
return [sentence.taggedWords[i + 2].tag];
|
|
366
352
|
}
|
|
367
353
|
else {
|
|
368
354
|
return [];
|
|
369
355
|
}
|
|
370
356
|
}
|
|
371
357
|
|
|
372
|
-
function current_word_and_next_tag_are(
|
|
358
|
+
function current_word_and_next_tag_are(sentence, i, parameter1, parameter2) {
|
|
373
359
|
var next_tag = false;
|
|
374
360
|
// check current word
|
|
375
|
-
var current_word = (
|
|
361
|
+
var current_word = (sentence.taggedWords[i].token === parameter1);
|
|
376
362
|
// check next tag
|
|
377
|
-
if (i <
|
|
378
|
-
next_tag = (
|
|
363
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
364
|
+
next_tag = (sentence.taggedWords[i+1].tag === parameter2);
|
|
379
365
|
}
|
|
380
366
|
return(current_word && next_tag);
|
|
381
367
|
}
|
|
382
368
|
|
|
383
|
-
function current_word_and_prev_tag_are(
|
|
369
|
+
function current_word_and_prev_tag_are(sentence, i, parameter1, parameter2) {
|
|
384
370
|
var prev_tag = false;
|
|
385
371
|
// check current word
|
|
386
|
-
var current_word = (
|
|
372
|
+
var current_word = (sentence.taggedWords[i].token === parameter2);
|
|
387
373
|
// check prev tag
|
|
388
374
|
if (i > 0) {
|
|
389
|
-
prev_tag = (
|
|
375
|
+
prev_tag = (sentence.taggedWords[i-1].tag === parameter1);
|
|
390
376
|
}
|
|
391
377
|
return(current_word && prev_tag);
|
|
392
378
|
}
|
|
393
379
|
|
|
394
|
-
function current_word_and_2_tag_before_are(
|
|
380
|
+
function current_word_and_2_tag_before_are(sentence, i, parameter1, parameter2) {
|
|
395
381
|
var two_tags_before = false;
|
|
396
382
|
// check current word
|
|
397
|
-
var current_word = (
|
|
383
|
+
var current_word = (sentence.taggedWords[i].token === parameter2);
|
|
398
384
|
if (i > 1) {
|
|
399
385
|
// check two tags before
|
|
400
|
-
two_tags_before = (
|
|
386
|
+
two_tags_before = (sentence.taggedWords[i - 2].tag === parameter1);
|
|
401
387
|
}
|
|
402
388
|
return(current_word && two_tags_before);
|
|
403
389
|
}
|
|
404
390
|
|
|
405
391
|
function twoTagBeforeParameterValues(sentence, i) {
|
|
406
392
|
if (i > 1) {
|
|
407
|
-
return [sentence[i - 2].tag];
|
|
393
|
+
return [sentence.taggedWords[i - 2].tag];
|
|
408
394
|
}
|
|
409
395
|
else {
|
|
410
396
|
return [];
|
|
411
397
|
}
|
|
412
398
|
}
|
|
413
399
|
|
|
414
|
-
function current_word_and_2_after_are(
|
|
400
|
+
function current_word_and_2_after_are(sentence, i, parameter1, parameter2) {
|
|
415
401
|
var two_words_after = false;
|
|
416
402
|
// check current word
|
|
417
|
-
var current_word = (
|
|
418
|
-
if (i <
|
|
419
|
-
two_words_after = (
|
|
403
|
+
var current_word = (sentence.taggedWords[i].token === parameter1);
|
|
404
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
405
|
+
two_words_after = (sentence.taggedWords[i+2].token === parameter2);
|
|
420
406
|
}
|
|
421
407
|
return(current_word && two_words_after);
|
|
422
408
|
}
|
|
423
409
|
|
|
424
|
-
function prev_word_is(
|
|
410
|
+
function prev_word_is(sentence, i, parameter) {
|
|
425
411
|
if (i > 0) {
|
|
426
|
-
return(
|
|
412
|
+
return(sentence.taggedWords[i - 1].token.toLowerCase() === parameter.toLowerCase());
|
|
427
413
|
}
|
|
428
414
|
else {
|
|
429
415
|
return(false);
|
|
@@ -433,21 +419,21 @@ function prev_word_is(tagged_sentence, i, parameter) {
|
|
|
433
419
|
// Returns the right value for parameter 1 of prev_word_is
|
|
434
420
|
function prevWordParameterValues(sentence, i) {
|
|
435
421
|
if (i > 0) {
|
|
436
|
-
return [sentence[i - 1].token];
|
|
422
|
+
return [sentence.taggedWords[i - 1].token];
|
|
437
423
|
}
|
|
438
424
|
else {
|
|
439
425
|
return [];
|
|
440
426
|
}
|
|
441
427
|
}
|
|
442
428
|
|
|
443
|
-
function prev_1_or_2_word_is(
|
|
429
|
+
function prev_1_or_2_word_is(sentence, i, parameter) {
|
|
444
430
|
var prev_1 = false;
|
|
445
431
|
var prev_2 = false;
|
|
446
432
|
if (i > 0) {
|
|
447
|
-
prev_1 = (
|
|
433
|
+
prev_1 = (sentence.taggedWords[i-1].token.toLowerCase() === parameter.toLowerCase());
|
|
448
434
|
}
|
|
449
435
|
if (i > 1) {
|
|
450
|
-
prev_2 = (
|
|
436
|
+
prev_2 = (sentence.taggedWords[i-2].token.toLowerCase() === parameter.toLowerCase());
|
|
451
437
|
}
|
|
452
438
|
return(prev_1 || prev_2);
|
|
453
439
|
}
|
|
@@ -465,8 +451,8 @@ function prev1Or2WordParameterValues(sentence, i) {
|
|
|
465
451
|
|
|
466
452
|
// Indicates whether or not this string ends with the specified string.
|
|
467
453
|
// Adapted from the original Javascript Brill tagger
|
|
468
|
-
function current_word_ends_with(
|
|
469
|
-
var word =
|
|
454
|
+
function current_word_ends_with(sentence, i, parameter) {
|
|
455
|
+
var word = sentence.taggedWords[i].token;
|
|
470
456
|
if (!parameter || (parameter.length > word.length)) {
|
|
471
457
|
return false;
|
|
472
458
|
}
|
|
@@ -480,85 +466,85 @@ function currentWordEndsWithParameterValues(sentence, i) {
|
|
|
480
466
|
return values;
|
|
481
467
|
}
|
|
482
468
|
|
|
483
|
-
function right_bigram_is(
|
|
484
|
-
var word_1 = (
|
|
469
|
+
function right_bigram_is(sentence, i, parameter1, parameter2) {
|
|
470
|
+
var word_1 = (sentence.taggedWords[i].token === parameter1);
|
|
485
471
|
var word_2 = false;
|
|
486
|
-
if (i <
|
|
487
|
-
word_2 = (
|
|
472
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
473
|
+
word_2 = (sentence.taggedWords[i+1].token === parameter2);
|
|
488
474
|
}
|
|
489
475
|
return(word_1 && word_2);
|
|
490
476
|
}
|
|
491
477
|
|
|
492
|
-
function left_bigram_is(
|
|
478
|
+
function left_bigram_is(sentence, i, parameter1, parameter2) {
|
|
493
479
|
var word_1 = false;
|
|
494
|
-
var word_2 = (
|
|
480
|
+
var word_2 = (sentence.taggedWords[i].token === parameter2);
|
|
495
481
|
if (i > 0) {
|
|
496
|
-
word_1 = (
|
|
482
|
+
word_1 = (sentence.taggedWords[i-1].token === parameter1);
|
|
497
483
|
}
|
|
498
484
|
return(word_1 && word_2);
|
|
499
485
|
}
|
|
500
486
|
|
|
501
|
-
function next_bigram_is(
|
|
487
|
+
function next_bigram_is(sentence, i, parameter1, parameter2) {
|
|
502
488
|
var word_1 = false;
|
|
503
489
|
var word_2 = false;
|
|
504
|
-
if (i <
|
|
505
|
-
word_1 = (
|
|
490
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
491
|
+
word_1 = (sentence.taggedWords[i + 1].token === parameter1);
|
|
506
492
|
}
|
|
507
|
-
if (i <
|
|
508
|
-
word_2 = (
|
|
493
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
494
|
+
word_2 = (sentence.taggedWords[i + 2].token === parameter2);
|
|
509
495
|
}
|
|
510
496
|
return(word_1 && word_2);
|
|
511
497
|
}
|
|
512
498
|
|
|
513
499
|
function twoWordAfterParameterValues(sentence, i) {
|
|
514
|
-
if (i < sentence.length - 2) {
|
|
515
|
-
return [sentence[i + 2].token];
|
|
500
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
501
|
+
return [sentence.taggedWords[i + 2].token];
|
|
516
502
|
}
|
|
517
503
|
else {
|
|
518
504
|
return [];
|
|
519
505
|
}
|
|
520
506
|
}
|
|
521
507
|
|
|
522
|
-
function prev_bigram_is(
|
|
508
|
+
function prev_bigram_is(sentence, i, parameter1, parameter2) {
|
|
523
509
|
var word_1 = false;
|
|
524
510
|
var word_2 = false;
|
|
525
511
|
if (i > 1) {
|
|
526
|
-
word_1 = (
|
|
512
|
+
word_1 = (sentence.taggedWords[i-2].token === parameter1);
|
|
527
513
|
}
|
|
528
514
|
if (i > 0) {
|
|
529
|
-
word_2 = (
|
|
515
|
+
word_2 = (sentence.taggedWords[i-1].token === parameter2);
|
|
530
516
|
}
|
|
531
517
|
return(word_1 && word_2);
|
|
532
518
|
}
|
|
533
519
|
|
|
534
520
|
function twoWordBeforeParameterValues(sentence, i) {
|
|
535
521
|
if (i > 1) {
|
|
536
|
-
return [sentence[i - 2].token];
|
|
522
|
+
return [sentence.taggedWords[i - 2].token];
|
|
537
523
|
}
|
|
538
524
|
else {
|
|
539
525
|
return [];
|
|
540
526
|
}
|
|
541
527
|
}
|
|
542
528
|
|
|
543
|
-
function next_1_or_2_word_is(
|
|
529
|
+
function next_1_or_2_word_is(sentence, i, parameter1, parameter2) {
|
|
544
530
|
next_1 = false;
|
|
545
531
|
next_2 = false;
|
|
546
|
-
if (i <
|
|
547
|
-
next_1 = (
|
|
532
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
533
|
+
next_1 = (sentence.taggedWords[i+1].token === parameter1);
|
|
548
534
|
}
|
|
549
|
-
if (i <
|
|
550
|
-
next_2 = (
|
|
535
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
536
|
+
next_2 = (sentence.taggedWords[i+2].token === parameter2);
|
|
551
537
|
}
|
|
552
538
|
return(next_1 || next_2);
|
|
553
539
|
}
|
|
554
540
|
|
|
555
541
|
function next1Or2WordParameterValues(sentence, i) {
|
|
556
542
|
var values = [];
|
|
557
|
-
if (i < sentence.length - 1) {
|
|
558
|
-
values.push(sentence[i + 1].token);
|
|
543
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
544
|
+
values.push(sentence.taggedWords[i + 1].token);
|
|
559
545
|
}
|
|
560
|
-
if (i < sentence.length - 2) {
|
|
561
|
-
values.push(sentence[i + 2].token);
|
|
546
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
547
|
+
values.push(sentence.taggedWords[i + 2].token);
|
|
562
548
|
}
|
|
563
549
|
return values;
|
|
564
550
|
}
|
|
@@ -566,9 +552,9 @@ function next1Or2WordParameterValues(sentence, i) {
|
|
|
566
552
|
// ==================================
|
|
567
553
|
// Predicates about tags
|
|
568
554
|
// ==================================
|
|
569
|
-
function next_tag_is(
|
|
570
|
-
if (i <
|
|
571
|
-
return(
|
|
555
|
+
function next_tag_is(sentence, i, parameter) {
|
|
556
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
557
|
+
return(sentence.taggedWords[i + 1].tag === parameter);
|
|
572
558
|
}
|
|
573
559
|
else {
|
|
574
560
|
return(false);
|
|
@@ -576,17 +562,17 @@ function next_tag_is(tagged_sentence, i, parameter) {
|
|
|
576
562
|
}
|
|
577
563
|
|
|
578
564
|
function nextTagParameterValues(sentence, i) {
|
|
579
|
-
if (i < sentence.length - 1) {
|
|
580
|
-
return [sentence[i + 1].tag];
|
|
565
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
566
|
+
return [sentence.taggedWords[i + 1].tag];
|
|
581
567
|
}
|
|
582
568
|
else {
|
|
583
569
|
return [];
|
|
584
570
|
}
|
|
585
571
|
}
|
|
586
572
|
|
|
587
|
-
function next_2_tag_is(
|
|
588
|
-
if (i <
|
|
589
|
-
return(
|
|
573
|
+
function next_2_tag_is(sentence, i, parameter) {
|
|
574
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
575
|
+
return(sentence.taggedWords[i+2].tag === parameter);
|
|
590
576
|
}
|
|
591
577
|
else {
|
|
592
578
|
return(false);
|
|
@@ -594,74 +580,74 @@ function next_2_tag_is(tagged_sentence, i, parameter) {
|
|
|
594
580
|
}
|
|
595
581
|
|
|
596
582
|
function next2TagParameterValues(sentence, i) {
|
|
597
|
-
if (i < sentence.length - 2) {
|
|
598
|
-
return [sentence[i+2].tag];
|
|
583
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
584
|
+
return [sentence.taggedWords[i+2].tag];
|
|
599
585
|
}
|
|
600
586
|
else {
|
|
601
587
|
return [];
|
|
602
588
|
}
|
|
603
589
|
}
|
|
604
590
|
|
|
605
|
-
function next_1_or_2_tag_is(
|
|
591
|
+
function next_1_or_2_tag_is(sentence, i, parameter) {
|
|
606
592
|
var next_1 = false;
|
|
607
593
|
var next_2 = false;
|
|
608
|
-
if (i <
|
|
609
|
-
next_1 = (
|
|
594
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
595
|
+
next_1 = (sentence.taggedWords[i+1].tag === parameter);
|
|
610
596
|
}
|
|
611
|
-
if (i <
|
|
612
|
-
next_2 = (
|
|
597
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
598
|
+
next_2 = (sentence.taggedWords[i+2].tag === parameter);
|
|
613
599
|
}
|
|
614
600
|
return(next_1 || next_2);
|
|
615
601
|
}
|
|
616
602
|
|
|
617
603
|
function next1Or2TagIsParameterValues(sentence, i) {
|
|
618
604
|
var values = [];
|
|
619
|
-
if (i < sentence.length - 1) {
|
|
620
|
-
values.push(sentence[i + 1].tag);
|
|
605
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
606
|
+
values.push(sentence.taggedWords[i + 1].tag);
|
|
621
607
|
}
|
|
622
|
-
if (i < sentence.length - 2) {
|
|
623
|
-
values.push(sentence[i + 2].tag);
|
|
608
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
609
|
+
values.push(sentence.taggedWords[i + 2].tag);
|
|
624
610
|
}
|
|
625
611
|
return values;
|
|
626
612
|
}
|
|
627
613
|
|
|
628
|
-
function next_1_or_2_or_3_tag(
|
|
614
|
+
function next_1_or_2_or_3_tag(sentence, i, parameter) {
|
|
629
615
|
var next_1 = false;
|
|
630
616
|
var next_2 = false;
|
|
631
617
|
var next_3 = false;
|
|
632
|
-
if (i <
|
|
633
|
-
next_1 = (
|
|
618
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
619
|
+
next_1 = (sentence.taggedWords[i+1].tag === parameter);
|
|
634
620
|
}
|
|
635
|
-
if (i <
|
|
636
|
-
next_2 = (
|
|
621
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
622
|
+
next_2 = (sentence.taggedWords[i+2].tag === parameter);
|
|
637
623
|
}
|
|
638
|
-
if (i <
|
|
639
|
-
next_3 = (
|
|
624
|
+
if (i < sentence.taggedWords.length - 3) {
|
|
625
|
+
next_3 = (sentence.taggedWords[i+3].tag === parameter);
|
|
640
626
|
}
|
|
641
627
|
return(next_1 || next_2 || next_3);
|
|
642
628
|
}
|
|
643
629
|
|
|
644
630
|
function next1Or2Or3TagParameterValues(sentence, i) {
|
|
645
631
|
var values = [];
|
|
646
|
-
if (i < sentence.length - 1) {
|
|
647
|
-
values.push(sentence[i + 1].tag);
|
|
632
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
633
|
+
values.push(sentence.taggedWords[i + 1].tag);
|
|
648
634
|
}
|
|
649
|
-
if (i < sentence.length - 2) {
|
|
650
|
-
values.push(sentence[i + 2].tag);
|
|
635
|
+
if (i < sentence.taggedWords.length - 2) {
|
|
636
|
+
values.push(sentence.taggedWords[i + 2].tag);
|
|
651
637
|
}
|
|
652
|
-
if (i < sentence.length - 3) {
|
|
653
|
-
values.push(sentence[i + 3].tag);
|
|
638
|
+
if (i < sentence.taggedWords.length - 3) {
|
|
639
|
+
values.push(sentence.taggedWords[i + 3].tag);
|
|
654
640
|
}
|
|
655
641
|
return values;
|
|
656
642
|
}
|
|
657
643
|
|
|
658
|
-
function surrounded_by_tags(
|
|
659
|
-
if (i <
|
|
644
|
+
function surrounded_by_tags(sentence, i, parameter1, parameter2) {
|
|
645
|
+
if (i < sentence.taggedWords.length - 1) {
|
|
660
646
|
// check next tag
|
|
661
|
-
if (
|
|
647
|
+
if (sentence.taggedWords[i+1].tag === parameter2) {
|
|
662
648
|
// check previous tag
|
|
663
649
|
if (i > 0) {
|
|
664
|
-
return(
|
|
650
|
+
return(sentence.taggedWords[i-1].tag === parameter1)
|
|
665
651
|
}
|
|
666
652
|
else {
|
|
667
653
|
return(false);
|
|
@@ -676,18 +662,18 @@ function surrounded_by_tags(tagged_sentence, i, parameter1, parameter2) {
|
|
|
676
662
|
}
|
|
677
663
|
}
|
|
678
664
|
|
|
679
|
-
function prev_1_or_2_or_3_tag(
|
|
665
|
+
function prev_1_or_2_or_3_tag(sentence, i, parameter) {
|
|
680
666
|
var prev_1 = null;
|
|
681
667
|
if (i > 0) {
|
|
682
|
-
prev_1 =
|
|
668
|
+
prev_1 = sentence.taggedWords[i-1].tag;
|
|
683
669
|
}
|
|
684
670
|
var prev_2 = null;
|
|
685
671
|
if (i > 1) {
|
|
686
|
-
prev_2 =
|
|
672
|
+
prev_2 = sentence.taggedWords[i-2].tag;
|
|
687
673
|
}
|
|
688
674
|
var prev_3 = null;
|
|
689
675
|
if (i > 2) {
|
|
690
|
-
prev_3 =
|
|
676
|
+
prev_3 = sentence.taggedWords[i-3].tag;
|
|
691
677
|
}
|
|
692
678
|
return((prev_1 === parameter) || (prev_2 === parameter) || (prev_3 === parameter));
|
|
693
679
|
}
|
|
@@ -695,25 +681,25 @@ function prev_1_or_2_or_3_tag(tagged_sentence, i, parameter) {
|
|
|
695
681
|
function prev1Or2Or3TagParameterValues(sentence, i) {
|
|
696
682
|
var values = [];
|
|
697
683
|
if (i > 0) {
|
|
698
|
-
values.push(sentence[i - 1].tag);
|
|
684
|
+
values.push(sentence.taggedWords[i - 1].tag);
|
|
699
685
|
}
|
|
700
686
|
if (i > 1) {
|
|
701
|
-
values.push(sentence[i - 2].tag);
|
|
687
|
+
values.push(sentence.taggedWords[i - 2].tag);
|
|
702
688
|
}
|
|
703
689
|
if (i > 2) {
|
|
704
|
-
values.push(sentence[i - 3].tag);
|
|
690
|
+
values.push(sentence.taggedWords[i - 3].tag);
|
|
705
691
|
}
|
|
706
692
|
return values;
|
|
707
693
|
}
|
|
708
694
|
|
|
709
|
-
function prev_1_or_2_tag(
|
|
695
|
+
function prev_1_or_2_tag(sentence, i, parameter) {
|
|
710
696
|
var prev_1 = null;
|
|
711
697
|
if (i > 0) {
|
|
712
|
-
prev_1 =
|
|
698
|
+
prev_1 = sentence.taggedWords[i - 1].tag;
|
|
713
699
|
}
|
|
714
700
|
var prev_2 = null;
|
|
715
701
|
if (i > 1) {
|
|
716
|
-
prev_2 =
|
|
702
|
+
prev_2 = sentence.taggedWords[i - 2].tag;
|
|
717
703
|
}
|
|
718
704
|
return((prev_1 === parameter) || (prev_2 === parameter));
|
|
719
705
|
}
|
|
@@ -721,25 +707,25 @@ function prev_1_or_2_tag(tagged_sentence, i, parameter) {
|
|
|
721
707
|
function prev1Or2TagParameterValues(sentence, i) {
|
|
722
708
|
values = [];
|
|
723
709
|
if (i > 0) {
|
|
724
|
-
values.push(sentence[i - 1].tag);
|
|
710
|
+
values.push(sentence.taggedWords[i - 1].tag);
|
|
725
711
|
}
|
|
726
712
|
if (i > 1) {
|
|
727
|
-
values.push(sentence[i - 2].tag);
|
|
713
|
+
values.push(sentence.taggedWords[i - 2].tag);
|
|
728
714
|
}
|
|
729
715
|
return values;
|
|
730
716
|
}
|
|
731
717
|
|
|
732
|
-
function prev_tag_is(
|
|
718
|
+
function prev_tag_is(sentence, i, parameter) {
|
|
733
719
|
var prev = false;
|
|
734
720
|
if (i > 0) {
|
|
735
|
-
prev = (
|
|
721
|
+
prev = (sentence.taggedWords[i-1].tag === parameter);
|
|
736
722
|
}
|
|
737
723
|
return(prev);
|
|
738
724
|
}
|
|
739
725
|
|
|
740
726
|
function prevTagParameterValues(sentence, i) {
|
|
741
727
|
if (i > 0) {
|
|
742
|
-
return [sentence[i - 1].tag];
|
|
728
|
+
return [sentence.taggedWords[i - 1].tag];
|
|
743
729
|
}
|
|
744
730
|
else {
|
|
745
731
|
return [];
|
|
@@ -748,19 +734,19 @@ function prevTagParameterValues(sentence, i) {
|
|
|
748
734
|
|
|
749
735
|
// Looks like a useless predicate because transformation already take the
|
|
750
736
|
// current tag into account
|
|
751
|
-
function current_word_is_tag(
|
|
752
|
-
return(
|
|
737
|
+
function current_word_is_tag(sentence, i, parameter) {
|
|
738
|
+
return(sentence.taggedWords[i].tag === parameter);
|
|
753
739
|
}
|
|
754
740
|
|
|
755
|
-
function prev_2_tag_is(
|
|
741
|
+
function prev_2_tag_is(sentence, i, parameter) {
|
|
756
742
|
var prev_2 = false;
|
|
757
743
|
if (i > 1) {
|
|
758
|
-
prev_2 = (
|
|
744
|
+
prev_2 = (sentence.taggedWords[i-2].tag === parameter);
|
|
759
745
|
}
|
|
760
746
|
return(prev_2);
|
|
761
747
|
}
|
|
762
748
|
|
|
763
|
-
function default_predicate(
|
|
749
|
+
function default_predicate(sentence, i, parameter) {
|
|
764
750
|
return(false);
|
|
765
751
|
}
|
|
766
752
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Sentence class that generates sample elements from sentences
|
|
3
|
+
Copyright (C) 2018 Hugo W.L. ter Doest
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var Context = require('../../classifiers/maxent/Context');
|
|
21
|
+
|
|
22
|
+
function Sentence() {
|
|
23
|
+
this.taggedWords = [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Sentence.prototype.addTaggedWord = function(token, tag) {
|
|
27
|
+
this.taggedWords.push({
|
|
28
|
+
"token": token,
|
|
29
|
+
"tag": tag
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Sentence.prototype.clone = function() {
|
|
34
|
+
var s = new Sentence();
|
|
35
|
+
this.taggedWords.forEach(function(wordObject) {
|
|
36
|
+
s.addTaggedWord(wordObject.token, wordObject.tag);
|
|
37
|
+
});
|
|
38
|
+
return s;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = Sentence;
|