The table_operations API reference

Copyright 2019 Simon Vandevelde, Bram Aerts, Joost Vennekens This code is licensed under GNU GPLv3 license (see LICENSE) for more information. This file is part of the cDMN solver.

table_operations.create_dependency_graph(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbd582e0>], parser: <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07100>) → Dict[KT, VT][source]

Function to create dependency graph of variables. Basically, we check for every output of a decision table what the inputs are. The outputs depend on these inputs. By doing this for every table, we can build a graph of what knowledge depends on what other knowledge.

  • tables – the list of arrays, each containing a table.
  • parser – the parser.
Returns str:

the theory for the IDP file.

table_operations.create_display(goal_var: List[str]) → str[source]

Format the display block for a DMN specification.

table_operations.create_main(inf: Dict[str, object], parser: <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07100>) → str[source]

Function which creates the main for the IDP file.

  • inf – a dictionary containing the inference method and it’s applicable variables (e.g. what the term looks like, or how many models should be generated)
  • parser – the parser, needed to parse the optimization term.
Returns str:

the main for the IDP file.

table_operations.create_struct(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc059a0>], parser: <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07100>, glossary: <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07460>) → str[source]

The structure consists of data supplied by data tables.

The data inside data tables is interpreted and set as “struct_args”. “struct_args” is then used in the to_idp_struct() method to form the structure.

  • tables – the list of arrays, each containing a table.
  • parser – the parser to read the headers of data tables.
  • glossary – the glossary
Returns str:

the structure for the IDP file.

table_operations.create_theory(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05af0>], parser: <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07100>) → str[source]

Function to create the theory in the IDP format.

  • tables – the list of arrays, each containing a table.
  • parser – the parser.
Returns str:

the theory for the IDP file.


Function which creates the vocabulary for the IDP file.

Returns str:the vocabulary for the IDP file.
table_operations.explore(sheet: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07880>], boundaries: List[int])[source]

Tries to find the ranges for each table.

  • sheet – the sheet containing all the tables.
  • bounaries – a list containing the theoretic boundaries.
Returns None:
table_operations.fill_in_merged(file_name: str, sheet_names: List[str] = None) → List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07b20>][source]

Loads up a specific sheet and returns it. A sheet is comprised of a list of tables.

  • file_name – path to the xlsx file.
  • sheet – name of the sheet to load in.
Returns List<np.array>:

a list of all the tables in a sheet.

table_operations.find_auxiliary_variables(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbd58040>], parser: <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07100>) → List[str][source]

Due to a bug in the IDP systems, the variables in a C# table each need to use an auxiliary variable to function properly. This has the same name as the variable, but preceded with an underscore.

This function gets the auxiliary variables for every table.

table_operations.find_datatables(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05ac0>]) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05f70>[source]

Locates the Datatable, which contains data that needs to be expressed in the structure or our idp file.

Parameters:tables – the list of arrays, each containing a table.
Returns np.array:
 containing the datatable
table_operations.find_execute_method(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05700>]) → Dict[str, object][source]

Locates the Goal table, which contains the inference method. There are four possible inference methods:

  • “get x models”, where x is the number of required models;
  • “get all models”, in order to get all models;
  • “minimize x”, where x is a term to minimize;
  • “maximize x”, where x is a term to maximize.
Parameters:tables – the list of arrays, each containing a table.
Returns Dict[str, str]:
 contains the inference method and its applicable variables.
table_operations.find_first(sheet: <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07610>) → tuple[source]


Parameters:sheet – the sheet
table_operations.find_glossary(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05dc0>]) → Dict[str, <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05e80>][source]

Locates the glossarytables, and places them in a dictionary for each type. The five tables it looks for are:

  • Type
  • Function
  • Constant
  • Relation
  • Boolean
Returns Dict[str, np.array]:
 containing the glossary for type, function,

constant, relation and boolean.

table_operations.find_glossary_table(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05430>], name: str, critical: bool = False) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05b20>[source]

Looks for a specific glossary table with name “name”.

If the critical boolean is set, an error is returned when no glossary is found. For example, there should always be a type glossary. Non-critical glossaries only print warnings when none are found.

  • tables – the list of arrays, each containing a table.
  • name – the name of the table to find.
  • critical – True if a table needs to be found. E.g. if the table is not found, an error is thrown.
Returns np.array:

the glossary table, if found.

table_operations.find_tables(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05b80>]) → List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05820>][source]

Looks for decision tables and constraint tables.

Parameters:tables – the list of arrays, each containing a table.
Returns List[np.array]:
 a list containing only the decision and constraint tables.
table_operations.find_tables_by_name(tables, name)[source]

Looks for tables based on a regex expression representing their name.

  • np.array – the tables.
  • str – the name, in regex.
Returns List<np.array>:

the tables found.

table_operations.get_dependencies(variable, dependency_graph, level=0, downstream=False) → Dict[KT, VT][source]

If downstream is False, then the function returns all the upstream dependencies, i.e., the variables that need to have values before the variable’s value can be set.

If downstream is set to True, it does the opposite: it returns all the upstream dependencies, i.e. the variables that depend on this variable’s value.

table_operations.identify_tables(sheets: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07d60>]) → List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbb07d30>][source]

Function which looks for all the tables in a given sheet. Creates a list of boundaries for the tables.

Parameters:sheets – a list containing a numpy array representing the sheet.
Returns List[np.array]:
 containing boundaries of all the tables.
table_operations.replace_with_error_check(tables: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05790>], check_error: str, target_error, rule_error=None, deps=[]) → List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f66cbc05b50>][source]

Replaces a model by one for error checking. There are three types of errors which can be checked for errors:

  • Overlap in the inputs (multiple rules fire for same input).
  • Gaps in the inputs (input for which no rules applies).
  • Shadowed rules (rules which can never fire).
  • tables – the list of arrays, each containing a table.
  • target_error – the table which we want to find.
  • check_error – the type of error check to do.
  • rule_error – the rule to check for errors. Only for shadowed.
Returns List[np.array]:

a list containing only the decision and constraint