rule_engine Package

expressions Module

normalisation_rule Module

class ternip.rule_engine.normalisation_rule.NormalisationRule(match, type=None, id='', value=None, change_type=None, freq=None, quant=None, mod=None, guards=None, after_guards=None, before_guards=None, sent_guards=None, after=None, tokenise=True, deliminate_numbers=False)[source]

Bases: ternip.rule_engine.rule.Rule

A class that represents normalisation rules

apply(timex, cur_context, dct, body, before, after)[source]

Applies this rule to this timex, where body is the full extent covered by this timex, before is the preceeding text in the sentence, and after is the proceeding text in the sentence, in the [(token, POS), ...] form

A boolean indicating whether or not application was successful is returned. The timex may also be modified, so should be passed in by reference.

normalisation_rule_block Module

class ternip.rule_engine.normalisation_rule_block.NormalisationRuleBlock(id, after, type, rules)[source]

Bases: ternip.rule_engine.rule_block.RuleBlock

A block of normalisation rules

apply(timex, cur_context, dct, body, before, after)[source]

Apply rules in this block, in order, to this sentence, either until one rule is successful, or all rules have been applied.

normalisation_rule_engine Module

class ternip.rule_engine.normalisation_rule_engine.NormalisationRuleEngine[source]

Bases: ternip.rule_engine.rule_engine.RuleEngine

A class which does normalisation using a rule engine

Complex rules must have a string member called ‘id’, which is used for after ordering, a list of strings called ‘after’ (which can be an empty list) which consists of IDs that must have run before this rule. Additionally, a function called ‘apply’ which takes a list of (token, pos, timexes) tuples and returns them in the same form with potentially modified timexes.

annotate(sents, dct)[source]

This annotates all the timexes in the sents. dct means the document creation time (in the TIDES-modified ISO8601 format), which some rules may use to determine a context.

recognition_rule Module

class ternip.rule_engine.recognition_rule.RecognitionRule(match, type, id, guards=None, after_guards=None, before_guards=None, after=None, squelch=False, case_sensitive=False, deliminate_numbers=False)[source]

Bases: ternip.rule_engine.rule.Rule

A class that represents identification rules

apply(sent)[source]

Applies this rule to the tokenised sentence. The ‘after’ ordering must be checked by the caller to ensure correct rule application.

sent is a list of tuples (token, POS, [timexes])

A tuple is returned where the first element is a list in the same form as sent, with additional timexes added to the 3rd element if need be, and the second element in the tuple is whether or not this rule matched anything

recognition_rule_block Module

class ternip.rule_engine.recognition_rule_block.RecognitionRuleBlock(id, after, type, rules)[source]

Bases: ternip.rule_engine.rule_block.RuleBlock

A block of recognition rules

apply(sent)[source]

Apply rules in this block, in order, to this sentence, either until one rule is successful, or all rules have been applied.

recognition_rule_engine Module

class ternip.rule_engine.recognition_rule_engine.RecognitionRuleEngine[source]

Bases: ternip.rule_engine.rule_engine.RuleEngine

A class which does recognition using a rule engine

Complex rules must have a string member called ‘id’, which is used for after ordering, a list of strings called ‘after’ (which can be an empty list) which consists of IDs that must have run before this rule. Additionally, a function called ‘apply’ which takes a list of (token, pos, timexes) tuples and returns them in the same form with potentially modified timexes.

tag(sents)[source]

This function actually does word recognition. It expects content to be split into tokenised, POS tagged, sentences. i.e., a list of lists of tuples ([[(token, pos-tag, timexes), ...], ...]). Rules are applied one at a time.

What is returned is in the same form, except the token tuples contain a third element consisting of the set of timexes associated with that token.

rule Module

class ternip.rule_engine.rule.Rule[source]

Bases: object

Base class for recognition and normalisation rules

rule_block Module

class ternip.rule_engine.rule_block.RuleBlock(id, after, type, rules)[source]

Bases: object

rule_engine Module

class ternip.rule_engine.rule_engine.RuleEngine[source]

Bases: object

A base class for rule engines to use

load_block(filename)[source]

Load a block of rules, then check for consistency Throws rule_load_errors if a rule fails to load

load_rule(filename)[source]

Load a rule, then check for consistency

Throws rule_load_error if a rule fails to load

load_rules(path)[source]

Do rule loading. Loads all files ending in .pyrule as ‘complex’ rules (direct Python code), .rule using the documented rule format, and .ruleblock as blocks which contain sequences of rules. For direct Python code, the rule must be a class called ‘rule’.

Throws rule_load_errors containing errors for all rules that failed to load.

exception ternip.rule_engine.rule_engine.RuleLoadError(filename, errorstr)[source]

Bases: exceptions.Exception

Error for when a rule fails to load

exception ternip.rule_engine.rule_engine.RuleLoadErrors(errors)[source]

Bases: exceptions.Exception

Error which bundles multiple rule_load_errors together. Allows for delayed exit on multiple load errors.