From 2855f14f58a16a733081901927f0400896fd06d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl>
Date: Wed, 27 Apr 2011 13:02:32 +0200
Subject: [PATCH] Corpus2::Chunk wrapper

---
 swig/Makefile         | 25 ++++++++++++++++------
 swig/libcorpuschunk.i | 50 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 6 deletions(-)
 create mode 100644 swig/libcorpuschunk.i

diff --git a/swig/Makefile b/swig/Makefile
index fe8d19f..caccecb 100644
--- a/swig/Makefile
+++ b/swig/Makefile
@@ -17,7 +17,8 @@ CBIN=libcorpustag.o \
 		 libcorpustagset.o \
 		 libcorpustagsetmanager.o \
 		 libcorpuslexeme.o \
-		 libcorpussentence.o
+		 libcorpussentence.o \
+		 libcorpuschunk.o
 
 CBINOUT=_boost_shared_ptr.so \
 				_libcorpustag.so \
@@ -25,7 +26,8 @@ CBINOUT=_boost_shared_ptr.so \
 				_libcorpustagsetmanager.so \
 				_libcorpuslexeme.so \
 				_libcorpustoken.so \
-				_libcorpussentence.so
+				_libcorpussentence.so \
+				_libcorpuschunk.so
 
 CWRAP=boost_shared_ptr_wrap.cxx \
 			libcorpustag_wrap.cxx \
@@ -33,7 +35,8 @@ CWRAP=boost_shared_ptr_wrap.cxx \
 			libcorpustagsetmanager_wrap.cxx \
 			libcorpuslexeme_wrap.cxx \
 			libcorpustoken_wrap.cxx \
-			libcorpussentence_wrap.cxx
+			libcorpussentence_wrap.cxx \
+			libcorpuschunk_wrap.cxx
 
 CWRAPBIN=boost_shared_ptr_wrap.o \
 				 libcorpustag_wrap.o \
@@ -41,7 +44,8 @@ CWRAPBIN=boost_shared_ptr_wrap.o \
 				 libcorpustagsetmanager_wrap.o \
 				 libcorpuslexeme_wrap.o \
 				 libcorpustoken_wrap.o \
-				 libcorpussentence_wrap.o
+				 libcorpussentence_wrap.o \
+				 libcorpuschunk_wrap.o
 
 PYMODULES=boost_shared_ptr.py \
 					libcorpustag.py \
@@ -49,7 +53,8 @@ PYMODULES=boost_shared_ptr.py \
 					libcorpustagsetmanager.py \
 					libcorpuslexeme.py \
 					libcorpustoken.py \
-					libcorpussentence.py
+					libcorpussentence.py \
+					libcorpuschunk.py
 
 PYCBIN=boost_shared_ptr.pyc \
 			 libcorpustag.pyc \
@@ -57,7 +62,8 @@ PYCBIN=boost_shared_ptr.pyc \
 			 libcorpustagsetmanager.pyc \
 			 libcorpuslexeme.pyc \
 			 libcorpustoken.pyc \
-			 libcorpussentence.pyc
+			 libcorpussentence.pyc \
+			 libcorpuschunk.pyc
 
 # -----------------------------------------------------------------------------
 all:boost_shared_ptr.o $(CBIN)
@@ -105,6 +111,13 @@ libcorpuslexeme.o:
 	$(CPP) -shared libcorpuslexeme_wrap.o \
 		$(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpuslexeme.so
 
+# Chunk
+libcorpuschunk.o:
+	$(SWIG) $(SWIGOPTS_LANG) libcorpuschunk.i
+	$(CPP) -c libcorpuschunk_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS)
+	$(CPP) -shared libcorpuschunk_wrap.o \
+		$(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpuschunk.so
+
 # Sentence
 libcorpussentence.o:
 	$(SWIG) $(SWIGOPTS_LANG) libcorpussentence.i
diff --git a/swig/libcorpuschunk.i b/swig/libcorpuschunk.i
new file mode 100644
index 0000000..1f5badb
--- /dev/null
+++ b/swig/libcorpuschunk.i
@@ -0,0 +1,50 @@
+#ifndef SWIG_LIBCORPUS2_CHUNK_I
+#define SWIG_LIBCORPUS2_CHUNK_I
+
+%module libcorpuschunk
+%{
+  #include <libcorpus2/chunk.h>
+%}
+
+
+%include "std_set.i"
+%include "std_map.i"
+%include "std_pair.i"
+%include "std_string.i"
+%include "std_vector.i"
+%include "boost_shared_ptr.i"
+
+%include "libcorpussentence.i"
+
+%template(attr_map_t) std::map<std::string, std::string>;
+
+namespace Corpus2 {
+  class Chunk {
+  public:
+    Chunk();
+    ~Chunk();
+
+    /* --------------------------------------------------------------------- */
+
+    boost::shared_ptr<Chunk> clone_shared() const;
+
+    bool empty() const;
+    size_t size() const;
+
+    bool has_attribute(const std::string& name) const;
+    std::string get_attribute(const std::string& name) const;
+    void set_attribute(const std::string& name, const std::string& value);
+
+    std::vector< boost::shared_ptr<Sentence> >& sentences();
+    const std::vector< boost::shared_ptr<Sentence> >& sentences() const;
+    void append(const boost::shared_ptr<Sentence>& s);
+
+    typedef std::map<std::string, std::string> attr_map_t;
+    const attr_map_t& attributes() const;
+  };
+}
+
+using namespace std;
+using namespace Corpus2;
+
+#endif /* SWIG_LIBCORPUS2_CHUNK_I */
-- 
GitLab