use of java.io.BufferedWriter in project druid by druid-io.
the class LongCompressionBenchmarkFileGenerator method main.
public static void main(String[] args) throws IOException, URISyntaxException {
if (args.length >= 1) {
dirPath = args[0];
}
BenchmarkColumnSchema enumeratedSchema = BenchmarkColumnSchema.makeEnumerated("", ValueType.LONG, true, 1, 0d, ImmutableList.<Object>of(0, 1, 2, 3, 4), ImmutableList.of(0.95, 0.001, 0.0189, 0.03, 0.0001));
BenchmarkColumnSchema zipfLowSchema = BenchmarkColumnSchema.makeZipf("", ValueType.LONG, true, 1, 0d, -1, 1000, 1d);
BenchmarkColumnSchema zipfHighSchema = BenchmarkColumnSchema.makeZipf("", ValueType.LONG, true, 1, 0d, -1, 1000, 3d);
BenchmarkColumnSchema sequentialSchema = BenchmarkColumnSchema.makeSequential("", ValueType.LONG, true, 1, 0d, 1470187671, 2000000000);
BenchmarkColumnSchema uniformSchema = BenchmarkColumnSchema.makeDiscreteUniform("", ValueType.LONG, true, 1, 0d, 0, 1000);
Map<String, BenchmarkColumnValueGenerator> generators = new HashMap<>();
generators.put("enumerate", new BenchmarkColumnValueGenerator(enumeratedSchema, 1));
generators.put("zipfLow", new BenchmarkColumnValueGenerator(zipfLowSchema, 1));
generators.put("zipfHigh", new BenchmarkColumnValueGenerator(zipfHighSchema, 1));
generators.put("sequential", new BenchmarkColumnValueGenerator(sequentialSchema, 1));
generators.put("uniform", new BenchmarkColumnValueGenerator(uniformSchema, 1));
File dir = new File(dirPath);
dir.mkdir();
// create data files using BenchmarkColunValueGenerator
for (Map.Entry<String, BenchmarkColumnValueGenerator> entry : generators.entrySet()) {
final File dataFile = new File(dir, entry.getKey());
dataFile.delete();
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dataFile)))) {
for (int i = 0; i < ROW_NUM; i++) {
writer.write((long) entry.getValue().generateRowValue() + "\n");
}
}
}
// create compressed files using all combinations of CompressionStrategy and LongEncoding provided
for (Map.Entry<String, BenchmarkColumnValueGenerator> entry : generators.entrySet()) {
for (CompressedObjectStrategy.CompressionStrategy compression : compressions) {
for (CompressionFactory.LongEncodingStrategy encoding : encodings) {
String name = entry.getKey() + "-" + compression.toString() + "-" + encoding.toString();
System.out.print(name + ": ");
File compFile = new File(dir, name);
compFile.delete();
File dataFile = new File(dir, entry.getKey());
TmpFileIOPeon iopeon = new TmpFileIOPeon(true);
LongSupplierSerializer writer = CompressionFactory.getLongSerializer(iopeon, "long", ByteOrder.nativeOrder(), encoding, compression);
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile)));
try (FileChannel output = FileChannel.open(compFile.toPath(), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) {
writer.open();
String line;
while ((line = br.readLine()) != null) {
writer.add(Long.parseLong(line));
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.closeAndConsolidate(new ByteSink() {
@Override
public OutputStream openStream() throws IOException {
return baos;
}
});
output.write(ByteBuffer.wrap(baos.toByteArray()));
} finally {
iopeon.close();
br.close();
}
System.out.print(compFile.length() / 1024 + "\n");
}
}
}
}
use of java.io.BufferedWriter in project che by eclipse.
the class DynaProviderMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File outFile = new File(outputDirectory, typeName.replace('.', File.separatorChar) + ".java");
String packageName = typeName.substring(0, typeName.lastIndexOf('.'));
String className = typeName.substring(typeName.lastIndexOf('.') + 1, typeName.length());
DynaProviderGenerator generator = new DynaProviderGenerator(packageName, className, classpath);
try {
Files.createDirectories(outFile.toPath().getParent());
} catch (IOException e) {
throw new MojoExecutionException("Can't create packages folders", e);
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFile))) {
writer.write(generator.generate());
} catch (IOException e) {
throw new MojoExecutionException("Can't write file content", e);
}
}
use of java.io.BufferedWriter in project lucida by claritylab.
the class NuggetEvaluationFilter method targetFinished.
/** gather data from instances and write it to global log file
*/
public static void targetFinished() {
try {
BufferedWriter br = new BufferedWriter(new FileWriter(baseFileName, true));
br.newLine();
// String titleLine = ";;";
String titleLine = null;
for (Iterator<NuggetEvaluationFilter> ii = instanceSet.values().iterator(); ii.hasNext(); ) {
NuggetEvaluationFilter nef = ii.next();
if (titleLine == null)
titleLine = ("\"" + nef.lastTarget + "\";\"#chars\";\"#vital\"");
titleLine += ";" + nef.fileNameMarker + ";;;;";
}
// for (NuggetEvaluationFilter instance : instances)
// titleLine += ";" + instance.fileNameMarker + ";;;";
br.write(titleLine);
br.newLine();
for (int i = 0; i < 7; i++) {
String line = targetID + ";" + ((i + 1) * 1000) + ";" + numVital;
for (Iterator<NuggetEvaluationFilter> ii = instanceSet.values().iterator(); ii.hasNext(); ) {
NuggetEvaluationFilter nef = ii.next();
line += ";" + nef.lastOk[i] + ";" + nef.lastVital[i] + ";;;";
}
// for (NuggetEvaluationFilter instance : instances)
// line += ";" + instance.lastOk[i] + ";" + instance.lastVital[i] + ";;";
br.write(line);
br.newLine();
}
br.flush();
br.close();
} catch (Exception e) {
}
}
use of java.io.BufferedWriter in project lucida by claritylab.
the class NuggetEvaluationFilter method apply.
/**
* Extracts NEs of particular types from the answer strings of the
* <code>Result</code> objects and creates a new <code>Result</code> for
* each extracted unique answer.
*
* @param results array of <code>Result</code> objects
* @return extended array of <code>Result</code> objects
*/
public Result[] apply(Result[] results) {
if ((results.length == 0) || (targetId == null))
return results;
this.lastTarget = results[0].getQuery().getOriginalQueryString();
int nonWhiteLength = 0;
int notifyLength = 1000;
BufferedWriter br = null;
try {
br = new BufferedWriter(new FileWriter(this.fileName, true));
br.write("===== Assessing target " + targetId + " (" + results[0].getQuery().getOriginalQueryString() + ") =====");
br.newLine();
} catch (Exception e) {
}
BufferedWriter cbr = null;
try {
cbr = new BufferedWriter(new FileWriter(this.conciseFileName, true));
cbr.write("===== Assessing target " + targetId + " (" + results[0].getQuery().getOriginalQueryString() + ") =====");
cbr.newLine();
} catch (Exception e) {
}
float maxScore = results[0].getScore();
boolean maxCutWritten = false;
HashSet<TRECNugget> covered = new LinkedHashSet<TRECNugget>();
HashMap<TRECNugget, Integer> coveredWhen = new HashMap<TRECNugget, Integer>();
int vital = 0;
int ok = 0;
for (int i = 0; i < 7; i++) {
lastVital[i] = 0;
lastOk[i] = 0;
}
for (int r = 0; r < results.length; r++) {
Result res = results[r];
boolean resWritten = false;
String[] tok = res.getAnswer().split("\\s++");
for (int t = 0; t < tok.length; t++) nonWhiteLength += tok[t].length();
// write all snippets for the first 7000 characters
if ((br != null) && (nonWhiteLength < 7000))
try {
br.write("Result " + r + " (" + res.getScore() + ") is: " + res.getAnswer());
br.newLine();
resWritten = true;
} catch (Exception e) {
}
if (nonWhiteLength > notifyLength) {
int index = ((notifyLength - 1) / 1000);
if (index < 7) {
lastVital[index] = vital;
lastOk[index] = ok;
}
if (br != null)
try {
br.write("===== " + notifyLength + " non-white char cutoff ===== ");
br.newLine();
} catch (Exception e) {
}
notifyLength += 1000;
}
if ((br != null) && !maxCutWritten && ((res.getScore() * 2) < maxScore))
try {
br.write("===== half score cutoff ===== ");
br.newLine();
maxCutWritten = true;
} catch (Exception e) {
}
int n = 0;
while (n < nuggets.size()) {
TRECNugget nug = nuggets.get(n);
String[] uncovered = covers(res.getAnswer(), nug.nugget);
if ((uncovered.length * 2) <= nug.size) {
if (br != null)
try {
if (!resWritten) {
br.write("Result " + r + " (" + res.getScore() + ") is: " + res.getAnswer());
br.newLine();
resWritten = true;
}
br.write(" Nugget covered (" + nug.nuggetID + "," + nug.nuggetType + "): " + nug.nugget);
br.newLine();
if (uncovered.length != 0) {
br.write(" Uncovered:");
for (String u : uncovered) br.write(" " + u);
br.newLine();
}
} catch (Exception e) {
}
res.addCoveredNuggetID(nug.nuggetID);
covered.add(nug);
if ((uncovered.length * 4) <= nug.size)
nuggets.remove(n);
else
n++;
if (!coveredWhen.containsKey(nug)) {
if ("vital".equals(nug.nuggetType))
vital++;
else
ok++;
coveredWhen.put(nug, new Integer(nonWhiteLength));
}
} else {
n++;
}
}
if (resWritten && (br != null))
try {
br.newLine();
} catch (Exception e) {
}
}
if (br != null)
try {
ArrayList<TRECNugget> coveredNugs = new ArrayList<TRECNugget>(covered);
for (TRECNugget nug : coveredNugs) {
int when = -1;
if (coveredWhen.containsKey(nug))
when = coveredWhen.get(nug).intValue();
br.write(" (probably) covered (" + nug.nuggetID + "," + nug.nuggetType + ")" + ((when == -1) ? "" : (" first at " + when)) + ": " + nug.nugget);
br.newLine();
}
for (TRECNugget nug : nuggets) {
br.write(" Not (securely) covered (" + nug.nuggetID + "," + nug.nuggetType + "): " + nug.nugget);
br.newLine();
}
br.newLine();
br.newLine();
br.flush();
br.close();
} catch (Exception e) {
}
if (cbr != null)
try {
ArrayList<TRECNugget> coveredNugs = new ArrayList<TRECNugget>(covered);
for (TRECNugget nug : coveredNugs) {
int when = -1;
if (coveredWhen.containsKey(nug))
when = coveredWhen.get(nug).intValue();
cbr.write(" (probably) covered (" + nug.nuggetID + "," + nug.nuggetType + ")" + ((when == -1) ? "" : (" first at " + when)) + ": " + nug.nugget);
cbr.newLine();
}
for (TRECNugget nug : nuggets) {
cbr.write(" Not (securely) covered (" + nug.nuggetID + "," + nug.nuggetType + "): " + nug.nugget);
cbr.newLine();
}
cbr.newLine();
cbr.newLine();
cbr.flush();
cbr.close();
} catch (Exception e) {
}
return results;
}
use of java.io.BufferedWriter in project lucida by claritylab.
the class MsgPrinter method setLogFile.
/** set the log file
* @param logFile the path and name of the filte to write log entries to (in addition to System.out)
*/
public static synchronized void setLogFile(String logFile) {
try {
if (logFile == null) {
if (logWriter != null) {
logWriter.close();
logWriter = null;
}
} else {
if (logWriter != null)
logWriter.close();
logWriter = new BufferedWriter(new FileWriter(logFile));
}
} catch (Exception e) {
logWriter = null;
}
}
Aggregations