utils.py
def generate_scu(sentence, max_scus=5):
    """ Given a scu sentence retrieve SCUs"""

    srl = predictor.predict(sentence=sentence['scuSentence'])
    # ipdb.set_trace()
    scus = srl['verbs']
    scu_list = []
    tokens = srl['words']
    for scu in scus:
        tags = scu['tags']
        words = []
        if not ("B-ARG1" in tags or "B-ARG2" in tags or "B-ARG0" in tags):
            continue
        scu_start_offset = None
        for ind, tag in enumerate(tags):
            # if "ARG0" in tag or "ARG1" in tag or "V" in tag:
            if "O" not in tag:
                if scu_start_offset is None:
                    if ind == 0:
                        scu_start_offset = sentence['scuSentCharIdx'] + ind
                    else:
                        scu_start_offset = sentence['scuSentCharIdx'] + len(" ".join(tokens[:ind]))
                else:
                    scu_end_offset = sentence['scuSentCharIdx'] + len(" ".join(tokens[:ind + 1]))
                words.append(tokens[ind])

        if len(words) <= 4:
            continue
        tmp = copy.deepcopy(sentence)
        tmp['scuText'] = " ".join(words)
        tmp['scuOffsets'] = (scu_start_offset, scu_end_offset)
        scu_list.append(tmp)
    # select the best SCU
    # sort SCUs based on their length and select middle one
    scu_list = sorted(scu_list, key=lambda x: len(x['scuText'].split()), reverse=True)
    # print(f"Best SCU:::{scu_list[int(len(scu_list)/2)]}")
    # return scu_list[int(len(scu_list)/2)]
    return scu_list[:max_scus]
 Given a scu sentence retrieve SCUs
Given a scu sentence retrieve SCUs
Given a scu sentence retrieve SCUs
def generate_scu(sentence, max_scus=5):
    srl = predictor.predict(sentence=sentence['scuSentence'])
    scus = srl['verbs']
    scu_list = []
    tokens = srl['words']
    for scu in scus:
        tags = scu['tags']
        words = []
        if not ("B-ARG1" in tags or "B-ARG2" in tags or "B-ARG0" in tags):
            continue
        scu_start_offset = None
        for ind, tag in enumerate(tags):
            if "O" not in tag:
                if scu_start_offset is None:
                    if ind == 0:
                        scu_start_offset = sentence['scuSentCharIdx'] + ind
                    else:
                        scu_start_offset = sentence['scuSentCharIdx'] + len(" ".join(tokens[:ind]))
                else:
                    scu_end_offset = sentence['scuSentCharIdx'] + len(" ".join(tokens[:ind + 1]))
                words.append(tokens[ind])
        if len(words) <= 4:
            continue
        tmp = copy.deepcopy(sentence)
        tmp['scuText'] = " ".join(words)
        tmp['scuOffsets'] = (scu_start_offset, scu_end_offset)
        scu_list.append(tmp)
    scu_list = sorted(scu_list, key=lambda x: len(x['scuText'].split()), reverse=True)
    return scu_list[:max_scus]
def generate_scu ( sentence , max_scus = 5 ) : srl = predictor . predict ( sentence = sentence [ 'scuSentence' ] ) scus = srl [ 'verbs' ] scu_list = [ ] tokens = srl [ 'words' ] for scu in scus : tags = scu [ 'tags' ] words = [ ] if not ( "B-ARG1" in tags or "B-ARG2" in tags or "B-ARG0" in tags ) : continue scu_start_offset = None for ind , tag in enumerate ( tags ) : if "O" not in tag : if scu_start_offset is None : if ind == 0 : scu_start_offset = sentence [ 'scuSentCharIdx' ] + ind else : scu_start_offset = sentence [ 'scuSentCharIdx' ] + len ( " " . join ( tokens [ : ind ] ) ) else : scu_end_offset = sentence [ 'scuSentCharIdx' ] + len ( " " . join ( tokens [ : ind + 1 ] ) ) words . append ( tokens [ ind ] ) if len ( words ) <= 4 : continue tmp = copy . deepcopy ( sentence ) tmp [ 'scuText' ] = " " . join ( words ) tmp [ 'scuOffsets' ] = ( scu_start_offset , scu_end_offset ) scu_list . append ( tmp ) scu_list = sorted ( scu_list , key = lambda x : len ( x [ 'scuText' ] . split ( ) ) , reverse = True ) return scu_list [ : max_scus ]
Given a scu sentence retrieve SCUs
Given a scu sentence retrieve SCUs
""" Given a scu sentence retrieve SCUs""" # ipdb.set_trace() # if "ARG0" in tag or "ARG1" in tag or "V" in tag: # select the best SCU # sort SCUs based on their length and select middle one # print(f"Best SCU:::{scu_list[int(len(scu_list)/2)]}") # return scu_list[int(len(scu_list)/2)]
sentence
max_scus