C API Fact functions

From RL3 Wiki
Jump to: navigation, search

rl3_fact_create_simple

struct RL3_Fact* rl3_fact_create_simple(struct RL3_Engine* engine, const char* label, const char* value, double weight);

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

engine: a pointer to an engine structure
label: a name (label) of the fact
value: fact value
weight: fact weight
Returns: a pointer to a new simple fact structure

rl3_fact_create_shared

struct RL3_Fact* rl3_fact_create_shared(struct RL3_Engine* engine, const char* label, struct RL3_SharedText* text, double weight, unsigned int annotation_start, unsigned int annotation_end);

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

engine: a pointer to an engine structure
label: a name (label) of the fact
text: a pointer to a SharedText instance
weight: fact weight
annotation_start: fact start position in the text (measured in Unicode characters, not bytes)
annotation_end: fact end position in the text (measured in Unicode characters, not bytes)
Returns: a pointer to a new shared fact structure

rl3_fact_destroy

void rl3_fact_destroy(struct RL3_Engine* engine, struct RL3_Fact* fact);

Destroy a fact (works both for simple and shared facts).

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: nothing

rl3_fact_get_label

const char* rl3_fact_get_label(struct RL3_Engine* engine, struct RL3_Fact* fact);

Get fact name (label).

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: a pointer to the first character in the return string

rl3_fact_get_value

const char* rl3_fact_get_value(struct RL3_Engine* engine, struct RL3_Fact* fact);

Get fact value.

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: a pointer to the first character in the return string

rl3_fact_get_weight

double rl3_fact_get_weight(struct RL3_Engine* engine, struct RL3_Fact* fact);

Get fact weight.

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: double

rl3_fact_get_annotation_start

unsigned int rl3_fact_get_annotation_start(struct RL3_Engine* engine, struct RL3_Fact* fact);

Get the start position of fact annotation.

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: integer (measured in Unicode characters, not bytes)

rl3_fact_get_annotation_end

unsigned int rl3_fact_get_annotation_end(struct RL3_Engine* engine, struct RL3_Fact* fact);

Get the end position of fact annotation.

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: integer (measured in Unicode characters, not bytes)

rl3_fact_has_factsheet

unsigned char rl3_fact_has_factsheet(struct RL3_Engine* engine, struct RL3_Fact* fact);

Check whether a fact contains a factsheet.

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: 1 if a fact contains a factsheet, 0 if otherwise

rl3_fact_get_factsheet

struct RL3_Factsheet* rl3_fact_get_factsheet(struct RL3_Engine* engine, struct RL3_Fact* fact);

Get a factsheet from a fact.

engine: a pointer to an engine structure
fact: a pointer to a fact structure
Returns: a pointer to a factsheet structure; if a fact does not contain a factsheet, the function creates and returns an empty factsheet to which facts can be further asserted.

rl3_fact_to_json

const char* rl3_fact_to_json(RL3_Engine* engine, RL3_Fact* fact, RL3_SharedText* root_text, unsigned char include_text);

Save Fact as JSON string.

engine: a pointer to an engine structure
fact: a pointer to a fact structure to be serializer
root_text: NULL if fact should be considered as independent / self-containing structure.
include_text 1 if text field should be included in the output; 0 otherwise.
Returns: a pointer to the first character in the return string.

rl3_fact_from_json

RL3_Fact* rl3_fact_from_json(RL3_Engine* engine, const char* json, RL3_SharedText* root_text);

Restore Fact from JSON string.

engine: a pointer to an engine structure
json: input json string (zero terminated).
root_text: NULL if fact should be considered as independent / self-containing structure.
Returns: a pointer to a new fact structure.