gpt4 book ai didi

linux - Linux系统Prolog程序中TXT文件编码问题

转载 作者:太空狗 更新时间:2023-10-29 12:18:53 27 4
gpt4 key购买 nike

我正在研究一个由 SWI Prolog 文本分析器组成的大学 Prolog,它非常简单地执行以下操作:

  1. 读取包含一些文本的 .txt 输入文件,并将此文本放入 ASCII 字符列表,我称之为:dataggare.txt
  2. 对这个原始的 ASCII 字符列表进行一些操作,并将其保存在一个名为 System.txt
  3. 的新文件中
  4. 最后将新修改的 System.txt 文件与另一个名为 oracolo.txt 的文件进行比较(代表 System.txt 应该是如果所有操作都成功完成),FMeasure 值表示 System.txtoracolo.txt 有多少相似之处,但是现在这不重要

当我将新的 System.txt 文件与 oracolo.txt 文件进行比较时出现问题,只有当我使用 Linux 运行程序时才会出现此问题(如果我在 Windows 上运行它,我没有问题)

所以问题是,当我执行以下查询时,我有一系列与 oracolo.txt 文件的编码相关的警告

[debug]  ?- tagConfronto('dataggare.txt', 'oracolo.txt', FMeasure).
Warning: oracolo.txt:1:422: Illegal UTF-8 continuation
Warning: oracolo.txt:2:77: Illegal UTF-8 continuation
Warning: oracolo.txt:2:129: Illegal UTF-8 continuation
Warning: oracolo.txt:3:31: Illegal UTF-8 continuation
Warning: oracolo.txt:3:71: Illegal UTF-8 continuation
Warning: oracolo.txt:3:199: Illegal UTF-8 start
Warning: oracolo.txt:3:258: Illegal UTF-8 continuation
............
Warning: oracolo.txt:12:222: Illegal UTF-8 continuation
Warning: oracolo.txt:12:563: Illegal UTF-8 continuation
FMeasure = 0.02564102564102564

tagConfronto/3 谓词将 dataggare.txt 文件内容与 oracolo.txt 文件进行比较,并计算相关的 FMeasure

如您所见,执行此操作会发现 oracolo.txt 编码 存在一些问题,这给我带来了很多问题,因为它显着改变了 FMeasure< 的值.

只有当我在 Linux 上运行该程序时才会出现此问题,而在 Windows 下运行时不会出现(在第二种情况下,我没有警告和正确的 FMeasure 值)

一些同事告诉我,也许我可以通过某种方式解决这个重新保存文件更改编码(我不知道我是否必须保存以不同的方式 System.txtoracolo.txt 我不知道我必须使用哪种编码 或者是否有不同的解决方案)

有什么想法吗?

最佳答案

在 Unix 上,

?- current_prolog_flag(encoding,X).
X = utf8.

在 Windows 上

?- current_prolog_flag(encoding,X).
X = text.

也许你应该在打开文件时设置相同的值,使用 open/4 - 或者全局更改,使用 set_prolog_flag/2。要更改已打开的流,请使用 set_stream/2。

我不确定 encoding(text) 是否合适,请参阅 documentation page对于所有支持的值。

关于linux - Linux系统Prolog程序中TXT文件编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16740600/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com