def generate_sentences(text='<STR_LIT>', train_path=None, case_sensitive=True, ext=['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'],<EOL>normalize_ordinals=<NUM_LIT:1>, normalize_newlines=<NUM_LIT:1>, normalize_sentence_boundaries=<NUM_LIT:1>,<EOL>epochs=<NUM_LIT:20>, classifier=nlup.BinaryAveragedPerceptron,<EOL>re_eol=r'<STR_LIT>', **kwargs):
ext = [ext] if isinstance(ext, basestring) else ext<EOL>if isinstance(text, basestring) and len(text) <= <NUM_LIT>:<EOL><INDENT>if os.path.isfile(text) and os.path.splitext(text)[-<NUM_LIT:1>].lower() in ext:<EOL><INDENT>text = open(text)<EOL><DEDENT>elif os.path.isdir(text):<EOL><INDENT>return chain.from_iterable((<EOL>generate_sentences(text=stat['<STR_LIT:path>'], train_path=train_path, ext=ext,<EOL>normalize_ordinals=normalize_ordinals, normalize_newlines=normalize_ordinals,<EOL>normalize_sentence_boundaries=normalize_sentence_boundaries,<EOL>epochs=epochs, classifier=classifier, re_eol=re_eol, **kwargs)<EOL>for stat in find_files(text, ext=ext)))<EOL><DEDENT><DEDENT>if isinstance(text, basestring):<EOL><INDENT>texts = Split(text=text, re_delim=re_eol)<EOL><DEDENT>else:<EOL><INDENT>texts = chain.from_iterable(Split(text=doc, re_delm=re_eol) for doc in text)<EOL><DEDENT>if normalize_newlines:<EOL><INDENT>re_eol = re.compile(r'<STR_LIT>')<EOL>texts = (re_eol.sub(r'<STR_LIT:\n>', doc) for doc in texts)<EOL><DEDENT>if normalize_ordinals:<EOL><INDENT>re_ord = re.compile(r'<STR_LIT>')<EOL>texts = (re_ord.sub(r'<STR_LIT>', doc) for doc in texts)<EOL><DEDENT>if normalize_sentence_boundaries:<EOL><INDENT>re_eos = re.compile(r'<STR_LIT>')<EOL>texts = (re_eos.sub(r'<STR_LIT>', doc) for doc in texts)<EOL><DEDENT>if train_path:<EOL><INDENT>generate_sentences.detector = Detector(slurp(train_path), epochs=epochs, nocase=not case_sensitive)<EOL><DEDENT>elif not isinstance(getattr(generate_sentences, '<STR_LIT>', None), Detector):<EOL><INDENT>generate_sentences.detector = Detector.load(<EOL>os.path.join(DATA_PATH, '<STR_LIT>'))<EOL><DEDENT>return iter(chain.from_iterable((s.lstrip() for s in generate_sentences.detector.segments(text)) for text in texts))<EOL>
Generate sentences from a sequence of characters (text)

    Wrapped text (newlines at column 80, for instance) will break this, breaking up sentences.
    Wrapper and preprocessor for Kyle Gorman's "DetectorMorse" module

    Arguments:
      preprocess (bool): whether to assume common sentence delimitters in markdown and asciidoc formatting
                         using r'[.?!][ \t]*\n\n|[.?!][ \t]*\r\n\r\n|[.?!][ \t]*\r\r|[.?!][ ][ ][A-Z]'
      case_sensitive (int): whether to consider case to make decisions about sentence boundaries
      epochs (int): number of epochs (iterations for classifier training)