mflbackend/src/handleparadigms.py
def remove_word_from_paradigm(lexicon, paradigm, paradigms, identifier, pos):
    """
    Remove a word from a paradigm  (update language model, save to karp)
    Args:
        lexicon (str): the lexicon name
        paradigm (obj): the paradigm (Paradigm.py)
        paradigms (dict): a dictionary with all paradigms
            '{"lexname": {"nn": [], "vb": []}'
        identifier (str): the tables identifier
        pos (str): the tables word class
    """
    logging.debug('old count %s', paradigm.count)
    # remove variable_instances
    for ix, var_inst in enumerate(paradigm.var_insts):
        if dict(var_inst).get('first-attest', '') == identifier:
            paradigm.var_insts.pop(ix)
            break

    # remove from members
    try:
        paradigm.members.remove(identifier)
    except Exception as e:
        logging.exception(e)
        logging.warning('identifier %s cannot be removed, since it was not present in %s',
                        identifier, paradigm.p_id)

    # remove the words classes from the paradigm if they are not used by other
    # words, by first removing all and then readding the all classes used by
    # other words
    paradigm.empty_classes()
    # get all classes from all other words, add to paradigm:
    q = 'extended||and|paradigm|equals|%s||not|%s|equals|%s'\
        % (paradigm.p_id, lexconfig.get_identifierfield(lexicon), identifier)
    for iclass in lexconfig.get_inflectionalclassnames(lexicon):
        res = helpers.karp_query('statlist',
                                 {'q': q, 'size': 1000,
                                  'buckets': '%s.bucket' % iclass},
                                 resource=lexconfig.get_lexiconname(lexicon),
                                 mode=lexconfig.get_lexiconmode(lexicon))
        paradigm.add_class(iclass, [cl[0] for cl in res.get('stattable', [])])

    # decrease paradigm member count
    paradigm.count -= 1
    logging.debug('new count %s', paradigm.count)
    if paradigm.count > 0:
        # TODO remove from alphabet
        helpers.karp_update(paradigm.uuid, paradigm.jsonify(),
                            resource=lexconfig.get_paradigmlexicon(lexicon))
    else:
        remove_paradigm(lexicon, paradigm, paradigms, pos)

    Remove a word from a paradigm  (update language model, save to karp)
    Args:
        lexicon (str): the lexicon name
        paradigm (obj): the paradigm (Paradigm.py)
        paradigms (dict): a dictionary with all paradigms
            '{"lexname": {"nn": [], "vb": []}'
        identifier (str): the tables identifier
        pos (str): the tables word class
    
Remove a word from a paradigm  (update language model, save to karp)
Remove a word from a paradigm ( update language model save to karp )
def remove_word_from_paradigm(lexicon, paradigm, paradigms, identifier, pos):
    logging.debug('old count %s', paradigm.count)
    for ix, var_inst in enumerate(paradigm.var_insts):
        if dict(var_inst).get('first-attest', '') == identifier:
            paradigm.var_insts.pop(ix)
            break
    try:
        paradigm.members.remove(identifier)
    except Exception as e:
        logging.exception(e)
        logging.warning('identifier %s cannot be removed, since it was not present in %s',
                        identifier, paradigm.p_id)
    paradigm.empty_classes()
    q = 'extended||and|paradigm|equals|%s||not|%s|equals|%s'\
        % (paradigm.p_id, lexconfig.get_identifierfield(lexicon), identifier)
    for iclass in lexconfig.get_inflectionalclassnames(lexicon):
        res = helpers.karp_query('statlist',
                                 {'q': q, 'size': 1000,
                                  'buckets': '%s.bucket' % iclass},
                                 resource=lexconfig.get_lexiconname(lexicon),
                                 mode=lexconfig.get_lexiconmode(lexicon))
        paradigm.add_class(iclass, [cl[0] for cl in res.get('stattable', [])])
    paradigm.count -= 1
    logging.debug('new count %s', paradigm.count)
    if paradigm.count > 0:
        helpers.karp_update(paradigm.uuid, paradigm.jsonify(),
                            resource=lexconfig.get_paradigmlexicon(lexicon))
    else:
        remove_paradigm(lexicon, paradigm, paradigms, pos)
def remove_word_from_paradigm ( lexicon , paradigm , paradigms , identifier , pos ) : logging . debug ( 'old count %s' , paradigm . count ) for ix , var_inst in enumerate ( paradigm . var_insts ) : if dict ( var_inst ) . get ( 'first-attest' , '' ) == identifier : paradigm . var_insts . pop ( ix ) break try : paradigm . members . remove ( identifier ) except Exception as e : logging . exception ( e ) logging . warning ( 'identifier %s cannot be removed, since it was not present in %s' , identifier , paradigm . p_id ) paradigm . empty_classes ( ) q = 'extended||and|paradigm|equals|%s||not|%s|equals|%s' % ( paradigm . p_id , lexconfig . get_identifierfield ( lexicon ) , identifier ) for iclass in lexconfig . get_inflectionalclassnames ( lexicon ) : res = helpers . karp_query ( 'statlist' , { 'q' : q , 'size' : 1000 , 'buckets' : '%s.bucket' % iclass } , resource = lexconfig . get_lexiconname ( lexicon ) , mode = lexconfig . get_lexiconmode ( lexicon ) ) paradigm . add_class ( iclass , [ cl [ 0 ] for cl in res . get ( 'stattable' , [ ] ) ] ) paradigm . count -= 1 logging . debug ( 'new count %s' , paradigm . count ) if paradigm . count > 0 : helpers . karp_update ( paradigm . uuid , paradigm . jsonify ( ) , resource = lexconfig . get_paradigmlexicon ( lexicon ) ) else : remove_paradigm ( lexicon , paradigm , paradigms , pos )
Remove a word from a paradigm  (update language model, save to karp)
Remove a word from a paradigm ( update language model save to karp )
"""
    Remove a word from a paradigm  (update language model, save to karp)
    Args:
        lexicon (str): the lexicon name
        paradigm (obj): the paradigm (Paradigm.py)
        paradigms (dict): a dictionary with all paradigms
            '{"lexname": {"nn": [], "vb": []}'
        identifier (str): the tables identifier
        pos (str): the tables word class
    """ # remove variable_instances # remove from members # remove the words classes from the paradigm if they are not used by other # words, by first removing all and then readding the all classes used by # other words # get all classes from all other words, add to paradigm: # decrease paradigm member count # TODO remove from alphabet
lexicon
the lexicon name
the lexicon name
paradigm
the paradigm (Paradigm.py)
the paradigm ( Paradigm . py )
paradigms
a dictionary with all paradigms
'{"lexname": {"nn": [], "vb": []}'
a dictionary with all paradigms ' { " lexname " : { " nn " : [] " vb " : [] } '
identifier
the tables identifier
the tables identifier
pos
the tables word class
the tables word class