mflbackend/src/backend.py
def inflectcandidate():
    " Inflect a known candidate according to it's assigned paradigms "
    lexicon = request.args.get('lexicon', C.config['default'])
    lexconf = lexconfig.get_lexiconconf(lexicon)
    identifier = request.args.get('identifier', '')
    # ask karp for the saved candidates and its assigned paradigms
    q = 'extended||and|%s.search|equals|%s' % ('identifier', identifier)
    res = helpers.karp_query('query', query={'q': q},
                             mode=lexconf['candidateMode'],
                             resource=lexconf['candidatelexiconName'])
    if helpers.es_total(res) < 1:
        raise e.MflException("Could not find candidate %s" % identifier,
                             code="unknown_candidate")
    candidate = helpers.es_first_source(res)
    pos = pc.get_pos(candidate)
    lemgram = helpers.make_identifier(lexicon, pc.get_baseform(candidate), pos)
    ans = []
    # go through each possible paradigm
    for inflection in pc.candidateparadigms(candidate):
        var_inst = []
        # get the variable instansiation
        for varname, var in pc.inflectionvariables(inflection):
            if varname.isdigit():
                var_inst.append((int(varname), var))
        var_inst = [var for key, var in sorted(var_inst)]
        # get the paradigm with the given ID
        paras, n, l = helpers.relevant_paradigms(paradigmdict, lexicon,
                                                 pos,
                                                 possible_p=[pc.get_uuid(inflection)])
        # the paradigm might be removed, then skip it
        # if not, save the table
        if paras:
            ans.append(helpers.make_table(lexicon, paras[0], var_inst, 0, pos,
                                          lemgram=lemgram))

    if not pc.candidateparadigms(candidate):
        # if the candidate don't have assigned paradigms, make a table with all
        # known forms
        table = helpers.tableize_obj(candidate, add_tags=True, identifier=lemgram)
        # get the paradigm representation from pextract
        paradigm = pex.learnparadigms([table])[0]
        obj = {'score': 0, 'paradigm': '', 'new': True}
        if paradigm is not None:
            obj['variables'] = [var for ix, var in paradigm.var_insts[0][1:]]
            obj['paradigm'] = paradigm.name
            obj['pattern'] = paradigm.jsonify()
        obj['WordForms'] = pc.get_wordforms(candidate)
        obj['identifier'] = lemgram
        obj['partOfSpeech'] = pos
        obj['count'] = 0
        ans = [helpers.show_inflected(lexicon, obj)]
    return jsonify({"Results": ans})
 Inflect a known candidate according to it's assigned paradigms 
Inflect a known candidate according to it's assigned paradigms
Inflect a known candidate according to it ' s assigned paradigms
def inflectcandidate():
    lexicon = request.args.get('lexicon', C.config['default'])
    lexconf = lexconfig.get_lexiconconf(lexicon)
    identifier = request.args.get('identifier', '')
    q = 'extended||and|%s.search|equals|%s' % ('identifier', identifier)
    res = helpers.karp_query('query', query={'q': q},
                             mode=lexconf['candidateMode'],
                             resource=lexconf['candidatelexiconName'])
    if helpers.es_total(res) < 1:
        raise e.MflException("Could not find candidate %s" % identifier,
                             code="unknown_candidate")
    candidate = helpers.es_first_source(res)
    pos = pc.get_pos(candidate)
    lemgram = helpers.make_identifier(lexicon, pc.get_baseform(candidate), pos)
    ans = []
    for inflection in pc.candidateparadigms(candidate):
        var_inst = []
        for varname, var in pc.inflectionvariables(inflection):
            if varname.isdigit():
                var_inst.append((int(varname), var))
        var_inst = [var for key, var in sorted(var_inst)]
        paras, n, l = helpers.relevant_paradigms(paradigmdict, lexicon,
                                                 pos,
                                                 possible_p=[pc.get_uuid(inflection)])
        if paras:
            ans.append(helpers.make_table(lexicon, paras[0], var_inst, 0, pos,
                                          lemgram=lemgram))
    if not pc.candidateparadigms(candidate):
        table = helpers.tableize_obj(candidate, add_tags=True, identifier=lemgram)
        paradigm = pex.learnparadigms([table])[0]
        obj = {'score': 0, 'paradigm': '', 'new': True}
        if paradigm is not None:
            obj['variables'] = [var for ix, var in paradigm.var_insts[0][1:]]
            obj['paradigm'] = paradigm.name
            obj['pattern'] = paradigm.jsonify()
        obj['WordForms'] = pc.get_wordforms(candidate)
        obj['identifier'] = lemgram
        obj['partOfSpeech'] = pos
        obj['count'] = 0
        ans = [helpers.show_inflected(lexicon, obj)]
    return jsonify({"Results": ans})
def inflectcandidate ( ) : lexicon = request . args . get ( 'lexicon' , C . config [ 'default' ] ) lexconf = lexconfig . get_lexiconconf ( lexicon ) identifier = request . args . get ( 'identifier' , '' ) q = 'extended||and|%s.search|equals|%s' % ( 'identifier' , identifier ) res = helpers . karp_query ( 'query' , query = { 'q' : q } , mode = lexconf [ 'candidateMode' ] , resource = lexconf [ 'candidatelexiconName' ] ) if helpers . es_total ( res ) < 1 : raise e . MflException ( "Could not find candidate %s" % identifier , code = "unknown_candidate" ) candidate = helpers . es_first_source ( res ) pos = pc . get_pos ( candidate ) lemgram = helpers . make_identifier ( lexicon , pc . get_baseform ( candidate ) , pos ) ans = [ ] for inflection in pc . candidateparadigms ( candidate ) : var_inst = [ ] for varname , var in pc . inflectionvariables ( inflection ) : if varname . isdigit ( ) : var_inst . append ( ( int ( varname ) , var ) ) var_inst = [ var for key , var in sorted ( var_inst ) ] paras , n , l = helpers . relevant_paradigms ( paradigmdict , lexicon , pos , possible_p = [ pc . get_uuid ( inflection ) ] ) if paras : ans . append ( helpers . make_table ( lexicon , paras [ 0 ] , var_inst , 0 , pos , lemgram = lemgram ) ) if not pc . candidateparadigms ( candidate ) : table = helpers . tableize_obj ( candidate , add_tags = True , identifier = lemgram ) paradigm = pex . learnparadigms ( [ table ] ) [ 0 ] obj = { 'score' : 0 , 'paradigm' : '' , 'new' : True } if paradigm is not None : obj [ 'variables' ] = [ var for ix , var in paradigm . var_insts [ 0 ] [ 1 : ] ] obj [ 'paradigm' ] = paradigm . name obj [ 'pattern' ] = paradigm . jsonify ( ) obj [ 'WordForms' ] = pc . get_wordforms ( candidate ) obj [ 'identifier' ] = lemgram obj [ 'partOfSpeech' ] = pos obj [ 'count' ] = 0 ans = [ helpers . show_inflected ( lexicon , obj ) ] return jsonify ( { "Results" : ans } )
Inflect a known candidate according to it's assigned paradigms
Inflect a known candidate according to it ' s assigned paradigms
" Inflect a known candidate according to it's assigned paradigms " # ask karp for the saved candidates and its assigned paradigms # go through each possible paradigm # get the variable instansiation # get the paradigm with the given ID # the paradigm might be removed, then skip it # if not, save the table # if the candidate don't have assigned paradigms, make a table with all # known forms # get the paradigm representation from pextract