Prolog中如何进行大小写转换?

发布于 2024-07-30 15:30:13 字数 223 浏览 3 评论 0原文

我正在与 WordNet 进行交互,我想要分类的一些术语(各种专有名称)是在数据库中大写,但我得到的输入可能无法正确大写。 我最初的想法是编写一个谓词来生成输入可能的各种大写字母,但我不确定如何去做。

有谁知道如何解决这个问题,或者更好,更有效的方法来实现我想做的事情?

I'm interfacing with WordNet, and some of the terms I'd like to classify (various proper names) are capitalised in the database, but the input I get may not be capitalised properly. My initial idea here is to write a predicate that produces the various capitalisations possible of an input, but I'm not sure how to go about it.

Does anyone have an idea how to go about this, or even better, a more efficient way to achieve what I would like to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听你说爱我 2024-08-06 15:30:52

这取决于您使用的 Prolog 实现,但可能有您可以使用的库函数。

例如来自 SWI-Prolog 参考手册

4.22.1 大小写转换

Prolog 标准中没有任何内容可以转换文本数据中的大小写。 SWI-Prolog
谓词 code_type/2 和 char_type/2 可用于测试和转换单个
人物。 我们已经开始了一些额外的支持:

downcase_atom(+AnyCase, -LowerCase)

像 char_type/2 一样将 AnyCase 的字符转换为小写(即基于
定义的语言环境(如果 Prolog 在托管平台上提供语言环境支持)并统一
小写原子与 LowerCase。

upcase_atom(+AnyCase, -UpperCase)

与 downcase_atom/2 类似,将原子转换为大写。

由于这只是将传递给它的任何内容小写,因此您可以轻松编写一个简单的谓词来在进行任何分析之前清理每个输入。

It depends on what Prolog implementation you're using, but there may be library functions you can use.

e.g. from the SWI-Prolog reference manual:

4.22.1 Case conversion

There is nothing in the Prolog standard for converting case in textual data. The SWI-Prolog
predicates code_type/2 and char_type/2 can be used to test and convert individual
characters. We have started some additional support:

downcase_atom(+AnyCase, -LowerCase)

Converts the characters of AnyCase into lowercase as char_type/2 does (i.e. based on the
defined locale if Prolog provides locale support on the hosting platform) and unifies the
lowercase atom with LowerCase.

upcase_atom(+AnyCase, -UpperCase)

Converts, similar to downcase_atom/2, an atom to upper-case.

Since this just downcases whatever's passed to it, you can easily write a simple predicate to sanitise every input before doing any analysis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文