I am using the Java Weka API to build a classification model. I can use the builtin stopwords filter. However, I need to use a custom filter for my problem. I do not know how to use a custom stopwords filter in the Java Weka API.
2 Answers
$\begingroup$
$\endgroup$
1
You can try the following code.
import weka.core.converters.ConverterUtils.DataSource;
import weka.filters.unsupervised.attribute.StringToWordVector;
import weka.core.Instances;
Instances data = DataSource.read(".../document.txt"); //Your document .
filter.setInputFormat(data);
StringToWordVector filter = new StringToWordVector();
filter.setStopwords(new File(".../stopwords.txt")); //stop words file.
Instances data = Filter.useFilter(data,filter);
You can also read the following document for better understanding of the Weka API for Java. http://weka.sourceforge.net/doc.stable/
-
$\begingroup$ I appreciate your support. Thanks a lot. Your code and the link of the document really help me lot. $\endgroup$ Commented Nov 6, 2018 at 2:52
$\begingroup$
$\endgroup$
3
First of all you have to prepare a text file for your custom stopwords. Then you can use the following code:
import weka.filters.unsupervised.attribute.StringToWordVector;
StringToWordVector filter = new StringToWordVector(10000);
filter.setStopwords(new File(".../stopwords.txt"));
Hope it will help you.
-
-
$\begingroup$ I am very new in Java weka-api programming. I do not understand clearly. Anyone please provide me little more elaborate answer. Thanks in advance for your support. $\endgroup$ Commented Nov 6, 2018 at 2:34
-
$\begingroup$ Please let us know which part do not you understand? $\endgroup$– RejaCommented Dec 4, 2018 at 0:57