コード例 #1
0
  @Test
  public void testSentiment() {
    LuceneClassifier classifier =
        new LuceneClassifier("resources/sentiment.idx", "positive", false, true);

    try {
      assertTrue(classifier.classify("great"));
      assertFalse(classifier.classify("horrible"));
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #2
0
  @Test
  public void testClassify() {
    LuceneClassifier classifier =
        new LuceneClassifier("resources/coffee-test-set.idx", "positive", false, false);
    try {
      assertTrue(classifier.classify(testDocs.get(0)));
      assertFalse(classifier.classify(testDocs.get(1)));
      assertFalse(classifier.classify(testDocs.get(2)));
      assertFalse(classifier.classify(testDocs.get(3)));
      assertFalse(classifier.classify(testDocs.get(4)));

    } catch (Exception e) {
      System.out.println("caught exception in test clasify");
      e.printStackTrace();
    }
  }
コード例 #3
0
  @Test
  public void testCorpus() {

    LuceneClassifier posClassifier =
        new LuceneClassifier("resources/twitter-sentiment.idx", "positive", true, true);
    LuceneClassifier negClassifier =
        new LuceneClassifier("resources/twitter-sentiment.idx", "negative", true, true);
    LuceneClassifier neutralClassifier =
        new LuceneClassifier("resources/twitter-sentiment.idx", "neutral", true, true);
    System.out.println("Training Complete!");
    try {
      int nCorrect = 0;

      ArrayList<String[]> testData = getTestData("resources/test-data.csv");

      for (String[] s : testData) {
        if (s[0].equals("positive")) {
          if (posClassifier.classify(s[1])) {
            nCorrect++;
          }
        } else if (s[0].equals("negative")) {
          if (negClassifier.classify(s[1])) {
            nCorrect++;
          }
        } else if (s[0].equals("neutral")) {
          if (neutralClassifier.classify(s[1])) {
            nCorrect++;
          }
        }
      }

      System.out.println((float) (nCorrect) / (float) (testData.size()));

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }