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

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

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This version represents the developer version, the "bleeding edge" of development, you could say. New functionality gets added to this version.

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

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

package weka.core.stopwords;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 
 * Uses the regular expressions stored in the file for determining whether a word is a stopword (ignored if pointing to a directory). One expression per line.
 * 

* * 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 (ignored if directory)
 *  (default: .)
* * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 10979 $ */ public class RegExpFromFile extends AbstractFileBasedStopwords { /** for serialization. */ private static final long serialVersionUID = -722795295494945193L; /** The list of regular expressions. */ protected List m_Patterns; /** * Returns a string describing the stopwords scheme. * * @return a description suitable for displaying in the gui */ @Override public String globalInfo() { return "Uses the regular expressions stored in the file for determining " + "whether a word is a stopword (ignored if " + "pointing to a directory). One expression per line.\n" + "More information on regular expressions:\n" + "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html"; } /** * 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 regular expressions."; } /** * Performs intialization of the scheme. */ @Override protected void initialize() { List patterns; super.initialize(); m_Patterns = new ArrayList(); patterns = read(); for (String pattern: patterns) { m_Patterns.add(Pattern.compile(pattern)); } } /** * 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) { for (Pattern pattern: m_Patterns) { if (pattern.matcher(word.trim().toLowerCase()).matches()) { if (m_Debug) debug(pattern.pattern() + " --> true"); return true; } else { if (m_Debug) debug(pattern.pattern() + " --> false"); } } return false; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy