How to do case conversion in Prolog?

孤街浪徒 提交于 2019-12-13 16:16:16

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1243748/how-to-do-case-conversion-in-prolog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!