Package main

Source Code of main.NERC

package main;
/***************************************************************************
  Clinical Named Entity Recognizer and Normalizer(Clinical NERC), (v0.1).
    Copyright (C) 2013  Azad Dehghan
   
    Contact:  a.dehghan@manchester.ac.uk
*****************************************************************************/
import gate.creole.ResourceInstantiationException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import classification.MappingPipeline;


/**
* User Interface: Clinical NERC, command line
*/
public class NERC {

  public static void main(String[] args) throws IOException
  {     
    try {
      parseCmdLine(args);
    } catch (IOException | InterruptedException e) {
      usage();
    }
  }
 
  /**
   * print usage information.
   *
   * @return
   */
  private static String usage()
  {
    return "\n**********************************************************************************************************" +
        "\nClinical Named Entity Recognizer and Normalizer(Clinical NERC), (v0.1) \n" +
        "Copyright (C) 2013 Azad Dehghan\n\n" +
        "Usage:$ java -jar NERC.jar [--options] [--mode] [args...]\n\n" +
        "Where mode include:\n" +
        "--ner\t\t:NER mode\n" +
        "--nerc\t\t:NERC mode\n\n" +
        "Where options and arguments include:\n" +
        "-h\t\t\t\t\t\t\t:prints this.\n\n" +
        "--ss [--nerc|--ner] <port>\t\t\t\t:starts a socket server on <port>. To exit send: quit();\n\n" +
        "--stdio [--nerc|--ner]\t\t\t\t\t:open a input stream. To exit send: quit();\n\n" +
        "--gatexml [--nerc|--ner] <dir:input> <dir:output>\t:outputs a GATE xml document for each input document\n\n" +
        "--gatedoc [--nerc|--ner] <dir:input> <dir:output>  :outputs a GATE serilalized document for each input\n\n" +
        "--offsfile [--nerc|--ner] <dir:input> <dir:output>\t:outputs a offset file: NER_offsets.txt\n\n" +
        "************************************************************************************************************\n";
  }
 
  /**
   * handle user command line interface input
   *
   * @param args
   * @throws IOException
   * @throws InterruptedException
   * @throws ResourceInstantiationException
   */
  private static void parseCmdLine(String[] args) throws IOException, InterruptedException
  {
    boolean nercFlag = false;
   
    if(args.length < 2){
      System.out.println(usage());
    }
    else if(args[0].toLowerCase().contentEquals("--stdio") || args[0].toLowerCase().contentEquals("--gatexml") ||
        args[0].toLowerCase().contentEquals("--offsfile") || args[0].toLowerCase().contentEquals("--ss") ||
        args[0].toLowerCase().contentEquals("--gatedoc"))
    {
      if(args[1].toLowerCase().contentEquals("--nerc"))
        nercFlag = true;
     
      /**
       * argument: --stdio
       * opens input stream reader, returns result in \newline
       * result format: startOffset\tendOffset||text=<Tx identified>
       */
      if(args[0].toLowerCase().contentEquals("--stdio"))
      { 
        MLPipeline p = new MLPipeline();
        MappingPipeline mp = null;
       
        if(nercFlag)
          mp = new MappingPipeline();
       
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String x = null
            while((x = input.readLine()) != null && !x.equals("quit();")) {
              System.out.println(Logic.opt1(x, p, mp, nercFlag));
            }
      } // --ss <port>
      else if(args[0].toLowerCase().contentEquals("--ss") && args.length == 3)
      { 
        SocketServer.startServer(Integer.parseInt(args[2]), nercFlag); //throws exception if contains alphabetic character
      } // --gatexml <dir: input> <dir: output>
      else if(args[0].toLowerCase().contentEquals("--gatexml") && args.length == 4)
      { 
        String r_corpus = args[2];
        String w_output = args[3];
        Logic.opt2(r_corpus, w_output, nercFlag);
      } // --gatedoc <dir: input> <dir: output>
      else if(args[0].toLowerCase().contentEquals("--gatedoc") && args.length == 4)
      { 
        String r_corpus = args[2];
        String w_output = args[3];
        Logic.opt3(r_corpus, w_output, nercFlag);
      } // --offsfile <dir: input> <dir: output>
      else if(args[0].toLowerCase().contentEquals("--offsfile") && args.length == 4)
      { 
        String r_corpus = args[2];
        String w_output = args[3];
        Logic.opt4(r_corpus, w_output, nercFlag);
      }
      else
        System.out.println(usage());
    }
    else
    {
      if(args[0].toLowerCase().contentEquals("--help")||args[0].toLowerCase().contentEquals("-h"))
      {
        System.out.println(usage());
      }
      else
        System.err.println(usage());
    }
  }
}
TOP

Related Classes of main.NERC

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.