Skip to content

Commit

Permalink
Merge pull request #672 from trueagi-io/changes_for_kwargs
Browse files Browse the repository at this point in the history
changes for Kwargs
  • Loading branch information
Necr0x0Der authored Apr 25, 2024
2 parents fe52d94 + 072d490 commit d0b9aeb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 8 additions & 1 deletion python/hyperon/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def execute(self, *atoms, res_typ=AtomType.UNDEFINED):
except:
raise RuntimeError(f"Incorrect kwarg format {kwarg}")
try:
kwargs[repr(kwarg[0])] = kwarg[1].get_object().content
kwargs[get_string_value(kwarg[0])] = kwarg[1].get_object().content
except:
raise NoReduceError()
continue
Expand Down Expand Up @@ -705,3 +705,10 @@ def iterator(self):
for r in res:
result.append(Bindings(r))
return iter(result)

def get_string_value(value) -> str:
if not isinstance(value, str):
value = repr(value)
if len(value) > 2 and ("\"" == value[0]) and ("\"" == value[-1]):
return value[1:-1]
return value
9 changes: 1 addition & 8 deletions python/hyperon/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

from .atoms import ExpressionAtom, E, GroundedAtom, OperationAtom, ValueAtom, NoReduceError, AtomType, MatchableObject, \
G, S, Atoms
G, S, Atoms, get_string_value
from .base import Tokenizer, SExprParser
from .ext import register_atoms, register_tokens
import hyperonpy as hp
Expand Down Expand Up @@ -63,13 +63,6 @@ def bool_ops():
r"not": notAtom
}

def get_string_value(value) -> str:
if not isinstance(value, str):
value = repr(value)
if len(value) > 2 and ("\"" == value[0]) and ("\"" == value[-1]):
return value[1:-1]
return value

class RegexMatchableObject(MatchableObject):
''' To match atoms with regular expressions'''

Expand Down

0 comments on commit d0b9aeb

Please sign in to comment.