scallop-lang / scallop

Framework and Language for Neurosymbolic Programming. Join Our Discord: https://discord.gg/RavzdND229
https://www.scallop-lang.org
MIT License
182 stars 9 forks source link

String operator #11

Open qwang0225 opened 1 year ago

qwang0225 commented 1 year ago

Hi, I'm trying to define a relation that can apply operations like adding a prefix or suffix to a input word, the different operations would also be defined in a relation.

ctx = scallopy.ScallopContext("difftopkproofs")
ctx.add_relation("opr", str, input_mapping=["pref", "suf"])
ctx.add_relation("word1", str)
ctx.add_relation("word2", str)

ctx.add_rule("add_pref(w2+w1)) :- word1(w1), opr("pref"), word2(w2)")
ctx.add_rule("add_suf(w1+w2) :- word1(w1), opr("suf"), word2(w2)")

However, when I run I got an error saying opr takes no argument(expected 1), can you explain where went wrong? Thanks

Liby99 commented 1 year ago

I think there's syntax error in the code for defining add_pref, I have provided a fix here:

ctx.add_rule("add_pref(w2+w1) :- word1(w1), opr(\"pref\"), word2(w2)")

Notice that for add_pref you have an additional parenthesis and the string "pref" is not escaped.

Can you see whether this fixes the error?