Yesterday, I managed to get an implementation to work such that it can handle both import and export from and to CSV-files. I've still got some polishing to do but here's a short introduction to using it.
Assuming we've got a set of link-facts in Working Memory:
CLIPS> (facts)We can export them to a CSV-file using the function CSV-export:
f-0 (initial-fact)
f-1 (link (title "CLIPSESG") (url "http://groups.google.com/group/CLIPSESG"))
f-2 (link (title "CLIPS") (url "http://clipsrules.sourceforge.net/"))
For a total of 3 facts.
CLIPS> (load "csv.clp")The file links.csv looks like this afterwards:
:!!!!
TRUE
CLIPS> (CSV-export "links.csv" link)
2
title,urlAnd if we instead want to load the link-facts from file we can use CSV-import:
"CLIPSESG","http://groups.google.com/group/CLIPSESG"
"CLIPS","http://clipsrules.sourceforge.net/"
CLIPS> (load "csv.clp")Both functions take the filename and the deftemplate as parameters. You can also specify which slots should be exported/imported but that's really not neccessary. However, the first row of the CSV-file must contain slot names (column headers) if you import facts without specifying slots.
:!!!!
TRUE
CLIPS> (CSV-import "links.csv" link)
2
CLIPS> (facts)
f-0 (initial-fact)
f-1 (link (title "CLIPSESG") (url "http://groups.google.com/group/CLIPSESG"))
f-2 (link (title "CLIPS") (url "http://clipsrules.sourceforge.net/"))
For a total of 3 facts.
Inga kommentarer:
Skicka en kommentar
Obs! Endast bloggmedlemmar kan kommentera.