### MeTTa DSL Graph Traversal Examples Source: https://github.com/trueagi-io/metta-examples/blob/main/traverser/README.md Illustrates practical usage of the MeTTa Gremlin-like DSL for common graph traversal operations, such as selecting all vertices, specific vertices, retrieving properties, and filtering results. ```MeTTa ; g.V() !(V) ; g.V(1) !(V 1) ; g.V(1).values('name') !(values name (V 1)) ; g.V(1).outE('knows') !(outE knows (V 1)) ; g.V(1).outE('knows').inV().values('name') !(values name (inV (outE knows (V 1)))) ; g.V(1).out('knows').values('name') !(values name (out knows (V 1))) ; g.V(1).out('knows').has('age', gt(30)).values('name') !(values name (has age (gt 30) (out knows (V 1)))) ``` -------------------------------- ### Metta Import Syntax Example (Outdated) Source: https://github.com/trueagi-io/metta-examples/blob/main/tutorials/debug_py_script_launched_from_metta/README.md Provides an example of an import statement for Metta, noting that the syntax shown might be outdated in newer releases. This snippet illustrates how external functions or modules might be integrated. ```metta !(import! &self additional_funcs) ``` -------------------------------- ### Metta: Understanding the 'M' Type and Functorial Behavior Source: https://github.com/trueagi-io/metta-examples/blob/main/functors/readme.md Explains the 'M' type as a wrapper for values and 'mkM' as its constructor. It illustrates how 'M' instances behave like functors, allowing functions to be applied to the wrapped values directly, simplifying operations and enabling advanced control flow. ```metta !(get-type (mkM 1)) ; outputs [(: M Number)] !((mkM 1) add1) ; outputs [(mkM 2)] ; Since ((mkM A) B) == (mkM (B A)) under all circumstances, instances of M are functors. ``` -------------------------------- ### MeTTa Gremlin-like Graph Traversal DSL Source: https://github.com/trueagi-io/metta-examples/blob/main/traverser/README.md A Domain Specific Language (DSL) formulated in MeTTa to mimic Gremlin's graph traversal capabilities. It defines functions for accessing vertices, edges, properties, and performing traversals. ```APIDOC MeTTa Graph Traversal DSL: Core Functions: (= (E) (? (Outgoing $src $label $dst $weight))) - Description: Returns all outgoing edges in the graph. - Returns: A list of Outgoing edge statements. (= (V) (? (Node $label $id))) - Description: Returns all vertices (nodes) in the graph. - Returns: A list of Node statements. (= (V $id) (? (Node $label $id))) - Description: Returns a specific vertex by its ID. - Parameters: - $id: The identifier of the vertex. - Returns: The Node statement for the specified ID. Property Access: (= (values $p (Node $label $id)) (transform (Prop $p $v $id) $v)) - Description: Retrieves the value of a specific property '$p' for a given Node. - Parameters: - $p: The name of the property to retrieve. - (Node $label $id): The target Node. - Returns: The value of the property. Edge Traversal: (= (outE $l (Node $label $id)) (? (Outgoing $id $l $dst $weight))) - Description: Returns outgoing edges from a given Node with a specific label '$l'. - Parameters: - $l: The label of the outgoing edge. - (Node $label $id): The source Node. - Returns: A list of Outgoing edge statements. (= (inV (Outgoing $id $l $dst $weight)) (? (Node $_ $dst))) - Description: Returns the incoming vertex (inV) of an Outgoing edge. - Parameters: - (Outgoing $id $l $dst $weight): The edge statement. - Returns: The Node statement of the destination vertex. (= (out $l (Node $_1 $src)) (transform (Outgoing $src $l $dst $w) (Node $_ $dst))) - Description: Traverses outgoing edges with label '$l' from a source Node and returns the destination Nodes. - Parameters: - $l: The label of the outgoing edge. - (Node $_1 $src): The source Node. - Returns: A list of destination Node statements. Filtering: (= (has $l $cond (Node $_1 $src)) (_has $cond (Node $_1 $src) (values $l (Node $_1 $src)))) - Description: Filters nodes based on a condition applied to a property '$l'. - Parameters: - $l: The property to filter on. - $cond: The condition (e.g., gt(30)). - (Node $_1 $src): The set of nodes to filter. - Returns: Nodes that satisfy the condition. Internal Helper for Filtering: (= (_has $cond (Node $_1 $src) $v) (if ($cond $v) (Node $_1 $src) (empty))) - Description: Internal helper function to apply a condition to a property value and return the node if the condition is met. - Parameters: - $cond: The condition to evaluate. - (Node $_1 $src): The current node being evaluated. - $v: The value of the property for the current node. - Returns: The Node statement if the condition is true, otherwise an empty result. ``` -------------------------------- ### Metta: Redefining Unary Atoms for Queries Source: https://github.com/trueagi-io/metta-examples/blob/main/functors/readme.md Demonstrates how unary atoms like `(a)` can be redefined to query binary instances such as `(a 1)`. It shows how to map results to wrapped values of type `M` and perform operations like retrieving all values associated with a symbol. ```metta (= (add1 $n) (+ $n 1)) (A 1) (A 2) !(gimme A) ; outputs [1, 2] !(to A add1) !(gimme A) ; outputs [2, 3] !(A) ; outputs [(mkM 2), (mkM 3)] ``` -------------------------------- ### MeTTa JSON to Graph Transformations Source: https://github.com/trueagi-io/metta-examples/blob/main/traverser/README.md Defines MeTTa transformations to convert raw JSON data into structured knowledge graph statements. It maps JSON properties to MeTTa concepts like Node, Prop, and Outgoing edges, facilitating data ingestion. ```MeTTa ; what are all the id's !(transform (json $_ (id $id)) $id) ; define nodes !(transform_ (, (json $i (id $id)) (json $i (label $label))) (Node $label $id)) ; define properties !(transform_ (, (json $i (id $id)) (json $i (properties (age 0 (value $age))))) (Prop age $age $id)) !(transform_ (, (json $i (id $id)) (json $i (properties (name 0 (value $name))))) (Prop name $name $id)) ; define edges !(transform_ (, (json $i (id $src)) (json $i (outE ($label $k (inV $dst)))) (json $i (outE ($label $k (properties (weight $weight)))))) (Outgoing $src $label $dst $weight)) ``` -------------------------------- ### MeTTa Atoms after Curiosity Behavior Source: https://github.com/trueagi-io/metta-examples/blob/main/child_ai/README.md Examples of MeTTa Atoms generated after executing a curiosity_behavior() function, illustrating the representation of sequential and object-related relationships in the AI's knowledge base. ```metta ((LinksEdge Next) (MemoryNode Need) (MemoryNode Action)) ((LinksEdge Next) (MemoryNode Action) (MemoryNode Reaction)) ((LinksEdge Next) (MemoryNode Action) (MemoryNode Result)) ((LinksEdge Previous) (MemoryNode Result) (MemoryNode Action)) ``` ```metta ((LinksEdge ObjectFor) (MemoryNode Object) (MemoryNode ReactionVisual)) ((LinksEdge ObjectFor) (MemoryNode Object) (MemoryNode ReactionHearing)) ((LinksEdge ObjectFor) (MemoryNode Object) (MemoryNode ReactionTouch)) ``` -------------------------------- ### MeTTa Benchmark Formulations Source: https://github.com/trueagi-io/metta-examples/blob/main/aunt-kg/README.md This section outlines benchmark results for different MeTTa formulations against various genealogical datasets. It compares the performance of 'simple_conversion.metta', 'baseline_formulation.metta', and 'sergey_rodionov_formulation.metta' across datasets of varying sizes. ```APIDOC Benchmark Results: Query Types: parent, mother, sister, aunt, predecessor Datasets: - Simpsons (11 people) - Lord of the Rings (86 people) - Adam and Eve (479 people) - royal92 (2998 people) - G37S-9NQ (8696 people) Formulations: 1. simple_conversion.metta - Simpsons: 0m0.113s - LotR: 0m2.171s - Adam/Eve: 0m31.144s - royal92: 36m52.226s - G37S-9NQ: 252m46.136s (partial) 2. baseline_formulation.metta - Simpsons: 0m0.178s - LotR: 0m4.872s - Adam/Eve: 0m53.724s - royal92: ERROR (stack overflow) - G37S-9NQ: ERROR (stack overflow) 3. sergey_rodionov_formulation.metta - Simpsons: 0m1.028s - LotR: 0m43.516s - Adam/Eve: 36m56.999s - royal92: IN PROGRESS (12h+) - G37S-9NQ: IN PROGRESS (12h+) Note: 'IN PROGRESS' and 'ERROR' indicate performance issues or ongoing computation. ``` -------------------------------- ### Metta Stack Interpreter Definition and Program Source: https://github.com/trueagi-io/metta-examples/blob/main/stack-based/README.md Defines a tail-recursive stack interpreter in Metta, including rules for pushing, adding, and printing. It also shows how to define a program as a stack waiting for the interpreter. ```metta (= ((basic $s) (put $x)) (basic ($s $x))) (= ((basic (($s $x) $y)) add) (basic ($s (+ $x $y)))) (= ((basic ($s $x)) say) (let $_ (println! $x) (basic $s))) ``` ```metta (= (f1 $int) (((($int (put 2)) (put 3)) add) say)) ``` -------------------------------- ### Running the Tic-Tac-Toe Simulation Source: https://github.com/trueagi-io/metta-examples/blob/main/noughts-and-crosses/README.md Commands to compile and run the Tic-Tac-Toe simulation using MeTTaLog. Demonstrates different execution modes including compilation for performance and direct interpretation. ```bash mettalog --compile=full tic-tac-toe.metta ``` ```bash mettalog tic-tac-toe.metta ``` ```bash metta tic-tac-toe.metta ``` -------------------------------- ### Python Child AI Sensory Perception (Conceptual) Source: https://github.com/trueagi-io/metta-examples/blob/main/child_ai/README.md Describes the Python code for a child's sensory perception PoC, focusing on catching a toy. It outlines the Plan-Do-Check-Act approach and mentions placeholders for specific algorithms and data handling. ```python # child_ai.py - Conceptual outline # This script implements a simplified sensory perception exercise for a child AI. # The AI pays attention to a toy by hearing an adult's voice, looks at it, and tries to catch it. # It's independent of Hyperon libraries and uses a Plan-Do-Check-Act approach. # Dependencies: Likely includes libraries for audio processing, vision, and robotics control. # Training data is largely hard-coded in this PoC. # Placeholders for advanced algorithms: # - Atom Key Code vector creation # - Match Ratio algorithm # class ChildAI: # def __init__(self): # # Initialize sensors, actuators, and internal state # pass # def perceive_toy(self): # # Listen for adult's voice (hearing sensor) # # Locate toy (visual sensor) # pass # def plan_action(self): # # Based on perception, decide to catch the toy # # Implement Plan-Do-Check-Act steps # pass # def execute_action(self): # # Move arm to catch the toy # pass # def run_cycle(self): # # Execute one cycle of perception, planning, and action # self.perceive_toy() # self.plan_action() # self.execute_action() # Example usage: # if __name__ == "__main__": # ai_agent = ChildAI() # ai_agent.run_cycle() ``` -------------------------------- ### MeTTaLog Options and Behavior Source: https://github.com/trueagi-io/metta-examples/blob/main/noughts-and-crosses/README.md Documentation for various configuration options available in the MeTTaLog Tic-Tac-Toe simulation. These options control player roles, interaction methods, and execution flow. ```APIDOC MeTTaLog Tic-Tac-Toe Configuration Options: - `(is-human X)` - Behavior: Force the human player to play as 'X' (the first player). - Usage: Uncomment this line in the MeTTaLog script to enable. - `(is-human O)` - Behavior: Force the human player to play as 'O' (the second player). - Usage: Uncomment this line in the MeTTaLog script to enable. - `!(ask-who-plays)` - Behavior: Prompts the user at runtime to decide who plays (human or AI) and as which symbol (X or O). - Usage: Uncomment this line to enable interactive player selection. - `!(my-tests)` - Behavior: Executes internal test cases defined within the simulation instead of running a standard game. - Usage: Uncomment this line to run automated tests. - `!(set-random-seed &rng 0)` - Behavior: Initializes the random number generator with a fixed seed (0) for reproducible results. - Usage: Essential for debugging and consistent simulation runs. - `!(assertEqualToResult (play-now) (()))` - Behavior: Asserts that the `play-now` function, which starts the game, returns an empty result, indicating successful execution without errors. - Usage: Used for verifying the game's startup logic. - `!(repl!)` - Behavior: (MeTTaLog only) Drops the user into an interactive Read-Eval-Print Loop (REPL) after the game concludes. - Usage: Uncomment to enable post-game interactive exploration. Requires `mettalog` interpreter. ``` -------------------------------- ### CZ2 Benchmark Results Source: https://github.com/trueagi-io/metta-examples/blob/main/aunt-kg/README.md This entry presents benchmark results for the CZ2 system, specifically its 'space-wide ops' capability, across various genealogical datasets. It highlights CZ2's significantly faster performance compared to the MeTTa formulations for the tested queries. ```APIDOC CZ2 Benchmark Results: Operation: space-wide ops Datasets: - Simpsons (11 people): 0m0.005s - Lord of the Rings (86 people): 0m0.009s - Adam and Eve (479 people): 0m0.034s - royal92 (2998 people): 0m0.201s - G37S-9NQ (8696 people): 0m0.556s Note: CZ2 demonstrates significantly lower execution times across all tested dataset sizes. ``` -------------------------------- ### MeTTa Parametrized ADT for Lambda Calculus Source: https://github.com/trueagi-io/metta-examples/blob/main/red-black-lambda/README.md Illustrates how to parametrize the MeTTa ADT for Lambda calculus using type variables `$B` and `$V`. This creates a generic `LambdaTheory` that can be instantiated with different base types for ground terms and variables, enhancing reusability. ```MeTTa (= (LambdaTheory $B $V) (superpose ( (: Term Type) (: Ground (-> $B Term)) (: Mention (-> $V Term)) (: Abstraction (-> $V (-> Term Term))) (: Application (-> Term (-> Term Term))) ))) ``` -------------------------------- ### MeTTa Parametrized ADT with Type Constructor Source: https://github.com/trueagi-io/metta-examples/blob/main/red-black-lambda/README.md Presents a further parametrized MeTTa ADT using a type constructor `$F`. This allows wrapping the `Term` type, enabling the creation of distinct, qualified types such as `(RC Term)` which is crucial for differentiating types in systems like the Red and Black Lambda calculus. ```MeTTa (= (LambdaTheory $F $B $V) (superpose ( (: ($F Term) Type) (: ($F Ground) (-> $B ($F Term))) (: ($F Mention) (-> $V ($F Term))) (: ($F Abstraction) (-> $V (-> ($F Term) ($F Term)))) (: ($F Application) (-> ($F Term) (-> ($F Term) ($F Term)))) ))) ``` -------------------------------- ### Metta Stack Rewrites for Constant Folding Source: https://github.com/trueagi-io/metta-examples/blob/main/stack-based/README.md Demonstrates Metta rewrite rules for common stack manipulations such as duplicate, swap, drop, rotate, and over. These rules can be used for constant folding operations. ```metta (= (($s $x) dup) (($s $x) $x)) (= ((($s $x) $y) swap) (($s $y) $x)) (= (($s $x) drop) $s) (= (((($s $x) $y) $z) rot) ((($s $y) $z) $x)) (= ((($s $x) $y) over) ((($s $x) $y) $x)) ``` ```metta !( (( ( ($int (put 2)) dup ) mul ) (put 5) ) swap ) ``` -------------------------------- ### MeTTa Tic-Tac-Toe Game Playthrough Log Source: https://github.com/trueagi-io/metta-examples/blob/main/noughts-and-crosses/README.md This log details a complete game of Tic-Tac-Toe played within the MeTTa environment. It includes initial compilation and interpretation times, followed by a step-by-step record of the game board state, computer moves, and decision-making commentary. ```MeTTaLog ; MeTTaLog-Compiler: 0.04 seconds. ; MeTTaLog-Interpeter: 6.21 seconds. ; Hyperon-Experimatal: 62.06 seconds. 1 | 2 | 3 ----------- 4 | 5 | 6 ----------- 7 | 8 | 9 ("Computer is moving as " X "...") ("? No win or threat — picking a random move.") (X Move 5) 1 | 2 | 3 ----------- 4 | X | 6 ----------- 7 | 8 | 9 ("Computer is moving as " O "...") ("? No win or threat — picking a random move.") (O Move 9) 1 | 2 | 3 ----------- 4 | X | 6 ----------- 7 | 8 | O ("Computer is moving as " X "...") ("? No win or threat — picking a random move.") (X Move 4) 1 | 2 | 3 ----------- X | X | 6 ----------- 7 | 8 | O ("Computer is moving as " O "...") ("?? Blocking " X " from winning!") (O Move 6) 1 | 2 | 3 ----------- X | X | O ----------- 7 | 8 | O ("Computer is moving as " X "...") ("?? Blocking " O " from winning!") (X Move 3) 1 | 2 | X ----------- X | X | O ----------- 7 | 8 | O ("Computer is moving as " O "...") ("?? Blocking " X " from winning!") (O Move 7) 1 | 2 | X ----------- X | X | O ----------- O | 8 | O ("Computer is moving as " X "...") ("?? Blocking " O " from winning!") (X Move 8) 1 | 2 | X ----------- X | X | O ----------- O | X | O ("Computer is moving as " O "...") ("?? Blocking " X " from winning!") (O Move 2) 1 | O | X ----------- X | X | O ----------- O | X | O ("Computer is moving as " X "...") ("? No win or threat — picking a random move.") (X Move 1) X | O | X ----------- X | X | O ----------- O | X | O ("It was a draw!") ``` -------------------------------- ### MeTTaLog Tic-Tac-Toe Configuration Source: https://github.com/trueagi-io/metta-examples/blob/main/noughts-and-crosses/README.md Configuration options for the Tic-Tac-Toe simulation in MeTTaLog. This includes setting up AI vs AI play, enabling human player interaction, running test cases, and controlling random seed for reproducibility. ```lisp ;; ---------------------------------------- ;; Entry point: starts AI vs AI by default ;; ---------------------------------------- ;; Optionally, uncomment one of these to **force the human to play as X or O**: ; (is-human X) ;; Human goes first (as X) ; (is-human O) ;; Human goes second (as O) ;; Or, uncomment this to **ask at runtime** who should play: ; !(ask-who-plays) ;; Or, uncomment to run test cases: ; !(my-tests) !(set-random-seed &rng 0) !(random-int &rng 1 10) !(random-int &rng 1 10) !(random-int &rng 1 10) !(assertEqualToResult (play-now) (())) ;; Optionally drop into a REPL after the game (mettalog only): ; !(repl!) ``` -------------------------------- ### Solve NxN Sudoku with MeTTa (sudoku-n) Source: https://github.com/trueagi-io/metta-examples/blob/main/sudoku-n-by-n/Readme.md Illustrates solving NxN Sudoku puzzles using the `sudoku-n` function in MeTTa. This function requires the square root of the board size as a parameter. The input includes the size parameter and a MeTTa array representing the board. ```MeTTa !(sudoku-n 2 ( (x x x x) (x x 1 2) (2 4 x x) (x x x x) )) ``` -------------------------------- ### Scala Implementation of Red and Black Lambda Calculus Source: https://github.com/trueagi-io/metta-examples/blob/main/red-black-lambda/README.md Provides a Scala implementation for the Red and Black Lambda calculus. It defines traits for `LambdaTheory`, `RedLambda`, and `BlackLambda`, along with case classes for terms. The `RedBlackLambda` object unifies these, defining type aliases and methods for `equivalent` and `reduce` operations on a disjoint union of terms. ```Scala trait LambdaTheory[B,V] { trait Term case class Ground( b : B ) extends Term case class Mention( v : V ) extends Term case class Abstraction( v : V, body : Term ) extends Term case class Application( op : Term, arg : Term ) extends Term def equivalent( l : Term, r : Term ) : Boolean = ??? def reduce( t : Term ) : Option[Term] = ??? } trait RedLambda { type RV type BLC trait RTheory extends LambdaTheory[BLC,RV] } trait BlackLambda { type BV type RLC trait BTheory extends LambdaTheory[RLC,BV] } object RedBlackLambda extends RedLambda with BlackLambda { type BV = RV type BLC = BTheory type RLC = RTheory object RC extends RTheory object BC extends BTheory type RBTerm = Either[RC.Term,BC.Term] def equivalent( l : RBTerm, r : RBTerm ) : Boolean = { ( l, r ) match { case ( Left( t ), Left( u ) ) => { RC.equivalent( t, u ) } case ( Right( t ), Right( u ) ) => { BC.equivalent( t, u ) } case _ => false } } def reduce( t : RBTerm ) : Option[RBTerm] = { t match { case Left( lt ) => { RC.reduce( lt ) match { case Some( u : RC.Term ) => { u match { case RC.Ground( bu : BC.Term ) => reduce( Right( bu ) ) case _ => Some( Left( u ) ) } } case None => None } } case Right( rt ) => { BC.reduce( rt ) match { case Some( u : BC.Term ) => { u match { case BC.Ground( ru : RC.Term ) => reduce( Left( ru ) ) case _ => Some( Right( u ) ) } } case None => None } } } } } ``` -------------------------------- ### MeTTa ADT Representation for Lambda Calculus Source: https://github.com/trueagi-io/metta-examples/blob/main/red-black-lambda/README.md Defines the basic Abstract Data Type (ADT) structure for Lambda calculus terms in MeTTa. It establishes types for `Term` and its constructors: `Ground`, `Mention`, `Abstraction`, and `Application`, specifying their type signatures. ```MeTTa (: Term Type) (: Ground (-> B Term)) (: Mention (-> V Term)) (: Abstraction (-> V (-> Term Term))) (: Application (-> Term (-> Term Term))) ``` -------------------------------- ### GEDCOM to JSON Conversion Tool Source: https://github.com/trueagi-io/metta-examples/blob/main/aunt-kg/README.md This snippet refers to an external tool for converting GEDCOM files into JSON format. It's a crucial first step in preparing genealogical data for processing with MeTTa. The tool is based on the gedcom.json library. ```APIDOC Tool: Name: GEDCOM to JSON Converter Purpose: Convert GEDCOM files to JSON format. Source: https://codesandbox.io/p/sandbox/delicate-haze-2zv77m Based On: https://github.com/Jisco/gedcom.json Input: GEDCOM file Output: JSON file ``` -------------------------------- ### JSON to MeTTa Conversion Script Source: https://github.com/trueagi-io/metta-examples/blob/main/aunt-kg/README.md This entry describes a Python script used to convert data from JSON format into MeTTa files. This script is part of the data pipeline for preparing genealogical information for MeTTa-based analysis. ```Python # json_to_metta.py # Converts JSON data to MeTTa format. # Usage: python json_to_metta.py ``` -------------------------------- ### Call Python Operation from Metta Source: https://github.com/trueagi-io/metta-examples/blob/main/tutorials/debug_py_script_launched_from_metta/README.md This Metta script demonstrates how to import and call a Python operation registered with Metta. It imports the Python script (assumed to be named `additional_funcs.py`) and then invokes the `concatstr!` operation. ```metta !(import! &self additional_funcs) ; additional_funcs is our python script's name !(concatstr! "Hello" "World") ``` -------------------------------- ### Query TV's Contribution to Music Source: https://github.com/trueagi-io/metta-examples/blob/main/edges-to-edges/README.md Transforms the relationship where 'TV' is the subject to list all predicates connecting 'TV' to 'MUSIC'. This query finds all predicates ($p) for edges where 'TV' is the subject and 'MUSIC' is the object. ```MeTTa !(transform (NTE "TV" $p "MUSIC") $p) ``` -------------------------------- ### Rust Graph KB Parsing Function (Conceptual) Source: https://github.com/trueagi-io/metta-examples/blob/main/child_ai/README.md Illustrates a conceptual Rust function, GraphKB::parse_graph, for parsing graph knowledge base data. This function handles converting MeTTa Expression Atoms with Symbol Atoms into those with Grounded Atoms, including logic for finding or creating nodes and edges. ```rust // Conceptual representation of GraphKB::parse_graph function // This function would parse MeTTa expressions and interact with Hyperon Space. // It handles finding existing Grounded Atoms or creating new ones. struct GraphKB<'a> { // ... internal state, e.g., reference to Hyperon Space } impl<'a> GraphKB<'a> { // Constructor // fn new(space: &'a HyperonSpace) -> Self { ... } // Parses a MeTTa expression representing a graph edge. // Attempts to find Grounded Atoms for Link, Source, and Destination. // If not found, creates new ones. // fn parse_graph(&mut self, expression_atom: &ExpressionAtom) -> Result<(), Error> { // // 1. Extract Symbol Atoms for Link, Node1, Node2 from expression_atom // // 2. Try to find Grounded Atoms by Symbol Link and Node Names in Hyperon Space. // // 3. If Grounded Atoms are not found, create new ones using Name from MeTTa Expression. // // 4. If interpretation is not needed, add Expression Atom to Space. // // 5. If interpretation is needed, return requested information from Grounded Atoms. // Ok(()) // } // Placeholder for adding MeTTa functions, similar to Python's self.add_atom // fn add_metta_function(&mut self, name: &str, function_atom: Atom) { // // ... add function to MeTTa context // } } // Example of adding a function to get atom type, similar to Python's implementation // fn newGetAtomTypeAtom(graph_kb: &GraphKB) -> Atom { // // ... create and return Atom representing the function // } ``` -------------------------------- ### Define Python Operation for Metta Source: https://github.com/trueagi-io/metta-examples/blob/main/tutorials/debug_py_script_launched_from_metta/README.md This Python script defines a function `strAppend` and registers it as a Metta operation `concatstr!` using the `hyperon` library. It's designed to be called from Metta scripts, demonstrating basic string concatenation. ```python from hyperon.atoms import OperationAtom, ValueAtom from hyperon.ext import * def strAppend(str1, str2): print(str1 + " " + str2) @register_atoms def my_glob_atoms(): return { 'concatstr!': OperationAtom("concatstr!", strAppend, unwrap=False), } ``` -------------------------------- ### Genealogical Data to Simplified MeTTa Statements Source: https://github.com/trueagi-io/metta-examples/blob/main/aunt-kg/README.md This MeTTa script is used to transform genealogical data, likely after JSON conversion, into simplified statements. These statements are then used for querying and analysis within the MeTTa framework. ```MeTTa ; simple_conversion.metta ; Converts genealogical data into simplified MeTTa statements. ``` -------------------------------- ### Solve 9x9 Sudoku with MeTTa Source: https://github.com/trueagi-io/metta-examples/blob/main/sudoku-n-by-n/Readme.md Demonstrates solving a 9x9 Sudoku puzzle using the MeTTa programming language. The input is a MeTTa array representing the board, where 'x' denotes unknown cells. The output is the solved board. ```MeTTa !(sudoku ( (x x x x 2 x 3 5 x) (3 9 x 8 x x 7 6 x) (x x x x x x x x 9) (x x x 6 x 5 x 9 x) (5 8 x x x 4 x 2 6) (x x x 2 x 9 5 8 3) (4 x x 5 x 8 9 3 x) (x x 1 3 4 2 6 x 8) (6 x x 1 x 7 2 x 5) )) ```