diff --git a/libcorpus2/ann/annotatedsentence.h b/libcorpus2/ann/annotatedsentence.h index b1207f48cd86ac33cf340012c4168c8cc63f9a10..d186248e652f85660b68bf21c24adc01ad02a5db 100644 --- a/libcorpus2/ann/annotatedsentence.h +++ b/libcorpus2/ann/annotatedsentence.h @@ -96,6 +96,19 @@ public: return i->second; } + /** + * Add a copy of the given annotation channel. + * If a channel of the given name already exists, will do nothing and return false. + * Otherwise, will add the channel and return true. + */ + bool add_channel(const std::string& name, const AnnotationChannel& chan) { + if (has_channel(name)) { + return false; + } + channels_.insert(std::make_pair(name, chan)); + return true; + } + const chan_map_t& all_channels() const { return channels_; } diff --git a/swig/annotatedsentence.i b/swig/annotatedsentence.i index 07232be2e89d604040e814b8226e37396129b990..0c59edb90eb7cdcdfeb5155f704fd6c1ee61cda2 100644 --- a/swig/annotatedsentence.i +++ b/swig/annotatedsentence.i @@ -49,6 +49,7 @@ namespace Corpus2 { AnnotationChannel& get_channel(const std::string& name); const AnnotationChannel& get_channel(const std::string& name) const; + bool add_channel(const std::string& name, const AnnotationChannel& chan); const chan_map_t& all_channels() const; /* --------------------------------------------------------------------- */