Пример #1
0
  public static void main(String[] args) {
    Map<String, String> array = new HashMap<String, String>();
    array.put("male", "M");
    array.put("female", "F");
    MNBTClassifer classifier = new MNBTClassifer(array);
    Tokenizer tokenizer = new Tokenizer();
    TokenizeDirectory dir = new TokenizeDirectory();
    dir.DirectoryTokenizer("BLOGS", classifier.getClasses());
    classifier.updatevocsize();
    String dirktest = "TESTTEST.txt";
    //		String spam = "TESTMAILS/spmsgc34.txt";
    //		String ham =  "TESTMAILS/8-817msg1.txt";
    // System.out.println("V_SIZE " + classifier.getClasses()[0].getname() + "= " +
    // classifier.getClasses()[0].getvocsize());
    // System.out.println("V_SIZE " + classifier.getClasses()[1].getname() + "= " +
    // classifier.getClasses()[1].getvocsize());
    // System.out.println("wordprob /'company/' :" + classifier.wordprob("company",
    // classifier.getClasses()[0]) + " class: " + classifier.getClasses()[0].getname());
    // System.out.println("wordprob /'company/' :" + classifier.wordprob("company",
    // classifier.getClasses()[1]) + " class: " + classifier.getClasses()[1].getname());

    System.out.println(
        "Supposed to be female: " + classifier.classify(tokenizer.tokenize(dirktest)));
    // System.out.println("Supposed to be ham: " + classifier.classify(tokenizer.tokenize(ham)));

    // TODO Auto-generated method stub

  }
Пример #2
0
 public static void main(String[] args) {
   Map<String, String> array = new HashMap<String, String>();
   array.put("spam", "spm");
   array.put("ham", "msg");
   MNBTClassifer classifier = new MNBTClassifer(array);
   Tokenizer tokenizer = new Tokenizer();
   TokenizeDirectory dir = new TokenizeDirectory();
   dir.DirectoryTokenizer("EMAILS", classifier.getClasses());
   classifier.updatevocsize();
   String directorypath = "TESTMAILS";
   ClassifierClass[] classes = classifier.getClasses();
   TokenizeDirectory tokenizedirectory = new TokenizeDirectory();
   double correct = 0;
   double incorrect = 0;
   File directory = new File(directorypath);
   File[] directoryListing = directory.listFiles();
   System.out.println(Arrays.toString(directoryListing));
   if (directoryListing != null) {
     for (File child : directoryListing) {
       if (child.getName().endsWith(".txt")) {
         String filename = directorypath + "/" + child.getName();
         String category = tokenizedirectory.getCategory(classes, filename);
         String totest = classifier.classify(tokenizer.tokenize(filename));
         if (totest.equals(category)) {
           correct += 1;
         } else {
           incorrect += 1;
         }
         System.out.println("supposed to be " + category + ": " + totest);
       }
     }
   }
   double percentage = correct / (correct + incorrect);
   System.out.println("percentage correct: " + percentage);
 }