commit e8e234262d4a1d7df9e50c550706427a44edc431 Author: vaydheesh Date: Thu Jul 11 11:21:44 2019 +0530 Wrapper for apertium-tagger diff --git a/python/apertium_core.i b/python/apertium_core.i index 5751e78..4888902 100644 --- a/python/apertium_core.i +++ b/python/apertium_core.i @@ -5,6 +5,7 @@ #include #include #include +#include #include class apertium: public Transfer, public Interchunk, public Postchunk @@ -19,6 +20,16 @@ public: void transfer_text(char arg, char *transferfile, char *datafile, char *input_path, char *output_path); }; +class apertium_tag: public Apertium::apertium_tagger +{ +public: + /** + * Imitates functionality of apertium-tagger + * Pass int to int&, char** to char**& + */ + apertium_tag(int argc, char **argv): apertium_tagger(argc, argv) {;} +}; + void apertium::transfer_text(char arg, char *transferfile, char *datafile, char *input_path, char *output_path) { @@ -76,8 +87,39 @@ apertium::postchunk_text(char arg, char *transferfile, char *datafile, char *inp %include %include %include +%include %include +// Wrapper on char ** for char **argv +// Modified for python 3 from http://www.swig.org/Doc1.3/Python.html#Python_nn59 + +%typemap(in) char ** { + if (PyList_Check($input)) { + int size = PyList_Size($input); + int i = 0; + $1 = (char **) malloc((size+1)*sizeof(char *)); + for (i = 0; i < size; i++) { + PyObject *py_obj = PyList_GetItem($input,i); + if (PyUnicode_Check(py_obj)){ + $1[i] = strdup(PyUnicode_AsUTF8(py_obj)); + } + else { + PyErr_SetString(PyExc_TypeError,"list must contain strings"); + free($1); + return NULL; + } + } + $1[i] = 0; + } else { + PyErr_SetString(PyExc_TypeError,"not a list"); + return NULL; + } +} + +%typemap(freearg) char ** { + free((char *) $1); +} + class apertium: public Transfer, public Interchunk, public Postchunk { public: @@ -89,3 +131,13 @@ public: void postchunk_text(char arg, char *transferfile, char *datafile, char *input_path, char *output_path); void transfer_text(char arg, char *transferfile, char *datafile, char *input_path, char *output_path); }; + +class apertium_tag: public Apertium::apertium_tagger +{ +public: + /** + * Imitates functionality of apertium-tagger + * Pass int to int&, char** to char**& + */ + apertium_tag(int argc, char **argv); +}; diff --git a/python/setup.py.in b/python/setup.py.in index de18a2b..07da53a 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -19,11 +19,19 @@ class CustomBuild(build): def get_sources(): sources = ['apertium_core.i'] - cc_sources = ['apertium_re.cc', 'interchunk.cc', 'interchunk_word.cc', 'postchunk.cc', - 'pretransfer.cc', 'string_utils.cc', 'transfer.cc', 'transfer_data.cc', - 'transfer_instr.cc', 'transfer_mult.cc', 'transfer_token.cc', - 'transfer_word.cc', 'transfer_word_list.cc', 'trx_reader.cc', - 'utf_converter.cc', 'xml_reader.cc'] + cc_sources = ['a.cc', 'align.cc', 'analysis.cc', 'apertium_re.cc', 'basic_5_3_1_tagger.cc', 'basic_5_3_2_tagger.cc', + 'basic_exception_type.cc', 'basic_stream_tagger.cc', 'basic_stream_tagger_trainer.cc', 'basic_tagger.cc', + 'collection.cc', 'constant_manager.cc', 'endian_double_util.cc', 'exception_type.cc', 'feature_vec.cc', + 'feature_vec_averager.cc', 'file_morpho_stream.cc', 'file_tagger.cc', 'hmm.cc', 'i.cc', 'interchunk.cc', + 'interchunk_word.cc', 'lemma.cc', 'linebreak.cc', 'lswpost.cc', 'morpheme.cc', 'morpho_stream.cc', + 'mtx_reader.cc', 'perceptron_spec.cc', 'perceptron_tagger.cc', 'postchunk.cc', 'pretransfer.cc', + 'sentence_stream.cc', 'shell_utils.cc', 'stream.cc', 'stream_5_3_1_tagger.cc', + 'stream_5_3_1_tagger_trainer.cc', 'stream_5_3_2_tagger.cc', 'stream_5_3_2_tagger_trainer.cc', + 'stream_5_3_3_tagger.cc', 'stream_5_3_3_tagger_trainer.cc', 'stream_tagger.cc', 'stream_tagger_trainer.cc', + 'string_utils.cc', 'tag.cc', 'tagger.cc', 'tagger_data.cc', 'tagger_data_hmm.cc', 'tagger_data_lsw.cc', + 'tagger_data_percep_coarse_tags.cc', 'tagger_utils.cc', 'tagger_word.cc', 'transfer.cc', 'transfer_data.cc', + 'transfer_instr.cc', 'transfer_mult.cc', 'transfer_token.cc', 'transfer_word.cc', 'transfer_word_list.cc', + 'trx_reader.cc', 'tsx_reader.cc', 'utf_converter.cc', 'wchar_t_exception_type.cc', 'xml_reader.cc'] rel_path = '@top_srcdir@/apertium' sources.extend(path.join(rel_path, f) for f in cc_sources) return sources