-
Notifications
You must be signed in to change notification settings - Fork 11
Project Architecture Overview
The Metta language processing system incorporates the Atomspace blackboard as its central knowledge representation and storage component. Atomspace, associated with OpenCog, is a powerful framework for storing symbolic structures—atoms—that represent concepts, code, or data. This integration allows for a flexible and semantic representation of knowledge, code, and logic within the system, making it more collaborative and decentralized.
Below is a detailed description of the MeTTa language system architecture, organized into major components and subcomponents. Each file is linked for easy navigation.
Purpose: Handles the initial processing of MeTTa source code, including parsing and syntactic analysis, converting code into internal representations for further processing.
-
Parser
-
Files:
-
metta_parser.pl
: Parses MeTTa source code into abstract syntax trees (ASTs) or other internal representations. -
metta_convert.pl
: Converts parsed structures into formats suitable for evaluation or compilation.
-
-
Functionality:
- Lexical analysis (if included within the parser).
- Syntax checking and validation.
- Generation of ASTs.
-
Files:
Purpose: Provides foundational functions, definitions, and constructs essential for MeTTa programs and logical reasoning.
-
Core Libraries
-
MeTTa Core Library
-
corelib.metta
: Core language constructs and standard functions written in MeTTa. -
corelib.metta.buffer~
: Backup file forcorelib.metta
.
-
-
Prolog Core Library
-
metta_corelib.pl
: Core predicates and functions implemented in Prolog to support MeTTa operations.
-
-
MeTTa Core Library
-
Standard Libraries
-
MettaLog Standard Library
-
stdlib_mettalog.metta
: Standard predicates and functions for logical reasoning in MettaLog. -
stdlib_mettalog.metta.buffer~
: Backup file forstdlib_mettalog.metta
.
-
-
MettaLog Standard Library
Purpose: Translates MeTTa code into executable form and executes it, either by compiling or interpreting.
-
Compiler
-
Files:
-
metta_compiler.pl
: Compiles MeTTa code into an executable or intermediate form. -
metta_comp_templates.pl
: Templates used during the compilation process for code generation.
-
-
Functionality:
- Code optimization.
- Bytecode or machine code generation (if applicable).
-
Files:
-
Interpreter
-
Files:
-
metta_interp.pl
: Main interpreter integrating parsing and evaluation for executing MeTTa code. -
metta_eval.pl
: Evaluates the internal representations of MeTTa code.
-
-
Functionality:
- Direct execution of MeTTa code.
- Managing the execution context and environment.
-
Files:
Purpose: Manages the execution context, including variable scopes, data storage, and runtime utilities.
-
Execution Space
-
metta_space.pl
: Defines workspaces, scopes, and variable bindings.
-
-
Substitution and Pattern Matching
-
metta_subst.pl
: Handles variable substitution and pattern matching operations.
-
-
Type System
-
metta_types.pl
: Implements the type system and type-checking mechanisms.
-
-
Persistence
-
metta_persists.pl
: Manages saving and loading of program states and data.
-
-
Concurrency
-
metta_threads.pl
: Provides threading and concurrency support.
-
Purpose: Facilitates interactive execution of MeTTa code, allowing users to input commands and receive immediate feedback.
-
REPL Implementation
-
metta_repl.pl
: Implements the interactive shell environment in Prolog.
-
-
Default REPL Script
-
repl.default.metta
: Default script defining REPL behaviors and startup routines.
-
Purpose: Provides tools for developers to debug and test MeTTa programs, ensuring reliability and correctness.
-
Debugging Tools
-
metta_debug.pl
: Utilities for tracing execution, inspecting variables, and logging.
-
-
Testing Framework
-
metta_testing.pl
: Contains test cases and frameworks for validating language features.
-
Purpose: Enhances MeTTa with logic programming capabilities, allowing for advanced reasoning and knowledge representation.
-
Ontology Management
-
metta_ontology.pfc.pl
: Represents and manipulates ontologies using Prolog Forward Chaining.
-
-
Prolog Forward Chaining Support
-
metta_pfc_base.pl
: Base definitions for PFC integration. -
metta_pfc_support.pl
: Additional utilities supporting PFC operations.
-
Purpose: Enables interoperability between MeTTa and Python, allowing MeTTa code to utilize Python libraries and functions.
-
Integration Layer
-
metta_python.pl
: Facilitates calls between MeTTa and Python within Prolog.
-
-
Python Overrides and Patching
-
metta_python_override.py
: Overrides Python behaviors for integration. -
metta_python_override_new.py
: Updated version with enhancements. -
metta_python_patcher.py
: Modifies Python code for compatibility.
-
-
Python Proxy
-
metta_python_proxy.py
: Manages communication and data exchange between MeTTa and Python.
-
Purpose: Allows MeTTa to operate as a server or service, handling network connections and client requests.
-
Server Implementation
-
metta_server.pl
: Sets up the server environment for network interactions.
-
Purpose: Provides general-purpose functions and support for the MeTTa system, ensuring smooth operation across different platforms.
-
Utility Functions
-
metta_utils.pl
: Commonly used helper predicates and functions.
-
-
Output Formatting
-
metta_printer.pl
: Manages how data structures and results are formatted and displayed.
-
-
SWI-Prolog Support
-
swi_support.pl
: Ensures compatibility with SWI-Prolog-specific features.
-
Purpose: Handles the startup routines, configuration settings, and loading of necessary modules when MeTTa is launched.
-
Initialization Scripts
-
init.default.metta
: Default initialization script for setting up the environment.
-
-
Loader
-
metta_loader.pl
: Manages the loading of MeTTa files and dependencies.
-
To better understand how these components interact within the MeTTa system, here's a high-level flow of operations:
-
Startup and Initialization
- The system begins by executing
init.default.metta
, which sets up the initial environment. - Necessary modules and core libraries (
corelib.metta
,metta_corelib.pl
) are loaded usingmetta_loader.pl
.
- The system begins by executing
-
User Interaction via REPL or Script Execution
- If the user engages with MeTTa interactively,
metta_repl.pl
andrepl.default.metta
handle inputs and outputs. - For script execution, the interpreter processes MeTTa files directly.
- If the user engages with MeTTa interactively,
-
Parsing Source Code
- Source code is fed into
metta_parser.pl
, which parses it into internal representations. -
metta_convert.pl
may further process these representations for compatibility with the evaluator or compiler.
- Source code is fed into
-
Compilation or Interpretation
-
Compilation Path:
-
metta_compiler.pl
compiles the code, using templates frommetta_comp_templates.pl
.
-
-
Interpretation Path:
-
metta_interp.pl
usesmetta_eval.pl
to evaluate the parsed code directly.
-
-
Compilation Path:
-
Runtime Execution
- The runtime environment (
metta_space.pl
,metta_subst.pl
,metta_types.pl
) manages variable scopes, type checking, and pattern matching during execution. - Concurrency support is provided by
metta_threads.pl
if needed.
- The runtime environment (
-
Utilizing Core Libraries and Extensions
- Core functions from
corelib.metta
andmetta_corelib.pl
are available throughout execution. - Logic programming features are accessed via
metta_ontology.pfc.pl
,metta_pfc_base.pl
, andmetta_pfc_support.pl
. - Python interoperability is handled by the
metta_python
suite of files.
- Core functions from
-
Output and Feedback
- Results and outputs are formatted by
metta_printer.pl
and displayed to the user. - Debugging information (if enabled) is provided by
metta_debug.pl
.
- Results and outputs are formatted by
-
Persistence and State Management
-
metta_persists.pl
allows the saving and loading of program states as needed.
-
-
Server Operations
- If running in server mode,
metta_server.pl
manages client connections and request handling.
- If running in server mode,
Below is a textual representation of the MeTTa system architecture, showing the relationships between components:
[ User Interface ]
|
V
[ REPL (metta_repl.pl) ] -- [ REPL Script (repl.default.metta) ]
|
V
[ Parser (metta_parser.pl) ] -- [ Converter (metta_convert.pl) ]
|
V
[ Interpreter (metta_interp.pl) ] -- [ Compiler (metta_compiler.pl) ]
| |
V V
[ Evaluator (metta_eval.pl) ] [ Compilation Templates (metta_comp_templates.pl) ]
|
V
[ Runtime Environment ]
|
|-- [ Execution Space (metta_space.pl) ]
|-- [ Substitution (metta_subst.pl) ]
|-- [ Type System (metta_types.pl) ]
|-- [ Concurrency (metta_threads.pl) ]
|
[ Core Libraries ]
|
|-- [ corelib.metta ]
|-- [ metta_corelib.pl ]
|
[ Extensions and Integrations ]
|
|-- [ Logic Programming ]
| |-- [ metta_ontology.pfc.pl ]
| |-- [ metta_pfc_base.pl ]
| |-- [ metta_pfc_support.pl ]
|
|-- [ Python Integration ]
|-- [ metta_python.pl ]
|-- [ metta_python_override.py ]
|-- [ metta_python_patcher.py ]
|-- [ metta_python_proxy.py ]
The MeTTa language system is structured to facilitate ease of use, extensibility, and powerful features for logical reasoning and interoperability. Here's a brief recap:
- Front-End: Parses and prepares code for execution.
- Core Libraries: Provide essential functions and definitions.
- Interpreter/Compiler: Execute or compile code for running programs.
- Runtime Environment: Manages execution contexts and supports runtime features.
- REPL: Offers an interactive environment for code execution.
- Debugging/Testing: Tools for ensuring code correctness.
- Extensions: Enhances MeTTa with logic programming and Python interoperability.
- Server Support: Allows MeTTa to function as a networked service.
- Utilities: Additional support functions and compatibility layers.
- Initialization: Handles startup routines and environment setup.
Note: The descriptions and architecture are based on standard naming conventions and typical functionalities associated with similar files in programming language implementations. For precise implementation details, please refer to the actual source code and official documentation.
The other directories and files in the project provide additional functionality and support. Each top-level directory is expandable, and the link is provided outside the spoiler.
src
: Main Source Code of the Project
Click to expand the src
directory contents.
src/ext
: External Modules Interfacing with External Libraries
These modules provide integration with external libraries and tools, extending the capabilities of the Metta system.
-
bhv_binding.py
: Implements behavior bindings, potentially for integrating AI behavior models. -
dasgate.py
: Gateway to the Distributed Annotation System (DAS), used for accessing and integrating biological data. -
kwargsme.py
: Experiments with PyTorch keyword arguments, potentially for machine learning applications. -
metta_repl.py
: Interactive REPL for Metta written in Python, providing an alternative interface. -
neurospace.py
: Defines neural spaces for simulations, aiding in neural network modeling. -
numme.py
: Numerical experiments using NumPy, supporting mathematical computations. -
parse_torch_func_signatures.py
: Parses PyTorch function signatures, facilitating integration with PyTorch. -
parsing_exceptions.py
: Handles parsing exceptions, improving error handling during code parsing. -
r.py
: Utility script for resolution tasks, possibly related to logic programming. -
resolve.py
: Implements resolution logic, essential for logical inference mechanisms. -
sql_space.py
: Provides SQL space integration, enabling database interactions. -
tm_test.py
: Test script for PyTorch models, useful for machine learning development. -
torchme.py
: Script interfacing with PyTorch, aiding in deep learning tasks.
src/main
: Contains the Last Known Good Version of the Source Code
This directory holds a stable version of the source code, ensuring that a working copy is available for reference or rollback.
src/metta_jupyter_kernel.py
: Implements a Jupyter Kernel for the Metta Language
Allows Metta code to be executed within Jupyter notebooks, facilitating interactive development and data analysis.
src/mettalog
: Python Metta Logic Library for Logical Reasoning
This library provides logical reasoning capabilities within the Metta environment.
-
logic.py
: Core logic functions that implement fundamental logical operations. -
reasoning.py
: Reasoning algorithms that enable inference and deduction. -
utils.py
: Utility functions supporting the logic library.
docs
: Contains Project Documentation, Including User Guides and API References
Contents
-
user_guide.md
: Comprehensive guide for users, covering installation, usage, and best practices. -
api_reference.md
: Detailed API documentation, outlining functions, classes, and modules. -
developer_guide.md
: Guidelines for developers contributing to the project, including coding standards and development workflows.
setup.py
: Build Script Specifying How to Package and Install Project Components
This script ensures that the project components are correctly packaged and installed, managing dependencies and configurations.
notebooks
: Contains Jupyter Notebooks for Experimentation and Data Analysis
Contents
-
experiment1.ipynb
: Analysis of dataset X, showcasing data processing capabilities. -
visualization.ipynb
: Data visualization examples, illustrating how to create visual representations of data. -
from_das
: Demonstrations of data retrieval from the Distributed Annotation System (DAS).-
das_example.ipynb
: Using DAS data, demonstrating how to access and utilize biological data.
-
-
images
: Visual assets used in notebooks, such as charts and diagrams.
scripts
: Utility Scripts for Data Processing, Testing, and Environment Setup
Files
-
Defragmenter.py
: Defragments data files for optimization, improving performance. -
generate_allure_environment.py
: Generates configurations for Allure reports, aiding in test reporting. -
generate_allure_executor.py
: Creates executor configurations for Allure, facilitating test execution tracking. -
into_junit.py
: Converts test results into JUnit format, standardizing test reporting.
library
: Reusable Code Modules and Libraries
Click to expand the library
directory contents.
graphml
: Scripts Related to the GraphML Format
-
ext_loader_graphml.pl
: Parses GraphML files, enabling the import of graph data. -
tests
: Test cases for the GraphML loader, ensuring correct functionality.
genome
: Prolog Scripts for Genomic Data Processing
Modules focused on processing genomic data, integrating with bioinformatics databases.
-
chado_xml_loader.pl
: Loads genomic data from Chado XML files, used in biological databases. -
das_classic_loader.pl
: Loads data using the DAS classic protocol, facilitating access to genomic annotations. -
ext_loader_csv.pl
: Loads data from CSV files, a common format for biological data. -
ext_loader_fasta.pl
: Loads sequences from FASTA files, essential for genetic sequence data. -
ext_loader_gff.pl
: Parses GFF files, another format for genomic annotations. -
ext_loader_json.pl
: Processes genomic data in JSON format. -
ext_loader_obo.pl
: Handles OBO files, used for ontologies in biology. -
ext_loader_tsv.pl
: Loads data from TSV files. -
flybase_convert.pl
: Converts FlyBase data, a database of Drosophila genetics. -
flybase_induced_types.pl
: Generates induced types from FlyBase data, aiding in data classification. -
flybase_learn.pl
: Implements learning algorithms using FlyBase data. -
flybase_loader.pl
: Loads FlyBase data into the system. -
flybase_main.pl
: Main entry point for processing FlyBase data. -
flybase_scheme.pl
: Defines data structures for FlyBase data.
tests
: Various Test Suites to Ensure Correctness and Stability
Test Suites
-
baseline_compat
: Tests for baseline compatibility, ensuring fundamental functionalities work as expected. -
compiler_baseline
: Tests for compiler baseline functionality. -
direct_comp
: Tests for direct compilation processes without intermediate steps. -
extended_compat
: Tests for compatibility with extended features and modules. -
features
: Tests focused on specific features of the Metta language and system. -
flybase
: Tests related to the processing of FlyBase data. -
more-anti-regression
: Additional regression tests to catch unintended changes. -
nars_interp
: Tests for the NARS (Non-Axiomatic Reasoning System) interpreter integration. -
nars_w_comp
: Tests for NARS with compiler integrations, ensuring reasoning capabilities. -
performance
: Performance measurement tests to benchmark system efficiency. -
python_compat
: Tests for Python compatibility, verifying the integration between Metta and Python. -
timing
: Scripts and tests focused on measuring execution times and performance metrics.
This detailed overview provides an in-depth look into the architecture and workflow of the Metta language processing system. Starting from the REPL interface, which allows users to interact with the interpreter and load files, the system efficiently manages code addition, parsing, forward chaining for logical inference, compilation, and execution. The inclusion of utilities and support modules enhances the system's capabilities, offering integration with external languages like Python and providing tools for debugging and testing.
Understanding each component's role and how they interact enhances appreciation of the system's workflow and capabilities. This comprehensive guide serves as a valuable resource for both users and developers navigating and utilizing the Metta language processing system.
For further clarification, refer to the docs
directory or contact the development team.