row_arity / 1抛出错误,csv_read_file / 3,在SWI-Prolog的

问题描述 投票:0回答:2

我想读一个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
2个回答
1
投票

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


0
投票

在我区分我的第一栏是空的

© www.soinside.com 2019 - 2024. All rights reserved.