From 12ed6c78436783a45b797b576406680f72a75a7d Mon Sep 17 00:00:00 2001 From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl> Date: Thu, 17 Nov 2011 13:28:55 +0100 Subject: [PATCH] make Annotation aware of its original segment idx --- libcorpus2/ann/channel.cpp | 1 + libcorpus2/ann/channel.h | 6 +++++- swig/annotationchannel.i | 3 ++- tests/ann_basic.cpp | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libcorpus2/ann/channel.cpp b/libcorpus2/ann/channel.cpp index 34e7549..581c9dd 100644 --- a/libcorpus2/ann/channel.cpp +++ b/libcorpus2/ann/channel.cpp @@ -152,6 +152,7 @@ std::vector<Annotation> AnnotationChannel::make_annotation_vector( rv.resize(smax = s); } rv[s - 1].indices.push_back(i); + rv[s - 1].seg_number = s; if (heads_[i]) { rv[s - 1].head_index = i; } diff --git a/libcorpus2/ann/channel.h b/libcorpus2/ann/channel.h index 204ee2c..d0ba721 100644 --- a/libcorpus2/ann/channel.h +++ b/libcorpus2/ann/channel.h @@ -13,12 +13,16 @@ namespace Corpus2 { /** * A general indexed annotation spanning a possibly disjoint group of * tokens, with a distinguished 'head' token. + * The annotation contains information about token indices (array subscripts + * referring to the original sentence), the index of a token marked as head, + * as well as the original segment number (segment index). */ struct Annotation { - Annotation() : indices(), head_index(-1) {} + Annotation() : indices(), head_index(-1), seg_number(0) {} std::vector<int> indices; int head_index; + int seg_number; bool empty() const { return indices.empty(); } diff --git a/swig/annotationchannel.i b/swig/annotationchannel.i index 1d9c8da..8ffeb1d 100644 --- a/swig/annotationchannel.i +++ b/swig/annotationchannel.i @@ -18,9 +18,10 @@ namespace Corpus2 { struct Annotation { - Annotation() : indices(), head_index(-1) {} + Annotation() : indices(), head_index(-1), seg_number(0) {} std::vector<int> indices; int head_index; + int seg_number; bool empty() const; bool sane() const; }; diff --git a/tests/ann_basic.cpp b/tests/ann_basic.cpp index 54a1e0d..5a4204b 100644 --- a/tests/ann_basic.cpp +++ b/tests/ann_basic.cpp @@ -119,6 +119,10 @@ BOOST_AUTO_TEST_CASE( make_ann ) BOOST_CHECK_EQUAL(anns[2].indices[1], 4); BOOST_CHECK_EQUAL(anns[3].indices[0], 5); BOOST_CHECK_EQUAL(anns[2].head_index, 3); + BOOST_CHECK_EQUAL(anns[0].seg_number, 1); + BOOST_CHECK_EQUAL(anns[1].seg_number, 2); + BOOST_CHECK_EQUAL(anns[2].seg_number, 3); + BOOST_CHECK_EQUAL(anns[3].seg_number, 4); } -- GitLab