From 1d1f10c95f881c0bfd29541ba75f242c958e981c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <Pawel.Kedzia@pwr.wroc.pl> Date: Thu, 17 Nov 2011 15:51:00 +0100 Subject: [PATCH] Swig code clean up --- swig/annotatedsentence.i | 3 +-- swig/annotationchannel.i | 11 +++++++++-- swig/annotationview.i | 3 ++- swig/chunk.i | 4 ---- swig/iob.i | 2 +- swig/lexeme.i | 2 +- swig/relation.i | 1 - swig/sentence.i | 8 +++++--- swig/tag.i | 2 ++ swig/tagset.i | 4 ++-- swig/tagsetmanager.i | 1 - swig/token.i | 6 +++++- swig/tokenmetadata.i | 1 + swig/tokenreader.i | 9 +++++---- swig/tokenwriter.i | 2 ++ swig/unicodestring.i | 18 +++++++++--------- 16 files changed, 45 insertions(+), 32 deletions(-) diff --git a/swig/annotatedsentence.i b/swig/annotatedsentence.i index 87cb5a3..e04c0a0 100644 --- a/swig/annotatedsentence.i +++ b/swig/annotatedsentence.i @@ -17,9 +17,8 @@ %feature("notabstract") Corpus2::AnnotatedSentence; -%template(chan_map_t) std::map<std::string, Corpus2::AnnotationChannel>; -%template(SentencePtr) boost::shared_ptr<Corpus2::Sentence>; %template(AnnotatedSentencePtr) boost::shared_ptr<Corpus2::AnnotatedSentence>; +%template(ConstAnnotatedSentencePtr) boost::shared_ptr<const Corpus2::AnnotatedSentence>; namespace Corpus2 { class MissingAnnotationChannel : public Corpus2Error { diff --git a/swig/annotationchannel.i b/swig/annotationchannel.i index 8ffeb1d..405c0ca 100644 --- a/swig/annotationchannel.i +++ b/swig/annotationchannel.i @@ -8,14 +8,21 @@ %include "std_string.i" %include "std_vector.i" +%include "boost_shared_ptr.i" %include "iob.i" %include "std_defs.i" -// %template(IntVector) std::vector<int>; -%template(IOBVector) std::vector<Corpus2::IOB::Enum>; +%template(chan_map_t) std::map<std::string, Corpus2::AnnotationChannel>; + +%template(AnnotationoPtr) boost::shared_ptr<Corpus2::Annotation>; +%template(ConstAnnotationoPtr) boost::shared_ptr<const Corpus2::Annotation>; + %template(AnnotationVector) std::vector<Corpus2::Annotation>; +%template(AnnotationChannelPtr) boost::shared_ptr<Corpus2::AnnotationChannel>; +%template(ConstAnnotationChannelPtr) boost::shared_ptr<const Corpus2::AnnotationChannel>; + namespace Corpus2 { struct Annotation { Annotation() : indices(), head_index(-1), seg_number(0) {} diff --git a/swig/annotationview.i b/swig/annotationview.i index 10fbb1c..977c1d3 100644 --- a/swig/annotationview.i +++ b/swig/annotationview.i @@ -14,6 +14,7 @@ %include "boost_shared_ptr.i" %template(AnnotationViewPtr) boost::shared_ptr<Corpus2::AnnotationView>; +%template(ConstAnnotationViewPtr) boost::shared_ptr<const Corpus2::AnnotationView>; %nodefaultctor Corpus2::TokenWriter; @@ -24,7 +25,7 @@ namespace Corpus2 { ~AnnotationView(); /* --------------------------------------------------------------------- */ - Ptr clone_shared() const; + boost::shared_ptr<Sentence> clone_shared() const; /* --------------------------------------------------------------------- */ void commit(); diff --git a/swig/chunk.i b/swig/chunk.i index b0af757..44ba6b9 100644 --- a/swig/chunk.i +++ b/swig/chunk.i @@ -8,7 +8,6 @@ %include "std_defs.i" - %include "std_set.i" %include "std_map.i" %include "std_pair.i" @@ -22,9 +21,6 @@ %template(ConstChunkPtr) boost::shared_ptr<const Corpus2::Chunk>; %template(ChunkPtrVector) std::vector< boost::shared_ptr<Corpus2::Chunk> >; -%template(SentencePtrVector) std::vector<boost::shared_ptr<Sentence> >; -// %template(attr_map_t) std::map<std::string, std::string>; - namespace Corpus2 { class Chunk { public: diff --git a/swig/iob.i b/swig/iob.i index 0f4be84..361e6c5 100644 --- a/swig/iob.i +++ b/swig/iob.i @@ -6,7 +6,7 @@ #include <libcorpus2/ann/iob.h> %} -// %include "...i" +%template(IOBVector) std::vector<Corpus2::IOB::Enum>; namespace Corpus2 { namespace IOB { diff --git a/swig/lexeme.i b/swig/lexeme.i index c78ade4..00646e2 100644 --- a/swig/lexeme.i +++ b/swig/lexeme.i @@ -18,7 +18,7 @@ %rename(__op_eq__) Corpus2::Lexeme::operator==(const Lexeme& other) const; %rename(__op_lw__) Corpus2::Lexeme::operator<(const Lexeme& other) const; -/* %template(TagPtr) boost::shared_ptr<Corpus2::Tag>; */ +%template(LexemeVector) std::vector<Corpus2::Lexeme>; namespace Corpus2 { class Lexeme { diff --git a/swig/relation.i b/swig/relation.i index 64084f2..89bc46d 100644 --- a/swig/relation.i +++ b/swig/relation.i @@ -10,7 +10,6 @@ %include "std_string.i" %include "boost_shared_ptr.i" -// %feature("notabstract") Corpus2::TokenMetaData; %template(DirectionPointPtr) boost::shared_ptr<Corpus2::DirectionPoint>; %template(ConstDirectionPointPtr) boost::shared_ptr<const Corpus2::DirectionPoint>; diff --git a/swig/sentence.i b/swig/sentence.i index f639b2f..edf2c47 100644 --- a/swig/sentence.i +++ b/swig/sentence.i @@ -10,9 +10,11 @@ %include "token.i" %include "boost_shared_ptr.i" -%template(Ptr) boost::shared_ptr<Corpus2::Sentence>; -%template(ConstPtr) boost::shared_ptr<const Corpus2::Sentence>; -%template(TokenPtrVector) std::vector<Corpus2::Token*>; +%template(SentencePtr) boost::shared_ptr<Corpus2::Sentence>; +%template(ConstSentencePtr) boost::shared_ptr<const Corpus2::Sentence>; + +%template(SentencePtrVector) std::vector<boost::shared_ptr<Corpus2::Sentence> >; +%template(ConstSentencePtrVector) std::vector<boost::shared_ptr<const Corpus2::Sentence> >; namespace Corpus2 { class Sentence { diff --git a/swig/tag.i b/swig/tag.i index 0197662..146175e 100644 --- a/swig/tag.i +++ b/swig/tag.i @@ -20,6 +20,8 @@ %rename(__op_eq__) Corpus2::Tag::operator==(const Tag& other) const; %rename(__op_lw__) Corpus2::Tag::operator<(const Tag& other) const; +%template(TagVector) std::vector<Corpus2::Tag>; + namespace Corpus2 { class Tag { public: diff --git a/swig/tagset.i b/swig/tagset.i index f4305db..8fe526e 100644 --- a/swig/tagset.i +++ b/swig/tagset.i @@ -15,8 +15,8 @@ %feature("notabstract") Corpus2::Tagset; -%template(TagVector) std::vector<Corpus2::Tag>; -// %template(StdStringVector) std::vector<std::string>; +%template(TagsetPtr) boost::shared_ptr<Corpus2::Tagset>; +%template(ConstTagsetPtr) boost::shared_ptr<const Corpus2::Tagset>; namespace Corpus2 { class Tagset; diff --git a/swig/tagsetmanager.i b/swig/tagsetmanager.i index a4aa9f4..113ed7e 100644 --- a/swig/tagsetmanager.i +++ b/swig/tagsetmanager.i @@ -14,7 +14,6 @@ %include "boost_shared_ptr.i" %feature("notabstract") Corpus2::TagsetManager; -%template(TagsetPtr) boost::shared_ptr<Tagset>; namespace Corpus2 { class TagsetNotFound : public Corpus2Error { diff --git a/swig/token.i b/swig/token.i index 19a0c56..e90abc8 100644 --- a/swig/token.i +++ b/swig/token.i @@ -20,7 +20,11 @@ %rename(__op_eq__) Corpus2::Token::operator==(const Corpus2::Token& other) const; -%template(LexemeVector) std::vector<Corpus2::Lexeme>; +%template(TokenPtr) boost::shared_ptr<Corpus2::Token>; +%template(ConstTokenPtr) boost::shared_ptr<const Corpus2::Token>; + +%template(TokenPtrVector) std::vector<Corpus2::Token*>; +%template(ConstTokenPtrVector) std::vector<const Corpus2::Token*>; namespace Corpus2 { class Token { diff --git a/swig/tokenmetadata.i b/swig/tokenmetadata.i index 422442b..8a80fd7 100644 --- a/swig/tokenmetadata.i +++ b/swig/tokenmetadata.i @@ -15,6 +15,7 @@ %feature("notabstract") Corpus2::TokenMetaData; %template(TokenMetaDataPtr) boost::shared_ptr<Corpus2::TokenMetaData>; +%template(ConstTokenMetaDataPtr) boost::shared_ptr<const Corpus2::TokenMetaData>; namespace Corpus2 { class TokenMetaData { diff --git a/swig/tokenreader.i b/swig/tokenreader.i index 505d664..1770331 100644 --- a/swig/tokenreader.i +++ b/swig/tokenreader.i @@ -17,11 +17,12 @@ %include "boost_shared_ptr.i" %nodefaultctor Corpus2::TokenReader; + %template(TokenReaderPtr) boost::shared_ptr<Corpus2::TokenReader>; -%template(TokenPtr) boost::shared_ptr<Corpus2::Token>; -// %template(StdStringVector) std::vector<std::string>; -// %template(ChunkPtr) boost::shared_ptr<Corpus2::Chunk>; -typedef boost::shared_ptr<Corpus2::Token> TokenPtr; +%template(ConstTokenReaderPtr) boost::shared_ptr<const Corpus2::TokenReader>; + +// typedef boost::shared_ptr<Corpus2::Token> TokenPtr; + namespace Corpus2 { class TokenReader { public: diff --git a/swig/tokenwriter.i b/swig/tokenwriter.i index bb55c1a..495e4b0 100644 --- a/swig/tokenwriter.i +++ b/swig/tokenwriter.i @@ -15,7 +15,9 @@ %include "boost_shared_ptr.i" %nodefaultctor Corpus2::TokenWriter; + %template(TokenWriterPtr) boost::shared_ptr<Corpus2::TokenWriter>; +%template(ConstTokenWriterPtr) boost::shared_ptr<const Corpus2::TokenWriter>; namespace Corpus2 { class TokenWriter { diff --git a/swig/unicodestring.i b/swig/unicodestring.i index 30997d7..ee6f096 100644 --- a/swig/unicodestring.i +++ b/swig/unicodestring.i @@ -17,11 +17,11 @@ class UnicodeString { UChar* getTerminatedBuffer(); %pythoncode %{ - def __unicode__(self): - return self.as_utf16().decode('utf16') + def __unicode__(self): + return self.as_utf16().decode('utf16') - def __str__(self): - return self.as_utf8() + def __str__(self): + return self.as_utf8() %} }; @@ -31,11 +31,11 @@ class UnicodeString { return std::string((char*)self->getTerminatedBuffer(), self->length()*2); } - std::string as_utf8() { - std::string r; - self->toUTF8String(r); - return r; - } + std::string as_utf8() { + std::string r; + self->toUTF8String(r); + return r; + } } -- GitLab