Write participle phrase file
774071
def _mangle_sentences_from_file(input_file):
    """"""
    try:
        with open(input_file, 'r') as f:
            # final sentence may not be a complete sentence, save and prepend to next chunk
            leftovers = ''
            sentence_no = 0
            for chunk in read_in_chunks(f): # lazy way of reading our file in case it's large
                # prepend leftovers to chunk
                chunk = chunk.decode('utf8')
                chunk = leftovers + chunk
                chunk = chunk.replace(';', '.') # replace semi colons with periods 
                doc = nlp(chunk)

                # last sentence may not be sentence, move to next chunk
                sents = [sent.string.strip() for sent in doc.sents]
                if len(sents) > 1:
                    leftovers = sents[-1] + chunk.rpartition(sents[-1])[-1]
                    sents = sents[:-1]

                for sent in sents:
                    sent = sent.replace('\n', ' ')
                    sent = sent.replace('\r', ' ')
                    sent = re.sub( '\s+', ' ', sent ).strip()
                    if len(sent) < 5:
                        continue # skip tiny sentences
                    # add original sentence to database
                    cursor.execute('''insert into orignal_sentences (sentence,
                    flesch_reading_ease, flesch_kincaid_grade_level) values (?,
                    ?, ?)''', (sent, textstat.flesch_reading_ease(sent),
                        textstat.flesch_kincaid_grade(sent)))
                    og_sent_id = cursor.lastrowid
                    for mangled_sentence in mangle_agreement(sent):
                        # add mangled sentence to database
                        cursor.execute('''insert into mangled_sentences
                        (original_sentence_id, sentence) values (?, ?)''',
                        (og_sent_id, mangled_sentence))
                conn.commit() # commit all sentences in this chunk

    except Exception as e:
        print('error on {}'.format(input_file))
        print(e)
462302
def write_preferences_file(self):
        
        user_data_dir = find_pmag_dir.find_user_data_dir("thellier_gui")
        if not os.path.exists(user_data_dir):
            find_pmag_dir.make_user_data_dir(user_data_dir)
        pref_file = os.path.join(user_data_dir, "thellier_gui_preferences.json")
        with open(pref_file, "w+") as pfile:
            print('-I- writing preferences to {}'.format(pref_file))
            json.dump(self.preferences, pfile)
514181
def _write(self, session, openFile, replaceParamFile):
        
        # Write lines
        for line in self.lines:
            openFile.write(line.contents)
602108
def write_to_file(self, f):
        """"""
        for section, values in self._values.iteritems():
            try:
                section_name, subsection_name = section
            except ValueError:
                (section_name, ) = section
                subsection_name = None
            if subsection_name is None:
                f.write("[%s]\n" % section_name)
            else:
                f.write("[%s \"%s\"]\n" % (section_name, subsection_name))
            for key, value in values.iteritems():
                f.write("%s = %s\n" % (key, _escape_value(value)))
1359881
def fmt(self):
      """"""
      lines = [ ]
      def write (line):
        lines.append(line)
      if self._defaults:
          write("[%s]\n" % DEFAULTSECT)
          for (key, value) in self._defaults.items():
              write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
          write("\n")
      for section in self._sections:
          write("[%s]\n" % section)
          for (key, value) in self._sections[section].items():
              if key == "__name__":
                  continue
              if (value is not None) or (self._optcre == self.OPTCRE):
                  key = " = ".join((key, str(value).replace('\n', '\n\t')))
              write("%s\n" % (key))
          write("\n")
      return "".join(lines)
588369
def simple_write(filename, group, times, features,
                 properties=None, item='item', mode='a'):
    """"""
    write(filename, group, [item], [times], [features], mode=mode,
          properties=[properties] if properties is not None else None)
461925
def write_listing_to_textfile(textfile, tracklisting):
    """"""
    with codecs.open(textfile, 'wb', 'utf-8') as text:
        text.write(tracklisting)
313951
def write_toc(self, args):
        """"""
        # FIXME: Can this logic be moved into the create_parser function?
        ordered = False
        if args.ordered_list_marker is not None:
            list_marker = args.ordered_list_marker
            ordered = True
        elif args.unordered_list_marker is not None:
            list_marker = args.unordered_list_marker
        else:
            list_marker = md_parser[
                args.parser]['list']['unordered']['default_marker']

        toc_struct = build_multiple_tocs(
            filenames=args.filename,
            ordered=ordered,
            no_links=args.no_links,
            no_indentation=args.no_indentation,
            no_list_coherence=args.no_list_coherence,
            keep_header_levels=int(args.header_levels),
            parser=args.parser,
            list_marker=list_marker)
        if args.in_place:
            write_strings_on_files_between_markers(
                filenames=args.filename,
                strings=toc_struct,
                marker=args.toc_marker)
        else:
            for toc in toc_struct:
                print(toc, end='')
131801
def input_phrases(phrases, options={})
      strings = phrases.map do |string_key, value|
        if value.is_a? Array
          output = []
          value.each_with_index do |string, index|
            output << {:string_key => string_key.to_s, :string => string, :context => index}
          end
          output
        else
          {:string_key => string_key.to_s, :string => value}
        end
      end
      input_strings(strings.flatten(1), options)
    end
167976
def _write_index_file(data_dir):
    
    cached_words = [
        w
        for w in _get_words(data_dir)
        if data_dir.joinpath("translations/{}.html".format(w)).is_file()
    ]

    content_str = _create_index_content(cached_words)
    html_string = HTML_TEMPLATE.replace("{% word %}", "Index")
    html_string = html_string.replace("{% content %}", content_str)

    filename = data_dir.joinpath("index.html")
    save_file(filename, html_string, mk_parents=True)
119762
public static void main(String[] argvs) {
        List<String[]> sentences = new ArrayList<>();
        List<PennTreebankPOS[]> labels = new ArrayList<>();
        
        load("D:\\sourceforge\\corpora\\PennTreebank\\PennTreebank2\\TAGGED\\POS\\WSJ", sentences, labels);        
        load("D:\\sourceforge\\corpora\\PennTreebank\\PennTreebank2\\TAGGED\\POS\\BROWN", sentences, labels);
        
        String[][] x = sentences.toArray(new String[sentences.size()][]);
        PennTreebankPOS[][] y = labels.toArray(new PennTreebankPOS[labels.size()][]);
        
        HMMPOSTagger tagger = HMMPOSTagger.learn(x, y);

        try {
            FileOutputStream fos = new FileOutputStream("hmmpostagger.model");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(tagger);
            oos.flush();
            oos.close();
        } catch (Exception ex) {
            logger.error("Failed to save HMM POS model", ex);
        }
    }
652877
def save(f, arr, vocab):
    
    f.write(('%d %d' % (arr.shape[0], arr.shape[1])).encode('utf-8'))
    for word, idx in vocab:
        _write_line(f, arr[idx], word)
1072646
def write_spelling(token_folder, spelling_file):
    
    token_pattern = r'[a-z]{3,}'
    tokens = []
    for base, dirlist, fnlist in os.walk(token_folder):
        for fn in fnlist:
            fp = os.path.join(base, fn)
            with open(fp) as f:
                toks = re.findall(token_pattern, f.read())
                tokens.extend(toks)

    token_ranked, _ = zip(*Counter(tokens).most_common())
    with open(spelling_file, 'w') as f:
        f.write('\n'.join(token_ranked))
1110672
def text(files):
    ''''''
    sentences = convert_timestamps(files)
    out = []
    for s in sentences:
        out.append(' '.join([w[0] for w in s['words']]))
    return '\n'.join(out)
812472
private static File writePartToFile(File splitDir, List<String> data) {
        BufferedWriter writer = null;
        File splitFile;
        try {
            splitFile = File.createTempFile("split-", ".part", splitDir);
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(splitFile.getAbsoluteFile(), false),
                    DataUtilDefaults.charSet));
            for(String item : data) {
                writer.write(item + DataUtilDefaults.lineTerminator);
            }
            writer.flush();
            writer.close();
            writer = null;
        } catch (UnsupportedEncodingException e) {
            throw new DataUtilException(e);
        } catch (FileNotFoundException e) {
            throw new DataUtilException(e);
        } catch (IOException e) {
            throw new DataUtilException(e);
        } finally {
            if(writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    // Intentionally we're doing nothing here
                }
            }
        }
        return splitFile;
    }
783490
def pos_tokenize(self: object, fileids: str):
        
        for para in self.paras(fileids):
            yield [
                self.pos_tagger(word_tokenize(sent))
                for sent in sent_tokenize(para)
            ]
1108589
def write(self, output_file):
        
        for message_level, message_text in self:
            output_file.write('%s=%s\r\n' % (message_level, message_text))
        output_file.write('\r\n')