row_arity/1 在 SWI-Prolog 中抛出错误 csv_read_file/3
row_arity/1 throws error, csv_read_file/3, in SWI-Prolog
我正在尝试将 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 文件包含两个额外的空行。多么愚蠢。因此,确保源文件完全正确很重要。
就我而言 - 我的第一列是空的
我正在尝试将 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 文件包含两个额外的空行。多么愚蠢。因此,确保源文件完全正确很重要。
就我而言 - 我的第一列是空的