/** * Log a message to the channels specified in this RedwoodChannels object. * @param obj The object to log */ public void log(Object... obj) { Object[] newArgs = new Object[channelNames.length+obj.length]; System.arraycopy(channelNames,0,newArgs,0,channelNames.length); System.arraycopy(obj,0,newArgs,channelNames.length,obj.length); Redwood.log(newArgs); }
private synchronized void logB(Object message){ char[] str = message.toString().toCharArray(); for (char c : str) { if(c == '\n'){ String msg = buffer.toString(); if (tag != null) { Redwood.log(tag, msg); } else { Redwood.log(msg); } buffer = new StringBuilder(); } else { buffer.append(String.valueOf(c)); } } }
/** * The Redwood equivalent to printf(). * @param format The format string, as per java's Formatter.format() object. * @param args The arguments to format. */ public static void logf(String format, Object... args){ log((Supplier<String>) () -> new Formatter().format(format, args).toString()); }
/** * The Redwood equivalent to printf(), with a logging level. * For including more channels, use {@link edu.stanford.nlp.util.logging.Redwood.RedwoodChannels}. * @param level The logging level to log at. * @param format The format string, as per java's Formatter.format() object. * @param args The arguments to format. */ public static void logf(Flag level, String format, Object... args){ log(level, (Supplier<String>) () -> new Formatter().format(format, args).toString()); }
void setIndexWriter() {try{ if(indexWriter == null){ dir = FSDirectory.open(indexDir.toPath()); Redwood.log(Redwood.DBG, "Updating lucene index at " + indexDir); indexWriter = new IndexWriter(dir, iwc); }}catch(IOException e){ throw new RuntimeException(e); } }
static synchronized void setIndexWriter() { try{ if(!openIndexWriter.get()){ dir = FSDirectory.open(indexDir.toPath()); Redwood.log(Redwood.DBG, "Updating lucene index at " + indexDir); indexWriter = new IndexWriter(dir, iwc); openIndexWriter.set(true); } }catch(IOException e){ throw new RuntimeException(e); } }
public FileHandler(String filename) { try { printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8"))); } catch (IOException e) { Redwood.log(Flag.ERROR, e); } }
public static<E> List<List<E>> getThreadBatches(List<E> keyset, int numThreads){ int num; if (numThreads == 1) num = keyset.size(); else num = keyset.size() / (numThreads - 1); Redwood.log(ConstantsAndVariables.extremedebug, "keyset size is " + keyset.size()); List<List<E>> threadedSentIds = new ArrayList<>(); for (int i = 0; i < numThreads; i++) { List<E> keys = keyset.subList(i * num, Math.min(keyset.size(), (i + 1) * num)); threadedSentIds.add(keys); Redwood.log(ConstantsAndVariables.extremedebug, "assigning from " + i * num + " till " + Math.min(keyset.size(), (i + 1) * num)); } return threadedSentIds; }
private void trainPolicy(List<List<Pair<CandidateAction, CandidateAction>>> examples) { List<Pair<CandidateAction, CandidateAction>> flattenedExamples = new ArrayList<>(); examples.stream().forEach(flattenedExamples::addAll); for (int epoch = 0; epoch < NUM_EPOCHS; epoch++) { Collections.shuffle(flattenedExamples, random); flattenedExamples.forEach(classifier::learn); } double totalCost = flattenedExamples.stream() .mapToDouble(e -> classifier.bestAction(e).cost).sum(); Redwood.log("scoref.train", String.format("Training cost: %.4f", 100 * totalCost / flattenedExamples.size())); }
public static void printFinalConllScore(String summary) { double finalScore = getFinalConllScore(summary); Redwood.log( "Final conll score ((muc+bcub+ceafe)/3) = " + (new DecimalFormat("#.##")).format(finalScore)); }
public static Map<String, Set<CandidatePhrase>> readSeedWords(Properties props) { String seedWordsFile = props.getProperty("seedWordsFiles"); if(seedWordsFile != null) return readSeedWords(seedWordsFile); else{ Redwood.log(Redwood.FORCE,"NO SEED WORDS FILES PROVIDED!!"); return Collections.emptyMap(); } }
public void printWeightVector(PrintWriter writer) { SortedMap<String, Double> sortedWeights = getWeightVector(); for (Map.Entry<String, Double> e : sortedWeights.entrySet()) { if (writer == null) { Redwood.log("scoref.train", e.getKey() + " => " + e.getValue()); } else { writer.println(e.getKey() + " => " + e.getValue()); } } }
public static void warn(Object...objs){ Redwood.log(revConcat(objs, WARN)); } public static void warning(Object...objs){ Redwood.log(revConcat(objs, WARN)); }
@Override public void printReasonForChoosing(Counter<CandidatePhrase> phrases){ Redwood.log(Redwood.DBG, "Features of selected phrases"); for(Entry<CandidatePhrase, Double> pEn: phrases.entrySet()) Redwood.log(Redwood.DBG, pEn.getKey().getPhrase() + "\t" + pEn.getValue() + "\t" + phraseScoresRaw.getCounter(pEn.getKey())); }
public Map<E, Set<String>> getFileSentIdsFromPats(Collection<E> pats) { Map<E, Set<String>> sents = new HashMap<>(); for(E pat: pats){ Set<String> ids = getFileSentIds(pat.getRelevantWords()); Redwood.log(ConstantsAndVariables.extremedebug, "For pattern with index " + pat + " extracted the following sentences from the index " + ids); sents.put(pat, ids); } return sents; }
@Override public boolean save(String dir) { try { IOUtils.ensureDir(new File(dir)); String f = dir+"/allpatterns.ser"; IOUtils.writeObjectToFile(this.patternsForEachToken, f); Redwood.log(Redwood.DBG, "Saving the patterns to " + f); } catch (IOException e) { throw new RuntimeException(e); } return true; }
public static void loadDomainNGrams() { assert(domainNGramsFile != null); if (domainNGramRawFreq == null || domainNGramRawFreq.size() == 0) { for (String line : IOUtils.readLines(domainNGramsFile)) { String[] t = line.split("\t"); domainNGramRawFreq.setCount(t[0], Double.valueOf(t[1])); } Redwood.log(ConstantsAndVariables.minimaldebug, "Data", "loading freq from domain ngram file " + domainNGramsFile); } } }
public static void setRatioGoogleNgramFreqWithDataFreq() { ratioGoogleNgramFreqWithDataFreq = GoogleNGramsSQLBacked.getTotalCount(1)/ Data.rawFreq.totalCount(); Redwood.log(ConstantsAndVariables.minimaldebug, "Data", "ratioGoogleNgramFreqWithDataFreq is " + ratioGoogleNgramFreqWithDataFreq); //return ratioGoogleNgramFreqWithDataFreq; }
@Override public void process(int id, Document document) { writerGold.print(CorefPrinter.printConllOutput(document, true)); writerBeforeCoref.print(CorefPrinter.printConllOutput(document, false)); long time = System.currentTimeMillis(); corefAlgorithm.runCoref(document); if (verbose) { Redwood.log(getName(), "Coref took " + (System.currentTimeMillis() - time) / 1000.0 + "s"); } CorefUtils.removeSingletonClusters(document); writerAfterCoref.print(CorefPrinter.printConllOutput(document, false, true)); }