def segment(self, source, language=None):
if language and not language in self.supported_languages:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(language))<EOL><DEDENT>chunks = ChunkList()<EOL>seek = <NUM_LIT:0><EOL>source_str = source.encode('<STR_LIT:utf-8>') if six.PY2 else source<EOL>results = self.tagger.parse(source_str).split('<STR_LIT:\n>')[:-<NUM_LIT:2>]<EOL>for row in results:<EOL><INDENT>if six.PY2:<EOL><INDENT>row = row.decode('<STR_LIT:utf-8>')<EOL><DEDENT>token = row.split('<STR_LIT:\t>')<EOL>word = token[<NUM_LIT:0>]<EOL>labels = token[<NUM_LIT:3>].split('<STR_LIT:->')<EOL>pos = labels[<NUM_LIT:0>]<EOL>label = labels[<NUM_LIT:1>] if len(labels) > <NUM_LIT:1> else None<EOL>if source[seek: seek + len(word)] != word:<EOL><INDENT>assert source[seek] == '<STR_LIT:U+0020>'<EOL>assert source[seek + <NUM_LIT:1>: seek + len(word) + <NUM_LIT:1>] == word<EOL>chunks.append(Chunk.space())<EOL>seek += <NUM_LIT:1><EOL><DEDENT>dependency = None<EOL>if pos in _DEPENDENT_POS_FORWARD:<EOL><INDENT>dependency = True<EOL><DEDENT>elif pos in _DEPENDENT_POS_BACKWARD:<EOL><INDENT>dependency = False<EOL><DEDENT>elif label in _DEPENDENT_LABEL_FORWARD:<EOL><INDENT>dependency = True<EOL><DEDENT>elif label in _DEPENDENT_LABEL_BACKWARD:<EOL><INDENT>dependency = False<EOL><DEDENT>chunk = Chunk(word, pos=pos, label=label, dependency=dependency)<EOL>if chunk.is_punct():<EOL><INDENT>chunk.dependency = chunk.is_open_punct()<EOL><DEDENT>chunks.append(chunk)<EOL>seek += len(word)<EOL><DEDENT>chunks.resolve_dependencies()<EOL>return chunks<EOL>
Returns a chunk list from the given sentence.

        Args:
          source (str): Source string to segment.
          language (:obj:`str`, optional): A language code.

        Returns:
          A chunk list. (:obj:`budou.chunk.ChunkList`)

        Raises:
          ValueError: If :obj:`language` is given and it is not included in
                      :obj:`supported_languages`.