1.1 --- a/lemon/lgf_reader.h Tue Jul 01 21:21:49 2008 +0200
1.2 +++ b/lemon/lgf_reader.h Wed Jul 02 10:37:14 2008 +0200
1.3 @@ -881,9 +881,15 @@
1.4 std::vector<int> map_index(_node_maps.size());
1.5 int map_num, label_index;
1.6
1.7 - if (!readLine())
1.8 - throw DataFormatError("Cannot find map captions");
1.9 -
1.10 + char c;
1.11 + if (!readLine() || !(line >> c) || c == '@') {
1.12 + if (readSuccess() && line) line.putback(c);
1.13 + if (!_node_maps.empty())
1.14 + throw DataFormatError("Cannot find map names");
1.15 + return;
1.16 + }
1.17 + line.putback(c);
1.18 +
1.19 {
1.20 std::map<std::string, int> maps;
1.21
1.22 @@ -912,14 +918,15 @@
1.23
1.24 {
1.25 std::map<std::string, int>::iterator jt = maps.find("label");
1.26 - if (jt == maps.end())
1.27 - throw DataFormatError("Label map not found in file");
1.28 - label_index = jt->second;
1.29 + if (jt != maps.end()) {
1.30 + label_index = jt->second;
1.31 + } else {
1.32 + label_index = -1;
1.33 + }
1.34 }
1.35 map_num = maps.size();
1.36 }
1.37
1.38 - char c;
1.39 while (readLine() && line >> c && c != '@') {
1.40 line.putback(c);
1.41
1.42 @@ -937,8 +944,11 @@
1.43 Node n;
1.44 if (!_use_nodes) {
1.45 n = _digraph.addNode();
1.46 - _node_index.insert(std::make_pair(tokens[label_index], n));
1.47 + if (label_index != -1)
1.48 + _node_index.insert(std::make_pair(tokens[label_index], n));
1.49 } else {
1.50 + if (label_index == -1)
1.51 + throw DataFormatError("Label map not found in file");
1.52 typename std::map<std::string, Node>::iterator it =
1.53 _node_index.find(tokens[label_index]);
1.54 if (it == _node_index.end()) {
1.55 @@ -964,8 +974,14 @@
1.56 std::vector<int> map_index(_arc_maps.size());
1.57 int map_num, label_index;
1.58
1.59 - if (!readLine())
1.60 - throw DataFormatError("Cannot find map captions");
1.61 + char c;
1.62 + if (!readLine() || !(line >> c) || c == '@') {
1.63 + if (readSuccess() && line) line.putback(c);
1.64 + if (!_arc_maps.empty())
1.65 + throw DataFormatError("Cannot find map names");
1.66 + return;
1.67 + }
1.68 + line.putback(c);
1.69
1.70 {
1.71 std::map<std::string, int> maps;
1.72 @@ -995,14 +1011,15 @@
1.73
1.74 {
1.75 std::map<std::string, int>::iterator jt = maps.find("label");
1.76 - if (jt == maps.end())
1.77 - throw DataFormatError("Label map not found in file");
1.78 - label_index = jt->second;
1.79 + if (jt != maps.end()) {
1.80 + label_index = jt->second;
1.81 + } else {
1.82 + label_index = -1;
1.83 + }
1.84 }
1.85 map_num = maps.size();
1.86 }
1.87
1.88 - char c;
1.89 while (readLine() && line >> c && c != '@') {
1.90 line.putback(c);
1.91
1.92 @@ -1013,7 +1030,7 @@
1.93 throw DataFormatError("Source not found");
1.94
1.95 if (!_reader_bits::readToken(line, target_token))
1.96 - throw DataFormatError("Source not found");
1.97 + throw DataFormatError("Target not found");
1.98
1.99 std::vector<std::string> tokens(map_num);
1.100 for (int i = 0; i < map_num; ++i) {
1.101 @@ -1048,8 +1065,11 @@
1.102 Node target = it->second;
1.103
1.104 a = _digraph.addArc(source, target);
1.105 - _arc_index.insert(std::make_pair(tokens[label_index], a));
1.106 + if (label_index != -1)
1.107 + _arc_index.insert(std::make_pair(tokens[label_index], a));
1.108 } else {
1.109 + if (label_index == -1)
1.110 + throw DataFormatError("Label map not found in file");
1.111 typename std::map<std::string, Arc>::iterator it =
1.112 _arc_index.find(tokens[label_index]);
1.113 if (it == _arc_index.end()) {
1.114 @@ -1723,8 +1743,14 @@
1.115 std::vector<int> map_index(_node_maps.size());
1.116 int map_num, label_index;
1.117
1.118 - if (!readLine())
1.119 - throw DataFormatError("Cannot find map captions");
1.120 + char c;
1.121 + if (!readLine() || !(line >> c) || c == '@') {
1.122 + if (readSuccess() && line) line.putback(c);
1.123 + if (!_node_maps.empty())
1.124 + throw DataFormatError("Cannot find map names");
1.125 + return;
1.126 + }
1.127 + line.putback(c);
1.128
1.129 {
1.130 std::map<std::string, int> maps;
1.131 @@ -1754,14 +1780,15 @@
1.132
1.133 {
1.134 std::map<std::string, int>::iterator jt = maps.find("label");
1.135 - if (jt == maps.end())
1.136 - throw DataFormatError("Label map not found in file");
1.137 - label_index = jt->second;
1.138 + if (jt != maps.end()) {
1.139 + label_index = jt->second;
1.140 + } else {
1.141 + label_index = -1;
1.142 + }
1.143 }
1.144 map_num = maps.size();
1.145 }
1.146
1.147 - char c;
1.148 while (readLine() && line >> c && c != '@') {
1.149 line.putback(c);
1.150
1.151 @@ -1779,8 +1806,11 @@
1.152 Node n;
1.153 if (!_use_nodes) {
1.154 n = _graph.addNode();
1.155 - _node_index.insert(std::make_pair(tokens[label_index], n));
1.156 + if (label_index != -1)
1.157 + _node_index.insert(std::make_pair(tokens[label_index], n));
1.158 } else {
1.159 + if (label_index == -1)
1.160 + throw DataFormatError("Label map not found in file");
1.161 typename std::map<std::string, Node>::iterator it =
1.162 _node_index.find(tokens[label_index]);
1.163 if (it == _node_index.end()) {
1.164 @@ -1806,8 +1836,14 @@
1.165 std::vector<int> map_index(_edge_maps.size());
1.166 int map_num, label_index;
1.167
1.168 - if (!readLine())
1.169 - throw DataFormatError("Cannot find map captions");
1.170 + char c;
1.171 + if (!readLine() || !(line >> c) || c == '@') {
1.172 + if (readSuccess() && line) line.putback(c);
1.173 + if (!_edge_maps.empty())
1.174 + throw DataFormatError("Cannot find map names");
1.175 + return;
1.176 + }
1.177 + line.putback(c);
1.178
1.179 {
1.180 std::map<std::string, int> maps;
1.181 @@ -1837,14 +1873,15 @@
1.182
1.183 {
1.184 std::map<std::string, int>::iterator jt = maps.find("label");
1.185 - if (jt == maps.end())
1.186 - throw DataFormatError("Label map not found in file");
1.187 - label_index = jt->second;
1.188 + if (jt != maps.end()) {
1.189 + label_index = jt->second;
1.190 + } else {
1.191 + label_index = -1;
1.192 + }
1.193 }
1.194 map_num = maps.size();
1.195 }
1.196
1.197 - char c;
1.198 while (readLine() && line >> c && c != '@') {
1.199 line.putback(c);
1.200
1.201 @@ -1852,10 +1889,10 @@
1.202 std::string target_token;
1.203
1.204 if (!_reader_bits::readToken(line, source_token))
1.205 - throw DataFormatError("Source not found");
1.206 + throw DataFormatError("Node u not found");
1.207
1.208 if (!_reader_bits::readToken(line, target_token))
1.209 - throw DataFormatError("Source not found");
1.210 + throw DataFormatError("Node v not found");
1.211
1.212 std::vector<std::string> tokens(map_num);
1.213 for (int i = 0; i < map_num; ++i) {
1.214 @@ -1890,8 +1927,11 @@
1.215 Node target = it->second;
1.216
1.217 e = _graph.addEdge(source, target);
1.218 - _edge_index.insert(std::make_pair(tokens[label_index], e));
1.219 + if (label_index != -1)
1.220 + _edge_index.insert(std::make_pair(tokens[label_index], e));
1.221 } else {
1.222 + if (label_index == -1)
1.223 + throw DataFormatError("Label map not found in file");
1.224 typename std::map<std::string, Edge>::iterator it =
1.225 _edge_index.find(tokens[label_index]);
1.226 if (it == _edge_index.end()) {
1.227 @@ -2325,8 +2365,12 @@
1.228 }
1.229
1.230 void readMaps(std::vector<std::string>& maps) {
1.231 - if (!readLine())
1.232 - throw DataFormatError("Cannot find map captions");
1.233 + char c;
1.234 + if (!readLine() || !(line >> c) || c == '@') {
1.235 + if (readSuccess() && line) line.putback(c);
1.236 + return;
1.237 + }
1.238 + line.putback(c);
1.239 std::string map;
1.240 while (_reader_bits::readToken(line, map)) {
1.241 maps.push_back(map);