Skip to content

Commit

Permalink
Merge pull request #56 from chillray/main
Browse files Browse the repository at this point in the history
[55] Fix planning editor adaptor
  • Loading branch information
haz authored Apr 28, 2024
2 parents 3ef6c88 + 71d00fe commit e6a279c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

class Predicate (object):
"""
Simple data structure for the predicate objects.
Expand Down Expand Up @@ -114,9 +116,12 @@ def export (self, lvl=1, sp=" ", untyped=False, grounding={}):
arg_s = " ".join (["%s - %s" % (v, t) for v, t in l])
else:
arg_s = " ".join ([v for v, t in l])

for k in grounding:
arg_s = arg_s.replace(k, grounding[k])

# Create a regex pattern that matches the keys exactly
pattern = '|'.join(re.escape(key) for key in sorted(grounding.keys(), key=len, reverse=True))

# Use re.sub() to replace all matched keys to their corresponding value
arg_s = re.sub(pattern, lambda match: grounding[match.group(0)], arg_s)

return (sp * lvl) + "(%s%s%s)" % (self.name, sep, arg_s)

Expand Down

0 comments on commit e6a279c

Please sign in to comment.