def _process_pred_annotations( self, pack: DataPack, labels: List[str], word_begin: int, word_end: int, current_pred_arg: List[Stack], verbal_pred_args: List[List[Tuple[PredicateArgument, str]]], ) -> None: """ Various cases will be handled regarding nested spans including: case 1: (xxx(xxx*)*) case 2: (xxx(xxx*) * *) case 3: (xxx(xxx* * *) * *) case 4: (xxx* * (xxx * *) * *) Where the `xxx` represents an argument type. A stack will be maintained to parse nested spans. """ # TODO: currently all nested spans will be parsed but only outer most # span will be stored into datapack. for label_index, label in enumerate(labels): label = label.strip() arg_type: str = "" i: int = 0 while i < len(label): c: str = label[i] if c == '*': i += 1 elif c == '(': # New argument span. j: int = i + 1 while j < len(label): arg_type += label[j] if j == len(label) - 1 or label[j + 1] in ['(', ')']: break j += 1 i = j + 1 arg_type = arg_type.strip("* ") stack: Stack = current_pred_arg[label_index] stack.append((word_begin, arg_type)) arg_type = "" elif c == ')': # End of current argument span. stack = current_pred_arg[label_index] assert len(stack) > 0, \ "invalid parsing state: mismatch argument span" arg_begin, arg_type = stack.pop() if not stack: # The outer most span will be stored into data pack if arg_type != "V": pred_arg = PredicateArgument( pack, arg_begin, word_end) verbal_pred_args[label_index].append( (pred_arg, arg_type)) i += 1