The glossary API reference

Copyright 2020 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.

class glossary.Glossary(glossary_dict: dict)[source]

The Glossary object contains all types, functions and predicates. During initialisation, it reads and interprets all the types, functions, constants, relations and booleans it can find and it reports any errors. Once the Glossary is created and initialized without errors, it’s possible to print out the predicates in their IDP version.

add_aux_var(aux)[source]

Some variables need to use auxiliary variables, for instance those found in the outputcolumns of C# tables. This method allows the creation of those variables. No aux var are created when makin an IDP file for the autoconfig interfaces.

:arg List<str> a list containing strings of the variables.

contains(typestr)[source]

Checks whether or not a type was already added to the glossary.

Returns bool:

True if the type has been added already.

find_type(t)[source]

Looks for types in the glossary.

Returns List<Type>:

the types found.

lookup(string: str)[source]

TODO REWORK ENTIRE METHOD.

read_datatables(datatables, parser)[source]

Reads and interprets the datatables. Also checks if the values in the datatables appear in the possible values column of the glossary.

Firstly it checks which columns are input, and which are output. A column is an inputcolumn if it contains the table title in the first cell, and an output if it contains None in the first cell.

Iterates over every outputcolumn, deciphers which predicate the outputcolumn represents, and sets its “struct_args” to a combination of the input arguments and the output column’s arguments. The predicate uses this struct_args to format its struct string.

Parameters:
  • List<np.array> – datatables, containing all the datatables.

  • parser

Returns None:

to_idp_voc()[source]

Function which turns every object in a glossary into their vocabulary definitions.

Returns voc:

string

to_json_dicts()[source]

Creates a dict entry for every predicate and function, which is later turned into json.

Returns dict:

class glossary.Predicate(name: str, args: List[Type], super_type: Type, partial=False, full_name=None, zero_arity=False)[source]

Class which represents both predicates and functions. This double meaning is a relic of the past, and is to be fixed. In the future, a separate Function class should be created.

property arity

Returns arity of the symbol’s domain.

Returns int:

static from_string(full_name: str, predicate: bool, super_type: Type, glossary: Glossary, partial=False, zero_arity=False)[source]

Static method to create a predicate from string.

Parameters:
  • str – full_name, the full name.

  • bool – predicate, true if predicate, false if function.

  • Type – super_type, the super type of the predicate.

  • Glossary – glossary, the glossary.

  • bool – partial, whether or not it’s a partial function.

  • zero_arity – bool which should be True when the predicate is a 0-arity predicate (constants and booleans).

Returns Predicate:

interpret_name()[source]

Method to interpret the name. This method forms a generic name representation, by replacing the arguments by dummies. In this way, it creates a skeleton structure for the name.

Thus, it returns the name, without the arguments. For instance, Country borders Country becomes (?P<arg0>.+) borders (?P<arg1>.+). This way, arg0 and arg1 can be found easily later on.

is_function()[source]

Method to check whether the predicate is a function. Since only functions have super types, we use that as a check. Note that constants are a special case of functions.

Returns boolean:

is_relation()[source]

Method to check whether the predicate is a relation. A predicate is either a relation or a function, so we use that as a check. Note that booleans are a special case of relations.

Returns boolean:

lookup(string: str)[source]

Method to compare a string to this predicate, to see if the predicate appears in the string in any form. TODO: make this more clear.

to_idp_struct()[source]

If a function or predicate receives a value in a datatable, we need to set it’s values in the structure. When parsing the datatable in “read_datatables”, we set the “struct_args” of the predicates/functions that get a value. struct_args could look like: {key1|key2:value}. However, it’s possible to input multiple keys per cell to save space.

For instance: “Jim|Skydiving, Soccer” needs to be formatted as “Jim, Skydiving; Jim, Soccer”. The same goes for functions.

To achieve this, we split the keys on their seperator, and then we split each key on a comma. This way, we have an array of keys in which each item is an array of subkeys. We need to form every possible combination of these keys, and to do this we use itertools.product.

Returns:

str

to_idp_voc()[source]

Convert the predicate/function to a string for the IDP vocabulary.

Returns str:

the predicate/function in vocabulary format.

class glossary.Type(name: str, super_type, posvals='-')[source]

TODO

property basetype

The basetype represents one of the ancestor types, such as int or str.

Returns type:

the basetype.

check_values(values, tablename)[source]

Method to check if the values listed in a datatable match with the values listed in the possible values column(if a datatable was used).

If the possible values column is left empty, then it assumes all the values are correct and it fills the possible values automatically. This is needed so that the type can input these values into constructed from.

If the possible values column contains values, then every value used in a datatable needs to match a value in the possible values.

Returns boolean:

True if all the values match.

Throws ValueError:

if a value appears in the datatable but not in posvals.

to_idp_struct()[source]

Converts all the information of the Type into a string for the IDP structure. Normal types don’t need a structure, as their possible values are listed as “constructed from” in the voc. This is here for future’s sake.

Returns str:

the string for the structure.

to_idp_voc()[source]

Converts all the information of the Type into a string for the IDP vocabulary.

Returns str:

the vocabulary form of the type.

to_theory()[source]

TODO