mflbackend/src/backend.py
def inflectclass():
    " Inflect a word according to a user defined category "
    lexicon = request.args.get('lexicon', C.config['default'])
    lexconf = lexconfig.get_lexiconconf(lexicon)
    word = request.args.get('wordform', '')
    # ppriorv: setting for pextract
    ppriorv = float(request.args.get('pprior', lexconf["pprior"]))
    classname = request.args.get('classname', '')
    classval = request.args.get('classval', '')
    pos = helpers.read_one_pos(lexconf)
    lemgram = helpers.make_identifier(lexicon, word, pos)
    # ask karp to filter out matching paradigm's IDs
    q = 'extended||and|%s.search|equals|%s||and|%s|equals|%s'\
        % (classname, classval, lexconf['pos'], pos)
    res = helpers.karp_query('statlist',
                             {'q': q,
                              'buckets': '_id',
                              'mode': lexconf['paradigmMode'],
                              'resource': lexconf['paradigmlexiconName']
                             }
                            )
    # get the internal objects for these paradigms
    possible_p = [line[0] for line in res['stat_table']]
    logging.debug('possible_p %s', possible_p)
    paras, numex, lms = helpers.relevant_paradigms(paradigmdict, lexicon,
                                                   pos, possible_p)
    # get the provided variable instances, if any
    var_inst = sorted([(int(key), val) for key, val in request.args.items()
                       if key.isdigit()])
    if classname == "paradigm" and var_inst:
        # Special case: '?classname=paradigm&classval=p14_oxe..nn.1&1=katt&2=a'
        # Will result in only one possible table
        # TODO rename to extractparadigm?
        if len(paras) < 1 or len(possible_p) < 1:
            raise e.MflException("Cannot find paradigm %s" % classval,
                                 code="unknown_paradigm")
        var_inst = [val for key, val in var_inst]
        logging.debug('look for %s as %s', classval, pos)
        table = helpers.make_table(lexicon, paras[0], var_inst, 0, pos, lemgram)
        ans = {"Results": [table]}

    else:
        # The user has provided a paradigm or inflection class:
        # '?classname=paradigm&classval=p14_oxe..nn.1&wordform=bolle'
        # Find the possible tables (zero or more).
        # is the given form necessarily the baseform?
        restrict_to_baseform = helpers.read_restriction(lexconf)
        res = mp.run_paradigms(paras, [word], kbest=100, pprior=ppriorv,
                               lms=lms, numexamples=numex,
                               baseform=restrict_to_baseform)
        logging.debug('generated %s results', len(res))
        results = helpers.format_kbest(lexicon, res, pos=pos, lemgram=lemgram)
        ans = {"Results": results}
    return jsonify(ans)
 Inflect a word according to a user defined category 
Inflect a word according to a user defined category
Inflect a word according to a user defined category
def inflectclass():
    lexicon = request.args.get('lexicon', C.config['default'])
    lexconf = lexconfig.get_lexiconconf(lexicon)
    word = request.args.get('wordform', '')
    ppriorv = float(request.args.get('pprior', lexconf["pprior"]))
    classname = request.args.get('classname', '')
    classval = request.args.get('classval', '')
    pos = helpers.read_one_pos(lexconf)
    lemgram = helpers.make_identifier(lexicon, word, pos)
    q = 'extended||and|%s.search|equals|%s||and|%s|equals|%s'\
        % (classname, classval, lexconf['pos'], pos)
    res = helpers.karp_query('statlist',
                             {'q': q,
                              'buckets': '_id',
                              'mode': lexconf['paradigmMode'],
                              'resource': lexconf['paradigmlexiconName']
                             }
                            )
    possible_p = [line[0] for line in res['stat_table']]
    logging.debug('possible_p %s', possible_p)
    paras, numex, lms = helpers.relevant_paradigms(paradigmdict, lexicon,
                                                   pos, possible_p)
    var_inst = sorted([(int(key), val) for key, val in request.args.items()
                       if key.isdigit()])
    if classname == "paradigm" and var_inst:
        if len(paras) < 1 or len(possible_p) < 1:
            raise e.MflException("Cannot find paradigm %s" % classval,
                                 code="unknown_paradigm")
        var_inst = [val for key, val in var_inst]
        logging.debug('look for %s as %s', classval, pos)
        table = helpers.make_table(lexicon, paras[0], var_inst, 0, pos, lemgram)
        ans = {"Results": [table]}
    else:
        restrict_to_baseform = helpers.read_restriction(lexconf)
        res = mp.run_paradigms(paras, [word], kbest=100, pprior=ppriorv,
                               lms=lms, numexamples=numex,
                               baseform=restrict_to_baseform)
        logging.debug('generated %s results', len(res))
        results = helpers.format_kbest(lexicon, res, pos=pos, lemgram=lemgram)
        ans = {"Results": results}
    return jsonify(ans)
def inflectclass ( ) : lexicon = request . args . get ( 'lexicon' , C . config [ 'default' ] ) lexconf = lexconfig . get_lexiconconf ( lexicon ) word = request . args . get ( 'wordform' , '' ) ppriorv = float ( request . args . get ( 'pprior' , lexconf [ "pprior" ] ) ) classname = request . args . get ( 'classname' , '' ) classval = request . args . get ( 'classval' , '' ) pos = helpers . read_one_pos ( lexconf ) lemgram = helpers . make_identifier ( lexicon , word , pos ) q = 'extended||and|%s.search|equals|%s||and|%s|equals|%s' % ( classname , classval , lexconf [ 'pos' ] , pos ) res = helpers . karp_query ( 'statlist' , { 'q' : q , 'buckets' : '_id' , 'mode' : lexconf [ 'paradigmMode' ] , 'resource' : lexconf [ 'paradigmlexiconName' ] } ) possible_p = [ line [ 0 ] for line in res [ 'stat_table' ] ] logging . debug ( 'possible_p %s' , possible_p ) paras , numex , lms = helpers . relevant_paradigms ( paradigmdict , lexicon , pos , possible_p ) var_inst = sorted ( [ ( int ( key ) , val ) for key , val in request . args . items ( ) if key . isdigit ( ) ] ) if classname == "paradigm" and var_inst : if len ( paras ) < 1 or len ( possible_p ) < 1 : raise e . MflException ( "Cannot find paradigm %s" % classval , code = "unknown_paradigm" ) var_inst = [ val for key , val in var_inst ] logging . debug ( 'look for %s as %s' , classval , pos ) table = helpers . make_table ( lexicon , paras [ 0 ] , var_inst , 0 , pos , lemgram ) ans = { "Results" : [ table ] } else : restrict_to_baseform = helpers . read_restriction ( lexconf ) res = mp . run_paradigms ( paras , [ word ] , kbest = 100 , pprior = ppriorv , lms = lms , numexamples = numex , baseform = restrict_to_baseform ) logging . debug ( 'generated %s results' , len ( res ) ) results = helpers . format_kbest ( lexicon , res , pos = pos , lemgram = lemgram ) ans = { "Results" : results } return jsonify ( ans )
Inflect a word according to a user defined category
Inflect a word according to a user defined category
" Inflect a word according to a user defined category " # ppriorv: setting for pextract # ask karp to filter out matching paradigm's IDs # get the internal objects for these paradigms # get the provided variable instances, if any # Special case: '?classname=paradigm&classval=p14_oxe..nn.1&1=katt&2=a' # Will result in only one possible table # TODO rename to extractparadigm? # The user has provided a paradigm or inflection class: # '?classname=paradigm&classval=p14_oxe..nn.1&wordform=bolle' # Find the possible tables (zero or more). # is the given form necessarily the baseform?