Read csv file from prolog and change to facts/clause

1k Views Asked by At

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().

1

There are 1 best solutions below

0
On BEST ANSWER

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.