Skip to content

Instantly share code, notes, and snippets.

@kenshin03
Created July 14, 2011 15:21
Show Gist options
  • Save kenshin03/1082659 to your computer and use it in GitHub Desktop.
Save kenshin03/1082659 to your computer and use it in GitHub Desktop.
scoring doc by readability
double readabilityMean = 0.0;
if (readabilityText != null){
BasicDBObject readabilityScoresObj = new BasicDBObject();
readabilityScoresObj.put("text", readabilityText);
BagOfReadabilityObjects readabilityStats = new Readability(readabilityText).getMetrics();
double normalizedFlesch = (100 - Math.abs(readabilityStats.getFleschReading() - 50))/100;
double normalizedFleschKincaid = (16 - Math.abs(readabilityStats.getFleschReading() - 13))/16;
double normalizedARI = (16 - Math.abs(readabilityStats.getARI() - 13))/16;
double normalizedLiau = (16 - Math.abs(readabilityStats.getColemanLiau() - 13))/16;
double normalizedGunning = (16 - Math.abs(readabilityStats.getGunningFog() - 12))/16;
double normalizedSMOG = (16 - Math.abs(readabilityStats.getSMOGIndex() - 12))/16;
readabilityMean = (normalizedFlesch + normalizedFleschKincaid + normalizedARI+ normalizedLiau + normalizedGunning + normalizedSMOG)/6;
readabilityScoresObj.put("mean", Double.valueOf(new DecimalFormat("#.####").format(readabilityMean)));
dbObj.put("readability", readabilityScoresObj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment