def statements(s: str):
last = ""
for _s in s.splitlines(keepends=False):
_s = _s.rstrip()
if not _s: continue
if _s.endswith("."):
last += _s[:-1]
yield last
last = ""
else:
last += _s
last += " "
if last:
yield last
def consultString(prolog: Prolog, s: str):
for ass in statements(s):
print(f"---------\n{ass}")
prolog.assertz(ass)
q = open("rulesandfacts.pl").read()
prolog = Prolog()
consultString(prolog,q)