0
왜 myCategorizer.categorize(); String [] 아파치 opennlp 1.8 대신에 아파치 OpenNLP 버전 1.5와 같은 문자열이 필요합니까? 배열 대신 별도의 문자열을 확인하고 싶기 때문에.문서 분류기 openNLP - 범주화 메서드
public void trainModel()
{
InputStream dataIn = null;
try
{;
dataIn = new FileInputStream("D:/training.txt");
ObjectStream lineStream = new PlainTextByLineStream(dataIn, "UTF-8");
ObjectStream sampleStream = new DocumentSampleStream(lineStream);
// Specifies the minimum number of times a feature must be seen
int cutoff = 2;
int trainingIterations = 30;
model = DocumentCategorizerME.train("NL", sampleStream, cutoff,trainingIterations);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (dataIn != null)
{
try
{
dataIn.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
public void classifyNewTweet(String tweet)
{
DocumentCategorizerME myCategorizer = new DocumentCategorizerME(model);
double[] outcomes = myCategorizer.categorize(tweet);
String category = myCategorizer.getBestCategory(outcomes);
if (category.equalsIgnoreCase("1"))
{
System.out.println("The tweet is positive :) ");
}
else
{
System.out.println("The tweet is negative :(");
}
}