Changeset 30
- Timestamp:
- 11/06/09 01:15:56 (15 years ago)
- Location:
- trunk/pymigemo
- Files:
-
- 1 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/pymigemo/README.ja_JP.UTF-8
r28 r30 1 PyMigemo 0.1 2 ============ 3 Atzm WATANABE (10/12/'05) 1 $Id$ 4 2 5 ããã¯äœïŒ 6 ---------- 7 C/Migemo ã Python ãã䜿ãããã®ã©ãããŒã§ãïŒ 3 = ããã¯äœïŒ = 4 C/Migemo ã Python ãã䜿ãããã® wrapper ã§ãïŒ 8 5 9 å¿10 èŠãªãã®11 ----------12 C/Migemo ã©ã€ãã©ãªãã€ã³ã¹ããŒã«ãããŠããããšã13 åæãšãªã£ãŠããŸãïŒã©ã€ãã©ãªæ€çŽ¢ãã¹ã« migemo.so14 ãïŒãããæ€çŽ¢ãã¹ã« migemo.h ãååšããããšã確èª15 ããŠäžããïŒ16 6 17 ã€ã³ã¹ããŒã«æ¹æ³ 18 ---------------- 19 å梱㮠setup.py ãå©çšããŠäžããïŒ 7 = å¿ 8 èŠãªãã® = 9 C/Migemo ã©ã€ãã©ãªãã€ã³ã¹ããŒã«ãããŠããããšãåæãšãªã£ãŠããŸãïŒ 10 ã©ã€ãã©ãªæ€çŽ¢ãã¹ã« migemo.so ãïŒãããæ€çŽ¢ãã¹ã« migemo.h ãååšããããšãã確èªäžããïŒ 20 11 21 $ ./setup.py build22 # ./setup.py install23 12 24 ã©ã€ã»ã³ã¹ 25 ---------- 26 FreeBSD ã¹ã¿ã€ã«ã©ã€ã»ã³ã¹ã«æºæ ããŸãïŒ 13 = ã€ã³ã¹ããŒã«æ¹æ³ = 14 å梱㮠setup.py ããå©çšäžããïŒ 27 15 28 䜿ãæ¹ 29 ------ 30 Python ã€ã³ã¿ããªã¿äžã§ migemo ã import ããŠäžããïŒ 16 {{{ 17 $ ./setup.py build 18 # ./setup.py install 19 }}} 31 20 32 ãªãã¡ã¬ã³ã¹ 33 - - - - - - - 34 ã¢ãžã¥ãŒã«ã³ã³ãã³ã 21 22 = ã©ã€ã»ã³ã¹ = 23 äºæ¡é 24 BSD ã©ã€ã»ã³ã¹ã«æºæ ããŸãïŒ 25 詳现ã¯å梱㮠LICENSE ãã¡ã€ã«ãã芧äžããïŒ 26 27 28 = 䜿ãæ¹ = 29 {{{ 30 >>> import migemo 31 >>> m = migemo.Migemo("/usr/share/migemo/migemo-dict") 32 >>> print m.query("hoge") 33 (hoge|ïœïœïœïœ 34 |ã»ã|æ鯚|åžæ¡|è£å 35 |ãã²) 36 }}} 37 38 39 == ãªãã¡ã¬ã³ã¹ == 40 === ã¢ãžã¥ãŒã«ã³ã³ãã³ã === 35 41 * VERSION 36 ** MIGEMO_VERSION 37 C/Migemo ã®ããŒãžã§ã³ 38 39 ** PYMIGEMO_VERSION 40 PyMigemo ã®ããŒãžã§ã³ 42 * MIGEMO_VERSION 43 * C/Migemo ã®ããŒãžã§ã³ 44 * PYMIGEMO_VERSION 45 * PyMigemo ã®ããŒãžã§ã³ 41 46 42 47 * DICTID 43 åŸè¿°ã® load ã¡ãœããã§äœ¿ãèŸæž IDïŒ 44 45 ** DICTID_MIGEMO 46 migemo-dict èŸæž 47 48 ** DICTID_ROMA2HIRA 49 ããŒãåâ平仮åå€æè¡š 50 51 ** DICTID_HIRA2KATA 52 平仮åâã«ã¿ã«ãå€æè¡š 53 54 ** DICTID_HAN2ZEN 55 åè§âå 48 * DICTID_MIGEMO 49 * migemo-dict èŸæž 50 * DICTID_ROMA2HIRA 51 * ããŒãåâ平仮åå€æè¡š 52 * DICTID_HIRA2KATA 53 * 平仮åâã«ã¿ã«ãå€æè¡š 54 * DICTID_HAN2ZEN 55 * åè§âå 56 56 šè§å€æè¡š 57 58 ** DICTID_ZEN2HAN 59 å 57 * DICTID_ZEN2HAN 58 * å 60 59 šè§âåè§å€æè¡š 61 62 ** DICTID_INVALID 63 load ã¡ãœããã§èŸæžã®èªã¿èŸŒã¿ã«å€±æããå Žåã«è¿ã 60 * DICTID_INVALID 61 * load ã¡ãœããã§èŸæžã®èªã¿èŸŒã¿ã«å€±æããå Žåã«è¿ã 64 62 65 63 * OPINDEX 66 åŸè¿°ã® Migemo.set_operatorïŒMigemo.get_operator ã¡ãœããã§äœ¿ã 67 ã€ã³ãã¯ã¹ïŒ 68 69 ** OPINDEX_OR 70 è«çåïŒããã©ã«ã㯠"|" 71 72 ** OPINDEX_NEST_IN 73 ã°ã«ãŒãã³ã°æã®éãæ¬åŒ§ïŒ 74 Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"(" 75 76 ** OPINDEX_NEST_OUT 77 ã°ã«ãŒãã³ã°æã®éãæ¬åŒ§ïŒ 78 Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠")" 79 80 ** OPINDEX_SELECT_IN 81 éžæã®éå§ãè¡šãéãéæ¬åŒ§ïŒ 82 Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"[" 83 84 ** OPINDEX_SELECT_OUT 85 éžæã®çµäºãè¡šãéãéæ¬åŒ§ïŒ 86 Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"]" 87 88 ** OPINDEX_NEWLINE 89 åæåã®éã«æ¿å 90 ¥ãããã0 å以äžã®ç©ºçœãããã¯æ¹è¡ã«ãããããã 91 ãã¿ãŒã³ïŒ 92 Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"" (空æåå) 64 * OPINDEX_OR 65 * è«çå 66 * Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"|" 67 * OPINDEX_NEST_IN 68 * ã°ã«ãŒãã³ã°æã®éãæ¬åŒ§ 69 * Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"(" 70 * OPINDEX_NEST_OUT 71 * ã°ã«ãŒãã³ã°æã®éãæ¬åŒ§ 72 * Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠")" 73 * OPINDEX_SELECT_IN 74 * éžæã®éå§ãè¡šãéãéæ¬åŒ§ 75 * Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"[" 76 * OPINDEX_SELECT_OUT 77 * éžæã®çµäºãè¡šãéãéæ¬åŒ§ 78 * Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"]" 79 * OPINDEX_NEWLINE 80 * åæåã®éã«æ¿å 81 ¥ãããã0 å以äžã®ç©ºçœãããã¯æ¹è¡ã«ãããããããã¿ãŒã³ 82 * Migemo.get_operator() ã«æž¡ããéã®ããã©ã«ã㯠"" (空æåå) 93 83 94 84 * Migemo ã¯ã©ã¹ 95 ** __init__(dictionary) 96 Migemo ã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ïŒ 97 *** åŒæ° 98 dictionary: migemo-dict èŸæžãã¡ã€ã«ã®ãã¹ (str) 85 * __init__(dictionary) 86 * Migemo ã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ 87 * åŒæ° 88 * dictionary: migemo-dict èŸæžãã¡ã€ã«ã®ãã¹ (str) 89 * get_encoding() 90 * migemo-dict èŸæžã®ãšã³ã³ãŒãã£ã³ã°ã str ã§è¿ãïŒ 91 äŸãã° EUC-JP ã§æžãããèŸæžã§ããã° "euc_jp" ãè¿ãïŒ 92 cp932ïŒeuc_jpïŒutf8 ã®ãããããè¿ããïŒ 93 èŸæžã®ãšã³ã³ãŒãã£ã³ã°ããããã«è©²åœããªãã£ãå Žå㯠"ascii" ãè¿ã 94 * åŒæ° 95 * ãªã 96 * è¿ãå€ 97 * ãšã³ã³ãŒãã£ã³ã°æåå (str) 98 * get_operator(index) 99 * index ã§æå®ãããïŒæ£èŠè¡šçŸã«äœ¿çšããã¡ã¿æåãè¿ã (str) 100 * åŒæ° 101 * index: åè¿°ã® OPINDEX ã®ãããã 102 * è¿ãå€ 103 * ã¡ã¿æåå (str) 104 * is_enable() 105 * Migemo å 106 éšã«ïŒæ£åžžã«èŸæžãèªã¿èŸŒããŠãããã©ããããã§ãã¯ãã 107 * åŒæ° 108 * ãªã 109 * è¿ãå€ 110 * çåœå€ (int) : æ£åžžã«èªã¿èŸŒããŠããå Žåã«ç 111 * load(dict_id, dict_file) 112 * Migemo ãªããžã§ã¯ãã«èŸæžãè¿œå ã§èªã¿èŸŒã 113 * åŒæ° 114 * dict_id: åè¿°ã® DICTID ã®ãããã 115 * dict_file: èŸæžãã¡ã€ã«ã®ãã¹ 116 * è¿ãå€ 117 * èªã¿èŸŒãã èŸæžã® DICTIDïŒ 118 èªã¿èŸŒã¿ã«å€±æããå Žå DICTID_INVALID ãè¿ã 119 * query(query) 120 * query ã§äžããããæååããæ¥æ¬èªæ€çŽ¢ã®ããã®æ£èŠè¡šçŸãè¿ã 121 * åŒæ° 122 * query: åãåãããæåå (Unicode or str)ïŒ 123 str 㧠ascii 以å€ã®æååãæž¡ãå ŽåïŒ 124 èŸæžãšåããšã³ã³ãŒãã£ã³ã°ã®æååã§ãªããšãšã©ãŒã«ãªãå¯èœæ§ããã 125 * è¿ãå€ 126 * æ£èŠè¡šçŸæåå (Unicode) 127 * set_operator(index, op) 128 * index ã§æå®ãããïŒæ£èŠè¡šçŸã«äœ¿çšããã¡ã¿æåã op ã«å€æŽãã 129 * åŒæ° 130 * index: åè¿°ã® OPINDEX ã®ãããã 131 * op: ã¡ã¿æåå (str) 132 * è¿ãå€ 133 * çåœå€ (int) : æåæã«ç 99 134 100 ** get_encoding()101 migemo-dict èŸæžã®ãšã³ã³ãŒãã£ã³ã°ã str ã§è¿ãïŒ102 äŸãã° EUC-JP ã§æžãããèŸæžã§ããã° "euc_jp" ãè¿ãïŒ103 cp932ïŒeuc_jpïŒutf8 ã®ãããããè¿ããïŒèŸæžã®ãšã³ã³ãŒãã£ã³ã°ãã104 ããã«è©²åœããªãã£ãå Žåã¯ãã¡ã€ã«ã·ã¹ãã ã®ããã©ã«ããšã³ã³ãŒãã£105 ã³ã°ãè¿ãïŒ106 *** åŒæ°107 ãªã108 *** è¿ãå€109 ãšã³ã³ãŒãã£ã³ã°æåå (str)110 135 111 ** get_operator(index) 112 index ã§æå®ãããïŒæ£èŠè¡šçŸã«äœ¿çšããã¡ã¿æåãè¿ã (str)ïŒ 113 *** åŒæ° 114 index: åè¿°ã® OPINDEX ã®ãããã 115 *** è¿ãå€ 116 ã¡ã¿æåå (str) 136 = ãã®ä» = 137 æ¬ãœãããŠã§ã¢ã«å¯Ÿããã³ã¡ã³ãïŒãã°å ±åïŒããããªã©ã¯å€§ãã«æè¿ããŸãïŒ 138 äžèšã¡ãŒã«ã¢ãã¬ã¹ãŸã§ãæ°è»œã«ãå¯ãäžããïŒ 117 139 118 ** is_enable()119 Migemo å120 éšã«ïŒæ£åžžã«èŸæžãèªã¿èŸŒããŠãããã©ããããã§ãã¯ããïŒ121 *** åŒæ°122 ãªã123 *** è¿ãå€124 çåœå€ (int) : æ£åžžã«èªã¿èŸŒããŠããå Žåã«ç125 126 ** load(dict_id, dict_file)127 Migemo ãªããžã§ã¯ãã«èŸæžãè¿œå ã§èªã¿èŸŒãïŒ128 *** åŒæ°129 dict_id: åè¿°ã® DICTID ã®ãããã130 dict_file: èŸæžãã¡ã€ã«ã®ãã¹131 *** è¿ãå€132 èªã¿èŸŒãã èŸæžã® DICTIDïŒ133 èªã¿èŸŒã¿ã«å€±æããå Žå DICTID_INVALID ãè¿ãïŒ134 135 ** query(query)136 query ã§äžããããæååããæ¥æ¬èªæ€çŽ¢ã®ããã®æ£èŠè¡šçŸãè¿ãïŒ137 *** åŒæ°138 query: åãåãããæåå (Unicode or str)139 str 㧠ascii 以å€ã®æååãæž¡ãå ŽåïŒèŸæžãšåããšã³140 ã³ãŒãã£ã³ã°ã®æååã§ãªããšãšã©ãŒã«ãªãå¯èœæ§ãããïŒ141 *** è¿ãå€142 æ£èŠè¡šçŸæåå (Unicode)143 144 ** set_operator(index, op)145 index ã§æå®ãããïŒæ£èŠè¡šçŸã«äœ¿çšããã¡ã¿æåã op ã«å€æŽããïŒ146 *** åŒæ°147 index: åè¿°ã® OPINDEX ã®ãããã148 op: ã¡ã¿æåå (str)149 *** è¿ãå€150 çåœå€ (int) : æåæã«ç151 152 äœè153 154 ----155 140 Atzm WATANABE <atzm@atzm.org> 156 157 æ¬ãœãããŠã§ã¢ã«å¯Ÿããã³ã¡ã³ãïŒãã°å ±åïŒããããªã©ã¯å€§ãã«æè¿158 ããŸãïŒäžèšã®ã¡ãŒã«ã¢ãã¬ã¹ãŸã§ãæ°è»œã«ãå¯ãäžããïŒ159 160 $Id$ -
trunk/pymigemo/pymigemo.c
r29 r30 1 1 /* 2 2 * pymigemo.c - C/Migemo wrapper for Python 3 * Copyright(C) 2005, Atzm WATANABE <atzm@atzm.org> 4 * License: BSD-style 3 * Copyright(C) 2005-2009, Atzm WATANABE <atzm@atzm.org> 5 4 * 6 5 * $Id$ … … 8 7 9 8 #include <Python.h> 10 #include "structmember.h" 11 #include "migemo.h" 12 13 #define PYMIGEMO_VERSION "0.1" 9 #include <structmember.h> 10 #include <migemo.h> 11 #include <string.h> 12 13 #define PYMIGEMO_VERSION "0.2" 14 14 15 15 /* for dereference migemo object members */ 16 struct _migemo 17 { 18 int enable; 19 void *mtree; 20 int charset; 21 void *roma2hira; 22 void *hira2kata; 23 void *han2zen; 24 void *zen2han; 25 void *rx; 26 void *addword; 27 void *char2int; 16 struct _migemo { 17 int enable; 18 void *mtree; 19 int charset; 20 void *roma2hira; 21 void *hira2kata; 22 void *han2zen; 23 void *zen2han; 24 void *rx; 25 void *addword; 26 void *char2int; 28 27 }; 29 28 30 29 typedef struct { 31 PyObject_HEAD32 migemo *migemo_obj;30 PyObject_HEAD 31 migemo *migemo_obj; 33 32 } Migemo; 34 33 … … 36 35 Migemo_dealloc(Migemo *self) 37 36 { 38 if (self->migemo_obj) 39 migemo_close(self->migemo_obj); 40 41 self->ob_type->tp_free((PyObject *)self); 37 if (self->migemo_obj) { 38 migemo_close(self->migemo_obj); 39 } 40 41 self->ob_type->tp_free((PyObject *)self); 42 42 } 43 43 … … 45 45 Migemo_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 46 46 { 47 Migemo *self; 48 49 self = (Migemo *)type->tp_alloc(type, 0); 50 if (self != NULL) 51 self->migemo_obj = NULL; 52 53 return (PyObject *)self; 47 Migemo *self; 48 49 self = (Migemo *)type->tp_alloc(type, 0); 50 51 if (self != NULL) { 52 self->migemo_obj = NULL; 53 } 54 55 return (PyObject *)self; 54 56 } 55 57 … … 57 59 Migemo_init(Migemo *self, PyObject *args, PyObject *kwds) 58 60 { 59 migemo *migemo_obj; 60 char *dictionary; 61 static char *kwlist[] = {"dictionary", NULL}; 62 63 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &dictionary)) 64 return -1; 65 66 if (dictionary) { 67 if (self->migemo_obj) 68 migemo_close(self->migemo_obj); 69 70 migemo_obj = migemo_open(dictionary); 71 72 if (migemo_obj) 73 self->migemo_obj = migemo_obj; 74 else 75 return -1; 76 } 77 78 return 0; 79 } 80 81 const char * 82 get_encoding(int charset) 83 { 84 const char *encoding; 85 86 switch(charset) { 87 case 1: 88 encoding = "cp932"; 89 break; 90 case 2: 91 encoding = "euc_jp"; 92 break; 93 case 3: 94 encoding = "utf8"; 95 break; 96 default: 97 encoding = Py_FileSystemDefaultEncoding; 98 } 99 100 return encoding; 61 migemo *migemo_obj; 62 char *dictionary; 63 64 static char *kwlist[] = {"dictionary", NULL}; 65 66 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &dictionary)) { 67 return -1; 68 } 69 70 if (dictionary) { 71 if (self->migemo_obj) { 72 migemo_close(self->migemo_obj); 73 } 74 75 migemo_obj = migemo_open(dictionary); 76 77 if (migemo_obj) { 78 self->migemo_obj = migemo_obj; 79 } 80 else { 81 return -1; 82 } 83 } 84 85 return 0; 86 } 87 88 static int 89 get_encoding(char *encoding, size_t size, int charset) 90 { 91 char *enc; 92 93 switch(charset) { 94 case 1: 95 enc = "cp932"; 96 break; 97 case 2: 98 enc = "euc_jp"; 99 break; 100 case 3: 101 enc = "utf_8"; 102 break; 103 default: 104 enc = "ascii"; 105 } 106 107 if (strlen(enc) < size) { 108 strcpy(encoding, enc); 109 return 1; 110 } 111 112 return 0; 101 113 } 102 114 … … 104 116 Migemo_get_encoding(Migemo *self) 105 117 { 106 return Py_BuildValue("s", get_encoding(self->migemo_obj->charset)); 118 char encoding[7]; 119 120 if (!get_encoding(encoding, sizeof(encoding), self->migemo_obj->charset)) { 121 return NULL; 122 } 123 124 return PyString_FromString(encoding); 107 125 } 108 126 … … 110 128 Migemo_query(Migemo *self, PyObject *args, PyObject *kwds) 111 129 { 112 PyObject *result, *query_obj; 113 static char *kwlist[] = {"query", NULL}; 114 115 const char *query, *encoding; 116 unsigned char *regex; 117 PyObject *query_str = NULL, *regex_strobj = NULL; 118 119 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &query_obj)) 120 return NULL; 121 122 encoding = get_encoding(self->migemo_obj->charset); 123 124 if (PyUnicode_Check(query_obj)) { 125 query_str = PyUnicode_AsEncodedString(query_obj, encoding, "strict"); 126 query = PyString_AS_STRING(query_str); 127 } 128 else if (PyString_Check(query_obj)) 129 query = PyString_AS_STRING(query_obj); 130 else 131 return NULL; 132 133 if (query) { 134 regex = migemo_query(self->migemo_obj, query); 135 136 if (regex) { 137 regex_strobj = PyString_FromString(regex); 138 139 if (regex_strobj) 140 result = PyUnicode_FromEncodedObject(regex_strobj, encoding, "strict"); 141 142 migemo_release(self->migemo_obj, regex); 143 } 144 } 145 146 Py_XDECREF(regex_strobj); 147 Py_XDECREF(query_str); 148 149 if (!result) 150 return NULL; 151 152 return result; 130 PyObject *result, *query_obj, *query_str = NULL, *regex_strobj = NULL; 131 char *query, encoding[7]; 132 unsigned char *regex; 133 134 static char *kwlist[] = {"query", NULL}; 135 136 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &query_obj)) { 137 return NULL; 138 } 139 140 if (!get_encoding(encoding, sizeof(encoding), self->migemo_obj->charset)) { 141 return NULL; 142 } 143 144 if (PyUnicode_Check(query_obj)) { 145 query_str = PyUnicode_AsEncodedString(query_obj, encoding, "strict"); 146 query = PyString_AS_STRING(query_str); 147 } 148 else if (PyString_Check(query_obj)) { 149 query = PyString_AS_STRING(query_obj); 150 } 151 else { 152 return NULL; 153 } 154 155 if (query) { 156 regex = migemo_query(self->migemo_obj, query); 157 158 if (regex) { 159 regex_strobj = PyString_FromString(regex); 160 161 if (regex_strobj) { 162 result = PyUnicode_FromEncodedObject(regex_strobj, encoding, "strict"); 163 } 164 165 migemo_release(self->migemo_obj, regex); 166 } 167 } 168 169 Py_XDECREF(regex_strobj); 170 Py_XDECREF(query_str); 171 172 if (!result) { 173 return NULL; 174 } 175 176 return result; 153 177 } 154 178 … … 156 180 Migemo_set_operator(Migemo *self, PyObject *args, PyObject *kwds) 157 181 { 158 PyObject *result; 159 static char *kwlist[] = {"index", "op", NULL}; 160 161 int index; 162 char *op; 182 PyObject *result; 183 char *op; 184 int index; 163 185 164 if (!PyArg_ParseTupleAndKeywords(args, kwds, "is", kwlist, &index, &op)) 165 return NULL; 166 167 if (op) 168 result = Py_BuildValue("i", migemo_set_operator(self->migemo_obj, index, op)); 169 170 if (!result) 171 return NULL; 172 173 return result; 186 static char *kwlist[] = {"index", "op", NULL}; 187 188 if (!PyArg_ParseTupleAndKeywords(args, kwds, "is", kwlist, &index, &op)) { 189 return NULL; 190 } 191 192 if (op) { 193 result = PyInt_FromLong((long)migemo_set_operator(self->migemo_obj, index, op)); 194 } 195 196 if (!result) { 197 return NULL; 198 } 199 200 return result; 174 201 } 175 202 … … 177 204 Migemo_get_operator(Migemo *self, PyObject *args, PyObject *kwds) 178 205 { 179 PyObject *result; 180 static char *kwlist[] = {"index", NULL}; 181 182 int index; 183 const unsigned char *op; 206 PyObject *result; 207 unsigned char *op; 208 int index; 184 209 185 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &index)) 186 return NULL; 187 188 op = migemo_get_operator(self->migemo_obj, index); 189 result = Py_BuildValue("s", op); 190 191 if (!result) 192 return NULL; 193 194 return result; 210 static char *kwlist[] = {"index", NULL}; 211 212 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &index)) { 213 return NULL; 214 } 215 216 if (op = migemo_get_operator(self->migemo_obj, index)) { 217 result = PyString_FromString(op); 218 } 219 220 if (!result) { 221 return NULL; 222 } 223 224 return result; 195 225 } 196 226 … … 198 228 Migemo_load(Migemo *self, PyObject *args, PyObject *kwds) 199 229 { 200 PyObject *result; 201 static char *kwlist[] = {"dict_id", "dict_file", NULL}; 202 203 int dict_id; 204 const char *dict_file; 230 PyObject *result; 231 char *dict_file; 232 int dict_id; 205 233 206 if (!PyArg_ParseTupleAndKeywords(args, kwds, "is", kwlist, &dict_id, &dict_file)) 207 return NULL; 208 209 if (dict_file) 210 result = Py_BuildValue("i", migemo_load(self->migemo_obj, dict_id, dict_file)); 211 212 if (!result) 213 return NULL; 214 215 return result; 234 static char *kwlist[] = {"dict_id", "dict_file", NULL}; 235 236 if (!PyArg_ParseTupleAndKeywords(args, kwds, "is", kwlist, &dict_id, &dict_file)) { 237 return NULL; 238 } 239 240 if (dict_file) { 241 result = PyInt_FromLong((long)migemo_load(self->migemo_obj, dict_id, dict_file)); 242 } 243 244 if (!result) { 245 return NULL; 246 } 247 248 return result; 216 249 } 217 250 … … 219 252 Migemo_is_enable(Migemo *self) 220 253 { 221 return Py_BuildValue("i",migemo_is_enable(self->migemo_obj));254 return PyInt_FromLong((long)migemo_is_enable(self->migemo_obj)); 222 255 } 223 256 224 257 static PyMethodDef Migemo_methods[] = { 225 {"query", (PyCFunction)Migemo_query, METH_KEYWORDS,226 "return regex from romaji string\n\258 {"query", (PyCFunction)Migemo_query, METH_KEYWORDS, 259 "return regex from romaji string\n\ 227 260 \n\ 228 261 def query(query)\n\ … … 230 263 \n\ 231 264 returns: regex string as Unicode object"}, 232 {"set_operator", (PyCFunction)Migemo_set_operator, METH_KEYWORDS,233 "set operator string as the meta character of regex\n\265 {"set_operator", (PyCFunction)Migemo_set_operator, METH_KEYWORDS, 266 "set operator string as the meta character of regex\n\ 234 267 \n\ 235 268 def set_operator(index, op):\n\ … … 239 272 \n\ 240 273 returns: boolean value"}, 241 {"get_operator", (PyCFunction)Migemo_get_operator, METH_KEYWORDS,242 "get operator string as the meta character of regex\n\274 {"get_operator", (PyCFunction)Migemo_get_operator, METH_KEYWORDS, 275 "get operator string as the meta character of regex\n\ 243 276 \n\ 244 277 def get_operator(index)\n\ … … 247 280 \n\ 248 281 returns: operator string (str)"}, 249 {"load", (PyCFunction)Migemo_load, METH_KEYWORDS,250 "add dictionary to Migemo object\n\282 {"load", (PyCFunction)Migemo_load, METH_KEYWORDS, 283 "add dictionary to Migemo object\n\ 251 284 \n\ 252 285 def load(dict_id, dict_file)\n\ … … 256 289 \n\ 257 290 returns: boolean value"}, 258 {"is_enable", (PyCFunction)Migemo_is_enable, METH_NOARGS,259 "check internal migemo_dict\n\291 {"is_enable", (PyCFunction)Migemo_is_enable, METH_NOARGS, 292 "check internal migemo_dict\n\ 260 293 \n\ 261 294 def is_enable()\n\ 262 295 returns: boolean value"}, 263 {"get_encoding", (PyCFunction)Migemo_get_encoding, METH_NOARGS,264 "get dictionary encoding\n\296 {"get_encoding", (PyCFunction)Migemo_get_encoding, METH_NOARGS, 297 "get dictionary encoding\n\ 265 298 \n\ 266 299 def get_encoding()\n\ 267 300 returns: encoding string (str)"}, 268 {NULL} /* Sentinel */301 {NULL} /* Sentinel */ 269 302 }; 270 303 271 304 static PyMemberDef Migemo_members[] = { 272 {NULL} /* Sentinel */305 {NULL} /* Sentinel */ 273 306 }; 274 307 275 308 static PyTypeObject MigemoType = { 276 PyObject_HEAD_INIT(NULL)277 0, /*ob_size*/278 "migemo.Migemo", /*tp_name*/279 sizeof(Migemo), /*tp_basicsize*/280 0, /*tp_itemsize*/281 (destructor)Migemo_dealloc, /*tp_dealloc*/282 0, /*tp_print*/283 0, /*tp_getattr*/284 0, /*tp_setattr*/285 0, /*tp_compare*/286 0, /*tp_repr*/287 0, /*tp_as_number*/288 0, /*tp_as_sequence*/289 0, /*tp_as_mapping*/290 0, /*tp_hash */291 0, /*tp_call*/292 0, /*tp_str*/293 0, /*tp_getattro*/294 0, /*tp_setattro*/295 0, /*tp_as_buffer*/296 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/297 "Migemo wrapper object", /* tp_doc */298 0, /* tp_traverse */299 0, /* tp_clear */300 0, /* tp_richcompare */301 0, /* tp_weaklistoffset */302 0, /* tp_iter */303 0, /* tp_iternext */304 Migemo_methods, /* tp_methods */305 Migemo_members, /* tp_members */306 0, /* tp_getset */307 0, /* tp_base */308 0, /* tp_dict */309 0, /* tp_descr_get */310 0, /* tp_descr_set */311 0, /* tp_dictoffset */312 (initproc)Migemo_init, /* tp_init */313 0, /* tp_alloc */314 Migemo_new, /* tp_new */309 PyObject_HEAD_INIT(NULL) 310 0, /*ob_size*/ 311 "migemo.Migemo", /*tp_name*/ 312 sizeof(Migemo), /*tp_basicsize*/ 313 0, /*tp_itemsize*/ 314 (destructor)Migemo_dealloc, /*tp_dealloc*/ 315 0, /*tp_print*/ 316 0, /*tp_getattr*/ 317 0, /*tp_setattr*/ 318 0, /*tp_compare*/ 319 0, /*tp_repr*/ 320 0, /*tp_as_number*/ 321 0, /*tp_as_sequence*/ 322 0, /*tp_as_mapping*/ 323 0, /*tp_hash */ 324 0, /*tp_call*/ 325 0, /*tp_str*/ 326 0, /*tp_getattro*/ 327 0, /*tp_setattro*/ 328 0, /*tp_as_buffer*/ 329 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 330 "Migemo wrapper object", /* tp_doc */ 331 0, /* tp_traverse */ 332 0, /* tp_clear */ 333 0, /* tp_richcompare */ 334 0, /* tp_weaklistoffset */ 335 0, /* tp_iter */ 336 0, /* tp_iternext */ 337 Migemo_methods, /* tp_methods */ 338 Migemo_members, /* tp_members */ 339 0, /* tp_getset */ 340 0, /* tp_base */ 341 0, /* tp_dict */ 342 0, /* tp_descr_get */ 343 0, /* tp_descr_set */ 344 0, /* tp_dictoffset */ 345 (initproc)Migemo_init, /* tp_init */ 346 0, /* tp_alloc */ 347 Migemo_new, /* tp_new */ 315 348 }; 316 349 317 350 static PyMethodDef module_methods[] = { 318 {NULL} /* Sentinel */351 {NULL} /* Sentinel */ 319 352 }; 320 353 … … 325 358 initmigemo(void) 326 359 { 327 PyObject* m;328 329 if (PyType_Ready(&MigemoType) < 0)330 return;331 332 m = Py_InitModule3("migemo", module_methods, "C/Migemo wrapper");333 334 Py_INCREF(&MigemoType);335 PyModule_AddObject(m, "Migemo", (PyObject *)&MigemoType);336 PyModule_AddObject(m, "PYMIGEMO_VERSION", Py_BuildValue("s", PYMIGEMO_VERSION));337 338 PyModule_AddObject(m, "MIGEMO_VERSION", Py_BuildValue("s", MIGEMO_VERSION));339 340 PyModule_AddObject(m, "DICTID_INVALID", Py_BuildValue("i", MIGEMO_DICTID_INVALID));341 PyModule_AddObject(m, "DICTID_MIGEMO", Py_BuildValue("i", MIGEMO_DICTID_MIGEMO));342 PyModule_AddObject(m, "DICTID_ROMA2HIRA", Py_BuildValue("i", MIGEMO_DICTID_ROMA2HIRA));343 PyModule_AddObject(m, "DICTID_HIRA2KATA", Py_BuildValue("i", MIGEMO_DICTID_HIRA2KATA));344 PyModule_AddObject(m, "DICTID_HAN2ZEN", Py_BuildValue("i", MIGEMO_DICTID_HAN2ZEN));345 PyModule_AddObject(m, "DICTID_ZEN2HAN", Py_BuildValue("i", MIGEMO_DICTID_ZEN2HAN));346 347 PyModule_AddObject(m, "OPINDEX_OR", Py_BuildValue("i", MIGEMO_OPINDEX_OR));348 PyModule_AddObject(m, "OPINDEX_NEST_IN", Py_BuildValue("i", MIGEMO_OPINDEX_NEST_IN));349 PyModule_AddObject(m, "OPINDEX_NEST_OUT", Py_BuildValue("i", MIGEMO_OPINDEX_NEST_OUT));350 PyModule_AddObject(m, "OPINDEX_SELECT_IN", Py_BuildValue("i", MIGEMO_OPINDEX_SELECT_IN));351 PyModule_AddObject(m, "OPINDEX_SELECT_OUT", Py_BuildValue("i", MIGEMO_OPINDEX_SELECT_OUT));352 PyModule_AddObject(m, "OPINDEX_NEWLINE", Py_BuildValue("i", MIGEMO_OPINDEX_NEWLINE));353 } 360 PyObject* m; 361 362 if (PyType_Ready(&MigemoType) < 0) 363 return; 364 365 m = Py_InitModule3("migemo", module_methods, "C/Migemo wrapper"); 366 367 Py_INCREF(&MigemoType); 368 PyModule_AddObject(m, "Migemo", (PyObject *)&MigemoType); 369 PyModule_AddObject(m, "PYMIGEMO_VERSION", Py_BuildValue("s", PYMIGEMO_VERSION)); 370 371 PyModule_AddObject(m, "MIGEMO_VERSION", Py_BuildValue("s", MIGEMO_VERSION)); 372 373 PyModule_AddObject(m, "DICTID_INVALID", Py_BuildValue("i", MIGEMO_DICTID_INVALID)); 374 PyModule_AddObject(m, "DICTID_MIGEMO", Py_BuildValue("i", MIGEMO_DICTID_MIGEMO)); 375 PyModule_AddObject(m, "DICTID_ROMA2HIRA", Py_BuildValue("i", MIGEMO_DICTID_ROMA2HIRA)); 376 PyModule_AddObject(m, "DICTID_HIRA2KATA", Py_BuildValue("i", MIGEMO_DICTID_HIRA2KATA)); 377 PyModule_AddObject(m, "DICTID_HAN2ZEN", Py_BuildValue("i", MIGEMO_DICTID_HAN2ZEN)); 378 PyModule_AddObject(m, "DICTID_ZEN2HAN", Py_BuildValue("i", MIGEMO_DICTID_ZEN2HAN)); 379 380 PyModule_AddObject(m, "OPINDEX_OR", Py_BuildValue("i", MIGEMO_OPINDEX_OR)); 381 PyModule_AddObject(m, "OPINDEX_NEST_IN", Py_BuildValue("i", MIGEMO_OPINDEX_NEST_IN)); 382 PyModule_AddObject(m, "OPINDEX_NEST_OUT", Py_BuildValue("i", MIGEMO_OPINDEX_NEST_OUT)); 383 PyModule_AddObject(m, "OPINDEX_SELECT_IN", Py_BuildValue("i", MIGEMO_OPINDEX_SELECT_IN)); 384 PyModule_AddObject(m, "OPINDEX_SELECT_OUT", Py_BuildValue("i", MIGEMO_OPINDEX_SELECT_OUT)); 385 PyModule_AddObject(m, "OPINDEX_NEWLINE", Py_BuildValue("i", MIGEMO_OPINDEX_NEWLINE)); 386 }
Note: See TracChangeset
for help on using the changeset viewer.