Open nworb999 opened 1 month ago
Hello @nworb999 ,
- Is there a better, cleaner, more Pythonic way to dump atoms in a space into a text file?
If you are running you MeTTa program from Python code using MeTTa
runner then you can use MeTTa.space()
method to get the top level space and use SpaceRef.get_atoms
or SpaceRef.query
method to get atoms from the space:
https://github.com/trueagi-io/hyperon-experimental/blob/1507f82756ca0766b5e69c8937b3b081b4409301/python/hyperon/runner.py#L78 https://github.com/trueagi-io/hyperon-experimental/blob/1507f82756ca0766b5e69c8937b3b081b4409301/python/hyperon/base.py#L229 https://github.com/trueagi-io/hyperon-experimental/blob/1507f82756ca0766b5e69c8937b3b081b4409301/python/hyperon/base.py#L248
- While dumping atoms into a space in a text file, there's a lot of generated code currently that looks like below, as well as many records of
(= True True), (= True True), (= True True)
, -- is there a way to automatically filter that out?
Am I right that these atoms are generated by your MeTTa program? In general they can be filtered out by specifying query to SpaceRef.query()
method, or iterating through the collection of atoms and filtering them out in Python according to some criteria. Another approach is to create few separate spaces in your MeTTa program using new-space
function from the MeTTa standard library and to keep auto generated code and useful atoms in separate spaces. Then you can save only space with useful data.
- Is there a way to filter the space without having to match the exact pattern, e.g. I want any atom that contains the string Necklace, without having to specify (fact $query ($rest))/(fact Necklace (is Brown)) or (entity $query)/(entity Necklace)?
It is possible doing this in Python by converting atom to string and check if the string contains some substring. But it is not poss in MeTTa program without writing additional MeTTa functions for doing these things.
Thank you so much!
Hello,
I am using the
hyperon
package for my Python application and I was wondering about some best practices for outputting the AtomSpace to a text file. Right now, I am usingmetta.run("!(get-atoms &self)")
to visually check that things I am adding are being represented correctly. I was wondering:(= True True), (= True True), (= True True),
-- is there a way to automatically filter that out? And only include atoms that have information like(Is Hat_Hat2279 Hat), (entity Hat_Hat2280), (Is Hat_Hat2280 Hat)
?Necklace
, without having to specify(fact $query ($rest))/(fact Necklace (is Brown))
or(entity $query)/(entity Necklace)
?Thank you for your work!