断言数据不同
Asserted data is different
我正在自学 Prolog。我有一个如下所示的文本文件:
table("0","Nicosia 2013 Vulkà Bianco (Etna)","Italy","White Blend","14","Kerin O’Keefe","87").
table("1","Quinta dos Avidagos 2011 Avidagos Red (Douro)","Portugal","Portuguese Red","15","Roger Voss","87").
table("2","Rainstorm 2013 Pinot Gris (Willamette Valley)","US","Pinot Gris","14","Paul Gregutt","87").
table("3","St. Julian 2013 Reserve Late Harvest Riesling (Lake Michigan Shore)","US","Riesling","13","Alexander Peartree","87").
我有 400 行,我想在序言中断言这些。我尝试了几个选项,此代码是最后一个:
load_file_data(File) :-
open(File, read, Stream),
repeat,
read(Stream, Term),
( Term = end_of_file
-> true
; assert(Term),
fail
),
close(Stream).
这个和其他几个版本断言,但不是我预期的那样。这是断言事实的样子:
table([48], [78, 105, 99, 111, 115, 105, 97, 32, 50, 48, 49, 51, 32, 86, 117, 108, 107, 195, 402, 194, 160, 32, 66, 105, 97, 110, 99, 111, 32, 32, 40, 69, 116, 110, 97, 41], [73, 116, 97, 108, 121], [87, 104, 105, 116, 101, 32, 66, 108, 101, 110, 100], [49, 52], [75, 101, 114, 105, 110, 32, 79, 195, 162, 226, 8218, 172, 226, 8222, 162, 75, 101, 101, 102, 101], [56, 55]).
table([49], [81, 117, 105, 110, 116, 97, 32, 100, 111, 115, 32, 65, 118, 105, 100, 97, 103, 111, 115, 32, 50, 48, 49, 49, 32, 65, 118, 105, 100, 97, 103, 111, 115, 32, 82, 101, 100, 32, 40, 68, 111, 117, 114, 111, 41], [80, 111, 114, 116, 117, 103, 97, 108], [80, 111, 114, 116, 117, 103, 117, 101, 115, 101, 32, 82, 101, 100], [49, 53], [82, 111, 103, 101, 114, 32, 86, 111, 115, 115], [56, 55]).
table([50], [82, 97, 105, 110, 115, 116, 111, 114, 109, 32, 50, 48, 49, 51, 32, 80, 105, 110, 111, 116, 32, 71, 114, 105, 115, 32, 40, 87, 105, 108, 108, 97, 109, 101, 116, 116, 101, 32, 86, 97, 108, 108, 101, 121, 41], [85, 83], [80, 105, 110, 111, 116, 32, 71, 114, 105, 115], [49, 52], [80, 97, 117, 108, 32, 71, 114, 101, 103, 117, 116, 116], [56, 55]).
像这样的东西 returns 正确:
?- table("1","Quinta dos Avidagos 2011 Avidagos Red(Douro)","Portugal","Portuguese Red","15","Roger Voss","87").
true.
当我尝试获取字段时,结果如下:
table("364",X,"US","Pinot Noir","48","Paul Gregutt","95").
X = [87, 105, 110, 100, 101, 114, 108, 101, 97|...] ;
false.
我解决了这个问题。实际上,这是一个非常简单的问题。
Starting with version 7, the syntax for a string object is text
between double quotes, such as "hello".
如版本 7 之前的文档中所述,SWI Prolog 不接受双引号中的字符串。最近因为一些原因降到了6.6.5版本。所以我只是解决了这个问题,我使用单引号而不是双引号并将字符串中的所有单引号更改为 `.
Prolog 中双引号文本的含义取决于标准 double_quotes
标志。该标准指定了三个可能的值:codes
(字符代码列表)、atom
和 chars
(单字符原子列表)。一些 Prolog 系统,例如SWI-Prolog 实现其他值,例如 string
。您可以通过调用检查标志的默认值:
?- current_prolog_flag(double_quotes, Value).
您可以使用 set_prolog_flag/2
谓词设置默认标志值。您还可以在包含双引号的子句之前使用 set_prolog_flag/2
指令为 Prolog 文件的内容设置标志值。例如:
:- set_prolog_flag(double_quotes, atom).
最便携的标志值是codes
,它对应于双引号文本的传统解释。
我正在自学 Prolog。我有一个如下所示的文本文件:
table("0","Nicosia 2013 Vulkà Bianco (Etna)","Italy","White Blend","14","Kerin O’Keefe","87").
table("1","Quinta dos Avidagos 2011 Avidagos Red (Douro)","Portugal","Portuguese Red","15","Roger Voss","87").
table("2","Rainstorm 2013 Pinot Gris (Willamette Valley)","US","Pinot Gris","14","Paul Gregutt","87").
table("3","St. Julian 2013 Reserve Late Harvest Riesling (Lake Michigan Shore)","US","Riesling","13","Alexander Peartree","87").
我有 400 行,我想在序言中断言这些。我尝试了几个选项,此代码是最后一个:
load_file_data(File) :-
open(File, read, Stream),
repeat,
read(Stream, Term),
( Term = end_of_file
-> true
; assert(Term),
fail
),
close(Stream).
这个和其他几个版本断言,但不是我预期的那样。这是断言事实的样子:
table([48], [78, 105, 99, 111, 115, 105, 97, 32, 50, 48, 49, 51, 32, 86, 117, 108, 107, 195, 402, 194, 160, 32, 66, 105, 97, 110, 99, 111, 32, 32, 40, 69, 116, 110, 97, 41], [73, 116, 97, 108, 121], [87, 104, 105, 116, 101, 32, 66, 108, 101, 110, 100], [49, 52], [75, 101, 114, 105, 110, 32, 79, 195, 162, 226, 8218, 172, 226, 8222, 162, 75, 101, 101, 102, 101], [56, 55]).
table([49], [81, 117, 105, 110, 116, 97, 32, 100, 111, 115, 32, 65, 118, 105, 100, 97, 103, 111, 115, 32, 50, 48, 49, 49, 32, 65, 118, 105, 100, 97, 103, 111, 115, 32, 82, 101, 100, 32, 40, 68, 111, 117, 114, 111, 41], [80, 111, 114, 116, 117, 103, 97, 108], [80, 111, 114, 116, 117, 103, 117, 101, 115, 101, 32, 82, 101, 100], [49, 53], [82, 111, 103, 101, 114, 32, 86, 111, 115, 115], [56, 55]).
table([50], [82, 97, 105, 110, 115, 116, 111, 114, 109, 32, 50, 48, 49, 51, 32, 80, 105, 110, 111, 116, 32, 71, 114, 105, 115, 32, 40, 87, 105, 108, 108, 97, 109, 101, 116, 116, 101, 32, 86, 97, 108, 108, 101, 121, 41], [85, 83], [80, 105, 110, 111, 116, 32, 71, 114, 105, 115], [49, 52], [80, 97, 117, 108, 32, 71, 114, 101, 103, 117, 116, 116], [56, 55]).
像这样的东西 returns 正确:
?- table("1","Quinta dos Avidagos 2011 Avidagos Red(Douro)","Portugal","Portuguese Red","15","Roger Voss","87").
true.
当我尝试获取字段时,结果如下:
table("364",X,"US","Pinot Noir","48","Paul Gregutt","95").
X = [87, 105, 110, 100, 101, 114, 108, 101, 97|...] ;
false.
我解决了这个问题。实际上,这是一个非常简单的问题。
Starting with version 7, the syntax for a string object is text between double quotes, such as "hello".
如版本 7 之前的文档中所述,SWI Prolog 不接受双引号中的字符串。最近因为一些原因降到了6.6.5版本。所以我只是解决了这个问题,我使用单引号而不是双引号并将字符串中的所有单引号更改为 `.
Prolog 中双引号文本的含义取决于标准 double_quotes
标志。该标准指定了三个可能的值:codes
(字符代码列表)、atom
和 chars
(单字符原子列表)。一些 Prolog 系统,例如SWI-Prolog 实现其他值,例如 string
。您可以通过调用检查标志的默认值:
?- current_prolog_flag(double_quotes, Value).
您可以使用 set_prolog_flag/2
谓词设置默认标志值。您还可以在包含双引号的子句之前使用 set_prolog_flag/2
指令为 Prolog 文件的内容设置标志值。例如:
:- set_prolog_flag(double_quotes, atom).
最便携的标志值是codes
,它对应于双引号文本的传统解释。