Python API class rl3.FactIterator

From RL3 Wiki
Jump to: navigation, search

rl3.FactIterator class overview

The rl3.FactIterator class implements the necessary set of functions that can be used in for/in loops to cycle through iterable objects:

# iterate and print all "continent" annotations
for i in factsheet.get_facts("name"):
    print i.get_value()

constructor

New FactIterator objects must not be created through the __init__ constructor directly.

is_end

def is_end(self):

Define whether an iterator has looked through all the items in a data structure.

Returns: a boolean

next

def next(self):

Obtain the next element in an iteration.

Returns: a reference to self

get_label

def get_label(self):

Get a fact name (label) when iterating.

Returns: a string

get_value

def get_value(self):

Get a fact value when iterating (as a unicode string).

Returns: a string

get_weight

def get_weight(self):

Get a fact weight when iterating.

Returns: a floating number

get_annotation_start

def get_annotation_start(self):

Get a fact annotation start (i.e. position in a text field) when iterating.

Returns: a number

get_annotation_end

def get_annotation_end(self):

Get a fact annotation end (i.e. position in a text field) when iterating.

Returns: a number

get_annotation

def get_annotation(self):

Get a fact annotation.

Returns: a tuple (a pair of two numbers - annotation start and annotation end)

has_factsheet

def has_factsheet(self):

Define whether a fact contains a factsheet when iterating.

Returns: boolean

get_factsheet

def get_factsheet(self):

Get a factsheet from a fact when iterating.

Returns: an rl3.Factsheet object or None if there is no factsheet.

to_json

def to_json(self, root_text = None, include_text = True):

Save an associated Fact as a JSON string.

root_text: None if a fact should be considered as independent / self-containing structure. By default is None.
include_text True if a text field should be included in the output; False otherwise. By default is True.
Returns: a JSON string.