def annotate_token(self, token): if token in self.parser.token2atom: suggested_type = self.parser.token2atom[token].atom.type()[0] else: suggested_type = 'X' atom_type = None while atom_type is None: self.print_status() options = '/'.join([colored_type(atype) for atype in ATOM_TYPES]) options += '/u' prompt_msg = '{} ({}) [{}] ? '.format(colored(str(token), 'white'), options, colored_type(suggested_type)) atom_type = input(prompt_msg).upper() if atom_type == '': atom_type = suggested_type elif atom_type == 'U': self.atoms = self.atoms[:-1] return 'u' elif atom_type not in ATOM_TYPES: print(colored('Invalid type. Please try again.', 'red')) atom_type = None atom = build_atom(str(token), atom_type) if atom_type != 'X': self.token2atom[token] = atom return atom
def _parse_post(self, post): author = build_atom(post['author'], 'C', 'reddit.user') for wedge in self._parse_title(post['title'], author): yield wedge