我想读一个CSV文件导入Prolog的知识基础。下面是代码:
:- use_module(library(csv)).
:- my_csv_read('../UserWeightings/userWeighting_dummy_25Oct2018.csv').
my_csv_read(F):-
csv_read_file(F,Data,[functor(weighting),strip(true)]),
maplist(assertz,Data).
我的CSV文件只有两列。柱1为URI,和第2列是数字(代表该URI的加权)。该文件是这样的:
'http://test/weightings#Red', 0.5
'http://test/weightings#Yellow', 0.3
'http://test/weightings#Green', 0.8
'http://test/weightings#Black', 1.2
'http://test/weightings#White', 2
当我运行的代码,它提供了以下错误:
ERROR: m:/{file path and line number}
Domain error: `row_arity(2)' expected, found `1'
Warning: m:/{path and line number}
Goal (directive) failed: user:my_csv_read('../UserWeightings/userWeighting_dummy_25Oct2018.csv')
有没有人有一个想法,为什么它只读取一列?非常感谢!
想通了。问题是,因为CSV文件中包含了两个额外的空行。多么愚蠢。因此,确保源文件是完全正确的是非常重要的。
在我区分我的第一栏是空的