Python API reference

Module functions

FunctionReturnsDescription
describe(df)strGives the structure of a Polars DataFrame.
print_info(df)NoneWrites the structure of a Polars DataFrame to the standard output.
to_turtle(df, base_url, row_stem)strConverts a Polars DataFrame to Turtle.

Class Rumo

Rumo(rules=None, rules_file=None, data=None, data_file=None, *,
     format=None, resource=None, predicate=None,
     base_url="http://example.org/", row_stem="r")

Methods

MethodReturnsDescription
read_rules_str(rules)NoneLoads the rule program from a string.
read_rules_file(path)NoneLoads the rule program from a file.
read_dataframe(df, resource=None, predicate=None, base_url="http://example.org/", row_stem="r")NoneLoads a pandas DataFrame or a Polars DataFrame.
read_data_str(data, format="turtle", resource=None, predicate=None)NoneLoads data from a string.
read_data_file(path, format=None, resource=None, predicate=None)NoneLoads data from a file.
reset_rules()NoneRemoves the rule program.
reset_data()NoneRemoves all data.
run(params=None, predicates=None)RumoResultsRuns the rules on the data.

Properties

PropertyTypeDescription
resourceslist[str]The resource names of the loaded data.

Default resource names

MethodDefault resource name
read_dataframedata.ttl
read_data_strdata.ttl
read_data_fileThe file name, for example sample.ttl

Class RumoResults

In this table, predicate is optional if the results have only one predicate.

MethodReturnsDescription
predicates()list[str]The names of the predicates.
columns(predicate=None)list[str]The column names of a predicate.
rows(predicate=None)list[tuple]The facts as tuples.
to_dicts(predicate=None, columns=None)list[dict]The facts as dictionaries.
to_pandas(predicate=None, columns=None)pandas.DataFrameThe facts as a pandas DataFrame.
to_polars(predicate=None, columns=None)polars.DataFrameThe facts as a Polars DataFrame.
to_dict()dict[str, list[dict]]All facts of all predicates.
results[predicate]list[dict]The facts as dictionaries.
predicate in resultsboolTrue if the predicate is in the results.
len(results)intThe number of predicates.
iter(results)iteratorThe names of the predicates.

Exceptions

ExceptionCause
ValueErrorAn argument is not correct, or there are no rules.
KeyErrorA predicate is not in the results.
RuntimeErrornemo cannot parse or run the rules.
OSErrorRumo cannot read a file.
ImportErrorpandas is not installed and you call to_pandas.