【问题标题】:row_arity/1 throws error, csv_read_file/3, in SWI-Prologrow_arity/1 在 SWI-Prolog 中抛出错误 csv_read_file/3
【发布时间】:2018-10-26 00:37:47
【问题描述】:

我正在尝试将 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 swi-prolog


    【解决方案1】:

    想通了。问题是因为 CSV 文件包含两个额外的空行。多么愚蠢。因此,确保源文件完全正确很重要。

    【讨论】:

      【解决方案2】:

      就我而言-我的第一列是空的

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-05
        • 1970-01-01
        • 2015-01-13
        • 1970-01-01
        • 1970-01-01
        • 2023-04-07
        • 1970-01-01
        相关资源
        最近更新 更多