Package com.yahoo.prelude.semantics
Class RuleBase
java.lang.Object
com.yahoo.prelude.semantics.RuleBase
A set of semantic production rules and named conditions used to analyze and rewrite queries
- Author:
- bratseth
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCondition
(NamedCondition namedCondition) Adds a named condition which can be referenced by rulesvoid
addRule
(ProductionRule productionRule) Analyzes a query over this rule baseprotected void
annotatePhrase
(PhraseMatcher.Phrase phrase, Query query, int traceLevel) Returns the named conditions in added orderstatic RuleBase
createFromFile
(String ruleFile, String automataFile, com.yahoo.language.Linguistics linguistics) Creates a rule base from filestatic RuleBase
createFromString
(String name, String ruleString, String automataFile, com.yahoo.language.Linguistics linguistics) Creates a rule base from a stringboolean
Returns true if the given object is a rule base having the same name as thisReturns the name of the automata file used, or null if nonegetCondition
(String name) Returns a named condition, or null if no condition with that name existsgetName()
Returns the name of this rule base.Thread safely gets the phrase matcher to use in thisThe identifying name of the source of this rule base.int
hashCode()
void
Include another rule base into this.boolean
Returns whether this rule base - directly or through other includes - includes the rule base with the given namevoid
Call this when all rules are added, before any rule evaluation starts.boolean
Returns whether this base is default, the semantics of default is left to the applicationprotected void
matchAutomata
(Query query, int traceLevel) Returns the rules in added orderrules()
Returns the rules unmodifiablevoid
setAutomataFile
(String automataFile) Sets the name of the automata file to use as a source of condition matches.void
setDefault
(boolean isDefault) Sets whether this base is default, the semantics of default is left to the applicationvoid
Sets the name of this rule base.void
setPhraseMatcher
(PhraseMatcher matcher) Thread safely sets the phrase matcher to use in this, or null to not use a phrase matchervoid
Sets the name of the source of this rule base.Returns a string containing all the rules and conditions of this rule base in the form they will be evaluated, with all included rule bases inlinedtoString()
boolean
Returns whether this uses a phrase matcher automata
-
Constructor Details
-
RuleBase
Creates an empty rule base
-
-
Method Details
-
createFromFile
public static RuleBase createFromFile(String ruleFile, String automataFile, com.yahoo.language.Linguistics linguistics) throws IOException, ParseException Creates a rule base from file- Parameters:
ruleFile
- the rule file to read. The name of the file (minus path) becomes the rule base name.automataFile
- the automata file, or null to not use an automata- Throws:
IOException
- if there is a problem reading one of the filesParseException
- if the rule file can not be parsed correctlyRuleBaseException
- if the rule file contains inconsistencies
-
createFromString
public static RuleBase createFromString(String name, String ruleString, String automataFile, com.yahoo.language.Linguistics linguistics) throws IOException, ParseException Creates a rule base from a string- Parameters:
name
- the name of the rule baseruleString
- the rule string to readautomataFile
- the automata file, or null to not use an automata- Throws:
IOException
- if there is a problem reading the automata fileParseException
- if the rule file can not be parsed correctlyRuleBaseException
- if the rule file contains inconsistencies
-
include
Include another rule base into this. This transfers ownership of the given rule base - it can not be subsequently used for any purpose (including accessing).
Each rule base will only be included by the first include directive enountered for that rule base.
-
addCondition
Adds a named condition which can be referenced by rules -
includes
Returns whether this rule base - directly or through other includes - includes the rule base with the given name -
setName
Sets the name of this rule base. If this rule base is given to a searcher, it must be removed before the name change, and then re-added -
getName
Returns the name of this rule base. This is never null. -
setAutomataFile
Sets the name of the automata file to use as a source of condition matches. To reload the automata, call this again. This can be done safely at any point by any thread while this rule base is in use.- Throws:
IllegalArgumentException
- if the file is not found
-
getAutomataFile
Returns the name of the automata file used, or null if none -
setDefault
public void setDefault(boolean isDefault) Sets whether this base is default, the semantics of default is left to the application -
isDefault
public boolean isDefault()Returns whether this base is default, the semantics of default is left to the application -
setPhraseMatcher
Thread safely sets the phrase matcher to use in this, or null to not use a phrase matcher -
getPhraseMatcher
Thread safely gets the phrase matcher to use in this -
getSource
The identifying name of the source of this rule base. The absolute file name if this came from a file. -
setSource
Sets the name of the source of this rule base. If this came from a file, the source must be set to the absolute file name of the rule base -
usesAutomata
public boolean usesAutomata()Returns whether this uses a phrase matcher automata -
addRule
-
getCondition
Returns a named condition, or null if no condition with that name exists -
initialize
public void initialize()Call this when all rules are added, before any rule evaluation starts.- Throws:
RuleBaseException
- if there is an inconsistency in the rule base.
-
analyze
Analyzes a query over this rule base- Parameters:
query
- the query to analyzetraceLevel
- the level of tracing to add to the query- Returns:
- the error caused by analyzing the query, or null if there was no error If there is an error, this query is destroyed (unusable)
-
matchAutomata
-
annotatePhrase
-
ruleIterator
Returns the rules in added order -
rules
Returns the rules unmodifiable -
conditionIterator
Returns the named conditions in added order -
equals
Returns true if the given object is a rule base having the same name as this -
hashCode
public int hashCode() -
toString
-
toContentString
Returns a string containing all the rules and conditions of this rule base in the form they will be evaluated, with all included rule bases inlined
-