Prolog,使用不同的分隔符从 CSV 中读取数据

Prolog, Read data from CSV with different separator

我需要在 prolog 中读取不同的 CSV 文件,一些行的格式为 0'\t,在其他文件中的格式为 space 0'.

我用过:

    read_points(Filename, Points) :-
       csv_read_file(Filename, P,[convert(true),functor(pt),separator(0'\t)]),
       csv_read_file(Filename, P,[convert(true),functor(pt),separator(0' )]).

但它不起作用,因为 return 我有两个不同的列表。

我怎样才能正确编码? 谢谢。

编辑: '0\t:

示例文件
0.1     5
3       5
5       8

示例 '0:

0.1 5
3 5
5 8

我使用 If 语句解决它,并在第一行搜索是否有 space。

read(Filename, Elements) :-
(   space(Filename)
->   csv_read_file(Filename, L,[functor(line),separator(0' )])
;   csv_read_file(Filename, L,[functor(line),separator(0'\t)])
).

space(File):-
  read_first(File,L),
  once(member(32,L)).

read_first(File, sol) :-
  see(File),
  read_one_line(Codes),
  seen,
  Sol = Codes.

read_one_line(Codes) :-
  get0(Code),
  (   Code < 0 /* end of file */ ->
      Codes = []
  ;   Code =:= 10 /* end of line */ ->
      Codes = []
  ;   Codes = [Code|Codes1],
      read_one_line(Codes1)
  ).