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[numpy.array], parser: cdmn.idply.Parser) Dict[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.

Parameters:
  • 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: cdmn.idply.Parser) str[source]

Function which creates the main for the IDP file.

Parameters:
  • 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[numpy.array], parser: cdmn.idply.Parser, glossary: cdmn.glossary.Glossary) 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.

Parameters:
  • 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[numpy.array], parser: cdmn.idply.Parser) str[source]

Function to create the theory in the IDP format.

Parameters:
  • tables – the list of arrays, each containing a table.

  • parser – the parser.

Returns str:

the theory for the IDP file.

table_operations.create_voc(glossary)[source]

Function which creates the vocabulary for the IDP file.

Parameters:

glossary

Returns str:

the vocabulary for the IDP file.

table_operations.explore(sheet: List[numpy.array], boundaries: List[int])[source]

Tries to find the ranges for each table.

Parameters:
  • 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 = None) List[numpy.array][source]

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

Parameters:
  • 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[numpy.array], parser: cdmn.idply.Parser) 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[numpy.array]) numpy.array[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[numpy.array]) 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: numpy.array) tuple[source]

TODO

Parameters:

sheet – the sheet

table_operations.find_glossary(tables: List[numpy.array]) Dict[str, numpy.array][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[numpy.array], name: str, critical: bool = False) numpy.array[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.

Parameters:
  • 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[numpy.array]) List[numpy.array][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_hp(tables, hp)[source]

Looks for tables based on a regex expression representing their hit policy.

Parameters:
  • np.array – the tables.

  • str – the hit policy, in regex.

Returns List<np.array>:

the tables found.

table_operations.find_tables_by_name(tables, name)[source]

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

Parameters:
  • 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[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[numpy.array]) List[numpy.array][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[numpy.array], check_error: str, target_error, rule_error=None, deps=[]) List[numpy.array][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).

Parameters:
  • 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