mflbackend/src/backend.py
def recomputecandiadtes():
    """
     Recompute the candidates' paradigm assignments
     Returns the number of candidates that have been updated
    """
    lexicon = request.args.get('lexicon', C.config['default'])
    lexconf = lexconfig.get_lexiconconf(lexicon)
    postags = helpers.read_pos(lexconf)
    # ppriorv: setting for pextract
    ppriorv = float(request.args.get('pprior', lexconf["pprior"]))
    counter = 0
    for pos in postags:
        # ask karp for all relevant candidates
        q = 'extended||and|%s.search|equals|%s' % (lexconf['pos'], pos)
        res = helpers.karp_query('query', query={'q': q},
                                 mode=lexconf['candidateMode'],
                                 resource=lexconf['candidatelexiconName'])
        # get all relevant paradigms
        paras, numex, lms = helpers.relevant_paradigms(paradigmdict, lexicon, pos)
        for hit in helpers.es_get_hits(res):
            # go through the candidates
            _id = helpers.es_get_id(hit)
            table = helpers.es_get_source(hit)
            logging.debug('table %s', table)
            # construct a pextract table from the datat
            forms = [table['baseform']]
            for wf in table.get('WordForms', []):
                form = wf['writtenForm']
                msd = wf.get('msd', '')
                if msd:
                    forms.append(form+'|'+msd)
                else:
                    forms.append(form)
            pex_table = helpers.tableize(','.join(forms), add_tags=False)
            logging.debug('inflect forms %s msd %s', pex_table[0], pex_table[1])
            # is the given form necessarily the baseform?
            restrict_to_baseform = helpers.read_restriction(lexconf)
            # get paradigm assignments from pextract
            res = mp.test_paradigms(pex_table, paras, numex, lms,
                                    C.config["print_tables"], C.config["debug"],
                                    ppriorv, returnempty=False,
                                    baseform=restrict_to_baseform)
            # format
            to_save = helpers.make_candidate(lexconf['candidatelexiconName'],
                                             table['identifier'], forms, res,
                                             table['partOfSpeech'])
            counter += 1
        logging.debug('will save %s', to_save)
        # save in karp
        helpers.karp_update(_id, to_save, resource=lexconf['candidatelexiconName'])
    return jsonify({"updated": counter})

     Recompute the candidates' paradigm assignments
     Returns the number of candidates that have been updated
    
Recompute the candidates' paradigm assignments
Returns the number of candidates that have been updated
Recompute the candidates ' paradigm assignments Returns the number of candidates that have been updated
def recomputecandiadtes():
    lexicon = request.args.get('lexicon', C.config['default'])
    lexconf = lexconfig.get_lexiconconf(lexicon)
    postags = helpers.read_pos(lexconf)
    ppriorv = float(request.args.get('pprior', lexconf["pprior"]))
    counter = 0
    for pos in postags:
        q = 'extended||and|%s.search|equals|%s' % (lexconf['pos'], pos)
        res = helpers.karp_query('query', query={'q': q},
                                 mode=lexconf['candidateMode'],
                                 resource=lexconf['candidatelexiconName'])
        paras, numex, lms = helpers.relevant_paradigms(paradigmdict, lexicon, pos)
        for hit in helpers.es_get_hits(res):
            _id = helpers.es_get_id(hit)
            table = helpers.es_get_source(hit)
            logging.debug('table %s', table)
            forms = [table['baseform']]
            for wf in table.get('WordForms', []):
                form = wf['writtenForm']
                msd = wf.get('msd', '')
                if msd:
                    forms.append(form+'|'+msd)
                else:
                    forms.append(form)
            pex_table = helpers.tableize(','.join(forms), add_tags=False)
            logging.debug('inflect forms %s msd %s', pex_table[0], pex_table[1])
            restrict_to_baseform = helpers.read_restriction(lexconf)
            res = mp.test_paradigms(pex_table, paras, numex, lms,
                                    C.config["print_tables"], C.config["debug"],
                                    ppriorv, returnempty=False,
                                    baseform=restrict_to_baseform)
            to_save = helpers.make_candidate(lexconf['candidatelexiconName'],
                                             table['identifier'], forms, res,
                                             table['partOfSpeech'])
            counter += 1
        logging.debug('will save %s', to_save)
        helpers.karp_update(_id, to_save, resource=lexconf['candidatelexiconName'])
    return jsonify({"updated": counter})
def recomputecandiadtes ( ) : lexicon = request . args . get ( 'lexicon' , C . config [ 'default' ] ) lexconf = lexconfig . get_lexiconconf ( lexicon ) postags = helpers . read_pos ( lexconf ) ppriorv = float ( request . args . get ( 'pprior' , lexconf [ "pprior" ] ) ) counter = 0 for pos in postags : q = 'extended||and|%s.search|equals|%s' % ( lexconf [ 'pos' ] , pos ) res = helpers . karp_query ( 'query' , query = { 'q' : q } , mode = lexconf [ 'candidateMode' ] , resource = lexconf [ 'candidatelexiconName' ] ) paras , numex , lms = helpers . relevant_paradigms ( paradigmdict , lexicon , pos ) for hit in helpers . es_get_hits ( res ) : _id = helpers . es_get_id ( hit ) table = helpers . es_get_source ( hit ) logging . debug ( 'table %s' , table ) forms = [ table [ 'baseform' ] ] for wf in table . get ( 'WordForms' , [ ] ) : form = wf [ 'writtenForm' ] msd = wf . get ( 'msd' , '' ) if msd : forms . append ( form + '|' + msd ) else : forms . append ( form ) pex_table = helpers . tableize ( ',' . join ( forms ) , add_tags = False ) logging . debug ( 'inflect forms %s msd %s' , pex_table [ 0 ] , pex_table [ 1 ] ) restrict_to_baseform = helpers . read_restriction ( lexconf ) res = mp . test_paradigms ( pex_table , paras , numex , lms , C . config [ "print_tables" ] , C . config [ "debug" ] , ppriorv , returnempty = False , baseform = restrict_to_baseform ) to_save = helpers . make_candidate ( lexconf [ 'candidatelexiconName' ] , table [ 'identifier' ] , forms , res , table [ 'partOfSpeech' ] ) counter += 1 logging . debug ( 'will save %s' , to_save ) helpers . karp_update ( _id , to_save , resource = lexconf [ 'candidatelexiconName' ] ) return jsonify ( { "updated" : counter } )
Recompute the candidates' paradigm assignments
Returns the number of candidates that have been updated
Recompute the candidates ' paradigm assignments Returns the number of candidates that have been updated
"""
     Recompute the candidates' paradigm assignments
     Returns the number of candidates that have been updated
    """ # ppriorv: setting for pextract # ask karp for all relevant candidates # get all relevant paradigms # go through the candidates # construct a pextract table from the datat # is the given form necessarily the baseform? # get paradigm assignments from pextract # format # save in karp