in pdq/java/src/main/java/pdqhashing/tools/Clusterize256xTool.java [79:154]
public static void main(String[] args) {
boolean doBruteForceQuery = false;
int distanceThreshold = DEFAULT_PDQ_DISTANCE_THRESHOLD;
int traceCount = 0;
// Parse command-line flags. I'm explicitly not using gflags or other such
// libraries, to minimize the number of external dependencies for this
// project.
int argi = 0;
int argc = args.length;
while (argi < argc) {
if (!args[argi].startsWith("-")) {
break;
}
if (args[argi].equals("-h") || args[argi].equals("--help")) {
usage(0);
} else if (args[argi].equals("-b") || args[argi].equals("--brute-force-query")) {
doBruteForceQuery = true;
argi++;
} else if (args[argi].equals("-d")) {
if ((argc - argi) < 2)
usage(1);
try {
distanceThreshold = Integer.parseInt(args[argi+1]);
} catch (NumberFormatException e) {
usage(1);
}
argi += 2;
} else if (args[argi].equals("--trace")) {
if ((argc - argi) < 2)
usage(1);
try {
traceCount = Integer.parseInt(args[argi+1]);
} catch (NumberFormatException e) {
usage(1);
}
argi += 2;
} else {
usage(1);
}
}
args = Arrays.copyOfRange(args, argi, argc);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MIH256<String> mihWithCenters = new MIH256<String>();
Map<Hash256,Integer> centersToIndices = new HashMap<Hash256,Integer>();
int lineCounter = 0;
if (args.length == 0) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
handleStream(reader, "(standard input)", mihWithCenters, centersToIndices, distanceThreshold,
lineCounter, traceCount, doBruteForceQuery);
} else {
for (String filename : args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(filename));
} catch (FileNotFoundException e) {
System.err.printf("%s: could not open \"%s\" for read.\n", PROGNAME, filename);
System.exit(1);
}
lineCounter = handleStream(reader, filename, mihWithCenters, centersToIndices, distanceThreshold,
lineCounter, traceCount, doBruteForceQuery);
try {
reader.close();
} catch (IOException e) {
System.err.printf("%s: could not close \"%s\" after read.\n", PROGNAME, filename);
System.exit(1);
}
}
}
}