Menu

Unicode Support

Help
G.P.
2015-07-02
2015-07-10
  • G.P.

    G.P. - 2015-07-02

    Following steps i do.

    1. create template person with slot name (type STRING)
    2. create fact person with (name "Geo-ä")
    3. create rule just for test

    (defrule some_rule
    (person (name ?some_name))
    =>
    (bind ?uppcase_name (upcase ?some_name))
    ;...........
    ; and other function calling............
    ;.......................
    )

    In this rule function 'upcase' asserts in debug(release no asserts :) ) but i get "Geo-ä" as result however i think it should be "GEO-Ä".

    Could you please told me some trick or some possibility to get correct result

     
  • Gary Riley

    Gary Riley - 2015-07-02

    Can you provide more details on how you determined the result was incorrect? This appears to work just fine:

    CLIPS> 
    (deftemplate person
       (slot name))
    CLIPS> (assert (person (name "Geo-ä")))
    <Fact-1>
    CLIPS> 
    (defrule some_rule
       (person (name ?some_name))
       =>
       (bind ?uppcase_name (upcase ?some_name))
       (printout t "Upper case name is " ?uppcase_name crlf))
    CLIPS> (run)
    Upper case name is GEO-ä
    CLIPS>
    
     
  • G.P.

    G.P. - 2015-07-03

    Yes you are totally right. my apology i get 'GEO-ä' not 'Geo-ä'.It was my misprint during write the text.

    But i want to emphasize symbol ä. at result must be 'GEO-Ä' if i make uppercase of symbol ä. But in your and my samples we get ä. I understand that it is Unicode symbol and maybe it is not supported such specific cases.

    I just want to ask if it is some trick you know or some possibilities to get GEO-Ä from Geo-ä and not GEO-ä.

    Sorry for my bad English! :)

     
  • Gary Riley

    Gary Riley - 2015-07-05

    Unfortunately, there doesn't appear to be a way to convert non-ASCII unicode characters from lower to upper case (and vice versa) that's portable using standard C/C++. There are some libraries that you can make use of to do the conversion:

    http://stackoverflow.com/questions/9929147/how-do-i-convert-a-utf-8-string-to-upper-case
    http://stackoverflow.com/questions/12493496/c-c-utf-8-upper-lower-case-conversions

    Alternately, if you're targeting specific languages you could use a str-replace function that replaces the non-ASCII characters of interest with their uppercase version. It's far from an ideal solution, but relatively straightforward:

    CLIPS> 
    (deffunction str-replace (?str ?find ?replace)
       (bind ?index (str-index ?find ?str))
       (while ?index
          (bind ?str (str-cat (sub-string 1 (- ?index 1) ?str)
                              ?replace
                              (sub-string (+ ?index 1) (str-length ?str) ?str)))
          (bind ?index (str-index ?find ?str)))
       (return ?str))
    CLIPS> (str-replace "GEO-ä" "ä" "Ä")
    "GEO-Ä"
    CLIPS>
    
     
  • G.P.

    G.P. - 2015-07-06

    ok. unfortunately i thought as you write!.

    But i think about one more possibility. Maybe it is possible to override standard CLIPS functions like 'UPCASE' , 'LOCASE' and etc. If it is possible i can get incomming parameter convert to string via RTNLexeme or DotoString convert it to value by using c++ and than return get result.

    In this case it just need to make needed function like virtual in c++. It is has way to do such operation??????

     
  • Gary Riley

    Gary Riley - 2015-07-06

    Most compilers allow you to compile C code as C++. If you do this, then it's easier to create a C function that can call C++ code. You can then create your own user defined functions which can be used in place of upcase and lowcase (give your functions different names). The core CLIPS source code is written in C rather than C++, so you can't override the functionality of the system functions as you can in C++. The CLIPS functions (such as RtnLexeme and DOToString) will return UTF-8 strings. You can pass these values to whatever C++ code you use for converting to uppercase.

     
  • G.P.

    G.P. - 2015-07-08

    yes i know,but if i create my own function for example Upcase_1 (just for example) it will be not user friendly. Anyone know function uppcase,lowcase. such names used everywhere. :)

    So it is not possible to catch somehow calling of the CLIPS internal functions and redirect it to other user defined function???

     
  • Gary Riley

    Gary Riley - 2015-07-09

    If you create a user function and register it using EnvDefineFunction with the same name as a system defined function, then you user function will be called. Alternately within CLIPS you can change the behavior of a system defined function using defmethods:

    CLIPS> (defmethod upcase ((?str STRING)) (str-cat * (call-next-method) *))
    CLIPS> (upcase "abc")
    "*ABC*"
    CLIPS>
    
     
  • G.P.

    G.P. - 2015-07-10

    "If you create a user function and register it using EnvDefineFunction with the same name as a system defined function, then you user function will be called."

    Hey it great solution for me. Thank you very much!

     

Log in to post a comment.