All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.core.stopwords.WordsFromFile Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This is the stable version. Apart from bugfixes, this version does not receive any other updates.

There is a newer version: 3.8.6
Show newest version
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 * WordsFromFile.java
 * Copyright (C) 2014 University of Waikato, Hamilton, New Zealand
 */

package weka.core.stopwords;

import java.util.HashSet;
import java.util.List;

/**
 
 * Uses the stopwords located in the specified file (ignored _if pointing to a directory). One stopword per line. Lines starting with '#' are considered comments and ignored.
 * 

* * Valid options are:

* *

 -D
 *  If set, stopword scheme is run in debug mode and
 *  may output additional info to the console
* *
 -stopwords <file>
 *  The file containing the stopwords.
 *  (default: .)
* * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 10978 $ */ public class WordsFromFile extends AbstractFileBasedStopwords { /** for serialization. */ private static final long serialVersionUID = -722795295494945193L; /** The hash set containing the list of stopwords. */ protected HashSet m_Words; /** * Returns a string describing the stopwords scheme. * * @return a description suitable for displaying in the gui */ @Override public String globalInfo() { return "Uses the stopwords located in the specified file (ignored _if " + "pointing to a directory). One stopword per line. Lines " + "starting with '#' are considered comments and ignored."; } /** * Returns the tip text for this property. * * @return tip text for this property suitable for displaying in the * explorer/experimenter gui */ @Override public String stopwordsTipText() { return "The file containing the stopwords."; } /** * Performs intialization of the scheme. */ @Override protected void initialize() { List words; super.initialize(); m_Words = new HashSet(); words = read(); for (String word: words) { // comment? if (!word.startsWith("#")) m_Words.add(word); } } /** * Returns true if the given string is a stop word. * * @param word the word to test * @return true if the word is a stopword */ @Override protected synchronized boolean is(String word) { return m_Words.contains(word.trim().toLowerCase()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy