From a878d6259a59d3b2c7f8d06cf8f59b00553da225 Mon Sep 17 00:00:00 2001 From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl> Date: Wed, 5 Dec 2012 10:02:13 +0100 Subject: [PATCH] CCL writer shall write only id and type chunk attrs (if non-empty), in compliance with DTD --- CMakeLists.txt | 2 +- libcorpus2/io/cclwriter.cpp | 15 +++++++++++++-- libcorpus2/io/writer.h | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19ce20e..dd9d2a7 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 "1") cmake_minimum_required(VERSION 2.8.0) diff --git a/libcorpus2/io/cclwriter.cpp b/libcorpus2/io/cclwriter.cpp index cd4c941..4bfc898 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 9e8978e..7168bb6 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: -- GitLab