From 027a4a9777e07c8ca3cdb723970e7757da5feb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl> Date: Tue, 26 Apr 2011 14:18:02 +0200 Subject: [PATCH] Corpus2::Lexeme wrapper --- swig/Makefile | 25 ++++++++++++++++----- swig/libcorpuslexeme.i | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 swig/libcorpuslexeme.i diff --git a/swig/Makefile b/swig/Makefile index c4b9c98..f905860 100644 --- a/swig/Makefile +++ b/swig/Makefile @@ -15,32 +15,38 @@ CPPFLAGS=-fPIC -O2 CBIN=libcorpustag.o \ libcorpustagset.o \ - libcorpustagsetmanager.o + libcorpustagsetmanager.o \ + libcorpuslexeme.o CBINOUT=_boost_shared_ptr.so \ _libcorpustag.so \ _libcorpustagset.so \ - _libcorpustagsetmanager.so + _libcorpustagsetmanager.so \ + _libcorpuslexeme.so CWRAP=boost_shared_ptr_wrap.cxx \ libcorpustag_wrap.cxx \ libcorpustagset_wrap.cxx \ - libcorpustagsetmanager_wrap.cxx + libcorpustagsetmanager_wrap.cxx \ + libcorpuslexeme_wrap.cxx CWRAPBIN=boost_shared_ptr_wrap.o \ libcorpustag_wrap.o \ libcorpustagset_wrap.o \ - libcorpustagsetmanager_wrap.o + libcorpustagsetmanager_wrap.o \ + libcorpuslexeme_wrap.o PYMODULES=boost_shared_ptr.py \ libcorpustag.py \ libcorpustagset.py \ - libcorpustagsetmanager.py + libcorpustagsetmanager.py \ + libcorpuslexeme.py PYCBIN=boost_shared_ptr.pyc \ libcorpustag.pyc \ libcorpustagset.pyc \ - libcorpustagsetmanager.pyc + libcorpustagsetmanager.pyc \ + libcorpuslexeme.pyc # ----------------------------------------------------------------------------- all:boost_shared_ptr.o $(CBIN) @@ -81,6 +87,13 @@ libcorpustagsetmanager.o: $(CPP) -shared libcorpustagsetmanager_wrap.o \ $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustagsetmanager.so +# Lexeme +libcorpuslexeme.o: + $(SWIG) $(SWIGOPTS_LANG) libcorpuslexeme.i + $(CPP) -c libcorpuslexeme_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared libcorpuslexeme_wrap.o \ + $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpuslexeme.so + # ----------------------------------------------------------------------------- clean: rm -f $(CBIN) $(CBINOUT) $(CWRAP) $(CWRAPBIN) $(PYMODULES) $(PYCBIN) diff --git a/swig/libcorpuslexeme.i b/swig/libcorpuslexeme.i new file mode 100644 index 0000000..058e8b7 --- /dev/null +++ b/swig/libcorpuslexeme.i @@ -0,0 +1,50 @@ +#ifndef SWIG_LIBCORPUS2_LEXEME_I +#define SWIG_LIBCORPUS2_LEXEME_I + +%module libcorpuslexeme +%{ + #include <unicode/unistr.h> + #include <libcorpus2/lexeme.h> +%} + +%include "libcorpustag.i" + +%include "std_string.i" +%include "std_vector.i" + +%feature("notabstract") Corpus2::Lexeme; + +%rename(__op_eq__) Corpus2::Lexeme::operator==(const Lexeme& other) const; +%rename(__op_lw__) Corpus2::Lexeme::operator<(const Lexeme& other) const; + +namespace Corpus2 { + class Lexeme { + public: + Lexeme(); + Lexeme(const UnicodeString& lemma, const Tag& tag); + + static Lexeme create(const UnicodeString& lemma, const Tag& tag); + // static Lexeme create_utf8(const std::string& lemma, const Tag& tag); + + const UnicodeString& lemma() const; + const std::string lemma_utf8() const; + + void set_lemma(const UnicodeString& l); + // void set_lemma_utf8(const std::string& l); + + const Tag& tag() const; + void set_tag(const Tag& tag); + + bool is_null() const; + void set_disamb(bool value); + bool is_disamb() const; + + bool operator<(const Lexeme& other) const; + bool operator==(const Lexeme& other) const; + }; +} + +using namespace std; +using namespace Corpus2; + +#endif /* SWIG_LIBCORPUS2_LEXEME_I */ -- GitLab