Skip to content

API

The meta_tools project.

log = logging.getLogger(__name__) module-attribute

Context

Context for grounding with extensions. Includes functions that can be called as external python function via @

ReifyExtension

Base class for reification extensions. Should be inherited by all extensions.

add_extension_encoding(ctl: Control) -> None

Add the extension's encoding to the given control object. This control object is used to obtain the reification Arguments


ctl Target control object.

additional_symbols() -> List[Symbol]

Gives a list of additional symbols to be added to the reification. Returns: List[Symbol]: The list of additional symbols.

register_options(parser: _ArgumentGroup) -> None

Register the extensions's options to the parser for command line usage

Arguments

parser: _ArgumentGroup Target argument group to register with.

transform(file_paths: List[str], program_string: str) -> str

Transforms a list of files and a program string and returns a string with the transformation

Note: I have it as a general function so that it can use something other than a transformer, like ASPEN Note: Having it like this implies multiple passes over the program

Parameters:

Name Type Description Default
file_paths List[str]

The list of file paths to process.

required
program_string str

The program string to process.

required

Returns:

Name Type Description
str str

The transformed program string.

update_context(context: object) -> None

Update the given context with any methods needed by the extension. Arguments


context Target context to update.

visit_ast(ast: AST) -> AST

Handle the given AST node and return the transformed AST node. Can be implemented using a transformer.

classic_reify(ctl_args: List[str], program_string: str, programs: Optional[Sequence[tuple[str, Sequence[Symbol]]]] = None) -> List[Symbol]

Reify the given program string using classic reification.

Parameters:

Name Type Description Default
ctl_args List[str]

The list of control arguments.

required
program_string str

The program string to reify.

required
programs Optional[Tuple[str, List[str]]]

The list of programs to ground. By default is [("base", [])].

None

Returns: List[Symbol]: The list of symbols defining the reification.

extend_reification(reified_out_prg: str, extensions: List[ReifyExtension], clean_output: bool = True) -> str

Extend the reification with the given extensions. It calls clingo with the reified program and the extension encodings.

Parameters:

Name Type Description Default
reified_out_prg str

The reified output program.

required
extensions List[ReifyExtension]

The list of extensions to apply.

required
clean_output bool

Whether to clean the output by hiding non-essential atoms. Defaults to True.

True

Returns:

Name Type Description
str str

The extended reified program.

transform(file_paths: List[str], prg: str = '', extensions: Optional[List[ReifyExtension]] = None) -> str

Transform the given files using the provided extensions.

Parameters:

Name Type Description Default
file_paths List[str]

The list of file paths to transform.

required
extensions List[ReifyExtension]

The list of extensions to use for transformation.

None

Returns:

Name Type Description
str str

The transformed program string.

__main__

The main entry point for the application.

main() -> None

Run the main function.

extensions

Basic tools for meta programming with Answer Set Programming (ASP).

ReifyExtension

Base class for reification extensions. Should be inherited by all extensions.

add_extension_encoding(ctl: Control) -> None

Add the extension's encoding to the given control object. This control object is used to obtain the reification Arguments


ctl Target control object.

additional_symbols() -> List[Symbol]

Gives a list of additional symbols to be added to the reification. Returns: List[Symbol]: The list of additional symbols.

register_options(parser: _ArgumentGroup) -> None

Register the extensions's options to the parser for command line usage

Arguments

parser: _ArgumentGroup Target argument group to register with.

transform(file_paths: List[str], program_string: str) -> str

Transforms a list of files and a program string and returns a string with the transformation

Note: I have it as a general function so that it can use something other than a transformer, like ASPEN Note: Having it like this implies multiple passes over the program

Parameters:

Name Type Description Default
file_paths List[str]

The list of file paths to process.

required
program_string str

The program string to process.

required

Returns:

Name Type Description
str str

The transformed program string.

update_context(context: object) -> None

Update the given context with any methods needed by the extension. Arguments


context Target context to update.

visit_ast(ast: AST) -> AST

Handle the given AST node and return the transformed AST node. Can be implemented using a transformer.

base_extension

Base class for reification extensions. Should be inherited by all extensions.

ReifyExtension

Base class for reification extensions. Should be inherited by all extensions.

add_extension_encoding(ctl: Control) -> None

Add the extension's encoding to the given control object. This control object is used to obtain the reification Arguments


ctl Target control object.

additional_symbols() -> List[Symbol]

Gives a list of additional symbols to be added to the reification. Returns: List[Symbol]: The list of additional symbols.

register_options(parser: _ArgumentGroup) -> None

Register the extensions's options to the parser for command line usage

Arguments

parser: _ArgumentGroup Target argument group to register with.

transform(file_paths: List[str], program_string: str) -> str

Transforms a list of files and a program string and returns a string with the transformation

Note: I have it as a general function so that it can use something other than a transformer, like ASPEN Note: Having it like this implies multiple passes over the program

Parameters:

Name Type Description Default
file_paths List[str]

The list of file paths to process.

required
program_string str

The program string to process.

required

Returns:

Name Type Description
str str

The transformed program string.

update_context(context: object) -> None

Update the given context with any methods needed by the extension. Arguments


context Target context to update.

visit_ast(ast: AST) -> AST

Handle the given AST node and return the transformed AST node. Can be implemented using a transformer.

utils

Utilities.

logging

Setup project wide loggers.

This is a thin wrapper around Python's logging module. It supports colored logging.

SingleLevelFilter

Bases: Filter

Filter levels.

colored(color: str, s: str) -> str

Returns the string colored by the given color.

Parameters:

Name Type Description Default
color str

A color name: GREY, BLUE, GREEN, YELLOW, RED

required

configure_logging(stream: TextIO, level: int, use_color: bool) -> None

Configure application logging.

get_logger(name: str) -> logging.Logger

Get a logger with the given name.

parser

The command line parser for the project.

get_parser() -> ArgumentParser

Return the parser for command line options.

theory

Utility functions for theory handling.

extend_with_theory_symbols(symbols: List[Symbol]) -> None

Add theory symbols to the given list of symbols.

The theory symbols are represented using clingo's clingo.Symbol class.

Parameters:

Name Type Description Default
symbols List[Symbol]

The list of symbols to extend.

required

visualization

Visualization utilities for meta_tools using clingraph.

visualize_reification(reified_out_prg: str, open_browser: bool = False) -> None

Visualize the reification using clingraph. Args: reified_out_prg (str): The reified program. open_browser (bool, optional): Whether to open the generated file. Defaults to False.