Skip to content

Instantly share code, notes, and snippets.

@fmbenhassine
Last active May 24, 2018 20:58
Show Gist options
  • Save fmbenhassine/f8c3af08e4fa597a4a3d2b090bed1269 to your computer and use it in GitHub Desktop.
Save fmbenhassine/f8c3af08e4fa597a4a3d2b090bed1269 to your computer and use it in GitHub Desktop.
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