Skip to content

Instantly share code, notes, and snippets.

View AlexTitovWork's full-sized avatar
🎯
Focused

Alex T AlexTitovWork

🎯
Focused
View GitHub Profile
/**
* Data model generator based on gen_data.txt
*/
public void makeDataTrainingModel() {
model = null;
System.out.println("POS model started");
InputStream dataIn = null;
try {
String currentDir = new File("").getAbsolutePath();
@AlexTitovWork
AlexTitovWork / textAnalysis.java
Created October 23, 2019 22:04
This code perform inputdata analysis and get it label from product categories
public ArrayList textAnalisis(String inputdata){
System.out.println("-> Nimbler: RestController: current message:\n " + inputdata);
/**
* Detector of sentence and divide text on independent sentence.
*/
String[] sentences = sentenceDetect(inputdata);
System.out.println(Arrays.toString(sentences));
/**
@AlexTitovWork
AlexTitovWork / makeDataTrainingModel.java
Created October 27, 2019 14:37
makeDataTrainingModel
public void makeDataTrainingModel() {
model = null;
System.out.println("POS model started");
// InputStream dataIn = null;
InputStreamFactory dataIn = null;
try {
final String currentDir = new File("").getAbsolutePath();
public String[] sentenceDetect(String message) {
System.out.println("-> OpenNLP: sentence detector");
return sentenceDetector.sentDetect(message);
}
public String[] tokenize(String message) {
System.out.println("-> OpenNLP: token detector");
return tokenizer.tokenize(message);
@AlexTitovWork
AlexTitovWork / NlpProductClassifier.java
Created October 27, 2019 14:45
NlpProductClassifier main test
import java.io.IOException;
public class NlpProductClassifier {
public static void main(String[] args) throws IOException {
NLPClassifier CL = new NLPClassifier();
/**
* Sentence detector test
*/
@AlexTitovWork
AlexTitovWork / DebitCreditWekaClassifierConstructor.java
Last active December 4, 2019 21:49
constructor of DebitCreditWekaClassifier class
/**
* Naive Bayes
*/
import weka.classifiers.bayes.NaiveBayesMultinomial;
/**
* Weka tools
*/
import weka.classifiers.Evaluation;
import weka.classifiers.meta.FilteredClassifier;
import weka.core.Attribute;
DebitCreditWekaClassifier() {
/*
* Class for running an arbitrary classifier on data that has been passed through an arbitrary filter.
*/
classifier = new FilteredClassifier();
/**
* Class for building and using a multinomial Naive Bayes classifier. For more information see,
* Andrew Mccallum, Kamal Nigam: A Comparison of Event Models for Naive Bayes Text Classification.
* https://weka.sourceforge.io/doc.dev/weka/classifiers/bayes/NaiveBayesMultinomial.html
*/
private static Logger LOGGER = Logger.getLogger("DebitCreditInternalSystem");
private FilteredClassifier classifier;
/**
* Declare train and test data Instances
*/
private Instances trainData;
/**
* Declare Instance's attributes
*/
@AlexTitovWork
AlexTitovWork / transformWeka.java
Last active December 6, 2019 21:38
transformWeka.java
/**
* load training data and set feature generators
*/
public void transform() {
try {
trainData = loadDataset(TRAIN_DATA);
saveArff(trainData, TRAIN_ARFF_ARFF);
/**
* create the filter and set the attribute to be transformed from text into a feature vector (the last one)
*/
/**
* Build prepared classifier on the training data
*/
public void fit() {
try {
classifier.buildClassifier(trainData);
} catch (Exception e) {
LOGGER.warning(e.getMessage());
}
}