Grammalecte  Diff

Differences From Artifact [1f04b155c5]:

To Artifact [7edc6f08c2]:


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
    }
    return lToken[i];
}


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

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 && lSelect.length != lMorph.length) {
        dTokenPos.get(nPos)["lMorph"] = lSelect;
    }
    return true;

}

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 && lSelect.length != lMorph.length) {
        dTokenPos.get(nPos)["lMorph"] = lSelect;
    }
    return true;
}

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


//// Disambiguation for graph rules

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) {
        return true;
    }



    let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 );
    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        oToken["lMorph"] = lSelect;
    }
    return true;

}

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) {



        return true;
    }
    let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 );
    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        oToken["lMorph"] = lSelect;
    }
    return true;
}

function g_addmorph (oToken, sNewMorph) {







|











>
>
>
|
<
<
|
|
>
|
|
|
<
<
>

<
>
|


<
<
<
<
<














|





>
>
>
|
<
<
|
|
>
|
|
|
<
<
|
>
>
>


<







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
    }
    return lToken[i];
}


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

function select (dTokenPos, nPos, sWord, sPattern, sNegPattern="") {
    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;
    if (sPattern) {
        if (sNegPattern) {
            lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 && sMorph.search(sNegPattern) === -1 );


        }
        else {
            lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 );
        }
    }
    else if (sNegPattern) {


        lSelect = lMorph.filter( sMorph => sMorph.search(sNegPattern) === -1 );
    }

    else {
        console.log("[Grammalecte] Error: missing pattern for disambiguation selection...");
        return true;
    }





    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        dTokenPos.get(nPos)["lMorph"] = lSelect;
    }
    return true;
}

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


//// Disambiguation for graph rules

function g_select (oToken, sPattern, sNegPattern="") {
    // 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) {
        return true;
    }
    let lSelect;
    if (sPattern) {
        if (sNegPattern) {
            lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 && sMorph.search(sNegPattern) === -1 );


        }
        else {
            lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 );
        }
    }
    else if (sNegPattern) {


        lSelect = lMorph.filter( sMorph => sMorph.search(sNegPattern) === -1 );
    }
    else {
        console.log("[Grammalecte] Error: missing pattern for disambiguation selection...");
        return true;
    }

    if (lSelect.length > 0 && lSelect.length != lMorph.length) {
        oToken["lMorph"] = lSelect;
    }
    return true;
}

function g_addmorph (oToken, sNewMorph) {