diff --git a/libcorpus2/io/relreader.cpp b/libcorpus2/io/relreader.cpp index a55f02c6a0ee08b3ed7cbdaf7c57263951cb0f9c..1fa75c0bcfa5f29c7a653802d4aad789314f8456 100644 --- a/libcorpus2/io/relreader.cpp +++ b/libcorpus2/io/relreader.cpp @@ -28,6 +28,8 @@ RelationReader::RelationReader(const std::string &rela_path) readed_ = false; in_relation_ = false; in_relations_ = false; + in_from_direct_ = false; + in_to_direct_ = false; file_.reset(new std::ifstream(rela_path.c_str(), std::ifstream::in)); @@ -73,9 +75,11 @@ void RelationReader::on_start_element(const Glib::ustring& name, parse_relation_name(attributes); } else if (in_relation_ && name == RELATION_DIRECT_FROM) { + in_from_direct_ = true; parse_direction_from(attributes); } else if (in_relation_ && name == RELATION_DIRECT_TO) { + in_to_direct_ = true; parse_direction_to(attributes); } else { @@ -84,6 +88,8 @@ void RelationReader::on_start_element(const Glib::ustring& name, } void RelationReader::on_end_element(const Glib::ustring& name) { + int annotation_number = 99999999; + if (name == RELATIONS_TAG) { in_relations_ = false; } @@ -96,6 +102,26 @@ void RelationReader::on_end_element(const Glib::ustring& name) { throw; } } + else if (in_from_direct_) { + std::istringstream (ann_number_) >> annotation_number; + rel_from_ = boost::make_shared<DirectionPoint>( + rel_from_->sentence_id(), + rel_from_->channel_name(), + annotation_number + ); + ann_number_ = ""; + in_from_direct_ = false; + } + else if (in_to_direct_) { + std::istringstream (ann_number_) >> annotation_number; + rel_to_ = boost::make_shared<DirectionPoint>( + rel_to_->sentence_id(), + rel_to_->channel_name(), + annotation_number + ); + ann_number_ = ""; + in_to_direct_ = false; + } else { // } @@ -156,8 +182,6 @@ void RelationReader::parse_direction(const AttributeList& attributes, std::string sentence_id = get_attribute_value(attributes, RELATION_SENTENCE_ID); std::string channel_name = get_attribute_value(attributes, RELATION_CHANNEL_NAME); - std::istringstream (ann_number_) >> annotation_number; - direct = boost::make_shared<DirectionPoint>( sentence_id, channel_name, annotation_number); } diff --git a/libcorpus2/io/relreader.h b/libcorpus2/io/relreader.h index 6ec9b79ebb76fd26379fcb71eca6e173f6d191c5..fea4cdab732f86ae2e12d53932a2f09f728cb8ed 100644 --- a/libcorpus2/io/relreader.h +++ b/libcorpus2/io/relreader.h @@ -105,6 +105,8 @@ private: bool readed_; bool in_relation_; bool in_relations_; + bool in_from_direct_; + bool in_to_direct_; /// File pointer boost::scoped_ptr<std::istream> file_;