vendredi 2 juin 2017

Why is Java skipping the For statement?

I'm new to Java. I'm working with the code that implements aspect-sentiment analysis of the text. I know that the code should work but somehow I keep getting the following error.

  ----jGRASP exec: java -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,suspend=y,server=y sto2.STO2Core
 ----jGRASP: connected to debugger.
Exception in thread "main" java.lang.Exception: Alpha should be specified as a positive real number.

 ----jGRASP debugger: run in canvas ended
    at sto2.STO2Core.main(STO2Core.java:114)

Here is the code of my main function up til the line where I get the error

public static void main(String [] args) throws Exception {
    int numTopics = 10;
    int numIterations = 100;
    int numSenti = 2;
    int numThreads = 1;
    String inputDir = null;
    String outputDir = null;
    String dicDir = null;
    double alpha = -1;
    double [] betas = null;
    double [] gammas = null;
    String [] betasStr = null;
    String [] gammasStr = null;
    boolean randomInit = false;

    String sentiFilePrefix = "SentiWords-";
    String wordListFileName = "WordList.txt";
    String docListFileName = "DocumentList.txt";
    String wordDocFileName = "BagOfSentences.txt";


    for (int i = 0; i < args.length/2; i++) {
        String option = args[2*i];
        String value = args[2*i+1];
        if (option.equals("-t")) numTopics = Integer.valueOf(30);
        else if (option.equals("-s")) numSenti = Integer.valueOf(2);
        else if (option.equals("-i")) numIterations = Integer.valueOf(1000);
        else if (option.equals("-th")) numThreads = Integer.valueOf(3);
        else if (option.equals("-d")) inputDir = value.replaceAll("T:/Summer 2017/ASUM/ASUM/Test data", "/").replaceAll("/$", "");
        else if (option.equals("-o")) outputDir = value.replaceAll("T:/Summer 2017/ASUM/ASUM/Output", "/").replaceAll("/$", "");
        else if (option.equals("-dic")) dicDir = value.replaceAll("T:/Summer 2017/ASUM/ASUM/Test data", "/").replaceAll("/$", "");
        else if (option.equals("-a")) alpha = Double.valueOf(0.1);
        else if (option.equals("-b")) betasStr = value.split("0.001/0.1/0");
        else if (option.equals("-g")) gammasStr = value.split("1/1");
        else if (option.equals("-r")) randomInit = value.toLowerCase().equals("true")?true:false;
    }
    if (inputDir == null) inputDir = ".";
    if (outputDir == null) outputDir = new String(inputDir);
    if (dicDir == null) dicDir = new String(inputDir);

    // Exceptions
    if (!new File(inputDir).exists()) throw new Exception("There's no such an input directory as " + inputDir);
    if (!new File(outputDir).exists()) throw new Exception("There's no such an output directory as " + outputDir);
    if (!new File(dicDir).exists()) throw new Exception("Tehre's no such a dictionary directory as " + dicDir);

    if (alpha <= 0) throw new Exception("Alpha should be specified as a positive real number.");

When I execute the program none of if or else if lines seem to run. What can be the source of the problem? Thank you!

Aucun commentaire:

Enregistrer un commentaire