Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.JSAPResult


    jsap.registerParameter(opt3);
    jsap.registerParameter(opt4);

        // check whether the command line was valid, and if it wasn't,
        // display usage information and exit.
    JSAPResult config = jsap.parse(args)
        if (!config.success()) {
          for (java.util.Iterator errs = config.getErrorMessageIterator(); errs.hasNext();) {
            System.err.println("Error: " + errs.next());
          }
          displayHelp(config, jsap);
            return;
        }
       
        if (config.getBoolean("help")){
          displayHelp(config, jsap);
          return;
        }
         
     String inDirName = config.getString("inDir");
     String outDirName = config.getString("outDir");
     
      // Make sure the code, bugs, and lda files exist
      if (! (new File((inDirName)).exists())){
          System.err.println("Error: " + inDirName + " does not exist.");
          return;
      }
         
      // If the output directory already exists, remove it (or else Lucene will complain)
    File indexDir   = new File(outDirName + "/index");
        if (indexDir.exists()){
            FileUtils.deleteDirectory(indexDir);
        }
       
        // Read the fileCodes, if there is one
        if (config.getString("fileCodes") != null){
          // TODO
        }


        // TODO: Run LDA, and build an LDAHelper object
        LDAHelper ldaHelper = new LDAHelper();
        ldaHelper.runLDA(config.getInt("numK"), inDirName);
   
    // Build the index, with the options specified.
    SimpleIndexer.indexDirectory(inDirName, outDirName, config.getString("fileCodes"), ldaHelper);
 
   
  }
View Full Code Here


    jsap.registerParameter(opt3);
    jsap.registerParameter(opt4);

    // check whether the command line was valid, and if it wasn't,
    // display usage information and exit.
    JSAPResult config = jsap.parse(args);
    if (!config.success()) {
      for (java.util.Iterator errs = config.getErrorMessageIterator(); errs
          .hasNext();) {
        logger.error("Error: " + errs.next());
      }
      displayHelp(config, jsap);
      return;
    }

    if (config.getBoolean("help")) {
      displayHelp(config, jsap);
      return;
    }

    // Read in the command line parameters
    String indexDirName    = config.getString("indexDir");
    String queryDirName    = config.getString("queryDir");
    String resultsDirName   = config.getString("resultsDir");
    int weightingCode     = config.getInt("weightingCode");
    int scoringCode       = config.getInt("scoringCode");

    // Make sure the output file exists
        File outDirF = new File(resultsDirName);
        if (!outDirF.exists()){
            outDirF.mkdirs();
View Full Code Here

    jsap.registerParameter(opt3);
    jsap.registerParameter(opt4);

    // check whether the command line was valid, and if it wasn't,
    // display usage information and exit.
    JSAPResult config = jsap.parse(args);
    if (!config.success()) {
      for (java.util.Iterator errs = config.getErrorMessageIterator(); errs
          .hasNext();) {
        logger.error("Error: " + errs.next());
      }
      displayHelp(config, jsap);
      return;
    }

    if (config.getBoolean("help")) {
      displayHelp(config, jsap);
      return;
    }
   
    String indexDirName    = config.getString("indexDir");
    String LDAIndexName    = config.getString("LDAIndexDir");
    String queryDirName    = config.getString("queryDir");
    String resultsDirName   = config.getString("resultsDir");
    int K                 = config.getInt("K");
    int scoringCode       = config.getInt("scoringCode");

        // Make sure output directory exists
        File outDirF = new File(resultsDirName);
        if (!outDirF.exists()){
            outDirF.mkdirs();
View Full Code Here

            new FlaggedOption("output-models-basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "output-models-basename",
                "Base filename for writing the models."),

        });

    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted())
      return;

    if (jsapResult.getBoolean("verbose")) {
      logger.setLevel(Level.DEBUG);
    }

    final String inFileName = jsapResult.getString("input-file");
    File inFile = new File(inFileName);
    final String outFileName = jsapResult.getString("output-assignment");

    final int nClusters = jsapResult.getInt("clusters");
    final int clusteringIterations = jsapResult.getInt("passes");

    // Load tree
    File taxoFile = new File(jsapResult.getString("taxonomy-file"));
    Taxonomy tree = new Taxonomy(taxoFile);

    // Build initial candidate
    Candidate initialCandidate;
    if (jsapResult.userSpecified("init-explicit")) {
      initialCandidate = new Candidate(tree, Util.split(jsapResult.getString("init-explicit")), null, null);

    } else if (jsapResult.userSpecified("init-all-level")) {
      initialCandidate = Candidate.createFixedLevelCandidate(tree, jsapResult.getInt("init-all-level"));

    } else if (jsapResult.getBoolean("init-all-leaves")) {
      initialCandidate = Candidate.createLeafCandidate(tree);

    } else {
      throw new IllegalArgumentException("Either --init-explicit, --init-all-leaves, or --init-all-level should be specified. See --help.");
    }
    logger.debug("Initial candidate is " + initialCandidate.toBriefString());

    // Set learning parameters
    Class<SearchStrategy> strategy = (Class<SearchStrategy>) Class.forName(SearchStrategy.class.getPackage().getName() + "." + jsapResult.getString("search-method"));
    logger.debug("Search strategy is " + strategy);

    double weight1 = -1;
    if (jsapResult.userSpecified("search-method-weight-1")) {
      weight1 = jsapResult.getDouble("search-method-weight-1");
      logger.info("Will use weight1=" + weight1);
    }
    int maxIterations = -1;
    if (jsapResult.userSpecified("max-iterations")) {
      maxIterations = jsapResult.getInt("max-iterations");
      logger.info("Will use maxIterations=" + maxIterations);
    }
    int batchSize = -1;
    if (jsapResult.userSpecified("batch-size")) {
      batchSize = jsapResult.getInt("batch-size");
      logger.info("Will use batchSize=" + batchSize);
    }

    // Do the clustering
    ClusterSequences clustering = new ClusterSequences(tree, inFile, nClusters, initialCandidate, strategy, weight1, maxIterations, batchSize);
    clustering.doClustering(clusteringIterations);

    // Write clusters
    clustering.printClusterAssignment(outFileName);

    // Write models
    if (jsapResult.userSpecified("output-models-basename")) {

      final String outModelsBasename = jsapResult.getString("output-models-basename");
      clustering.printModels(outModelsBasename);

    } else {
      logger.warn("You did not specify a file for writing the output models, will not print them");
    }
View Full Code Here

                "File containing the description of the HMM."),
            new FlaggedOption("taxonomy-file", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 't', "taxonomy-file",
                "File containing the taxonomy."),
    });
   
    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted())
      return;
    if (jsapResult.getBoolean("verbose")) {
      logger.setLevel(Level.DEBUG);
    }
   
    File modelFile = new File(jsapResult.getString("model-file"));
    File taxoFile = new File(jsapResult.getString("taxonomy-file"));
    int numSequences = jsapResult.getInt("num-sequences");
   
    StateSet taxo = new StateSet( modelFile, new Taxonomy(taxoFile) );
    Model hmm = new Model(modelFile, taxo);
   
    for( int i=0; i<numSequences; i++) {
View Full Code Here

        new FlaggedOption("taxonomy-file", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 't', "taxonomy-file", "File containing the taxonomy."),
        new FlaggedOption("input-file", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'i', "input-file", "File containing the input sequences."),
        new FlaggedOption("sequence", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 's', "sequence",
            "Optionally, pass a single sequence as a string. Place it between quotes, with space-separated symbols.") });

    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted())
      return;
    if (jsapResult.getBoolean("verbose")) {
      logger.setLevel(Level.DEBUG);
    }

    File modelFile = new File(jsapResult.getString("model-file"));
    File taxoFile = new File(jsapResult.getString("taxonomy-file"));
    StateSet stateSet = new StateSet(modelFile, new Taxonomy(taxoFile));
    Model hmm = new Model(modelFile, stateSet);

    if (jsapResult.userSpecified("input-file")) {
      File inputFile = new File(jsapResult.getString("input-file"));
      BufferedReader br = new BufferedReader(new FileReader(inputFile));

      String sequenceStr;
      double logProb = 0.0;
      int seqCount = 0;
      while ((sequenceStr = br.readLine()) != null) {
        logProb += hmm.viterbiCalculateNonOverlap(sequenceStr);
        seqCount++;
      }
      logger.info("Log probability = " + logProb);

    } else if (jsapResult.userSpecified("sequence")) {
      String sequenceStr = jsapResult.getString("sequence");
      logger.info("Probability = " + Math.exp(hmm.viterbiCalculateNonOverlap(sequenceStr)));

    } else {
      throw new IllegalArgumentException("You must specify either an input file or a sequence");
    }
View Full Code Here

                "Output model (winner) must have at most this number of states; this is taken only as a hint, so if there is no model with that few states, "
                    + "the one with the lower number of states will be selected"),
           
        });

    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted())
      return;

    if (jsapResult.getBoolean("verbose")) {
      logger.setLevel(Level.DEBUG);
    }

    File inputFile = new File(jsapResult.getString("input-file"));
    File taxoFile = new File(jsapResult.getString("taxonomy-file"));
    Taxonomy tree = new Taxonomy(taxoFile);
    Candidate initialCandidate;

    if (jsapResult.userSpecified("init-explicit")) {
      initialCandidate = new Candidate(tree, Util.split(jsapResult.getString("init-explicit")), null, null);

    } else if (jsapResult.userSpecified("init-all-level")) {
      initialCandidate = Candidate.createFixedLevelCandidate(tree, jsapResult.getInt("init-all-level"));
     
    } else if (jsapResult.getBoolean("init-all-leaves")) {
      initialCandidate = Candidate.createLeafCandidate(tree);

    } else {
      throw new IllegalArgumentException("Either --init-explicit, --init-all-leaves, or --init-all-level should be specified. See --help.");
    }
    logger.debug("Initial candidate is " + initialCandidate.toBriefString());
   
    Class<SearchStrategy> strategy = (Class<SearchStrategy>) Class.forName(SearchStrategy.class.getPackage().getName() + "." + jsapResult.getString("search-method"));
    logger.debug("Search strategy is " + strategy );
   
    double weight1 = jsapResult.getDouble("search-method-weight-1");
    if( jsapResult.userSpecified("search-method-weight-1") ) {
      logger.info( "Will use weight1=" + weight1 );
    }
   
    // Read input file
    logger.info("Reading input file");
    SymbolTransitionFrequencies symbolTransitions = new SymbolTransitionFrequencies(tree);
    symbolTransitions.processFile(inputFile);

    // Learning
    LearnModel learner = new LearnModel(tree, symbolTransitions, initialCandidate, strategy, weight1);
    if (jsapResult.userSpecified("max-iterations")) {
      learner.setMaxIterations(jsapResult.getInt("max-iterations"));
    }
    if (jsapResult.userSpecified("batch-size")) {
      learner.setBatchSize(jsapResult.getInt("batch-size"));
    }
    learner.learn();

    if (jsapResult.userSpecified("output-log")) {
      String fileName = jsapResult.getString("output-log");
      logger.info("Printing logfile to '" + fileName + "'");

      PrintWriter reportWriter = outputFile(fileName);
      learner.printReport(reportWriter);
      reportWriter.close();
    }

    if (jsapResult.userSpecified("output-model")) {
      int maxStates = jsapResult.getInt("winner-model-maxstates");
      if( jsapResult.userSpecified("winner-model-maxstates") ) {
        logger.info("Will pick the best model only among those having " + maxStates + " states or less" );
      }
     
      String fileName = jsapResult.getString("output-model");
      logger.info("Printing best model to '" + fileName + "'" );
      logger.info("You can use " + GenerateSequences.class.getName() + " to generate sequences");
      PrintWriter reportWriter = outputFile(fileName);
      learner.printBestModel(maxStates,reportWriter);
      reportWriter.close();
View Full Code Here

TOP

Related Classes of com.martiansoftware.jsap.JSAPResult

Copyright © 2018 www.massapicom. 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.