Package org.apache.log4j

Examples of org.apache.log4j.Logger$PrivateManager


     * Test the classifier using the files provided in the test/category directories
     */ 
    public static void main(String[] args) throws ClassNotFoundException, IOException
    {
      PropertyConfigurator.configure (Constants.LOG4J_FILE);
      Logger logger = Logger.getLogger(TestTtypeClassifier.class.getName());
      logger.debug("Started TestCatClassifier");

      //*-- read the classification model
      String modelFile = Constants.TTYPE_CLASS_MODEL;
      ObjectInputStream oi = new ObjectInputStream( new FileInputStream(modelFile) );
      LMClassifier compiledClassifier = (LMClassifier) oi.readObject();
      oi.close();
     
      //*-- loop through the identical categories and test the classification of test documents
    ConfusionMatrix confMatrix = new ConfusionMatrix(CATEGORIES);
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumIntegerDigits(1); nf.setMaximumFractionDigits(3);
    for (int i=0; i < CATEGORIES.length; ++i)
       {
    File classDir = new File(TESTING_DIR, CATEGORIES[i]);
    String[] testingFiles = classDir.list();
       
        //*-- for each file, find the best category using the classifier and compare with the
        //*-- designated category
    for (int j = 0; j < testingFiles.length; ++j)
         {
      String text = Files.readFromFile( new File(classDir, testingFiles[j]) );
      logger.debug("Testing on " + CATEGORIES[i] + File.separator + testingFiles[j]);
      JointClassification jc =  compiledClassifier.classifyJoint(text);
          confMatrix.increment(CATEGORIES[i], jc.bestCategory());
          logger.debug("Best Category: " + jc.bestCategory() );
          StringBuffer sb = new StringBuffer();
          sb.append("Scores ");
          for (int k = 0; k < CATEGORIES.length; k++) sb.append(nf.format(jc.score(k)) + " ");
          logger.debug(sb);
     } //*-- end of inner for
    } //*-- end of outer for
     
      logger.info("--------------------------------------------");
      logger.info("- Results ");
      logger.info("--------------------------------------------");
      int[][] imatrix = confMatrix.matrix();
      StringBuffer sb = new StringBuffer();
      sb.append(StringTools.fillin("CATEGORY", 10, true, ' ') );
      for (int i = 0; i < CATEGORIES.length; i++) sb.append(StringTools.fillin(CATEGORIES[i], 12, true, ' ') );
      logger.info(sb.toString());
     
      for (int i = 0; i < imatrix.length; i++)
      { sb = new StringBuffer();
        sb.append(StringTools.fillin(CATEGORIES[i], 10, true, ' ', 10 - CATEGORIES[i].length() ) );
        for (int j = 0; j < imatrix.length; j++)
         {  String out = "" + imatrix[i][j];
          sb.append(StringTools.fillin(out, 10, false, ' ', 10 - out.length() ) );
         }
        logger.info(sb.toString());
      }
     
    logger.info("Total Accuracy: " + nf.format(confMatrix.totalAccuracy()) );
      logger.info("Total Correct : " + confMatrix.totalCorrect() + " out of " + confMatrix.totalCount() );
    }
View Full Code Here


     * Test the classifier using the files provided in the test/category directories
     */ 
    public static void main(String[] args) throws ClassNotFoundException, IOException
    {
      PropertyConfigurator.configure (Constants.LOG4J_FILE);
      Logger logger = Logger.getLogger(TestMClassifier.class.getName());
      logger.debug("Started TestClassifier");

      //*-- read the classification model
      String modelFile = MUSTRU_HOME + File.separator + "data" + File.separator + "training" + File.separator + "tcat" + File.separator + "tcat_classifier";
      ObjectInputStream oi = new ObjectInputStream( new FileInputStream(modelFile) );
      LMClassifier compiledClassifier = (LMClassifier) oi.readObject();
      oi.close();
     
      //*-- loop through the identical categories and test the classification of test documents
    ConfusionMatrix confMatrix = new ConfusionMatrix(CATEGORIES);
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumIntegerDigits(1); nf.setMaximumFractionDigits(3);
    for (int i=0; i < CATEGORIES.length; ++i)
       {
    File classDir = new File(TESTING_DIR, CATEGORIES[i]);
    String[] testingFiles = classDir.list();
       
        //*-- for each file, find the best category using the classifier and compare with the
        //*-- designated category
    for (int j=0; j < testingFiles.length; ++j)
         {
      String text = Files.readFromFile( new File(classDir, testingFiles[j]) );
      logger.debug("Testing on " + CATEGORIES[i] + File.separator + testingFiles[j]);
      JointClassification jc =  compiledClassifier.classifyJoint(text);
          confMatrix.increment(CATEGORIES[i], jc.bestCategory());
          logger.debug("Best Category: " + jc.bestCategory() );
          StringBuffer sb = new StringBuffer();
          sb.append("Scores ");
          for (int k = 0; k < CATEGORIES.length; k++) sb.append(nf.format(jc.score(k)) + " ");
          logger.debug(sb);
     } //*-- end of inner for
    } //*-- end of outer for
     
      logger.info("--------------------------------------------");
      logger.info("- Results ");
      logger.info("--------------------------------------------");
      int[][] imatrix = confMatrix.matrix();
      StringBuffer sb = new StringBuffer();
      sb.append(StringTools.fillin("CATEGORY", 10, true, ' ') );
      for (int i = 0; i < CATEGORIES.length; i++) sb.append(StringTools.fillin(CATEGORIES[i], 8, false, ' ') );
      logger.info(sb.toString());
     
      for (int i = 0; i < imatrix.length; i++)
      { sb = new StringBuffer();
        sb.append(StringTools.fillin(CATEGORIES[i], 10, true, ' ', 10 - CATEGORIES[i].length() ) );
        for (int j = 0; j < imatrix.length; j++)
         {  String out = "" + imatrix[i][j];
          sb.append(StringTools.fillin(out, 8, false, ' ', 8 - out.length() ) );
         }
        logger.info(sb.toString());
      }
     
    logger.info("Total Accuracy: " + nf.format(confMatrix.totalAccuracy()) );
      logger.info("Total Correct : " + confMatrix.totalCorrect() + " out of " + confMatrix.totalCount() );
    }
View Full Code Here

     * Test the classifier using the files provided in the test/category directories
     */ 
    public static void main(String[] args) throws ClassNotFoundException, IOException
    {
      PropertyConfigurator.configure (Constants.LOG4J_FILE);
      Logger logger = Logger.getLogger(TestFtypeClassifier.class.getName());
      logger.debug("Started TestFtypeClassifier");

      //*-- read the classification model
      String modelFile = Constants.FTYPE_CLASS_MODEL;
      ObjectInputStream oi = new ObjectInputStream( new FileInputStream(modelFile) );
      LMClassifier compiledClassifier = (LMClassifier) oi.readObject();
      oi.close();
     
      //*-- loop through the identical categories and test the classification of test documents
    ConfusionMatrix confMatrix = new ConfusionMatrix(CATEGORIES);
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumIntegerDigits(1); nf.setMaximumFractionDigits(3);
    for (int i=0; i < CATEGORIES.length; ++i)
       {
    File classDir = new File(TESTING_DIR, CATEGORIES[i]);
    String[] testingFiles = classDir.list();
       
        //*-- for each file, find the best category using the classifier and compare with the
        //*-- designated category
    for (int j=0; j < testingFiles.length; ++j)
         {
      String text = Files.readFromFile( new File(classDir, testingFiles[j]) );
     
      //*-- limit the length of the text
        if (text.length() > 500text = text.substring(0, 500);
      logger.debug("Testing on " + CATEGORIES[i] + File.separator + testingFiles[j]);
      JointClassification jc =  compiledClassifier.classifyJoint(text);
     
      //*-- check if we have sufficient confidence in the decision
      String bestCategory = (jc.score(0) > -2.5) ? jc.bestCategory(): "text";
      confMatrix.increment(CATEGORIES[i], bestCategory)
          logger.debug("Best Category: " + bestCategory );
          StringBuffer sb = new StringBuffer();
          sb.append("Scores ");
          for (int k = 0; k < CATEGORIES.length; k++)
            sb.append(nf.format(jc.score(k)) + " ");
          logger.debug(sb);
     } //*-- end of inner for
    } //*-- end of outer for
     
      logger.info("--------------------------------------------");
      logger.info("- Results ");
      logger.info("--------------------------------------------");
      int[][] imatrix = confMatrix.matrix();
      StringBuffer sb = new StringBuffer();
      sb.append(StringTools.fillin("CATEGORY", 10, true, ' ') );
      for (int i = 0; i < CATEGORIES.length; i++) sb.append(StringTools.fillin(CATEGORIES[i], 8, false, ' ') );
      logger.info(sb.toString());
     
      for (int i = 0; i < imatrix.length; i++)
      { sb = new StringBuffer();
        sb.append(StringTools.fillin(CATEGORIES[i], 10, true, ' ', 10 - CATEGORIES[i].length() ) );
        for (int j = 0; j < imatrix.length; j++)
         {  String out = "" + imatrix[i][j];
          sb.append(StringTools.fillin(out, 8, false, ' ', 8 - out.length() ) );
         }
        logger.info(sb.toString());
      }
     
    logger.info("Total Accuracy: " + nf.format(confMatrix.totalAccuracy()) );
      logger.info("Total Correct : " + confMatrix.totalCorrect() + " out of " + confMatrix.totalCount() );
    }
View Full Code Here

private static boolean BOUNDED = false;

public static void main(String[] args) throws ClassNotFoundException, IOException
{
  PropertyConfigurator.configure (Constants.LOG4J_FILE);
  Logger logger = Logger.getLogger(TrainMClassifier.class.getName());
  logger.debug("Started TrainMClassifier");
  DynamicLMClassifier classifier = new DynamicLMClassifier(CATEGORIES, NGRAM_SIZE, BOUNDED);

  //*-- Start of training
  //*-- loop through the list of categories and verify that a directory exists for each one.
  for (int i = 0; i < CATEGORIES.length; ++i)
  {
   File classDir = new File(TRAINING_DIR, CATEGORIES[i]);
   if (!classDir.isDirectory())
   { logger.fatal("Could not find training directory=" + classDir); }

   //*-- get the list of training files for the category and train the classifier on each of the files
   String[] trainingFiles = classDir.list();
   for (int j=0; j<trainingFiles.length; ++j)
   {
    String text = Files.readFromFile(new File(classDir,trainingFiles[j]));
    logger.debug("Training on " + CATEGORIES[i] + File.separator + trainingFiles[j]);
    classifier.train(CATEGORIES[i], text);
   } //*-- end of inner for
  } //*-- end of outer for
  //*-- end of training

  //*-- dump the classification model to a file
  logger.info("Start compiling classifier");
  String modelFile = MUSTRU_HOME + File.separator + "data" + File.separator + "training" + File.separator + "tcat" + File.separator + "tcat_classifier";
  ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream(modelFile) );
  classifier.compileTo(os);
  os.close();
  logger.info("End compiling classifier");
  logger.debug("Ended TrainMClassifier");
}
View Full Code Here

  * @throws IOException
  */
public static void main(String[] args) throws IOException
{
  PropertyConfigurator.configure (Constants.LOG4J_FILE);
  Logger logger = Logger.getLogger(TrainPOSTagger.class.getName());
  logger.debug("Started POS tagged model generation");

  //*-- set up parser with estimator as handler
  HmmCharLmEstimator estimator = new HmmCharLmEstimator(N_GRAM, NUM_CHARS, LAMBDA_FACTOR);
  Parser parser = new BrownPosParser();
  parser.setHandler(estimator);

  //*-- train on files in data directory ending in "txt"
  if (!TRAINING_DIR.isDirectory())
  { logger.fatal("Could not find training directory=" + TRAINING_DIR); }
  File[] files = TRAINING_DIR.listFiles(new FileExtensionFilter("txt"));
  for (int i = 0; i < files.length; ++i)
  { logger.debug("Training on file: " + files[i]); parser.parse(files[i]); }

  //*-- write output to file
  File modelFile = new File(MUSTRU_HOME + File.separator + "data" + File.separator + "training" + File.separator + "pos" + File.separator + "pos_tagger");
  ObjectOutputStream objOut = new ObjectOutputStream(new FileOutputStream(modelFile));
  estimator.compileTo(objOut);
  Streams.closeOutputStream(objOut);
  logger.debug("Finished POS tagger model generation");
}
View Full Code Here

private static boolean BOUNDED = false;

public static void main(String[] args) throws ClassNotFoundException, IOException
{
  PropertyConfigurator.configure (Constants.LOG4J_FILE);
  Logger logger = Logger.getLogger(TrainFtypeClassifier.class.getName());
  logger.debug("Started TrainFtypeClassifier");
  DynamicLMClassifier classifier = new DynamicLMClassifier(CATEGORIES, NGRAM_SIZE, BOUNDED);

  //*-- Start of training
  //*-- loop through the list of categories and verify that a directory exists for each one.
  for (int i = 0; i < CATEGORIES.length; ++i)
  {
   File classDir = new File(TRAINING_DIR, CATEGORIES[i]);
   if (!classDir.isDirectory())
   { logger.fatal("Could not find training directory=" + classDir); }

   //*-- get the list of training files for the category and train the classifier on each of the files
   String[] trainingFiles = classDir.list();
   for (int j = 0; j < trainingFiles.length; ++j)
   {
    String text = Files.readFromFile(new File(classDir,trainingFiles[j]));
    logger.debug("Training on " + CATEGORIES[i] + File.separator + trainingFiles[j]);
    classifier.train(CATEGORIES[i], text);
   } //*-- end of inner for
  } //*-- end of outer for
  //*-- end of training

  //*-- dump the classification model to a file
  logger.info("Start compiling ftype classifier");
  String modelFile = Constants.FTYPE_CLASS_MODEL;
  ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream(modelFile) );
  classifier.compileTo(os);
  os.close();
  logger.info("End compiling ftype classifier");

  logger.debug("Ended TrainFtypeClassifier");
}
View Full Code Here

private static boolean BOUNDED = false;

public static void main(String[] args) throws ClassNotFoundException, IOException
{
  PropertyConfigurator.configure (Constants.LOG4J_FILE);
  Logger logger = Logger.getLogger(TrainTtypeClassifier.class.getName());
  logger.debug("Started TrainCatClassifier");
  DynamicLMClassifier classifier = new DynamicLMClassifier(CATEGORIES, NGRAM_SIZE, BOUNDED);

  //*-- Start of training
  //*-- loop through the list of categories and verify that a directory exists for each one.
  for (int i = 0; i < CATEGORIES.length; ++i)
  {
   File classDir = new File(TRAINING_DIR, CATEGORIES[i]);
   if (!classDir.isDirectory())
   { logger.fatal("Could not find training directory for category: " + classDir); }

   //*-- get the list of training files for the category and train the classifier on each of the files
   String[] trainingFiles = classDir.list();
   for (int j = 0; j < trainingFiles.length; ++j)
   {
    String text = Files.readFromFile(new File(classDir,trainingFiles[j]));
    logger.debug("Training on " + CATEGORIES[i] + File.separator + trainingFiles[j]);
    classifier.train(CATEGORIES[i], text);
   } //*-- end of inner for
  } //*-- end of outer for
  //*-- end of training

  //*-- dump the classification model to a file
  logger.info("Start compiling TrainCatClassifier");
  String modelFile = Constants.TTYPE_CLASS_MODEL;
  ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream(modelFile) );
  classifier.compileTo(os);
  os.close();
  logger.info("End compiling classifier");
  logger.debug("Ended TrainCatClassifier");
}
View Full Code Here

    Appender appender;
    if (logConfig.contains(",")) {
      st = new StringTokenizer(logConfig, ",");
      level = Level.toLevel(st.nextToken());
      String categoryAppenderStr = st.nextToken();
      Logger l = Logger.getLogger(categoryAppenderStr);
      if (l!=null) {
        appender = l.getAppender(categoryAppenderStr);
        if (appender==null) {
          appender = Logger.getRootLogger().getAppender(categoryAppenderStr);
        }
      } else {
        appender = null;
View Full Code Here

    Appender appender;
    if (logConfig.contains(",")) {
      st = new StringTokenizer(logConfig, ",");
      level = Level.toLevel(st.nextToken());
      String categoryAppenderStr = st.nextToken();
      Logger l = Logger.getLogger(categoryAppenderStr);
      if (l!=null) {
        appender = l.getAppender(categoryAppenderStr);
        if (appender==null) {
          appender = Logger.getRootLogger().getAppender(categoryAppenderStr);
        }
      } else {
        appender = null;
View Full Code Here

        public Logger makeNewLoggerInstance(String name) {
          return new ThreadLocalAwareLogger(name, threadLocalLogLevel_, logMessageModifier);
        }
      };
     
      final Logger originalRootLogger = LogManager.getRootLogger();
     
      final LoggerRepository parentRepository = originalRootLogger.getLoggerRepository();
     
      final LoggerRepository repository = new ThreadLocalAwareLoggerRepository(originalRootLogger, parentRepository, loggerFactory);
     
      LogManager.setRepositorySelector(new RepositorySelector() {
       
View Full Code Here

TOP

Related Classes of org.apache.log4j.Logger$PrivateManager

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.