package main.java.org.wikidata.analyzer;

import main.java.org.wikidata.analyzer.Processor.CounterProcessor;
import main.java.org.wikidata.analyzer.Processor.MapProcessor;
import main.java.org.wikidata.analyzer.Fetcher.DumpFetcher;
import org.json.simple.JSONObject;
import org.wikidata.wdtk.dumpfiles.DumpProcessingController;
import org.wikidata.wdtk.dumpfiles.MwDumpFile;

import java.io.*;

/**
 * @author Addshore
 */
public class WikidataAnalyzer {

    /**
     * Main method. Processes the whole dump using this processor and writes the results to disk.
     * This should be executed when in the root of the git repo to ensure the correct local dump dir is used.
     *
     * @param args
     */
    public static void main(String[] args) throws IOException {
        System.out.println("******************************************");
        System.out.println("*** Wikidata Toolkit: WikidataAnalyzer ***");
        System.out.println("******************************************");

        // Get the data directory
        File dataDir = null;
        try{
            dataDir = new File(args[0]);
            if (!dataDir.exists()) {
                System.out.println("Error: Data directory specified does not exist.");
                System.exit(1);
            }
        }
        catch( ArrayIndexOutOfBoundsException exception ) {
            System.out.println("Error: You must pass a data directory as a parameter.");
            System.exit(1);
        }
        System.out.println("Using data directory: " + dataDir.getAbsolutePath());

        if (Runtime.getRuntime().maxMemory() / 1024 / 1024 <= 1500) {
            System.out.println("WARNING: You may need to increase your memory limit!");
        }
        long startTime = System.currentTimeMillis();

        DumpProcessingController controller = new DumpProcessingController("wikidatawiki");
        controller.setOfflineMode(false);

        // Create Json output objects
        JSONObject mapGeoData = new JSONObject();
        JSONObject mapGraphData = new JSONObject();

        // Fetch and process dump
        controller.registerEntityDocumentProcessor(new CounterProcessor(), null, true);
        controller.registerEntityDocumentProcessor(new MapProcessor(mapGeoData, mapGraphData), null, true);
        DumpFetcher fetcher = new DumpFetcher(dataDir);
        System.out.println("Fetching dump");
        MwDumpFile dump = fetcher.getMostRecentDump();
        System.out.println("Processing dump");
        controller.processDump(dump);
        System.out.println("Processed!");
        System.out.println("Memory Usage (MB): " + Runtime.getRuntime().totalMemory() / 1024 / 1024);

        // Create all output files
        System.out.println("Writing map wdlabel.json");
        File mapLabelFile = new File( dataDir.getAbsolutePath() + File.separator + "wdlabel.json");
        BufferedWriter mapLabelWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapLabelFile)));
        mapGeoData.writeJSONString(mapLabelWriter);
        mapLabelWriter.close();
        System.out.println("Writing map graph.json");
        File mapGraphFile = new File( dataDir.getAbsolutePath() + File.separator + "graph.json");
        BufferedWriter mapGraphWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapGraphFile)));
        mapGraphData.writeJSONString(mapGraphWriter);
        mapGraphWriter.close();

        // Finish up
        System.out.println("All Done!");
        long elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
        System.out.println("Execution time: " + elapsedSeconds / 60 + ":" + elapsedSeconds % 60);
    }
}

@@ -468,20 +468,518 @@
   * 
-Main method.
+The arguments passed via the command line%0A     */%0A    private final String%5B%5D args;%0A%0A    /**%0A     * Main method. Instantiates and runs the analyzer%0A     * @param args Command line arguments%0A     */%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        WikidataAnalyzer analyzer = new WikidataAnalyzer( args );%0A        analyzer.run();%0A    %7D%0A%0A    /**%0A     * @param args Command line arguments%0A     */%0A    public WikidataAnalyzer( String%5B%5D args ) %7B%0A        this.args = args;%0A    %7D%0A%0A    /**%0A     *
  Pro
@@ -1173,77 +1173,30 @@
    *
-%0A     * @param args%0A     */%0A    public static void main(String%5B%5D args
+/%0A    public void run(
 ) th
@@ -1549,17 +1549,29 @@
 le(args%5B
-0
+args.length-1
 %5D);%0A    
@@ -4129,10 +4129,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Make WikidataAnalyzer class more OO