Java API Connection Problem - Solved!

Help
2009-12-02
2013-05-28
  • Hi,

    I was trying Cyc Java API lately, but it did not connect to the server. Server printed stack trace but Java API hangs forever. After investigating the problem, I realized that API sends request in following format (tcp dump);

    ….TASK-PROCESSOR-REQUEST
    ..5.CYC-..MAGE-..D….api client…b1efcb29-fd27-46aa-ba86-8d8b6076ebc5
    …..S#9781
    ..MESSAGE..Invalid API Request: NIL is not a proper list

      
    The problem is, Cyc Java API uses String.toUpperCase() but it does not specify locale. Then, Java uses default locale. If the uppercase letter is not same as English letter server will not understand the command and return error (For example in Turkish, upper case of letter 'i' is 'İ'). Strangely client does not understand this error message and waits forever.

    **The solution is**, in the Cyc Java API source file:

    CycObjectFactory.java

    change line 129:

    String symbolName = symbolNameAnyCase.toUpperCase();

    to:

    String symbolName = symbolNameAnyCase.toUpperCase(Locale.ENGLISH);

    and,

    change line 158:

    String symbolName = symbolNameAnyCase.toUpperCase();

    to:

    String symbolName = symbolNameAnyCase.toUpperCase(Locale.ENGLISH);

    then recompile the API.

    This solved the problem for me.

    Hope this helps for the other connection hangingJava API problems.

    FMG.

     
  • Well, actually you should change every instance of toUpperCase() to toUpperCase(Locale.ENGLISH) in Cyc Java API source files.

    Or, before accessing Cyc (before initializing CycAccess), setting default locale to english might also solve the problem;

    Locale.setDefault(Locale.ENGLISH);

     
  • David Baxter
    David Baxter
    2009-12-02

    Nice catch. This should be fixed in the next release of OpenCyc.

     
  • alestarrr
    alestarrr
    2010-05-17

    Hi , and excuse for the informal interruption
    I´m student from ISPEJAE Institute,CUBA and  i working in a desktop aplications, that use OpenCyc v2.0querys like:
    isa _asertions(for instance and example relation between term  )
    _genls
    asertions(for class-subclas herarchy dependence )

    I  did  use the default constructor to create an instance of CycAccess
    CycAccess access = new CycAccess();
    ,but previusly click the C:\opencyc-2.0\scripts\run-cyc.bat ´s srcrip to start cyc server. It shows the following in a comand prompt:
    Start time: Sun May 16 09:42:58 CEST 2010
    Lisp implementation: Cycorp Java SubL Runtime Environment
    JVM: Sun Microsystems Inc. Java HotSpot(TM) Client VM 1.6.0 (1.6.0-b105)
    Current KB: 5018
    Patch Level: 10.128401
    Running on: FRANCOIS1
    OS: Windows Vista 6.0 (x86)
    Working directory: C:\opencyc-2.0\server\cyc\run
    Total memory allocated to VM: 1169MB.
    Memory currently used: 541MB.
    Memory currently available: 627MB.
    Initializing HL backing store caches from units/5018/.
    ;;  At this point the cyc http server is running and you can access
    ;;  Cyc directly via the local web browser.
    ;;  http://localhost:3602/cgi-bin/cyccgi/cg?cb-start
    ;;  You can browse cyc via the Guest account or perform updates by
    ;;  logging on as CycAdminstrator.
    CYC(1):

    and the aplications works!!!!!!!!!!,but only as a batch process, a  thread( an aplications working with directories, no user interfase). The problems comes when i try to use a java frame,with buttoms for user interfase interaction.
    It seem that is impossible to use AWT. Anyway i´m working in Eclipse Release 3.2.0 and JRE 5.0
    My stack trace comes as :
    org.opencyc.api.CycApiException: Invalid attempt to synchronously communicate with Cyc from the AWT event thread.

    org.opencyc.api.DefaultSubLWorkerSynch:
    Id: null
    Server: host localhost, cfaslPort 3614
    Status: Working
    Incremental results: false
    Timeout: 0 msecs
    Command:
    (CYC-IMAGE-ID)

    Please sorry for the unplacent bothering,but could you please help me or know someone-were that could……..  8]

     
  • alestarrr
    alestarrr
    2010-05-18

    Another insteresting thinks to put out there to ilustrate the problem with the symbolNameAnyCase.toUpperCase(); sentence, from jdk 6 is:

    toUpperCase
    public String toUpperCase(Locale locale)
    Converts all of the characters in this String to upper case using the rules of the given Locale. Case mapping is based on the Unicode Standard version specified by the Character class. Since case mappings are not always 1:1 char mappings, the resulting String may be a different length than the original String.
    Examples of locale-sensitive and 1:M case mappings are in the following table.

    Language Code of Locale Lower Case Upper Case Description
    tr (Turkish) \u0069 \u0130 small letter i -> capital letter I with dot above
    tr (Turkish) \u0131 \u0049 small letter dotless i -> capital letter I
    (all) \u00df \u0053 \u0053 small letter sharp s -> two letters: SS
    (all) Fahrvergnügen FAHRVERGNÜGEN 

    Parameters:
    locale - use the case transformation rules for this locale
    Returns:
    the String, converted to uppercase.
    Since:
    1.1
    See Also:
    toUpperCase(), toLowerCase(), toLowerCase(Locale)


    toUpperCase
    public String toUpperCase()
    Converts all of the characters in this String to upper case using the rules of the default locale. This method is equivalent to toUpperCase(Locale.getDefault()).

    Note: This method is locale sensitive, and may produce unexpected results if used for strings that are intended to be interpreted locale independently. Examples are programming language identifiers, protocol keys, and HTML tags. For instance, "title".toUpperCase() in a Turkish locale returns "T?TLE", where '?' is the LATIN CAPITAL LETTER I WITH DOT ABOVE character. To obtain correct results for locale insensitive strings, use toUpperCase(Locale.ENGLISH).

    Returns:
    the String, converted to uppercase.
    See Also:
    toUpperCase(Locale)


    I hope this help alittle more to uderstand the problem, i use to have it and it solves thanks honestly to fmguler and friends

     
  • Just downloaded the latest OpenCyc on Win 7, and am encountering:
    S#9781 ..MESSAGE..Invalid API Request: NIL is not a proper list

    Inexperienced with Java - where would I add "Locale.setDefault(Locale.ENGLISH);" and how would I recompile the API java?
    Looking forward to writing my first slurper.