如何在Prolog中进行大小写转换? [英] How to do case conversion in Prolog?

查看:65
本文介绍了如何在Prolog中进行大小写转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与 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?

推荐答案

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

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

例如来自 SWI-Prolog 参考手册:

4.22.1 大小写转换

4.22.1 Case conversion

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

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)

downcase_atom(+AnyCase, -LowerCase)

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

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)

upcase_atom(+AnyCase, -UpperCase)

转换,类似于 downcase_atom/2,一个原子到大写.

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.

这篇关于如何在Prolog中进行大小写转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆