Python API class rl3.BaseEngine

From RL3 Wiki
Jump to: navigation, search


Class member functions

__del__

def __del__(self):

Delete an engine.

is_debug_mode

def is_debug_mode(self):

Check if debug mode is enabled.

Returns: boolean

set_debug_mode

def set_debug_mode(self, mode):

Enable or disable debug mode.

mode: True to enable debug mode, False to disable debug mode

is_update_mode

def is_update_mode(self):

Check if update mode is enabled.

Returns: boolean

set_update_mode

def set_update_mode(self, mode):

Enable or disable update mode.

mode: True to enable update mode, False to disable update mode

load

def load(self, file_path, silent = True):

Load a compiled engine model from file.

file_path: path to model file
silent: True to suppress system messages, False otherwise

create_sharedtext

def create_sharedtext(self, text):

Create a SharedText structure (used with multiple facts found in different parts of one text instance).

text: the text to be used as shared
Returns: rl3.SharedText object

create_fact

def create_fact(self, label, text, weight = 1.0, annotation_start = 0, annotation_end = 0):

Create a new shared fact (i.e. a fact linked to a SharedText instance).

label: a string name (label) of a fact
text: an instance of rl3.SharedText
weight: floating number (weight)
annotation_start: number - fact annotation start (position in the text)
annotation_end: number - fact annotation end (position in the text)
Returns: rl3.Fact object

create_simple_fact

def create_simple_fact(self, label, value, weight = 1.0):

Create a new simple fact.

label: string - fact name (label)
value: string - fact value
weight: floating number - fact weight
Returns: rl3.Fact object

create_fact_from_json

def create_fact_from_json(self, json, root_text = None):

Create a new fact from JSON string.

json: a JSON string
root_text: None if fact should be considered as independent / self-containing structure. Default is None
Returns: rl3.Fact object

create_factsheet

def create_factsheet(self):

Create a new empty factsheet.

Returns: rl3.Factsheet object

create_factsheet_from_json

def create_factsheet_from_json(self, json, root_text = None):

Create a new factsheet from JSON string.

json: a JSON string
root_text: None if factsheet should be considered as independent / self-containing structure. Default is None
Returns: rl3.Factsheet object

create_factsheet_from_html

def create_factsheet_from_html(self, html):

Create a new factsheet from HTML string.

html: an input HTML string
Returns: rl3.Factsheet object

derive_factsheet

def derive_factsheet(self, fact_sheet, local):

TBD: Clarify. Must be similar in function to rl3_factsheet_derive (in C API)

run

def run(self, premises, conclusions):

Execute the engine on an input factsheet and add resulting facts to an output factsheet.

premises: input rl3.Factsheet object
conclusions: output rl3.Factsheet object
Returns: True if new facts were asserted, otherwise False

update

def update(self, fact_sheet):

Execute the engine on an input factsheet and update it with new (resulting) facts.

factsheet: input and output rl3.Factsheet object
Returns: True if new facts were asserted, otherwise False

make_simple_annotation_def

def make_simple_annotation_def(self, target, pattern, name):

Create a simple (i.e. uncompouned) annotation pattern:

target: targeted field/fact name
pattern: a pattern to be searched
name: fact name (label) to be asserted
Returns: string (annotation definition code in RL3)

html_to_text

def html_to_text(self, html, section = 'body'):

Parse HTML section:

html: an input HTML string
section: a section to be extracted (body, title, description, keywords, abstract, author, copyright, publisher, classification, rating, coverage, category,pathway, apath, tlinks, hidden, frame_src, link_href, ads)
Returns: string (parsed HTML section)