From e11d00b85726ce4e0e814d9696e9e13f9df096c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl>
Date: Wed, 11 May 2011 16:20:56 +0200
Subject: [PATCH] (swig) Added wrapper for Wccl::Lexicon

---
 swig/Makefile        | 13 +++++++++
 swig/libccllexicon.i | 69 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 swig/libccllexicon.i

diff --git a/swig/Makefile b/swig/Makefile
index 4ee6bfd..63c97ce 100644
--- a/swig/Makefile
+++ b/swig/Makefile
@@ -39,6 +39,7 @@ CBIN=libcclvalue.o \
 	libcclmatchrule.o \
 	libcclmatchrulesequence.o \
 	libcclfunctionalopsequence.o \
+	libccllexicon.o \
 	libcclwcclfileopsections.o \
 	libcclwcclfile.o \
 	wccl.o
@@ -67,6 +68,7 @@ CBINOUT=_libcclvalue.so \
 				_libcclmatchrule.so \
 				_libcclmatchrulesequence.so \
 				_libcclfunctionalopsequence.so \
+				_libccllexicon.so \
 				_libcclwcclfileopsections.so \
 				_wccl.so \
 				_boost_shared_ptr.so
@@ -95,6 +97,7 @@ CWRAP=libcclvalue_wrap.cxx \
 			libcclmatchrule_wrap.cxx \
 			libcclmatchrulesequence_wrap.cxx \
 			libcclfunctionalopsequence_wrap.cxx \
+			libccllexicon_wrap.cxx \
 			libcclwcclfileopsections_wrap.cxx \
 			wccl_wrap.cxx \
 			boost_shared_ptr_wrap.cxx
@@ -123,6 +126,7 @@ CWRAPBIN=libcclvalue_wrap.o \
 				 libcclmatchrule_wrap.o \
 				 libcclmatchrulesequence_wrap.o \
 				 libcclfunctionalopsequence_wrap.o \
+				 libccllexicon_wrap.o \
 				 libcclwcclfileopsections_wrap.o \
 				 wccl_wrap.o \
 				 boost_shared_ptr_wrap.o
@@ -151,6 +155,7 @@ PYMODULES=libcclvalue.py \
 					libcclmatchrule.py \
 					libcclmatchrulesequence.py \
 					libcclfunctionalopsequence.py \
+					libccllexicon.py \
 					libcclwcclfileopsections.py \
 					wccl.py \
 					boost_shared_ptr.py
@@ -179,6 +184,7 @@ PYCBIN=libcclvalue.pyc \
 			 libcclmatchrule.pyc \
 			 libcclmatchrulesequence.pyc \
 			 libcclfunctionalopsequence.pyc \
+			 libccllexicon.pyc \
 			 libcclwcclfileopsections.pyc \
 			 wccl.pyc \
 			 boost_shared_ptr.pyc
@@ -374,6 +380,13 @@ libcclfunctionalopsequence.o:
 	$(CPP) -shared libcclfunctionalopsequence_wrap.o \
 		$(CCLBIN) $(ANTLRLIB) -o _libcclfunctionalopsequence.so
 
+# Lexicon
+libccllexicon.o:
+	$(SWIG) $(SWIGOPTS_LANG) libccllexicon.i
+	$(CPP) -c libccllexicon_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS)
+	$(CPP) -shared libccllexicon_wrap.o \
+		$(CCLBIN) $(ANTLRLIB) -o _libccllexicon.so
+
 # WcclFileOpSections
 libcclwcclfileopsections.o:
 	$(SWIG) $(SWIGOPTS_LANG) libcclwcclfileopsections.i
diff --git a/swig/libccllexicon.i b/swig/libccllexicon.i
new file mode 100644
index 0000000..69cc324
--- /dev/null
+++ b/swig/libccllexicon.i
@@ -0,0 +1,69 @@
+#ifndef SWIG_LIBWCCL_LEXICON_I
+#define SWIG_LIBWCCL_LEXICON_I
+
+%module libccllexicon
+%{
+  #include <libwccl/lexicon/lexicon.h>
+
+  #include <libcorpus2/lexeme.h> 
+  #include <boost/unordered_map.hpp>
+%}
+
+%include "libcclstrset.i"
+
+%include "std_string.i"
+%include "boost_shared_ptr.i"
+
+%rename(map_t) boost::unordered_map<UnicodeString, UnicodeString>;
+
+%nodefaultctor Wccl::Lexicon;
+
+namespace Wccl {
+  class Lexicon {
+  public:
+    typedef boost::unordered_map<UnicodeString, UnicodeString> map_t;
+
+    /* --------------------------------------------------------------------- */
+
+    Lexicon(const std::string& name, const std::string& file_name);
+
+    /* --------------------------------------------------------------------- */
+
+    const UnicodeString& translate(const UnicodeString& key) const;
+    // boost::shared_ptr<StrSet> translate(const StrSet& set) const;
+
+    // TODO
+    // std::string translate_utf8(const std::string&);
+
+    /* --------------------------------------------------------------------- */
+
+    std::string name() const;
+    std::string file_name() const;
+
+    /* --------------------------------------------------------------------- */
+
+    bool has_key(const UnicodeString& key) const;
+
+    // TODO
+    // bool has_key_utf8(const std::string& key) const 
+    
+    /* --------------------------------------------------------------------- */
+
+    void insert(const UnicodeString& key, const UnicodeString& value);
+    void insert(const UnicodeString& key);
+    
+    // TODO
+    // void insert_utf8(const std::string& key, const std::string& value);
+    // void insert_utf8(const std::string& key);
+
+    /* --------------------------------------------------------------------- */
+
+    const map_t& map() const;
+  };
+}
+
+using namespace boost;
+using namespace Wccl;
+using namespace std;
+
+#endif /* SWIG_LIBWCCL_LEXICON_I */
-- 
GitLab