Stemmer Occitan

routines (
           cleaning mark_regions
           R1  R2
           attached_pronoun
           standard_suffix
           verb_suffix
           residual_suffix
)

externals ( stem )

integers ( p1 p2 )

groupings ( v )

stringescapes {}

/* special characters (in ISO Latin I) */

stringdef a'   hex 'E1'  // a-acute
stringdef a`   hex 'E0'  // a-grave
stringdef c,   hex 'E7'  // c-cedilla
stringdef e'   hex 'E9'  // e-acute
stringdef e`   hex 'E8'  // e-grave
stringdef i'   hex 'ED'  // i-acute
stringdef i`   hex 'EC'  // i-grave
stringdef i"   hex 'EF'  // i-diaeresis
stringdef o'   hex 'F3'  // o-acute
stringdef o`   hex 'F2'  // o-grave
stringdef u'   hex 'FA'  // u-acute
stringdef u"   hex 'FC'  // u-diaeresis
stringdef -    hex '2D'   // - junhent
stringdef .    hex 'B7'   // - punt median

define v 'aeiou{a'}{a`}{e'}{e`}{i'}{i"}{o'}{o`}{u'}{u"}'

define mark_regions as (

    $p1 = limit
    $p2 = limit  // defaults

    do (
        gopast v gopast non-v setmark p1
        gopast v gopast non-v setmark p2
    )
)

define cleaning as repeat (
    [substring] among(
        '{a'}' (<- 'a')
        '{a`}' (<- 'a')
        '{e'}' (<- 'e')
        '{e`}' (<- 'e')
        '{i'}' (<- 'i')
        '{i`}' (<- 'i')
        '{o'}' (<- 'o')
        '{o`}' (<- 'o')
        '{u'}' (<- 'u')
        '{u"}' (<- 'u')
        '{i"}' (<- 'i')
        '{.}' (<- '.')
        ''     (next)
    ) //or next
)

backwardmode (

    define R1 as $p1 <= cursor
    define R2 as $p2 <= cursor

    define attached_pronoun as (
    [substring] among (
        '{'}s'  '{'}i' '{'}o' '{'}l' '{'}ls'
        '{-}ls' '{-}la' '{-}les' '{-}li'
        'vos' 'se'  'nos' '{-}nos' '{-}us' 'us'
        '{'}n' '{'}ns' '{-}n' '{-}ns'
        '{'}m' '{-}me' '{-}m'
        '{-}te' '{'}t'
        'li' 'lo' 'los'
        'me'  'sela' 'selo' 'selas' 'selos' 'le'
        'la' 'las' 'les' 'ens' 'o' 'i'
        (R1 delete)
    )
    )

    define standard_suffix as (
        [substring] among(
            'ar' 'atge' 'formas' 'icte' 'ictas'
            'el' 'elses' 'ella'  '{e'}s' '{e`}s' 'esc' 'essa' 'et' 'ets' 'eta'
            'eras' 'erias' 'ers' 'ina' 'inas' 'able' 'ls'
            'i{o'}' 'itat' 'itats' 'itzar' 'iva' 'ivas' 'ivisme' 'ius'
            'fer' 'ment' 'amen' 'ament' 'aments' 'ments' 'ot' 'sfera' 'al' 'als' 'era' 'ana' 'iste'
            'aire' 'eria' 'esa' 'esas' 'esos' 'or' '{i'}cia' '{i'}cias' 'icis' 'ici' '{i'}ci' '{i'}cis'
            '{a`}ria' '{a`}rias' 'alla' 'ci{o'}' 'cions' 'n{c,}a' 'ncas' '{o'}' 'dor' 'all'
            'il' '{i'}stic' 'enc' 'enca' '{i'}s' 'issa' 'issos' '{i'}ssem' '{i'}ssiu' 'issem' 'isseu' '{i'}sseu'
            '{o'}s' 'osa'  'dora' 'doras' 'dors' 'adura' 'ble' 'blas' '{i'}vol' '{i'}vola' 'd{i'}s' 'egar' 'ejar' 'ificar'
            'itar' 'ablas' 'adors' 'idoras' 'idors'
            'adora' 'aci{o'}' 'dur' 'duras' 'allengas'
            'ant' 'ants' 'ancia' 'ancias' 'at{o`}ria' 'at{o`}rias' 'tori' 'toris'
            'ats' 'ions'  'ota' 'isam' 'ors' 'ora' 'oras' 'isament'
            'bilitat' 'bilitats' 'ivitat' 'ivitats' 'ari' 'aris' 'ionisme' 'ionista' 'ionistas'
            'ialista' 'ialistas' 'ialisme' 'ialismas' 'ud' 'uts' 'uds' 'encia' 'encias' '{e`}ncia' '{e`}ncias'
            '{i"}tat' '{i"}tats' 'atiu' 'atius' 'ativas' 'ativa' 'ativitat' 'ativitats' 'ible' 'iblas'
            'assa' 'assas' 'assos'
             'ent' 'ents'
             '{i'}ssim' '{i'}ssima' '{i'}ssims' '{i'}ssimas' '{i`}ssem' '{i`}sseu' '{i`}sson'
             'ims' 'ima' 'imas'
             'isme' 'ista' 'ismas' 'istas'
             'inia' 'inias' '{i'}inia' '{i'}nias' 'ita' 'itas' 'triu' 'trius'
             'osas' 'osos' 'ient' 'otas' 'ots'
            (R1 delete)
            'acions' 'ada' 'adea'
            (R2 delete)
            'log{i'}a' 'log{i'}as''logia' 'logias' 'logi' 'logis' 'l{o'}gica' 'l{o'}gics' 'l{o'}gicas'
            (R2 <- 'log')
            'ic' 'ica' 'ics' 'iquas'
            (R2 <- 'ic')
            'qu{i'}ssim' 'qu{i'}ssims' 'qu{i'}ssimas' 'qu{i'}ssima'
            (R1 <- 'c')
        )
    )

    define verb_suffix as (
        [substring] among(
            'ador' 'adora'  'adors' 'adores' 're' 'ie'
             'ent' 'ents' 'udes' 'ar{a`}' 'eren'
            'ar{a'}' 'ar{i'}an' 'ar{i'}as' 'ar{a'}n' 'ar{a'}s' 'ar{i'}ais'
            'aria' 'arian' 'arien' 'aries' 'ar{a`}s'
            'ar{i'}a' 'ar{e'}is' 'ar{i'}amos' 'aremos' 'ara'
            'ar{e'}' 'ar{e'}s'
            'er{i'}an' 'er{i'}as' 'er{a'}n' 'er{a'}s' 'er{i'}ais'
            'er{i'}a' 'er{e'}is' 'er{i'}amos' 'eremos' 'er{a'}'
            'er{e'}' 'er' 'erau' 'erass'
            'ir{i'}an' 'ir{i'}as' 'ir{a'}n' 'ir{a'}s' 'ir{i'}ais'
            'ir{i'}a' 'ir{e'}is' 'ir{i'}amos' 'iremos' 'ir{a'}'
            'ir{e'}' '{i'}rem' '{i'}reu' '{i'}eu'
            'ia' 'ies' '{i'}em' '{i`}eu' 'ien'
            'at' 'ut' 'uda' 'ava' 'aves' 'avem' '{a'}vem' '{a`}vem' '{a`}veu' '{a'}veu' 'aven' 'au' 'ats'
            'asseu' 'esseu' 'eresseu' '{a`}sseu' '{a`}ssem' '{a`}ssim' '{a`}ssiu'
            'essen' 'esses' 'assen' 'asses' 'assim' 'assiu'
            '{e'}ssen' '{e'}sseu'  '{e'}ssim' '{e'}ssiu' '{e'}ssem'
            '{i'}' 'ares' '{a`}rem' '{a`}reu' '{a`}ren'
            'ar{i'}em' 'ar{i'}eu'
            'areu' 'aren' 'ant' '{i"}m' '{i"}u'
            '{e'}s' '{i"}en' 'en' 'es' 'em' 'am' 'ams' '{i"}a' '{i"}es'
            'dre' 'eix' 'eixer' 'tzar' 'eixes' 'ides' '{i"}des' 'it' '{i"}t' '{i"}da'
            'aba' 'ada' 'ades' 'ida' '{i'}a' 'iera' 'ad' 'ed' 'its'
            'id' 'ids'  'ase' 'iese' 'aste' 'iste' 'an' 'aban' '{i'}an'
            'aran' 'ieran' 'asen' 'iesen' 'aron' 'ieron' 'ado'
            'ido' 'iendo' 'i{o'}' 'ar' 'ir' 'as'
            'ieu' 'ii' 'io' 'i{a`}'
            'ess' 'essin' 'essis'  'ass' 'assin' 'assis' 'essim' '{e`}ssim' '{e`}ssiu'
            'abas' 'adas' 'idas' '{i'}as' 'aras' 'ieras' 'ases'
            'ieses' '{i'}s' '{a'}is' 'abais' '{i'}ais' 'arais'
            'ierais'  'aseis' 'ieseis' 'asteis' 'isteis' 'ados'
            'idos' 'amos' '{a'}bamos' '{i'}amos' 'imos' 'ques'
            '{a'}ramos' 'i{e'}ramos' 'i{e'}semos' '{a'}semos'
            'ira' 'iran' 'irem' 'iren' 'ires' 'ireu' 'iria' 'irien'
            'iries' 'ir{a`}' 'ir{a`}s' 'ir{e`}' 'ir{i`}em' 'ir{i`}eu'
            'isquen' 'iguem' 'igueu' 'esqui' 'esquin' 'esquis' 'eixi' 'eixin' 'eixis'
            'eixen' 'eixo' 'isin' 'isis'  'esques' 'sis' 'sin'
            'int' 'ir{i'}em' 'ir{i'}eu' 'isc' 'atges' 'esca' 'esquen'
            'issen' 'isses' 'issin' 'issis' 'isca' 'issiu' 'issim'
            '{i"}sc' '{i"}sca' '{i"}ssin' '{i'}ssiu' '{i'}ssim' '{i"}ssis' '{i"}guem' '{i"}gueu'
            '{i"}ra' '{i"}ren' '{i"}res'
            '{i"}squen' '{i"}sques' '{i"}ssen' '{i"}sses' '{i"}xo' '{i"}xen' '{i"}xes' '{i"}x'
            'ixo' 'ixen' 'ixes' 'ix' 'ixa' 'inin' 'inis' 'ini' 'ineu' 'itza' 'itzi' 'itzeu' 'itzis'
            'itzo' 'itz' 'itz{a`}' 'arem' 'in' '{a`}s' 'i{i"}' 'i{i"}n' 'i{i"}s'
                (R1 delete)
            'ando'
                (R2 delete)
        )
    )

    define residual_suffix as (
        [substring] among(
            'os' 'a' 'o' '{a'}' '{a`}' '{i'}' '{o'}' 'e' '{e'}' 'eu' 'iu'
            'is' 'i' 'ir'  's' '{i`}' 'itz' '{i"}' '{i"}n' '{i"}s' 'it'
            (R1 delete)
            'iqu'
            (R1 <- 'ic')
        )
    )
)

define stem as (
    do mark_regions
    backwards (
    do attached_pronoun
    do ( standard_suffix or
             verb_suffix
           )
        do residual_suffix
    )
    do cleaning
)