Home | History | Annotate | Download | only in openwnn
      1 /*
      2  * Copyright (C) 2008-2012  OMRON SOFTWARE Co., Ltd.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package jp.co.omronsoft.openwnn;
     18 
     19 /**
     20  * The implementation class of JNI wrapper for dictionary.
     21  *
     22  * @author Copyright (C) 2008, 2009 OMRON SOFTWARE CO., LTD.  All Rights Reserved.
     23  */
     24 public class OpenWnnDictionaryImplJni {
     25     /*
     26      * DEFINITION OF CONSTANTS
     27      */
     28     /**
     29      * Constant about the approximate pattern (for JNI native library)
     30      *
     31      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_TOUPPER
     32      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#setApproxPattern
     33      */
     34     public static final int APPROX_PATTERN_EN_TOUPPER               = WnnDictionary.APPROX_PATTERN_EN_TOUPPER;
     35     /**
     36      * Constant about the approximate pattern (for JNI native library)
     37      *
     38      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_TOLOWER
     39      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#setApproxPattern
     40      */
     41     public static final int APPROX_PATTERN_EN_TOLOWER               = WnnDictionary.APPROX_PATTERN_EN_TOLOWER;
     42     /**
     43      * Constant about the approximate pattern (for JNI native library)
     44      *
     45      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_QWERTY_NEAR
     46      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#setApproxPattern
     47      */
     48     public static final int APPROX_PATTERN_EN_QWERTY_NEAR           = WnnDictionary.APPROX_PATTERN_EN_QWERTY_NEAR;
     49     /**
     50      * Constant about the approximate pattern (for JNI native library)
     51      *
     52      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_QWERTY_NEAR_UPPER
     53      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#setApproxPattern
     54      */
     55     public static final int APPROX_PATTERN_EN_QWERTY_NEAR_UPPER     = WnnDictionary.APPROX_PATTERN_EN_QWERTY_NEAR_UPPER;
     56     /**
     57      * Constant about the approximate pattern (for JNI native library)
     58      *
     59      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_JAJP_12KEY_NORMAL
     60      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#setApproxPattern
     61      */
     62     public static final int APPROX_PATTERN_JAJP_12KEY_NORMAL        = WnnDictionary.APPROX_PATTERN_JAJP_12KEY_NORMAL;
     63 
     64     /**
     65      * Constant about the search operation (for JNI native library)
     66      *
     67      * @see jp.co.omronsoft.openwnn.WnnDictionary#SEARCH_EXACT
     68      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#searchWord
     69      */
     70     public static final int SEARCH_EXACT                           = WnnDictionary.SEARCH_EXACT;
     71     /**
     72      * Constant about the search operation (for JNI native library)
     73      *
     74      * @see jp.co.omronsoft.openwnn.WnnDictionary#SEARCH_PREFIX
     75      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#searchWord
     76      */
     77     public static final int SEARCH_PREFIX                          = WnnDictionary.SEARCH_PREFIX;
     78     /**
     79      * Constant about the search operation (for JNI native library)
     80      *
     81      * @see jp.co.omronsoft.openwnn.WnnDictionary#SEARCH_LINK
     82      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#searchWord
     83      */
     84     public static final int SEARCH_LINK                            = WnnDictionary.SEARCH_LINK;
     85 
     86     /**
     87      * Constant about the sort order (for JNI native library)
     88      *
     89      * @see jp.co.omronsoft.openwnn.WnnDictionary#ORDER_BY_FREQUENCY
     90      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#searchWord
     91      */
     92     public static final int ORDER_BY_FREQUENCY                     = WnnDictionary.ORDER_BY_FREQUENCY;
     93     /**
     94      * Constant about the sort order (for JNI native library)
     95      *
     96      * @see jp.co.omronsoft.openwnn.WnnDictionary#ORDER_BY_KEY
     97      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#searchWord
     98      */
     99     public static final int ORDER_BY_KEY                           = WnnDictionary.ORDER_BY_KEY;
    100 
    101     /**
    102      * Type of a part of speech (for JNI native library)
    103      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_V1
    104      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    105      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    106      */
    107     public static final int POS_TYPE_V1                             = WnnDictionary.POS_TYPE_V1;
    108     /**
    109      * Type of a part of speech (for JNI native library)
    110      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_V2
    111      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    112      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    113      */
    114     public static final int POS_TYPE_V2                             = WnnDictionary.POS_TYPE_V2;
    115     /**
    116      * Type of a part of speech (for JNI native library)
    117      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_V3
    118      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    119      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    120      */
    121     public static final int POS_TYPE_V3                             = WnnDictionary.POS_TYPE_V3;
    122     /**
    123      * Type of a part of speech (for JNI native library)
    124      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_BUNTOU
    125      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    126      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    127      */
    128     public static final int POS_TYPE_BUNTOU                         = WnnDictionary.POS_TYPE_BUNTOU;
    129     /**
    130      * Type of a part of speech (for JNI native library)
    131      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_TANKANJI
    132      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    133      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    134      */
    135     public static final int POS_TYPE_TANKANJI                       = WnnDictionary.POS_TYPE_TANKANJI;
    136     /**
    137      * Type of a part of speech (for JNI native library)
    138      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_SUUJI
    139      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    140      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    141      */
    142     public static final int POS_TYPE_SUUJI                          = WnnDictionary.POS_TYPE_SUUJI;
    143     /**
    144      * Type of a part of speech (for JNI native library)
    145      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_MEISI
    146      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    147      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    148      */
    149     public static final int POS_TYPE_MEISI                          = WnnDictionary.POS_TYPE_MEISI;
    150     /**
    151      * Type of a part of speech (for JNI native library)
    152      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_JINMEI
    153      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    154      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    155      */
    156     public static final int POS_TYPE_JINMEI                         = WnnDictionary.POS_TYPE_JINMEI;
    157     /**
    158      * Type of a part of speech (for JNI native library)
    159      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_CHIMEI
    160      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    161      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    162      */
    163     public static final int POS_TYPE_CHIMEI                         = WnnDictionary.POS_TYPE_CHIMEI;
    164     /**
    165      * Type of a part of speech (for JNI native library)
    166      * @see jp.co.omronsoft.openwnn.WnnDictionary#POS_TYPE_KIGOU
    167      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getLeftPartOfSpeechSpecifiedType
    168      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getRightPartOfSpeechSpecifiedType
    169      */
    170     public static final int POS_TYPE_KIGOU                          = WnnDictionary.POS_TYPE_KIGOU;
    171 
    172     /*
    173      * METHODS
    174      */
    175     /**
    176      * Create a internal work area.
    177      * A internal work area is allocated dynamically, and the specified dictionary library is loaded.
    178      *
    179      * @param dicLibPath    The path of the dictionary library file
    180      * @return              The internal work area or null
    181      */
    182     public static final native long createWnnWork( String dicLibPath );
    183 
    184     /**
    185      * Free the internal work area.
    186      * The specified work area and the loaded dictionary library is free.
    187      *
    188      * @param work      The internal work area
    189      * @return          0 if processing is successful; <0 if an error occur
    190      */
    191     public static final native int freeWnnWork( long work );
    192 
    193     /**
    194      * Clear all dictionary information.
    195      *
    196      * @see jp.co.omronsoft.openwnn.WnnDictionary#clearDictionary
    197      * @param work      The internal work area
    198      * @return          0 if processing is successful; <0 if an error occur
    199      */
    200     public static final native int clearDictionaryParameters( long work );
    201 
    202     /**
    203      * Set a dictionary information.
    204      *
    205      * @see jp.co.omronsoft.openwnn.WnnDictionary#setDictionary
    206      * @param work      The internal work area
    207      * @param index     The index of dictionary
    208      * @param base      The base frequency or -1
    209      * @param high      The maximum frequency or -1
    210      * @return           0 if processing is successful; <0 otherwise
    211      */
    212     public static final native int setDictionaryParameter( long work, int index, int base, int high );
    213 
    214     /**
    215      * Search a word from dictionaries.
    216      *
    217      * @see jp.co.omronsoft.openwnn.WnnDictionary#searchWord
    218      * @param work          The internal work area
    219      * @param operation     The search operation (see "Constant about the search operation")
    220      * @see jp.co.omronsoft.openwnn.WnnDictionary#SEARCH_EXACT
    221      * @see jp.co.omronsoft.openwnn.WnnDictionary#SEARCH_PREFIX
    222      * @param order         The sort order (see "Constant about the sort order")
    223      * @see jp.co.omronsoft.openwnn.WnnDictionary#ORDER_BY_FREQUENCY
    224      * @see jp.co.omronsoft.openwnn.WnnDictionary#ORDER_BY_KEY
    225      * @param keyString     The key string
    226      * @return              0 if no result is found; 1 if a result is found; <0 if an error occur
    227      *
    228      */
    229     public static final native int searchWord(long work, int operation, int order, String keyString );
    230 
    231     /**
    232      * Retrieve a word information.
    233      * A word information is stored to the internal work area. To retrieve a detail information,
    234      * use {@code getStroke()}, {@code getCandidate()}, {@code getFreqeuency(),} or other {@code get...()} method.
    235      *
    236      * @see jp.co.omronsoft.openwnn.WnnDictionary#getNextWord
    237      * @param work      The internal work area
    238      * @param length    >0 if only the result of specified length is retrieved; 0 if no condition exist
    239      * @return          0 if no result is retrieved; >0 if a result is retrieved; <0 if an error occur
    240      */
    241     public static final native int getNextWord( long work, int length );
    242 
    243     /**
    244      * Retrieve the key string from the current word information.
    245      *
    246      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getNextWord
    247      * @param work      The internal work area
    248      * @return          The Key string
    249      */
    250     public static final native String getStroke( long work );
    251 
    252     /**
    253      * Retrieve the candidate string from the current word information.
    254      *
    255      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getNextWord
    256      * @param work      The internal work area
    257      * @return          The candidate string
    258      */
    259     public static final native String getCandidate( long work );
    260 
    261     /**
    262      * Retrieve the frequency from the current word information.
    263      *
    264      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#getNextWord
    265      * @param work      The internal work area
    266      * @return          The frequency
    267      */
    268     public static final native int getFrequency( long work );
    269 
    270     /**
    271      * Retrieve the part of speech at left side from the current word information.
    272      *
    273      * @param work      The internal work area
    274      * @return          The part of speech
    275      */
    276     public static final native int getLeftPartOfSpeech( long work );
    277 
    278     /**
    279      * Retrieve the part of speech at right side from the current word information.
    280      *
    281      * @param work      The internal work area
    282      * @return          The part of speech
    283      */
    284     public static final native int getRightPartOfSpeech( long work );
    285 
    286     /**
    287      * Clear approximate patterns.
    288      *
    289      * @see jp.co.omronsoft.openwnn.WnnDictionary#clearApproxPattern
    290      * @param work      The internal work area.
    291      */
    292     public static final native void clearApproxPatterns( long work );
    293 
    294     /**
    295      * Set a approximate pattern.
    296      *
    297      * @see jp.co.omronsoft.openwnn.WnnDictionary#setApproxPattern
    298      * @param work      The internal work area
    299      * @param src       The string (before)
    300      * @param dst       The string (after)
    301      * @return          0 if processing is successful; <0 if an error occur
    302      */
    303     public static final native int setApproxPattern( long work, String src, String dst );
    304 
    305     /**
    306      * Set a predefined approximate pattern.
    307      *
    308      * @see jp.co.omronsoft.openwnn.WnnDictionary#setApproxPattern
    309      * @param work              The internal work area
    310      * @param approxPattern     The index of predefined approximate pattern (See "Constant about the approximate pattern")
    311      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_TOUPPER
    312      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_TOLOWER
    313      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_QWERTY_NEAR
    314      * @see jp.co.omronsoft.openwnn.WnnDictionary#APPROX_PATTERN_EN_QWERTY_NEAR_UPPER
    315      * @return                  0 if processing is successful; <0 if an error occur
    316      */
    317     public static final native int setApproxPattern( long work, int approxPattern );
    318 
    319     /**
    320      * Get the specified approximate pattern.
    321      * @param work      The internal work area
    322      * @param src       The string (before)
    323      * @return          The string array (after)
    324      */
    325     public static final native String[] getApproxPattern( long work, String src );
    326 
    327     /**
    328      * Clear the current word information.
    329      *
    330      * @param work      The internal work area
    331      */
    332     public static final native void clearResult( long work );
    333 
    334     /**
    335      * Set the part of speech at left side to the current word information.
    336      *
    337      * @param work          The internal work area
    338      * @param partOfSpeech  The part of speech
    339      * @return              0 if processing is successful; <0 if an error occur
    340      *
    341      */
    342     public static final native int setLeftPartOfSpeech( long work, int partOfSpeech );
    343     /**
    344      * Set the part of speech at right side to the current word information.
    345      *
    346      * @param work          The internal work area
    347      * @param partOfSpeech  The part of speech
    348      * @return              0 if processing is successful; <0 if an error occur
    349      *
    350      */
    351     public static final native int setRightPartOfSpeech( long work, int partOfSpeech );
    352 
    353     /**
    354      * Set the key string to the current word information.
    355      *
    356      * @param work          The internal work area
    357      * @param stroke        The key string
    358      * @return              0 if processing is successful; <0 if an error occur
    359      *
    360      */
    361     public static final native int setStroke( long work, String stroke );
    362     /**
    363      * Set the candidate string to the current word information.
    364      *
    365      * @param work          The internal work area
    366      * @param candidate     The candidate string
    367      * @return              0 if processing is successful; <0 if an error occur
    368      *
    369      */
    370     public static final native int setCandidate( long work, String candidate );
    371 
    372     /**
    373      * Set the previous word information from the current word information.
    374      *
    375      * @param work          The internal work area
    376      * @return              0 if processing is successful; <0 if an error occur
    377      */
    378     public static final native int selectWord( long work );
    379 
    380     /**
    381      * Retrieve the connect array
    382      *
    383      * @param work                  The internal work area
    384      * @param leftPartOfSpeech      The part of speech at left side
    385      * @return                      The connect array
    386      */
    387     public static final native byte[] getConnectArray( long work, int leftPartOfSpeech );
    388 
    389     /**
    390      * Retrieve the number of the part of speeches at left side.
    391      *
    392      * @return              The number
    393      */
    394     public static final native int getNumberOfLeftPOS( long work );
    395     /**
    396      * Retrieve the number of the part of speeches at right side.
    397      *
    398      * @return              The number
    399      */
    400     public static final native int getNumberOfRightPOS( long work );
    401 
    402     /**
    403      * Retrieve the specified part of speech at left side.
    404      *
    405      * @param work          The internal work area
    406      * @param type          The type of a part of speech
    407      * @return              0 if type is not found; <0 if an error occur; >0 The part of speech
    408      */
    409     public static final native int getLeftPartOfSpeechSpecifiedType( long work, int type );
    410 
    411     /**
    412      * Retrieve the specified part of speech at right side.
    413      *
    414      * @param work          The internal work area
    415      * @param type          The type of a part of speech
    416      * @return              0 if type is not found; <0 if an error occur; >0 The part of speech
    417      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_V1
    418      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_V2
    419      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_V3
    420      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_BUNTOU
    421      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_TANKANJI
    422      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_SUUJI
    423      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_MEISI
    424      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_JINMEI
    425      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_CHIMEI
    426      * @see jp.co.omronsoft.openwnn.OpenWnnDictionaryImplJni#POS_TYPE_KIGOU
    427      */
    428     public static final native int getRightPartOfSpeechSpecifiedType( long work, int type );
    429 
    430     /**
    431      * Create the string array that is used by operation of query
    432      *
    433      * @param work                  The internal work area
    434      * @param keyString             The key string
    435      * @param maxBindsOfQuery       The maximum number of binds of query
    436      * @param maxPatternOfApprox    The maximum number of approximate patterns per character
    437      * @return                     The string array for binding
    438      */
    439     public static final native String[] createBindArray( long work, String keyString, int maxBindsOfQuery, int maxPatternOfApprox );
    440 
    441     /**
    442      * Create the string which used query parameter
    443      *
    444      * @param work                  The internal work area
    445      * @param maxBindsOfQuery       The maximum number of binds of query
    446      * @param maxPatternOfApprox    The maximum number of approximate patterns per character
    447      * @param keyColumnName        The name of the key column
    448      * @return                     The string for querying
    449      */
    450     public static final native String createQueryStringBase( long work, int maxBindsOfQuery, int maxPatternOfApprox, String keyColumnName );
    451 }
    452