diff --git a/swig/Makefile b/swig/Makefile index f5fef21701afeb8a27a43a2dd184a873c7f6a0e5..4ff55987ed30fee961793d9322c89d0885a93006 100644 --- a/swig/Makefile +++ b/swig/Makefile @@ -15,40 +15,68 @@ ANTLRLIB=/usr/lib/libantlr-pic.a # CPPFLAGS=-fPIC -Wall -O2 CPPFLAGS=-fPIC -O2 -# CBIN=libcorpustag.o libcorpustagset.o libcorpustagsetmanager.o libcclparser.o -# CBIN=libcclvalue.o libcclbool.o libcclposition.o libccltset.o libcclstrset.o -# CBIN=libcclexpression.o libcclparsedexpression.o -CBIN=libcclfunctionaloperator.o +CBIN= +# CBIN=libcorpustag.o libcorpustagset.o libcorpustagsetmanager.o \ + libcclvalue.o libcclstrset.o libcclbool.o libcclposition.o \ + libccltset.o libcclexpression.o libcclparsedexpression.o \ + libcclfunctionaloperator.o libcclvariables.o libcclmatch.o \ + boostsharedptr.o libcorpustoken.o libcorpuslexeme.o \ + libcclsentencecontext.o libcorpussentence.o libccloperator.o CBINOUT=_libcorpustag.so _libcorpustagset.so _libcorpustagsetmanager.so \ _libcclvalue.so _libcclstrset.so _libcclbool.so _libcclposition.so \ _libccltset.so _libcclexpression.so _libcclparsedexpression.so \ - _libcclfunctionaloperator.so + _libcclfunctionaloperator.so _libcclvariables.so _libcclmatch.so \ + _boost_shared_ptr.so _libcorpustoken.so _libcorpuslexeme.so \ + _libcclsentencecontext.so _libcorpussentence.so _libccloperator.so CWRAP=libcorpustag_wrap.cxx libcorpustagset_wrap.cxx libcorpustagsetmanager_wrap.cxx \ libcclvalue_wrap.cxx libcclstrset_wrap.cxx libcclbool_wrap.cxx \ libcclparser_wrap.cxx libcclposition_wrap.cxx libccltset_wrap.cxx \ libcclexpression_wrap.cxx libcclparsedexpression_wrap.cxx \ - libcclfunctionaloperator_wrap.cxx + libcclfunctionaloperator_wrap.cxx libcclvariables_wrap.cxx libcclmatch_wrap.cxx \ + boost_shared_ptr_wrap.cxx libcorpustoken_wrap.cxx libcorpuslexeme_wrap.cxx \ + libcclsentencecontext_wrap.cxx libcorpussentence_wrap.cxx \ + libccloperator_wrap.cxx CWRAPBIN=libcorpustag_wrap.o libcorpustagset_wrap.o libcorpustagsetmanager_wrap.o \ libcclvalue_wrap.o libcclstrset_wrap.o libcclbool_wrap.o \ libcclposition_wrap.o libccltset_wrap.o \ libcclexpression_wrap.o libcclparsedexpression_wrap.o \ - libcclfunctionaloperator_wrap.o + libcclfunctionaloperator_wrap.o libcclvariables_wrap.o \ + libcclmatch_wrap.o boost_shared_ptr_wrap.o libcorpustoken_wrap.o \ + libcorpuslexeme_wrap.o libcclsentencecontext_wrap.o \ + libcorpussentence_wrap.o libccloperator_wrap.o PYMODULES=libcorpustag.py libcorpustagset.py libcorpustagsetmanager.py \ libcclvalue.py libcclstrset.py libcclbool.py \ libcclparser.py libcclposition.py libccltset.py \ - libcclexpression.py libcclparsedexpression.py + libcclexpression.py libcclparsedexpression.py libcclvariables.py \ + boost_shared_ptr.py libcorpuslexeme.py libcorpustoken.py \ + libcclsentencecontext.py libcorpussentence.py \ + libcclfunctionaloperator.py libccloperator.py PYCBIN=libcorpustag.pyc libcorpustagset.pyc libcorpustagsetmanager.pyc \ libcclvalue.pyc libcclstrset.pyc libcclbool.pyc \ - libcclposition.pyc libccltset.pyc libcclexpression.pyc libcclparsedexpression.pyc + libcclposition.pyc libccltset.pyc libcclexpression.pyc libcclparsedexpression.pyc \ + libcclvariables.pyc boost_shared_ptr.pyc libcorpuslexeme.pyc libcorpustoken.pyc \ + libcorpussentence.pyc libcclsentencecontext.pyc libcclfunctionaloperator.pyc \ + libccloperator.pyc -all:$(CBIN) +all:boost_shared_ptr.o $(CBIN) # Nothing to do +# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +# boost::shared_ptr wrappers +# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +# shared_ptr +boost_shared_ptr.o: + $(SWIG) $(SWIGOPTS_LANG) boost_shared_ptr.i + $(CPP) -c boost_shared_ptr_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared boost_shared_ptr_wrap.o -o _boost_shared_ptr.so + # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- @@ -74,7 +102,28 @@ libcorpustagsetmanager.o: $(SWIG) $(SWIGOPTS_LANG) libcorpustagsetmanager.i $(CPP) -c libcorpustagsetmanager_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) $(CPP) -shared libcorpustagsetmanager_wrap.o \ - $(CCLBIN) $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustagsetmanager.so + $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustagsetmanager.so + +# Token +libcorpustoken.o: + $(SWIG) $(SWIGOPTS_LANG) libcorpustoken.i + $(CPP) -c libcorpustoken_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared libcorpustoken_wrap.o \ + $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustoken.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 + +# Sentence +libcorpussentence.o: + $(SWIG) $(SWIGOPTS_LANG) libcorpussentence.i + $(CPP) -c libcorpussentence_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared libcorpussentence_wrap.o \ + $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpussentence.so # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- @@ -116,6 +165,13 @@ libcclstrset.o: $(CPP) -shared libcclstrset_wrap.o \ $(CCLBIN) $(ANTLRLIB) -o _libcclstrset.so +# match +libcclmatch.o: + $(SWIG) $(SWIGOPTS_LANG) libcclmatch.i + $(CPP) -c libcclmatch_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclmatch_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclmatch.so + # Expression libcclexpression.o: $(SWIG) $(SWIGOPTS_LANG) libcclexpression.i @@ -137,6 +193,29 @@ libcclfunctionaloperator.o: $(CPP) -shared libcclfunctionaloperator_wrap.o \ $(CCLBIN) $(ANTLRLIB) -o _libcclfunctionaloperator.so +# Operator +libccloperator.o: + $(SWIG) $(SWIGOPTS_LANG) libccloperator.i + $(CPP) -c libccloperator_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libccloperator_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libccloperator.so + + +# Variables +libcclvariables.o: + $(SWIG) $(SWIGOPTS_LANG) libcclvariables.i + $(CPP) -c libcclvariables_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclvariables_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclvariables.so + +# SentenceContext +libcclsentencecontext.o: + $(SWIG) $(SWIGOPTS_LANG) libcclsentencecontext.i + $(CPP) -c libcclsentencecontext_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclsentencecontext_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclsentencecontext.so + + # ----------------------------------------------------------------------------- clean: rm -f $(CBIN) $(CBINOUT) $(CWRAP) $(CWRAPBIN) $(PYMODULES) $(PYCBIN) diff --git a/swig/boost_shared_ptr.i b/swig/boost_shared_ptr.i index 1db8cbec5a26b3ca7b3709277971d8bc1ef6c9ad..7803b22154c79cba53773442e3387ca0e466f7da 100644 --- a/swig/boost_shared_ptr.i +++ b/swig/boost_shared_ptr.i @@ -4,7 +4,7 @@ #ifndef SWIG_BOOST_SHAREDPTR #define SWIG_BOOST_SHAREDPTR -%module swig_boost_shared_ptr +%module boost_shared_ptr %{ %} @@ -20,4 +20,6 @@ namespace boost { }; } +using namespace boost; + #endif /* SWIG_BOOST_SHAREDPTR */ diff --git a/swig/libcclexpression.i b/swig/libcclexpression.i index b401e859ee380a0b911092228eb12d6babccc89a..128f7a9f0492a0a05defd21bab6d3d501b54e14b 100644 --- a/swig/libcclexpression.i +++ b/swig/libcclexpression.i @@ -14,6 +14,7 @@ namespace Wccl { class Expression : boost::noncopyable { public: virtual std::string to_string(const Corpus2::Tagset& tagset) const = 0; + std::string to_raw_string() const; }; } diff --git a/swig/libcclfunctionaloperator.i b/swig/libcclfunctionaloperator.i index 6694916efdd8c08c2ed3c045c5c559510ed35a63..a36c72d8d2d750fcbdaea8354c411cd510e2bce4 100644 --- a/swig/libcclfunctionaloperator.i +++ b/swig/libcclfunctionaloperator.i @@ -1,27 +1,35 @@ #ifndef SWIG_LIBWCCL_FUNCTIONALOPERATOR_I #define SWIG_LIBWCCL_FUNCTIONALOPERATOR_I -%module libcclparsedexpression +%module libcclfunctionaloperator %{ #include <libwccl/ops/operator.h> %} +%include "libcclvalue.i" +%include "libcclvariables.i" +%include "libcclsentencecontext.i" %include "libcclparsedexpression.i" + %include "std_string.i" +%include "boost_shared_ptr.i" namespace Wccl { class FunctionalOperator : public ParsedExpression { public: // virtual boost::shared_ptr<const Value> base_apply(const SentenceContext& sc) = 0; - // boost::shared_ptr<FunctionalOperator> clone_ptr() const; - // boost::shared_ptr<FunctionalOperator> clone_clean_ptr() const; + boost::shared_ptr<FunctionalOperator> clone_ptr() const; + boost::shared_ptr<FunctionalOperator> clone_clean_ptr() const; protected: - // explicit FunctionalOperator(const Variables& variables); - // FunctionalOperator* clone_internal() const = 0; + explicit FunctionalOperator(const Variables& variables); + FunctionalOperator* clone_internal() const = 0; }; } +%template (FunctionalOperatorSharedPtr) boost::shared_ptr<Wccl::FunctionalOperator>; + +using namespace boost; using namespace std; using namespace Wccl; diff --git a/swig/libcclmatch.i b/swig/libcclmatch.i new file mode 100644 index 0000000000000000000000000000000000000000..41ba586bd2fc24102b69d20a9bc29dc212d2081d --- /dev/null +++ b/swig/libcclmatch.i @@ -0,0 +1,37 @@ +#ifndef SWIG_LIBWCCL_MATCH_I +#define SWIG_LIBWCCL_MATCH_I + +%module libcclbool +%{ + #include <libwccl/values/value.h> + #include <libwccl/values/match.h> +%} + +%include "libcclvalue.i" +%include "std_string.i" + +%feature("notabstract") Wccl::Match; + +namespace Wccl { + class Match : public Value { + public: + const char* get_type_name() const { return type_name; } + static std::string var_repr(const std::string &var_name); + std::string make_var_repr(const std::string &var_name) const { + return var_repr(var_name); + } + + Match(); + + // TODO + // virtual Position first_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>&) const; + // virtual Position last_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>&) const; + + std::string to_raw_string() const; + }; +} + +using namespace std; +using namespace Wccl; + +#endif /* SWIG_LIBWCCL_MATCH_I */ diff --git a/swig/libccloperator.i b/swig/libccloperator.i new file mode 100644 index 0000000000000000000000000000000000000000..609d91715a35d2ea7b424eb7232dac9418ac2b7a --- /dev/null +++ b/swig/libccloperator.i @@ -0,0 +1,71 @@ +#ifndef SWIG_LIBWCCL_OPERATOR_I +#define SWIG_LIBWCCL_OPERATOR_I + +%module libccloperator +%{ + #include <libwccl/ops/operator.h> +%} + + +%include "libcclvalue.i" +%include "libcclsentencecontext.i" +%include "libcclfunctionaloperator.i" + +/* +%include "libcclvariables.i" +%include "libcclparsedexpression.i" +*/ + +%include "std_string.i" +%include "boost_shared_ptr.i" + +%feature("notabstract") Wccl::Operator; + +%rename(__op_cop__) Wccl::Operator::operator=(const Operator& other); +%rename(__op_fun__) Wccl::Operator::operator()(const SentenceContext& sentence_context); + +namespace Wccl { + template <class T> class Operator : public FunctionalOperator { + public: + Operator(); + Operator& operator=(const Operator& other); +/* + Operator(const boost::shared_ptr<const Function<T> >& body, const Variables& variables); +*/ + + Operator(const Operator& other, bool clean = false); + + boost::shared_ptr<const T> operator()(const SentenceContext& sentence_context); + boost::shared_ptr<const T> apply(const SentenceContext& sentence_context); + boost::shared_ptr<T> copy_apply(const SentenceContext& sentence_context); + boost::shared_ptr<const Value> base_apply(const SentenceContext& sc); + + Operator clone() const; + Operator clone_clean() const; + + boost::shared_ptr<Operator<T> > clone_ptr() const; + boost::shared_ptr<Operator<T> > clone_clean_ptr() const; + + std::string to_string(const Corpus2::Tagset& tagset) const; + + protected: + Operator* clone_internal() const; + std::ostream& write_to(std::ostream& ostream) const; + }; + + %template (BoolOperator) Operator<Bool>; + %template (TSetOperator) Operator<TSet>; + %template (StrSetOperator) Operator<StrSet>; + %template (PositionOperator) Operator<Position>; + + %template (SharedPtrBoolOperator) boost::shared_ptr<Operator<Bool> >; + %template (SharedPtrTSetOperator) boost::shared_ptr<Operator<TSet> >; + %template (SharedPtrStrSetOperator) boost::shared_ptr<Operator<StrSet> >; + %template (SharedPtrPositionOperator) boost::shared_ptr<Operator<Position> >; +} + +using namespace boost; +using namespace std; +using namespace Wccl; + +#endif /* SWIG_LIBWCCL_OPERATOR_I */ diff --git a/swig/libcclparsedexpression.i b/swig/libcclparsedexpression.i index 6b224f7eb257ec1cffd37ce34180edb57deab9ff..12e3cfb6a688d4e03c1acf41b0d82e671dac93bb 100644 --- a/swig/libcclparsedexpression.i +++ b/swig/libcclparsedexpression.i @@ -6,33 +6,47 @@ #include <libwccl/ops/parsedexpression.h> %} +%include "libcclvalue.i" + +%include "libcclmatch.i" +%include "libcclbool.i" +%include "libccltset.i" +%include "libcclstrset.i" +%include "libcclposition.i" %include "libcclexpression.i" + %include "std_string.i" +%include "boost_shared_ptr.i" + +%rename(__op_get__) Wccl::ParsedExpression::operator[](const std::string& var_name) const; namespace Wccl { class ParsedExpression : public Expression { public: - // TODO - // const Value& operator[](const std::string& var_name) const; + const Value& operator[](const std::string& var_name) const; - // template<class T> - // const T& get(const std::string& var_name) const; + template<class T> T& get(const std::string& var_name); + %template(get_bool) get<Bool>; + %template(get_tset) get<TSet>; + %template(get_strset) get<StrSet>; + %template(get_position) get<Position>; + %template(get_match) get<Match>; - // template<class T> - // T& get(const std::string& var_name) - - // template<class T> - // void set(const std::string& var_name, const T& value); + template<class T> void set(const std::string& var_name, const T& value); + %template(set_bool) set<Bool>; + %template(set_tset) set<TSet>; + %template(set_strset) set<StrSet>; + %template(set_position) set<Position>; + %template(set_match) set<Match>; void clean(); - // boost::shared_ptr<ParsedExpression> clone_ptr() const; - // boost::shared_ptr<ParsedExpression> clone_clean_ptr() const; + boost::shared_ptr<ParsedExpression> clone_ptr() const; + boost::shared_ptr<ParsedExpression> clone_clean_ptr() const; std::string variables_string(const Corpus2::Tagset& tagset) const; - // std::ostream& dump_variables(std::ostream& ostream, const Corpus2::Tagset& tagset) const; + std::ostream& dump_variables(std::ostream& ostream, const Corpus2::Tagset& tagset) const; protected: - // explicit ParsedExpression(const Variables& variables); - // boost::shared_ptr<Variables> variables_; + explicit ParsedExpression(const Variables& variables); virtual ParsedExpression* clone_internal() const = 0; }; } diff --git a/swig/libcclsentencecontext.i b/swig/libcclsentencecontext.i new file mode 100644 index 0000000000000000000000000000000000000000..b1bb4459e9bbe96460fbf1037e28be6dabd136e0 --- /dev/null +++ b/swig/libcclsentencecontext.i @@ -0,0 +1,70 @@ +#ifndef SWIG_LIBWCCL_SENTENCECONTEXT_I +#define SWIG_LIBWCCL_SENTENCECONTEXT_I + +%module libcclsentencecontext +%{ + #include <libwccl/sentencecontext.h> +%} + +%include "libcorpustoken.i" +%include "libcorpuslexeme.i" +%include "libcorpussentence.i" + +%include "libcclposition.i" + +%include "std_string.i" +%include "boost_shared_ptr.i" + +// %feature("notabstract") Wccl::SentenceContext; + +namespace Wccl { + class SentenceContext { + public: + explicit SentenceContext(const boost::shared_ptr<Corpus2::Sentence>& s); + + SentenceContext duplicate() const; + SentenceContext* clone() const; + + Corpus2::Sentence& get_sentence(); + const Corpus2::Sentence& get_sentence() const; + + int size() const; + int get_position() const; + + bool is_current_inside() const; + bool is_inside(int abs_pos) const; + bool is_inside(const Position& pos) const; + + bool is_outside(int abs_pos) const; + bool is_outside(const Position& pos) const; + + bool validate_range( + const Position& left, + const Position& right, + int& abs_left, + int& abs_right) const; + + void set_position(int new_position); + void advance(); + void goto_start(); + + const Corpus2::Token* at(int abs_pos) const; + const Corpus2::Token* at(const Position& position) const; + Corpus2::Token* at(int abs_pos); + Corpus2::Token* at(const Position& position); + const Corpus2::Token* current() const; + Corpus2::Token* current(); + + int get_abs_position(const Position& position) const; + int get_rel_position(const Position& position) const; + int translate_special_position(int pos) const; + }; +} + +%template(SentenceContextSharedPtr) boost::shared_ptr<Wccl::SentenceContext>; + +using namespace boost; +using namespace std; +using namespace Wccl; + +#endif /* SWIG_LIBWCCL_SENTENCECONTEXT_I */ diff --git a/swig/libcclvalue.i b/swig/libcclvalue.i index 5ee3a9c2890f12797e4b24bd234ff52e7d2a57fa..62462210fbce71b3286b349fcd6916370eb73ef6 100644 --- a/swig/libcclvalue.i +++ b/swig/libcclvalue.i @@ -7,6 +7,7 @@ %} %include "std_string.i" +%include "boost_shared_ptr.i" namespace Wccl { class Value { @@ -22,6 +23,9 @@ namespace Wccl { }; } +// %template(BoolSharedPtr) boost::shared_ptr<Wccl::Value>; + +using namespace boost; using namespace std; using namespace Wccl; diff --git a/swig/libcclvariables.i b/swig/libcclvariables.i new file mode 100644 index 0000000000000000000000000000000000000000..593baeb0c36c981d388f52922f505064a84de929 --- /dev/null +++ b/swig/libcclvariables.i @@ -0,0 +1,165 @@ +#ifndef SWIG_LIBWCCL_VARIABLES_I +#define SWIG_LIBWCCL_VARIABLES_I + +%module libcclvariables +%{ + #include <libwccl/variables.h> +%} + +%include "libcclvalue.i" +%include "libcclmatch.i" +%include "libcclbool.i" +%include "libcclposition.i" +%include "libcclstrset.i" +%include "libccltset.i" + +%include "std_string.i" +%include "boost_shared_ptr.i" + +namespace Wccl { + /* ----------------------------------------------------------------------- */ + /* Helper detail class */ + namespace detail { + template<class T> class Vmap { + public: + typedef std::map< std::string, boost::shared_ptr<T> > map_t; + }; + + // %template(VmapBool) Vmap<Bool>; + + } // detail ns + + /* ----------------------------------------------------------------------- */ + /* Base Accessor */ + class BaseAccessor { + public: + const std::string get_name(); + + protected: + BaseAccessor(const std::string& varname); + }; + + /* ----------------------------------------------------------------------- */ + /* Variable Accessor */ + template<typename T> + class VariableAccessor : public BaseAccessor { + public: + }; + + /* ----------------------------------------------------------------------- */ + /* Variables */ + class Variables : + detail::Vmap<Value>, + detail::Vmap<Bool>, + detail::Vmap<Position>, + detail::Vmap<StrSet>, + detail::Vmap<TSet>, + detail::Vmap<Match> + { + public: + Variables(); + + template<typename T> int size() const; + %template(size_bool) size<Bool>; + %template(size_tset) size<TSet>; + %template(size_strset) size<StrSet>; + %template(size_position) size<Position>; + %template(size_match) size<Match>; + + void reset_values(); + + template<typename T> const typename detail::Vmap<T>::map_t get_all() const; + %template(get_all_bool) get_all<Bool>; + %template(get_all_tset) get_all<TSet>; + %template(get_all_strset) get_all<StrSet>; + %template(get_all_position) get_all<Position>; + %template(get_all_match) get_all<Match>; + + Variables* clone() const; + + template<typename T> boost::shared_ptr<T> get(const std::string& s) const; + %template(get_bool) get<Bool>; + %template(get_tset) get<TSet>; + %template(get_strset) get<StrSet>; + %template(get_position) get<Position>; + %template(get_match) get<Match>; + + template<typename T> boost::shared_ptr<T> get_or_throw(const std::string& s) const; + %template(get_or_throw_bool) get_or_throw<Bool>; + %template(get_or_throw_tset) get_or_throw<TSet>; + %template(get_or_throw_strset) get_or_throw<StrSet>; + %template(get_or_throw_position) get_or_throw<Position>; + %template(get_or_throw_match) get_or_throw<Match>; + + template<typename T> const typename T::value_type& get_value(const std::string& s) const; + %template(get_value_bool) get_value<Bool>; + %template(get_value_tset) get_value<TSet>; + %template(get_value_strset) get_value<StrSet>; + %template(get_value_position) get_value<Position>; + // %template(get_value_match) get_value<Match>; + + template<typename T> VariableAccessor<T> create_accessor(const std::string& s); + %template(create_accessor_bool) create_accessor<Bool>; + %template(create_accessor_tset) create_accessor<TSet>; + %template(create_accessor_strset) create_accessor<StrSet>; + %template(create_accessor_position) create_accessor<Position>; + %template(create_accessor_match) create_accessor<Match>; + + template<typename T> boost::shared_ptr<T> get_fast(const VariableAccessor<T>& a) const; + %template(get_fast_bool) get_fast<Bool>; + %template(get_fast_tset) get_fast<TSet>; + %template(get_fast_strset) get_fast<StrSet>; + %template(get_fast_position) get_fast<Position>; + %template(get_fast_match) get_fast<Match>; + + template<typename T> boost::shared_ptr<T> get_put(const std::string& s); + %template(get_put_bool) get_put<Bool>; + %template(get_put_tset) get_put<TSet>; + %template(get_put_strset) get_put<StrSet>; + %template(get_put_position) get_put<Position>; + %template(get_put_match) get_put<Match>; + + template<typename T> void put(const std::string& s, const boost::shared_ptr<T>& v); + %template(put_bool_2) put<Bool>; + %template(put_tset_2) put<TSet>; + %template(put_strset_2) put<StrSet>; + %template(put_position_2) put<Position>; + %template(put_match_2) put<Match>; + + void put_any(const std::string& s, const boost::shared_ptr<Value>& v); + + /* + template<typename T> bool del(const std::string& s); + %template(del_bool) del<Bool>; + %template(del_tset) del<TSet>; + %template(del_strset) del<StrSet>; + %template(del_position) del<Position>; + %template(del_match) del<Match>; + */ + + bool del_any(const std::string& s); + + template<typename T> void put(const std::string& s, T* v); + %template(put_bool) put<Bool>; + %template(put_tset) put<TSet>; + %template(put_strset) put<StrSet>; + %template(put_position) put<Position>; + %template(put_match) put<Match>; + + template<typename T> void set(const std::string& s, const T& v); + %template(set_bool) set<Bool>; + %template(set_tset) set<TSet>; + %template(set_strset) set<StrSet>; + %template(set_position) set<Position>; + %template(set_match) set<Match>; + }; +} + +%template(VariablesSharedPtr) boost::shared_ptr<Wccl::Variables>; + +using namespace boost; +using namespace std; +using namespace Wccl; +using namespace detail; + +#endif /* SWIG_LIBWCCL_VARIABLES_I */ diff --git a/swig/libcorpuslexeme.i b/swig/libcorpuslexeme.i new file mode 100644 index 0000000000000000000000000000000000000000..857553661fff94dc5373f116b96463cf05ce7e28 --- /dev/null +++ b/swig/libcorpuslexeme.i @@ -0,0 +1,43 @@ +#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); + const UnicodeString& lemma() const; + void set_lemma(const UnicodeString& l); + const std::string lemma_utf8() const; + 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 */ diff --git a/swig/libcorpussentence.i b/swig/libcorpussentence.i new file mode 100644 index 0000000000000000000000000000000000000000..89f3c0a9c1b715911d3dcb21630cf94be61518f9 --- /dev/null +++ b/swig/libcorpussentence.i @@ -0,0 +1,46 @@ +#ifndef SWIG_LIBCORPUS2_SENTENCE_I +#define SWIG_LIBCORPUS2_SENTENCE_I + +%module libcorpussentence +%{ + #include <libcorpus2/sentence.h> +%} + +%include "libcorpustoken.i" + +%include "std_string.i" +%include "std_vector.i" + +%include "boost_shared_ptr.i" + +%feature("notabstract") Corpus2::Sentence; + +%rename(__op_get__) Corpus2::Sentence::operator[](size_t idx) const; + +namespace Corpus2 { + class Sentence { + public: + Sentence(); + virtual ~Sentence(); + + virtual boost::shared_ptr<Sentence> clone_shared() const; + + void release_tokens(); + bool empty() const; + size_t size() const; + Token* operator[](size_t idx); + const std::vector<Token*>& tokens() const; + std::vector<Token*>& tokens(); + virtual void append(Token* t); + const Token* first_token() const; + + }; +} + +%template(SentenceSharedPtr) boost::shared_ptr<Corpus2::Sentence>; + +using namespace boost; +using namespace std; +using namespace Corpus2; + +#endif /* SWIG_LIBCORPUS2_SENTENCE_I */ diff --git a/swig/libcorpustag.i b/swig/libcorpustag.i index 4184bca38e9e286c4902a10f2223816866a2acc4..0197662fe0b59e1d699581e0709d180f746fbd31 100644 --- a/swig/libcorpustag.i +++ b/swig/libcorpustag.i @@ -17,6 +17,9 @@ %feature("notabstract") Corpus2::Tag; +%rename(__op_eq__) Corpus2::Tag::operator==(const Tag& other) const; +%rename(__op_lw__) Corpus2::Tag::operator<(const Tag& other) const; + namespace Corpus2 { class Tag { public: diff --git a/swig/libcorpustoken.i b/swig/libcorpustoken.i new file mode 100644 index 0000000000000000000000000000000000000000..664123cd95aaf24829725f55a4232f7f096ad8ab --- /dev/null +++ b/swig/libcorpustoken.i @@ -0,0 +1,54 @@ +#ifndef SWIG_LIBCORPUS2_TOKEN_I +#define SWIG_LIBCORPUS2_TOKEN_I + +%module libcorpustoken +%{ + #include <unicode/unistr.h> + #include <libcorpus2/token.h> +%} + +%include "libcorpuslexeme.i" +%include "libcorpustagset.i" + +%include "std_pair.i" +%include "std_string.i" +%include "std_vector.i" + +%feature("notabstract") Corpus2::Token; + +%rename(__op_eq__) Corpus2::Token::operator==(const Token& other) const; + +namespace Corpus2 { + class Token { + public: + Token(); + Token(const UnicodeString& orth, PwrNlp::Whitespace::Enum wa); + Token* clone() const; + + const UnicodeString& orth() const; + std::string orth_utf8() const; + void set_orth(const UnicodeString& orth); + const PwrNlp::Whitespace::Enum& wa() const; + void set_wa(const PwrNlp::Whitespace::Enum& wa); + const std::vector<Lexeme>& lexemes() const; + std::vector<Lexeme>& lexemes(); + void add_lexeme(const Lexeme& lex); + const Lexeme& get_preferred_lexeme(const Tagset& tagset) const; + size_t get_preferred_lexeme_index(const Tagset& tagset) const; + void make_ign(const Tagset& tagset); + void add_ign(const Tagset& tagset); + bool operator==(const Token& other) const; + bool check_duplicate_lexemes() const; + bool remove_duplicate_lexemes(); + bool has_disamb_lexeme() const; + int count_disamb_lexemes() const; + + // std::pair<lexeme_filter_iterator, lexeme_filter_iterator> disamb_lexemes() const; + }; +} + +using namespace std; +using namespace Corpus2; + + +#endif /* SWIG_LIBCORPUS2_TOKEN_I */