Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top