Search code examples
csvpredicateswi-prologfactprolog-assert

Read csv file from prolog and change to facts/clause


I use csv_read_file to read a csv file, which is:

csv file:

"nsubj(love-1, carol-2)"
"nsubj(like-3, carol-2)"

code:

csv_read_file('test.csv',L)

I got things like:

L = [row('nsubj(love-1, carol-2)'), row('nsubj(like-3, carol-2)')]

But what I need is

nsubj(love-1, carol-2) and nsubj(like-3, carol-2)

which are predicates actually.

How can I get rid of the row thing? I think after that I just need to do assert().


Solution

  • OK..I got it myself. It is actually quite easy but I'm new to Prolog so it took me time to figure it out. Since Prolog can recognise the pattern, so I just make the pattern explicitly as follows:

    Rows = [Head|Tail], Head = row(Element,_,_,_,_,_,_,_), List = [Element|Temp] ...

    The Element here is exactly what I want.