示例#1
0
 /** required flags: model-dir input-file output-file */
 public static void main(String[] args) throws Exception {
   final FNModelOptions options = new FNModelOptions(args);
   final File inputFile = new File(options.inputFile.get());
   final File outputFile = new File(options.outputFile.get());
   final String modelDirectory = options.modelDirectory.get();
   final int numThreads = options.numThreads.present() ? options.numThreads.get() : 1;
   final Semafor semafor = getSemaforInstance(modelDirectory);
   semafor.runParser(
       Files.newReaderSupplier(inputFile, Charsets.UTF_8),
       Files.newWriterSupplier(outputFile, Charsets.UTF_8),
       numThreads);
 }
示例#2
0
 protected static void writeLabelBindings(
     File dictOut, ARFFModel arffModel, String delimiter, boolean jsonDictonary)
     throws IOException {
   Writer writer = Files.newWriterSupplier(dictOut, Charsets.UTF_8, true).getOutput();
   try {
     if (jsonDictonary) {
       writeLabelBindingsJSON(writer, arffModel);
     } else {
       writeLabelBindings(writer, arffModel, delimiter);
     }
   } finally {
     Closeables.close(writer, false);
   }
 }
示例#3
0
 public static OutputStreamWriter writerForFile(String filename, boolean append)
     throws IOException {
   OutputSupplier<OutputStreamWriter> os =
       Files.newWriterSupplier(new File(filename), CHARSET, append);
   return os.getOutput();
 }
示例#4
0
  public static void main(String[] args) {
    Settings fullSettings;
    String settingsJson;
    Gson gson = new Gson();
    String settingsFileName = SETTINGS_FILE;

    for (int i = 0; i < args.length; ++i) {
      if (args[i].equals("--config") && ++i < args.length) {
        settingsFileName = args[i];
      }
    }

    File debugFile = new File(DEBUG_FILE);
    try {
      debugOut =
          new BufferedWriter(Files.newWriterSupplier(debugFile, Charsets.UTF_8, true).getOutput());
    } catch (IOException e1) {
      System.err.println("WARN: Cannot write to debug file");
    }

    BufferedReader settingsReader;
    if (settingsFileName.equals("-")) {
      settingsReader = new BufferedReader(new InputStreamReader(System.in, Charsets.UTF_8));
    } else {
      File settingsFile = new File(settingsFileName);
      try {
        settingsReader = Files.newReader(settingsFile, Charsets.UTF_8);
      } catch (FileNotFoundException e) {
        System.err.println("ERROR: Can't find settings file (" + settingsFile + ")");
        return;
      }
    }

    try {
      settingsJson = CharStreams.toString(settingsReader);
    } catch (IOException e) {
      System.err.println("ERROR: Error while reading settings file");
      return;
    }

    OuterSettings outerSettings;
    try {
      outerSettings = gson.fromJson(settingsJson, OuterSettings.class);
    } catch (JsonSyntaxException e) {
      System.err.println("ERROR: Settings file is malformed!");
      return;
    }

    fullSettings = outerSettings.getSettings();

    dumperEngine = fullSettings.getDumperEngine();
    sourceEngine = fullSettings.getSourceEngine();
    if (dumperEngine == null) dumperEngine = "DumperJSON";
    if (sourceEngine == null) sourceEngine = "YotsubaJSON";

    for (String boardName : fullSettings.getBoardSettings().keySet()) {
      if ("default".equals(boardName)) continue;
      try {
        spawnBoard(boardName, fullSettings);
      } catch (BoardInitException e) {
        System.err.println("ERROR: Error initializing dumper for /" + boardName + "/:");
        System.err.println("  " + e.getMessage());
      }
    }
  }