def from_text(cls, text): parts = [p for p in re.split(' :(?:SUBJ|OBJ|POBJ): ', text)] if len(parts) < 3: raise ParseEventError( 'expected at least 3 parts, separated by ::, ' 'got {}: {}'.format(len(parts), text)) pred = Predicate.from_text(parts[0]) subj = None if parts[1] != 'NONE': subj = Argument.from_text(parts[1]) obj = None if parts[2] != 'NONE': obj = Argument.from_text(parts[2]) pobj_list = [] if len(parts) > 3: for part in parts[3:]: prep, pobj = part.split(' : ') if prep != '': pobj_list.append((prep, Argument.from_text(pobj))) return cls(pred, subj, obj, pobj_list)
def from_text(cls, text): # TODO: change OBJ to DOBJ to avoid confusion parts = [p for p in re.split(' :(?:SUBJ|OBJ|POBJ): ', text)] assert len(parts) >= 3, \ 'expected at least 3 parts, separated by :(SUBJ|OBJ|POBJ):, ' \ 'found {}'.format(len(parts)) pred = Predicate.from_text(parts[0]) subj = None if parts[1] != 'NONE': subj = Argument.from_text(parts[1]) obj = None if parts[2] != 'NONE': obj = Argument.from_text(parts[2]) pobj_list = [] if len(parts) > 3: for part in parts[3:]: prep, pobj = part.split(' : ') if prep != '': pobj_list.append((prep, Argument.from_text(pobj))) return cls(pred, subj, obj, pobj_list)