Last active
May 24, 2018 20:58
-
-
Save fmbenhassine/f8c3af08e4fa597a4a3d2b090bed1269 to your computer and use it in GitHub Desktop.
Easy Batch implementation of http://aseigneurin.github.io/2015/01/23/spark-vs-command-line-tools.html #EasyBatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) throws FileNotFoundException { | |
Engine engine = new EngineBuilder() | |
.reader(new FlatFileRecordReader(new File("/path/tp/ChessData-master/data.pgn"))) | |
.filter(new GrepFilter("[Result")) | |
.processor(new ComputationalRecordProcessor<StringRecord, StringRecord, Map<String, Integer>>() { | |
Map<String, Integer> results = new HashMap<String, Integer>(); | |
public Map<String, Integer> getComputationResult() { | |
return results; | |
} | |
public StringRecord processRecord(StringRecord stringRecord) throws Exception { | |
String payload = stringRecord.getPayload(); | |
String result = payload.substring(payload.indexOf("\"") + 1, payload.indexOf("-")); | |
if (results.get(result) == null) { | |
results.put(result, 0); | |
} | |
results.put(result, results.get(result) + 1); | |
return stringRecord; | |
} | |
}) | |
.silentMode(true) | |
.build(); | |
Report report = engine.call(); | |
System.out.println("report = " + report); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment