I would like to construct a mechanism that constructs different facts depending from txt file,
imported in prolog. I already have found some examples where they directly assert the line that was read from the file, but I have to transform the data before assertion can take place.
To give an example:
man = {m1, m2}.
m1: w1 > w2.
should be read as:
man(m1).
man(m2).
prefer(m1, w1, 1).
prefer(m1, w2, 2).
Is it possible to construct these facts based on the symbols of the input?
thanks to the fact that data presented in example is valid Prolog syntax, this code will do
note that the precedence of operators in
m1: w1 > w2is not what we could expect, but it works anyway, thanks to complete pattern matching. Useto check precedence when not sure.