mflbackend/src/handleparadigms.py
def inflect_table(lexicon, table, paradigms, identifier, pos, ppriorv=None,
                  kbest=10, match_all=False):
    """
    Find matching paradigms for an inflectiontable, possibly by adding
    word forms to the original table.
    Args:
        lexicon (str): the lexicon name
        table (list): the comma separated word forms, possibly with msds.
                      "katt,katter|pl indef nom,katts"
        paradigms (dict): a dictionary with all paradigms
            '{"lexname": {"nn": [], "vb": []}'
        identifier (str, optional): the word's identifier
        pos (str): the tables word class
        ppriorv (int, optional): setting for pextract.
            Defaults to the lexicon config's value.
        kbest (int, optional): how many suggestion to return. Defaults to 10.
        match_all (bool, optional): must the output strictly match the input?
             Defaults to false. Set to true if the input table is complete and
             no extra forms may be added.
    Returns:
       {"Results": [results]}
         where a result consits of:
           {score: float, paradigm: str, new: bool,
            identifier: str,
            baseform: str,
            variables: dict of variable instansiations,
            WordForms: [{writtenForm: str, msd: str}]
            partOfSpeech: str,
            paradigm_entries: int,
            }
        If the paradigm is new, the key 'pattern' (str) will show a compact
        represention of the paradigm.
        Possibly more, lexicon specific fields are added.
    """
    lexconf = lexconfig.get_lexiconconf(lexicon)
    restrict_baseform = helpers.read_restriction(lexconf)
    paras, numex, lms = helpers.relevant_paradigms(paradigms, lexicon, pos)
    fill_tags = '|' in table
    pex_table = helpers.tableize(table, add_tags=False, fill_tags=fill_tags)
    logging.debug('inflect forms %s msd %s. Restricted %s',
                  pex_table[0], pex_table[1], restrict_baseform)
    res = []
    if paras:
        # if there are known paradigms for the current lexicon and part of
        # speech, try these
        if ppriorv is None:
            ppriorv = lexconfig.get_pprior(lexicon)
        res = mp.test_paradigms(pex_table, paras, numex, lms,
                                C.config["print_tables"], C.config["debug"],
                                ppriorv, returnempty=False,
                                baseform=restrict_baseform,
                                match_all=match_all)
    if res:
        ans = {"Results": helpers.format_kbest(lexicon, res, kbest=kbest,
                                               pos=pos,
                                               lemgram=identifier)}
    else:
        # if no results are found (no matching paradigms), make a new paradigm
        # giving exactly the input forms
        logging.debug('invent! %s', len(res))
        pex_table = helpers.tableize(table, add_tags=True,
                                     identifier=identifier)
        paradigm = pex.learnparadigms([pex_table])[0]
        logging.debug('learned %s', paradigm)
        ans = {'Results': [helpers.karp_tableize(lexicon, table,
                                                 paradigm=paradigm,
                                                 pos=pos,
                                                 identifier=identifier)]}
    return ans

    Find matching paradigms for an inflectiontable, possibly by adding
    word forms to the original table.
    Args:
        lexicon (str): the lexicon name
        table (list): the comma separated word forms, possibly with msds.
                      "katt,katter|pl indef nom,katts"
        paradigms (dict): a dictionary with all paradigms
            '{"lexname": {"nn": [], "vb": []}'
        identifier (str, optional): the word's identifier
        pos (str): the tables word class
        ppriorv (int, optional): setting for pextract.
            Defaults to the lexicon config's value.
        kbest (int, optional): how many suggestion to return. Defaults to 10.
        match_all (bool, optional): must the output strictly match the input?
             Defaults to false. Set to true if the input table is complete and
             no extra forms may be added.
    Returns:
       {"Results": [results]}
         where a result consits of:
           {score: float, paradigm: str, new: bool,
            identifier: str,
            baseform: str,
            variables: dict of variable instansiations,
            WordForms: [{writtenForm: str, msd: str}]
            partOfSpeech: str,
            paradigm_entries: int,
            }
        If the paradigm is new, the key 'pattern' (str) will show a compact
        represention of the paradigm.
        Possibly more, lexicon specific fields are added.
    
Find matching paradigms for an inflectiontable, possibly by adding
word forms to the original table.
Find matching paradigms for an inflectiontable possibly by adding word forms to the original table .
def inflect_table(lexicon, table, paradigms, identifier, pos, ppriorv=None,
                  kbest=10, match_all=False):
    lexconf = lexconfig.get_lexiconconf(lexicon)
    restrict_baseform = helpers.read_restriction(lexconf)
    paras, numex, lms = helpers.relevant_paradigms(paradigms, lexicon, pos)
    fill_tags = '|' in table
    pex_table = helpers.tableize(table, add_tags=False, fill_tags=fill_tags)
    logging.debug('inflect forms %s msd %s. Restricted %s',
                  pex_table[0], pex_table[1], restrict_baseform)
    res = []
    if paras:
        if ppriorv is None:
            ppriorv = lexconfig.get_pprior(lexicon)
        res = mp.test_paradigms(pex_table, paras, numex, lms,
                                C.config["print_tables"], C.config["debug"],
                                ppriorv, returnempty=False,
                                baseform=restrict_baseform,
                                match_all=match_all)
    if res:
        ans = {"Results": helpers.format_kbest(lexicon, res, kbest=kbest,
                                               pos=pos,
                                               lemgram=identifier)}
    else:
        logging.debug('invent! %s', len(res))
        pex_table = helpers.tableize(table, add_tags=True,
                                     identifier=identifier)
        paradigm = pex.learnparadigms([pex_table])[0]
        logging.debug('learned %s', paradigm)
        ans = {'Results': [helpers.karp_tableize(lexicon, table,
                                                 paradigm=paradigm,
                                                 pos=pos,
                                                 identifier=identifier)]}
    return ans
def inflect_table ( lexicon , table , paradigms , identifier , pos , ppriorv = None , kbest = 10 , match_all = False ) : lexconf = lexconfig . get_lexiconconf ( lexicon ) restrict_baseform = helpers . read_restriction ( lexconf ) paras , numex , lms = helpers . relevant_paradigms ( paradigms , lexicon , pos ) fill_tags = '|' in table pex_table = helpers . tableize ( table , add_tags = False , fill_tags = fill_tags ) logging . debug ( 'inflect forms %s msd %s. Restricted %s' , pex_table [ 0 ] , pex_table [ 1 ] , restrict_baseform ) res = [ ] if paras : if ppriorv is None : ppriorv = lexconfig . get_pprior ( lexicon ) res = mp . test_paradigms ( pex_table , paras , numex , lms , C . config [ "print_tables" ] , C . config [ "debug" ] , ppriorv , returnempty = False , baseform = restrict_baseform , match_all = match_all ) if res : ans = { "Results" : helpers . format_kbest ( lexicon , res , kbest = kbest , pos = pos , lemgram = identifier ) } else : logging . debug ( 'invent! %s' , len ( res ) ) pex_table = helpers . tableize ( table , add_tags = True , identifier = identifier ) paradigm = pex . learnparadigms ( [ pex_table ] ) [ 0 ] logging . debug ( 'learned %s' , paradigm ) ans = { 'Results' : [ helpers . karp_tableize ( lexicon , table , paradigm = paradigm , pos = pos , identifier = identifier ) ] } return ans
Find matching paradigms for an inflectiontable, possibly by adding
word forms to the original table.
Find matching paradigms for an inflectiontable possibly by adding word forms to the original table .
"""
    Find matching paradigms for an inflectiontable, possibly by adding
    word forms to the original table.
    Args:
        lexicon (str): the lexicon name
        table (list): the comma separated word forms, possibly with msds.
                      "katt,katter|pl indef nom,katts"
        paradigms (dict): a dictionary with all paradigms
            '{"lexname": {"nn": [], "vb": []}'
        identifier (str, optional): the word's identifier
        pos (str): the tables word class
        ppriorv (int, optional): setting for pextract.
            Defaults to the lexicon config's value.
        kbest (int, optional): how many suggestion to return. Defaults to 10.
        match_all (bool, optional): must the output strictly match the input?
             Defaults to false. Set to true if the input table is complete and
             no extra forms may be added.
    Returns:
       {"Results": [results]}
         where a result consits of:
           {score: float, paradigm: str, new: bool,
            identifier: str,
            baseform: str,
            variables: dict of variable instansiations,
            WordForms: [{writtenForm: str, msd: str}]
            partOfSpeech: str,
            paradigm_entries: int,
            }
        If the paradigm is new, the key 'pattern' (str) will show a compact
        represention of the paradigm.
        Possibly more, lexicon specific fields are added.
    """ # if there are known paradigms for the current lexicon and part of # speech, try these # if no results are found (no matching paradigms), make a new paradigm # giving exactly the input forms
[results]}
where a result consits of:
{score: float, paradigm: str, new: bool,
identifier: str,
baseform: str,
variables: dict of variable instansiations,
WordForms: [{writtenForm: str, msd: str}]
partOfSpeech: str,
paradigm_entries: int,
}
If the paradigm is new, the key 'pattern' (str) will show a compact
represention of the paradigm.
Possibly more, lexicon specific fields are added.
[ results ] } where a result consits of : { score : float paradigm : str new : bool identifier : str baseform : str variables : dict of variable instansiations WordForms : [ { writtenForm : str msd : str } ] partOfSpeech : str paradigm_entries : int } If the paradigm is new the key ' pattern ' ( str ) will show a compact represention of the paradigm . Possibly more lexicon specific fields are added .
{"Results"
lexicon
the lexicon name
the lexicon name
table
the comma separated word forms, possibly with msds.
"katt,katter|pl indef nom,katts"
the comma separated word forms possibly with msds . " katt katter|pl indef nom katts "
paradigms
a dictionary with all paradigms
'{"lexname": {"nn": [], "vb": []}'
a dictionary with all paradigms ' { " lexname " : { " nn " : [] " vb " : [] } '
identifier
the word's identifier
the word ' s identifier
pos
the tables word class
the tables word class
ppriorv
setting for pextract.
Defaults to the lexicon config's value.
setting for pextract . Defaults to the lexicon config ' s value .
kbest
None
10
match_all
must the output strictly match the input.
Defaults to false. Set to true if the input table is complete and
no extra forms may be added.
must the output strictly match the input . Defaults to false . Set to true if the input table is complete and no extra forms may be added .