diff --git a/CMakeLists.txt b/CMakeLists.txt index 285c5f61f7532b34b5c05471398a63fbee740bb6..9f337a4b4b1dfc969b06982a3bcbaf51a2ed2f79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ PROJECT(Corpus2Library) set(corpus2_ver_major "1") set(corpus2_ver_minor "2") -set(corpus2_ver_patch "0") +set(corpus2_ver_patch "3") cmake_minimum_required(VERSION 2.8.0) diff --git a/libcorpus2/ann/annotatedsentence.cpp b/libcorpus2/ann/annotatedsentence.cpp index 50c5ae81df19db8bcc128dbc7173fd1b09c761fa..137d0b413c98b2c0e14af561d0d1d46d49024ea8 100644 --- a/libcorpus2/ann/annotatedsentence.cpp +++ b/libcorpus2/ann/annotatedsentence.cpp @@ -34,7 +34,7 @@ AnnotatedSentence::~AnnotatedSentence() Sentence::Ptr AnnotatedSentence::clone_shared() const { boost::shared_ptr<AnnotatedSentence> copy; - copy = boost::make_shared<AnnotatedSentence>(); + copy = boost::make_shared<AnnotatedSentence>(id_); BOOST_FOREACH(const Token* t, tokens_) { copy->append(t->clone()); } @@ -48,7 +48,7 @@ boost::shared_ptr<AnnotatedSentence> AnnotatedSentence::wrap_sentence( boost::shared_ptr<AnnotatedSentence> a; a = boost::dynamic_pointer_cast<AnnotatedSentence>(s); if (!a) { - a = boost::make_shared<AnnotatedSentence>(); + a = boost::make_shared<AnnotatedSentence>(s->id()); BOOST_FOREACH(Token* t, s->tokens()) { a->append(t); } @@ -63,7 +63,7 @@ boost::shared_ptr<AnnotatedSentence> AnnotatedSentence::wrap_sentence_clone( boost::shared_ptr<AnnotatedSentence> a; a = boost::dynamic_pointer_cast<AnnotatedSentence>(s); if (!a) { - a = boost::make_shared<AnnotatedSentence>(); + a = boost::make_shared<AnnotatedSentence>(s->id()); BOOST_FOREACH(Token* t, s->tokens()) { a->append(t->clone()); } diff --git a/libcorpus2/io/cclwriter.cpp b/libcorpus2/io/cclwriter.cpp index cd4c941c160d212c8ca463552b852aa676fbdaa5..4bfc898a817be34a104e24230fc6fd6798026af5 100644 --- a/libcorpus2/io/cclwriter.cpp +++ b/libcorpus2/io/cclwriter.cpp @@ -127,9 +127,20 @@ void CclWriter::paragraph_head() void CclWriter::paragraph_head(const Chunk& c) { + // in CCL format chunks may have at most two attributes: + // id (unique XML-style id) and type (typically p for paragraphs) osi() << "<chunk"; - BOOST_FOREACH(const Chunk::attr_map_t::value_type& v, c.attributes()) { - os() << " " << v.first << "=\"" << v.second << "\""; + if (c.has_attribute("id")) { + const std::string &val = c.get_attribute("id"); + if (!val.empty()) { + os() << " id=\"" << val << "\""; + } + } + if (c.has_attribute("type")) { + const std::string &val = c.get_attribute("type"); + if (!val.empty()) { + os() << " type=\"" << val << "\""; + } } os() << ">\n"; } diff --git a/libcorpus2/io/writer.h b/libcorpus2/io/writer.h index 9e8978e02567f17032f4194f7e448f2664fca2bb..7168bb6d6ece4bb2af9b11670cc32364f6c62a0d 100644 --- a/libcorpus2/io/writer.h +++ b/libcorpus2/io/writer.h @@ -151,6 +151,10 @@ protected: return indent_; } + /** + * Write indentation spaces to the output stream and return the stream + * for writing. Convenience function useful when starting new lines + * in the output. */ std::ostream& osi(); private: diff --git a/libcorpus2/sentence.cpp b/libcorpus2/sentence.cpp index bb76754d3ad3bfc78e283da5babbd4c3df586baa..073d9a42ba6f1be3508380bb0cd3ff6d9d6fd554 100644 --- a/libcorpus2/sentence.cpp +++ b/libcorpus2/sentence.cpp @@ -33,7 +33,7 @@ Sentence::~Sentence() Sentence::Ptr Sentence::clone_shared() const { - Sentence::Ptr s = boost::make_shared<Sentence>(); + Sentence::Ptr s = boost::make_shared<Sentence>(id_); BOOST_FOREACH(const Token* t, tokens_) { s->append(t->clone()); } diff --git a/libcorpus2_whole/io/relwriter.h b/libcorpus2_whole/io/relwriter.h index 6f821154deb24b3e4e8c450c9800d27b6f4b8ac5..c6c326ca12f1bc49411426b5681680c29335121c 100755 --- a/libcorpus2_whole/io/relwriter.h +++ b/libcorpus2_whole/io/relwriter.h @@ -36,16 +36,14 @@ namespace whole { class RelationWriter { public: /** - * Reads a document with relations + * Writes a document with relations * @param rela_path path to file with relations */ RelationWriter(const std::string &rela_path); /** - * Lazy relations accessor. - * If relations are not readed then read relations and returns list of them. - * @return List of readed relations + * Writes given vector of Relations to the file specified before */ void write(const std::vector< boost::shared_ptr<Relation> >& relations); diff --git a/libcorpus2_whole/relation.cpp b/libcorpus2_whole/relation.cpp index b67558f63d8883e0c2ae9a8db71446422f4806c5..36e41e15046ca7e5e3b43257a83132a749d577a2 100755 --- a/libcorpus2_whole/relation.cpp +++ b/libcorpus2_whole/relation.cpp @@ -28,7 +28,7 @@ Relation::Relation(const std::string& name, { } -boost::shared_ptr<Relation> Relation::rel_pt(){ +boost::shared_ptr<Relation> Relation::clone_shared(){ relation_=boost::shared_ptr<Relation>(new Relation(name_,from_,to_)); return relation_; } diff --git a/libcorpus2_whole/relation.h b/libcorpus2_whole/relation.h index f1c17b87fbe17e817fd43182403fe0e43d48913d..0895cd4abf1f006f9e871e47bc8f0ae4b3973248 100755 --- a/libcorpus2_whole/relation.h +++ b/libcorpus2_whole/relation.h @@ -118,7 +118,8 @@ public: return name_; } - boost::shared_ptr<Relation> rel_pt(); + ///Shared pointer to copy of the relation + boost::shared_ptr<Relation> clone_shared(); private: /// Direction name diff --git a/swig/relation.i b/swig/relation.i index ad4b110986904eadc5124beea79ea43882a543f7..79b572f863134cabc3718228718abd795809b0cf 100755 --- a/swig/relation.i +++ b/swig/relation.i @@ -44,7 +44,7 @@ namespace whole { void set_to(const DirectionPoint& dp); void set_name(const std::string& s); - boost::shared_ptr<Relation> rel_pt(); + boost::shared_ptr<Relation> clone_shared(); /* It must be renamed because "from" is python keyword */ %rename(rel_from) from() const; const boost::shared_ptr<const DirectionPoint>& from() const;