Grammalecte  Diff

Differences From Artifact [4922b66d6d]:

To Artifact [66aee0aeb8]:


347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
362
363
364
365
366
367

368
369

370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
386
387
388
389
390

391
392

393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416
417
418

419
420
421


422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438

439
440

441
442
443
444
445
446
447
448
449
450
347
348
349
350
351
352
353

354
355
356
357
358
359
360
361
362
363
364
365
366

367


368



369
370
371
372

373
374
375
376
377
378
379
380
381
382
383
384
385

386


387



388
389
390
391
392
393
394
395
396
397
398
399

400
401
402
403



404
405
406

407



408
409



410
411
412

413
414
415
416



417
418
419

420


421



422
423
424
425
426
427
428







-
+












-
+
-
-
+
-
-
-




-
+












-
+
-
-
+
-
-
-












-
+



-
-
-



-
+
-
-
-
+
+
-
-
-



-
+



-
-
-



-
+
-
-
+
-
-
-







    }
    return lToken[i];
}


//////// Disambiguator for regex rules

function select (dTokenPos, nPos, sWord, sPattern, lDefault=null) {
function select (dTokenPos, nPos, sWord, sPattern) {
    if (!sWord) {
        return true;
    }
    if (!dTokenPos.has(nPos)) {
        console.log("Error. There should be a token at this position: ", nPos);
        return true;
    }
    let lMorph = gc_engine.oSpellChecker.getMorph(sWord);
    if (lMorph.length === 0  ||  lMorph.length === 1) {
        return true;
    }
    let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 );
    if (lSelect.length > 0) {
    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        if (lSelect.length != lMorph.length) {
            dTokenPos.get(nPos)["lMorph"] = lSelect;
        dTokenPos.get(nPos)["lMorph"] = lSelect;
        }
    } else if (lDefault) {
        dTokenPos.get(nPos)["lMorph"] = lDefault;
    }
    return true;
}

function exclude (dTokenPos, nPos, sWord, sPattern, lDefault=null) {
function exclude (dTokenPos, nPos, sWord, sPattern) {
    if (!sWord) {
        return true;
    }
    if (!dTokenPos.has(nPos)) {
        console.log("Error. There should be a token at this position: ", nPos);
        return true;
    }
    let lMorph = gc_engine.oSpellChecker.getMorph(sWord);
    if (lMorph.length === 0  ||  lMorph.length === 1) {
        return true;
    }
    let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 );
    if (lSelect.length > 0) {
    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        if (lSelect.length != lMorph.length) {
            dTokenPos.get(nPos)["lMorph"] = lSelect;
        dTokenPos.get(nPos)["lMorph"] = lSelect;
        }
    } else if (lDefault) {
        dTokenPos.get(nPos)["lMorph"] = lDefault;
    }
    return true;
}

function define (dTokenPos, nPos, sMorphs) {
    dTokenPos.get(nPos)["lMorph"] = sMorphs.split("|");
    return true;
}


//// Disambiguation for graph rules

function g_select (oToken, sPattern, lDefault=null) {
function g_select (oToken, sPattern) {
    // select morphologies for <oToken> according to <sPattern>, always return true
    let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]);
    if (lMorph.length === 0  || lMorph.length === 1) {
        if (lDefault) {
            oToken["lMorph"] = lDefault;
        }
        return true;
    }
    let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 );
    if (lSelect.length > 0) {
    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        if (lSelect.length != lMorph.length) {
            oToken["lMorph"] = lSelect;
        }
        oToken["lMorph"] = lSelect;
    }
    } else if (lDefault) {
        oToken["lMorph"] = lDefault;
    }
    return true;
}

function g_exclude (oToken, sPattern, lDefault=null) {
function g_exclude (oToken, sPattern) {
    // select morphologies for <oToken> according to <sPattern>, always return true
    let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]);
    if (lMorph.length === 0  || lMorph.length === 1) {
        if (lDefault) {
            oToken["lMorph"] = lDefault;
        }
        return true;
    }
    let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 );
    if (lSelect.length > 0) {
    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        if (lSelect.length != lMorph.length) {
            oToken["lMorph"] = lSelect;
        oToken["lMorph"] = lSelect;
        }
    } else if (lDefault) {
        oToken["lMorph"] = lDefault;
    }
    return true;
}

function g_add_morph (oToken, sNewMorph) {
    // Disambiguation: add a morphology to a token
    let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]);