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.
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/
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.