Print top W words in each topic to file.
326748
def topic_content(self, W, output_file="topic_description.csv"):

        

        topic_top_probs = []
        topic_top_words = []

        tt = self.tt_avg(False)

        for t in range(self.K):            
            top_word_indices = list(tt[:, t].argsort()[-W:][::-1])
            topic_top_probs.append(np.round(np.sort(tt[:, t])[-W:][::-1], 3))
            topic_top_words.append([list(self.token_key.keys())
                                   [list(self.token_key.values()).index(i)]
                                   for i in top_word_indices])            

        with codecs.open(output_file, "w", "utf-8") as f:
            for t in range(self.K):                
                words = ','.join(topic_top_words[t])
                probs = ','.join([str(i) for i in topic_top_probs[t]])
                f.write("topic" + str(t) + ',')
                f.write("%s\n" % words)
                f.write(" " + ',')
                f.write("%s\n" % probs)
670864
def show(self):
		"""'
		"""


		if self.classname()=="Corpus":
			for text in self.children:
				text.om("## showing Text " + text.name)
				text.show()
		else:
			words=self.words()
			for i in range(len(words)):
				word=words[i]
				word.om(str(i+1).zfill(6)+"\t"+str(word.output_minform()),conscious=False)
891626
def get_vocab(args):
    """"""
    counter = nlp.data.Counter()
    start = time.time()
    for filename in args.files:
        print('Starting processing of {} after {:.1f} seconds.'.format(
            filename,
            time.time() - start))
        with open(filename, 'r') as f:
            tokens = itertools.chain.from_iterable((l.split() for l in f))
            counter.update(tokens)

    if args.max_word_length:
        counter = {
            w: c
            for w, c in counter.items() if len(w) < args.max_word_length
        }

    total_time = time.time() - start
    print('Finished after {:.1f} seconds.'.format(total_time))
    num_words = sum(counter.values())
    print('Got {} words. Processed {:.1f} per second.'.format(
        num_words, num_words / total_time))

    start = time.time()
    print('Starting creation of vocabulary.')
    vocab = nlp.Vocab(counter, max_size=args.max_size, min_freq=args.min_freq,
                      unknown_token=None, padding_token=None, bos_token=None,
                      eos_token=None)
    with open(args.vocab_output, 'w') as f:
        f.write(vocab.to_json())
    print('Finished creation of vocabulary after {:.1f} seconds.'.format(
        time.time() - start))

    print('Writing word counts.')
    start = time.time()
    idx_to_counts = [counter[t] for t in vocab.idx_to_token]
    with open(args.counts_output, 'w') as f:
        json.dump(idx_to_counts, f)
    print('Finished writing word counts after {:.1f} seconds..'.format(
        time.time() - start))
378136
def load_common(self, wlist):
        """"""
        self.com_dict = os.path.join(self.base_dir, 'dicts', 'EN_vocab.txt')
        with open(self.com_dict) as words_file:
            data = words_file.read()
        self.common_words = set(data.splitlines())
        if wlist:
            new_words = ''
            for wl in wlist:
                with open(wl) as f:
                    new_words += f.read()
            if new_words:
                new_dict = set(data.splitlines())
                self.common_words.update(new_dict)
703954
def phrases_map(data):
  """"""
  (entry, text_fn) = data
  text = text_fn()
  filename = entry.filename

  logging.debug("Got %s", filename)
  for s in split_into_sentences(text):
    words = split_into_words(s.lower())
    if len(words) < PHRASE_LENGTH:
      yield (":".join(words), filename)
      continue
    for i in range(0, len(words) - PHRASE_LENGTH):
      yield (":".join(words[i:i+PHRASE_LENGTH]), filename)
167384
def topfnfile(self, fileobj):
		
		for entry in self:
			print >>fileobj, entry.path
		fileobj.close()
1176214
def Print(self):
        """"""
        for val, prob in sorted(self.d.iteritems()):
            print(val, prob)
1132784
def cat_top_keywords(self, session, cat, up=True,  offset=0, offsets=[]):
        ''''''
        print 'CAT:%s, level:%s'%(str(cat), str(cat.level))
        print 'OFFSET: %d'%offset
        response = []
        if not offsets or offset==0: 
            url = 'http://top.taobao.com/level3.php?cat=%s&level3=%s&show=focus&up=%s&offset=%d'%(cat.parent.cid, '' if cat.level==2 else str(cat.cid), 'true' if up else '', offset)
            print url
            rs = self.fetch(url)
            if not rs: return response
            soup = BeautifulSoup(rs.content, convertEntities=BeautifulSoup.HTML_ENTITIES, markupMassage=hexentityMassage)
            response = self.parse_cat_top_keywords(soup, offset)
        if offset==0:
            offsets = self.get_cat_top_keywords_pages(soup, offset)
            print 'OFFSETS: %s'%offsets
        if offsets:
            rs = []
            threadPool = ThreadPool(len(offsets) if len(offsets)<=5 else 5)
            for idx, page_offset in enumerate(offsets):
                page_url = 'http://top.taobao.com/level3.php?cat=%s&level3=%s&show=focus&up=%s&offset=%d'%(cat.parent.cid, '' if cat.level==2 else str(cat.cid), 'true' if up else '', page_offset)
                next_page = 'True' if idx == (len(offsets)-1) else 'False'
                threadPool.run(self.fetch, callback=None, url=page_url, config=dict(get_next=next_page, offset=page_offset))
            pages = threadPool.killAllWorkers(None)
            #print 'RESPONSES: %s'%pages
            for p in pages:
                if not p: continue
                soup2 = BeautifulSoup(p.content, convertEntities=BeautifulSoup.HTML_ENTITIES, markupMassage=hexentityMassage)
                offset2 = int(p.config['offset'])
                response += self.parse_cat_top_keywords(soup2, offset2)
                print 'GOT: %d'%offset2
                if p.config['get_next'] != 'True': continue
                offsets = self.get_cat_top_keywords_pages(soup2, offset2)
                print offsets
                if not offsets: continue
                response += self.cat_top_keywords(session, cat, up, offset2, offsets)
        #return sorted(response, key=itemgetter('pos')) if response else []
        #print "RETURN:%d"%offset
        for k in response:
            new_keyword = models.Keyword(k['name'].decode('utf-8'))
            new_keyword.categories.append(cat)
            session.add(new_keyword)
            try:
                session.commit()
            except IntegrityError:
                session.rollback()
                new_keyword = session.query(models.Keyword).filter(models.Keyword.name == k['name']).first()
                new_keyword.categories.append(cat)
                session.commit()
                print 'Duplicate %s'%new_keyword
        return response
1008765
def _removeStopwords(text_list):
    

    output_list = []

    for word in text_list:
        if word.lower() not in _stopwords:
            output_list.append(word)

    return output_list
1182731
def cli():
    """"""
    args = docopt.docopt(__doc__, version=__VERSION__)
    secure = args['--secure']
    numberofwords = int(args['<numberofwords>'])

    dictpath = args['--dict']
    if dictpath is not None:
        dictfile = open(dictpath)
    else:
        dictfile = load_stream('words.txt')
    with dictfile:
        wordlist = read_wordlist(dictfile)

    words = generate_words(numberofwords, wordlist, secure=secure)
    print(' '.join(words))
150821
def file_objects(self):
        """"""
        if self.topic.has_file:
            yield self.topic.file
        for reply in self.replies:
            if reply.has_file:
                yield reply.file
1354706
protected void printFeatures(IN wi, Collection<String> features) {
    if (flags.printFeatures == null || writtenNum > flags.printFeaturesUpto) {
      return;
    }
    try {
      if (cliqueWriter == null) {
        cliqueWriter = new PrintWriter(new FileOutputStream("feats" + flags.printFeatures + ".txt"), true);
        writtenNum = 0;
      }
    } catch (Exception ioe) {
      throw new RuntimeException(ioe);
    }
    if (writtenNum >= flags.printFeaturesUpto) {
      return;
    }
    if (wi instanceof CoreLabel) {
      cliqueWriter.print(wi.get(TextAnnotation.class) + ' ' + wi.get(PartOfSpeechAnnotation.class) + ' '
          + wi.get(CoreAnnotations.GoldAnswerAnnotation.class) + '\t');
    } else {
      cliqueWriter.print(wi.get(CoreAnnotations.TextAnnotation.class)
          + wi.get(CoreAnnotations.GoldAnswerAnnotation.class) + '\t');
    }
    boolean first = true;
    for (Object feat : features) {
      if (first) {
        first = false;
      } else {
        cliqueWriter.print(" ");
      }
      cliqueWriter.print(feat);
    }
    cliqueWriter.println();
    writtenNum++;
  }
767665
def idf2txt(txt):
    """"""
    astr = nocomment(txt)
    objs = astr.split(';')
    objs = [obj.split(',') for obj in objs]
    objs = [[line.strip() for line in obj] for obj in objs]
    objs = [[_tofloat(line) for line in obj] for obj in objs]
    objs = [tuple(obj) for obj in objs]
    objs.sort()

    lst = []
    for obj in objs:
        for field in obj[:-1]:
            lst.append('%s,' % (field, ))
        lst.append('%s;\n' % (obj[-1], ))

    return '\n'.join(lst)
554955
def write(self, output_io):
        ''''''
        for name, tax in self.taxonomy.items():
            output_io.write("%s\t%s\n" % (name, '; '.join(tax)))
1170387
def Dump(title=None):
    
    if title:
        print(title)
    for counter in sorted(CounterList):
        CounterList[counter].display()
827411
def write(self, fout_xlsx=None, fout_txt=None, verbose=False):
        """"""
        sortby = self._get_fncsortnt(self.objgrpd.grprobj.gosubdag.prt_attr['flds'])
        kws_sort = {'sortby' if verbose else 'section_sortby': sortby}
        sortobj = Sorter(self.objgrpd.grprobj, **kws_sort)
        # KWS: hdrgo_prt=True section_prt=None top_n=None use_sections=True
        # RET: {sortobj, sections, hdrgo_prt} or {sortobj flat hdrgo_prt}
        desc2nts = sortobj.get_desc2nts_fnc(
            hdrgo_prt=verbose,
            section_prt=True,
            top_n=None,
            use_sections=True)
        # print('FFFF', desc2nts['flds'])
        # Write user GO IDs in sections
        objgowr = WrXlsxSortedGos("init", sortobj, self.objgrpd.ver_list)
        if fout_xlsx is not None:
            kws_xlsx = {'shade_hdrgos':verbose}
            if not verbose:
                kws_xlsx['prt_flds'] = [f for f in desc2nts['flds'] if f not in self.excl_flds]
            objgowr.wr_xlsx_nts(fout_xlsx, desc2nts, **kws_xlsx)
            fout_desc = '{BASE}_desc.txt'.format(BASE=os.path.splitext(fout_xlsx)[0])
            self._wr_ver_n_key(fout_desc, verbose)
        if fout_txt is not None:
            self._wr_txt_nts(fout_txt, desc2nts, objgowr, verbose)
        if fout_xlsx is None and fout_txt is None:
            self._prt_ver_n_key(sys.stdout, verbose)
            prtfmt = self._get_prtfmt(objgowr, verbose)
            summary_dct = objgowr.prt_txt_desc2nts(sys.stdout, desc2nts, prtfmt)
            self._prt_ver_n_key(sys.stdout, verbose)
            if summary_dct:
                print("\n{N} GO IDs in {S} sections".format(
                    N=desc2nts['num_items'], S=desc2nts['num_sections']))
19218
static function printTopReportsList()
    {
        $debug = eZDebug::instance();
        $reportNames = array_keys( $debug->topReportsList );
        foreach ( $reportNames as $reportName )
        {
            echo $debug->topReportsList[$reportName];
        }
    }