OpenNLP doccat api, , . - , .
, :
customerserviceproblems They did not respond
customerserviceproblems They didn't respond
customerserviceproblems They didn't respond at all
customerserviceproblems They did not respond at all
customerserviceproblems I received no response from the website
customerserviceproblems I did not receive response from the website
etc.... , \n newline
, , , " ", , ,
java
DoccatModel model = null;
InputStream dataIn = new FileInputStream(yourFileOfSamplesLikeAbove);
try {
ObjectStream<String> lineStream =
new PlainTextByLineStream(dataIn, "UTF-8");
ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(lineStream);
model = DocumentCategorizerME.train("en", sampleStream);
OutputStream modelOut = new BufferedOutputStream(new FileOutputStream(modelOutFile));
model.serialize(modelOut);
System.out.println("Model complete!");
} catch (IOException e) {
e.printStackTrace();
}
, :
DocumentCategorizerME documentCategorizerME;
DoccatModel doccatModel;
doccatModel = new DoccatModel(new File(pathToModelYouJustMade));
documentCategorizerME = new DocumentCategorizerME(doccatModel);
private Map<String, Double> getScore(String text) throws Exception {
Map<String, Double> scoreMap = new HashMap<>();
double[] categorize = documentCategorizerME.categorize(text);
int catSize = documentCategorizerME.getNumberOfCategories();
for (int i = 0; i < catSize; i++) {
String category = documentCategorizerME.getCategory(i);
scoreMap.put(category, categorize[documentCategorizerME.getIndex(category)]);
}
return scoreMap;
}
, , , , , .