Пример #1
0
def correctStandoffsOffset(esdcs, new_entire_text, offset):
    modified_esdcs = ExtendedSdcGroup.copy(esdcs)
    update_rep_esdcs = []
    def callback(esdc):
        esdc.entireText = new_entire_text
        update_rep_esdcs.append(esdc)
        for fieldName in esdc.fieldNames:
            if esdc.childIsListOfWords(fieldName):
                new_standoffs = [correctStandoffOffset(s, new_entire_text, offset)
                                 for s in esdc[fieldName]]
                esdc.fields[fieldName] = new_standoffs
                    

    breadthFirstTraverse(modified_esdcs, callback)
    for e in reversed(update_rep_esdcs):
        e.updateRep()
    return ExtendedSdcGroup(modified_esdcs)
Пример #2
0
def correctStandoffsImmutable(sentenceStandoff, esdcs):
    """Corrects the standoffs in the esdcs
    to be relative to a larger standoff object.  Returns the new ESDC
    """
    
    modified_esdcs = ExtendedSdcGroup.copy(esdcs)
    def callback(esdc):
        for fieldName in esdc.fieldNames:
            if esdc.childIsListOfWords(fieldName):
                new_standoffs = [correctStandoffImmutable(sentenceStandoff, s)
                                 for s in esdc[fieldName]]
                esdc.fields[fieldName] = new_standoffs
                    
        esdc.entireText = sentenceStandoff.entireText
    breadthFirstTraverse(modified_esdcs, callback)
    for e in modified_esdcs:
        e.updateRep()
    return ExtendedSdcGroup(modified_esdcs)