Package org.apache.nutch.urlfilter.api
Class RegexURLFilterBase
java.lang.Object
org.apache.nutch.urlfilter.api.RegexURLFilterBase
- All Implemented Interfaces:
Configurable,URLFilter,Pluggable
- Direct Known Subclasses:
AutomatonURLFilter,RegexURLFilter
Generic
URLFilter based on regular
expressions.
The regular expressions rules are expressed in a file. The file of rules is
determined for each implementation using the
getRulesReader(Configuration conf) method.
The format of this file is made of many rules (one per line):
[+-]<regex>
where plus (+)means go ahead and index it and minus (
-)means no.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether there are host- or domain-specific rules.Fields inherited from interface org.apache.nutch.net.URLFilter
X_POINT_ID -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs a new empty RegexURLFilterBaseRegexURLFilterBase(File filename) Constructs a new RegexURLFilter and init it with a file of rules.protectedRegexURLFilterBase(Reader reader) Constructs a new RegexURLFilter and init it with a Reader of rules.RegexURLFilterBase(String rules) Constructs a new RegexURLFilter and inits it with a list of rules. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract RegexRulecreateRule(boolean sign, String regex) Creates a newRegexRule.protected abstract RegexRulecreateRule(boolean sign, String regex, String hostOrDomain) Creates a newRegexRule.Interface for a filter that transforms a URL: it can pass the original URL through or "delete" the URL by returning nullgetConf()protected abstract ReadergetRulesReader(Configuration conf) Returns the name of the file of rules to use for a particular implementation.static voidmain(RegexURLFilterBase filter, String[] args) Filter the standard input using a RegexURLFilterBase.voidsetConf(Configuration conf)
-
Field Details
-
hasHostDomainRules
protected boolean hasHostDomainRulesWhether there are host- or domain-specific rules. If there are no specific rules host and domain name are not extracted from the URL to speed up the matching.readRules(Reader)automatically sets this to true if host- or domain-specific rules are used in the rule file.
-
-
Constructor Details
-
RegexURLFilterBase
public RegexURLFilterBase()Constructs a new empty RegexURLFilterBase -
RegexURLFilterBase
Constructs a new RegexURLFilter and init it with a file of rules.- Parameters:
filename- is the name of rules file.- Throws:
IOException- if there is a fatal I/O error interpreting the inputFileIllegalArgumentException- if there is a fatal error processing the regex rules wiuthin theURLFilter
-
RegexURLFilterBase
Constructs a new RegexURLFilter and inits it with a list of rules.- Parameters:
rules- string with a list of rules, one rule per line- Throws:
IOException- if there is a fatal I/O error interpreting the input rulesIllegalArgumentException- if there is a fatal error processing the regex rules wiuthin theURLFilter
-
RegexURLFilterBase
Constructs a new RegexURLFilter and init it with a Reader of rules.- Parameters:
reader- is a reader of rules.- Throws:
IOException- if there is a fatal I/O error interpreting the inputReaderIllegalArgumentException- if there is a fatal error processing the regex rules wiuthin theURLFilter
-
-
Method Details
-
createRule
Creates a newRegexRule.- Parameters:
sign- of the regular expression. Atruevalue means that any URL matching this rule must be included, whereas afalsevalue means that any URL matching this rule must be excluded.regex- is the regular expression associated to this rule.- Returns:
RegexRule
-
createRule
Creates a newRegexRule.- Parameters:
sign- of the regular expression. Atruevalue means that any URL matching this rule must be included, whereas afalsevalue means that any URL matching this rule must be excluded.regex- is the regular expression associated to this rule.hostOrDomain- the host or domain to which this regex belongs- Returns:
RegexRule
-
getRulesReader
Returns the name of the file of rules to use for a particular implementation.- Parameters:
conf- is the current configuration.- Returns:
- the name of the resource containing the rules to use.
- Throws:
IOException- if there is a fatal error obtaining theReader
-
filter
Description copied from interface:URLFilterInterface for a filter that transforms a URL: it can pass the original URL through or "delete" the URL by returning null -
setConf
- Specified by:
setConfin interfaceConfigurable
-
getConf
- Specified by:
getConfin interfaceConfigurable
-
main
public static void main(RegexURLFilterBase filter, String[] args) throws IOException, IllegalArgumentException Filter the standard input using a RegexURLFilterBase.- Parameters:
filter- is the RegexURLFilterBase to use for filtering the standard input.args- some optional parameters (not used).- Throws:
IOException- if there is a fatal I/O error interpreting the input argumentsIllegalArgumentException- if there is a fatal error processing the input arguments
-