Skip to content

Commit 6e68f20

Browse files
committed
Reformat older code
1 parent 2cc9a1c commit 6e68f20

File tree

7 files changed

+820
-811
lines changed

7 files changed

+820
-811
lines changed

demo/geocoder-nlp.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,88 @@
1-
#include "postal.h"
21
#include "geocoder.h"
2+
#include "postal.h"
33

4-
#include <iostream>
54
#include <iomanip>
5+
#include <iostream>
66

77
using namespace GeoNLP;
88

99
int main(int argc, char *argv[])
1010
{
1111
Postal postal;
12-
//postal.set_initialize_every_call(true);
12+
// postal.set_initialize_every_call(true);
1313

1414
if (argc < 5)
1515
{
1616
std::cout << "Use: " << argv[0] << " dbase postal_global postal_country address\n"
17-
<< "where\n"
18-
<< " dbase - path to Geocoder-NLP database folder\n"
19-
<< " postal_global - path to libpostal database with language classifier\n"
20-
<< " postal_country - path to libpostal database covering country\n"
21-
<< " address - address to be parsed (please enclose it in \" \" to ensure that its a singe argument)\n";
17+
<< "where\n"
18+
<< " dbase - path to Geocoder-NLP database folder\n"
19+
<< " postal_global - path to libpostal database with language classifier\n"
20+
<< " postal_country - path to libpostal database covering country\n"
21+
<< " address - address to be parsed (please enclose it in \" \" to ensure that its "
22+
"a singe argument)\n";
2223
return -1;
2324
}
2425

25-
char *query = argv[4];
26-
std::vector< Postal::ParseResult > parsed_query;
27-
Postal::ParseResult nonorm;
26+
char *query = argv[4];
27+
std::vector<Postal::ParseResult> parsed_query;
28+
Postal::ParseResult nonorm;
2829

2930
postal.set_postal_datadir(argv[2], argv[3]);
3031
// postal.add_language("da");
3132
// postal.add_language("et");
3233
// postal.add_language("en");
3334
postal.set_initialize_every_call(true);
34-
35+
3536
postal.parse(query, parsed_query, nonorm);
3637

3738
std::cout << "\nAddress parsing before full normalization:\n\n";
38-
for (auto v: nonorm)
39+
for (auto v : nonorm)
3940
{
4041
std::cout << v.first << " ";
41-
for (auto k: v.second) std::cout << k << " ";
42+
for (auto k : v.second)
43+
std::cout << k << " ";
4244
std::cout << "\n";
4345
}
4446
std::cout << "\n";
4547

4648
std::cout << "Normalization:\n\n";
47-
for (auto r: parsed_query)
49+
for (auto r : parsed_query)
4850
{
49-
for (auto v: r)
51+
for (auto v : r)
5052
{
5153
std::cout << v.first << " ";
52-
for (auto k: v.second) std::cout << k << " ";
54+
for (auto k : v.second)
55+
std::cout << k << " ";
5356
std::cout << "\n";
5457
}
5558
std::cout << "\n";
5659
}
5760

5861
std::cout << std::endl;
59-
62+
6063
Geocoder geo(argv[1]);
6164
geo.set_max_queries_per_hierarchy(30);
6265
geo.set_max_results(25);
63-
//geo.set_result_language("en");
66+
// geo.set_result_language("en");
6467

6568
std::vector<Geocoder::GeoResult> result;
6669

6770
std::cout << "Geocoder loaded" << std::endl;
68-
71+
6972
geo.search(parsed_query, result);
7073

7174
std::cout << std::setprecision(8);
7275
std::cout << "Search results: \n\n";
7376
size_t counter = 0;
74-
for (const Geocoder::GeoResult &r: result)
77+
for (const Geocoder::GeoResult &r : result)
7578
{
7679
std::cout << r.title << "\n"
77-
<< r.address << "\n"
80+
<< r.address << "\n"
7881
<< "Postal code: " << r.postal_code << "\n"
79-
<< "Phone: " << r.phone << " / URL: " << r.website << "\n"
82+
<< "Phone: " << r.phone << " / URL: " << r.website << "\n"
8083
<< r.latitude << ", " << r.longitude << "\n"
81-
<< r.type << " / " << r.id << " / " << r.admin_levels << " / " << r.levels_resolved << "\n\n";
84+
<< r.type << " / " << r.id << " / " << r.admin_levels << " / " << r.levels_resolved
85+
<< "\n\n";
8286
counter++;
8387
}
8488

demo/nearby-line.cpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "postal.h"
21
#include "geocoder.h"
2+
#include "postal.h"
33

44
#include <fstream>
5-
#include <iostream>
65
#include <iomanip>
6+
#include <iostream>
77
#include <stdlib.h>
88

99
using namespace GeoNLP;
@@ -15,11 +15,11 @@ int main(int argc, char *argv[])
1515
if (argc < 8)
1616
{
1717
std::cout << "Use: " << argv[0] << " dbase postal_global postal_country address\n"
18-
<< "where\n"
19-
<< " dbase - path to Geocoder-NLP database folder\n"
20-
<< " postal_global - path to libpostal database with language classifier\n"
21-
<< " postal_country - path to libpostal database covering country\n"
22-
<< " line - text file containing lat lon coordinates, one per line\n"
18+
<< "where\n"
19+
<< " dbase - path to Geocoder-NLP database folder\n"
20+
<< " postal_global - path to libpostal database with language classifier\n"
21+
<< " postal_country - path to libpostal database covering country\n"
22+
<< " line - text file containing lat lon coordinates, one per line\n"
2323
<< " radius - distance in meters\n"
2424
<< " type - type of POI\n"
2525
<< " name - name of POI\n";
@@ -32,64 +32,60 @@ int main(int argc, char *argv[])
3232
std::vector<double> latitude, longitude;
3333
{
3434
std::ifstream fin(argv[4]);
35-
double lat, lon;
36-
while ( fin >> lat >> lon )
35+
double lat, lon;
36+
while (fin >> lat >> lon)
3737
{
3838
latitude.push_back(lat);
3939
longitude.push_back(lon);
4040
}
4141
}
4242
std::cout << "Loaded " << latitude.size() << " coordinates from " << argv[4] << "\n";
43-
44-
char *name_query = argv[7];
45-
std::vector< std::string > parsed_name;
43+
44+
char *name_query = argv[7];
45+
std::vector<std::string> parsed_name;
4646

4747
if (strlen(name_query) > 0)
4848
{
4949
postal.set_postal_datadir(argv[2], argv[3]);
5050
postal.set_initialize_every_call(true);
5151
postal.expand_string(name_query, parsed_name);
52-
52+
5353
std::cout << "Normalization of name:\n\n";
54-
for (auto r: parsed_name)
54+
for (auto r : parsed_name)
5555
std::cout << r << "\n";
5656
}
5757

5858
std::cout << std::endl;
5959

6060
std::vector<std::string> type_query;
61-
if (strlen(argv[6])>0)
61+
if (strlen(argv[6]) > 0)
6262
{
6363
type_query.push_back(argv[6]);
6464
std::cout << "Searching for type: " << argv[6] << "\n";
6565
}
66-
66+
6767
Geocoder geo(argv[1]);
6868
geo.set_max_queries_per_hierarchy(30);
6969
geo.set_max_results(25);
7070

7171
std::vector<Geocoder::GeoResult> result;
7272

7373
std::cout << "Geocoder loaded" << std::endl;
74-
75-
if ( !geo.search_nearby(parsed_name,
76-
type_query,
77-
latitude, longitude,
78-
radius,
79-
result,
80-
postal) )
74+
75+
if (!geo.search_nearby(parsed_name, type_query, latitude, longitude, radius, result, postal))
8176
std::cout << "Failed to search\n";
8277
else
8378
{
8479
std::cout << std::setprecision(8);
8580
std::cout << "Search results: \n\n";
8681
size_t counter = 0;
87-
for (const Geocoder::GeoResult &r: result)
82+
for (const Geocoder::GeoResult &r : result)
8883
{
8984
std::cout << r.title << "\n"
9085
<< r.address << "\n"
9186
<< r.latitude << ", " << r.longitude << ": distance - " << r.distance << "\n"
92-
<< r.type << " / " << r.id << " / " << r.admin_levels << " / " << r.levels_resolved << "\n\n";
87+
<< r.type << " / " << r.id << " / " << r.admin_levels << " / "
88+
<< r.levels_resolved << "\n\n";
9389
counter++;
9490
}
9591

demo/nearby-point.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "postal.h"
21
#include "geocoder.h"
2+
#include "postal.h"
33

44
#include <fstream>
5-
#include <iostream>
65
#include <iomanip>
6+
#include <iostream>
77
#include <stdlib.h>
88

99
using namespace GeoNLP;
@@ -15,11 +15,11 @@ int main(int argc, char *argv[])
1515
if (argc < 8)
1616
{
1717
std::cout << "Use: " << argv[0] << " dbase postal_global postal_country address\n"
18-
<< "where\n"
19-
<< " dbase - path to Geocoder-NLP database folder\n"
20-
<< " postal_global - path to libpostal database with language classifier\n"
21-
<< " postal_country - path to libpostal database covering country\n"
22-
<< " point - text file containing lat lon coordinate, the first pair is read only\n"
18+
<< "where\n"
19+
<< " dbase - path to Geocoder-NLP database folder\n"
20+
<< " postal_global - path to libpostal database with language classifier\n"
21+
<< " postal_country - path to libpostal database covering country\n"
22+
<< " point - text file containing lat lon coordinate, the first pair is read only\n"
2323
<< " radius - distance in meters\n"
2424
<< " type - type of POI\n"
2525
<< " name - name of POI\n";
@@ -32,65 +32,62 @@ int main(int argc, char *argv[])
3232
std::vector<double> latitude, longitude;
3333
{
3434
std::ifstream fin(argv[4]);
35-
double lat, lon;
36-
while ( fin >> lat >> lon )
35+
double lat, lon;
36+
while (fin >> lat >> lon)
3737
{
3838
latitude.push_back(lat);
3939
longitude.push_back(lon);
4040
break;
4141
}
4242
}
4343
std::cout << "Loaded " << latitude.size() << " coordinates from " << argv[4] << "\n";
44-
45-
char *name_query = argv[7];
46-
std::vector< std::string > parsed_name;
44+
45+
char *name_query = argv[7];
46+
std::vector<std::string> parsed_name;
4747

4848
if (strlen(name_query) > 0)
4949
{
5050
postal.set_postal_datadir(argv[2], argv[3]);
5151
postal.set_initialize_every_call(true);
5252
postal.expand_string(name_query, parsed_name);
53-
53+
5454
std::cout << "Normalization of name:\n\n";
55-
for (auto r: parsed_name)
55+
for (auto r : parsed_name)
5656
std::cout << r << "\n";
5757
}
5858

5959
std::cout << std::endl;
6060

6161
std::vector<std::string> type_query;
62-
if (strlen(argv[6])>0)
62+
if (strlen(argv[6]) > 0)
6363
{
6464
type_query.push_back(argv[6]);
6565
std::cout << "Searching for type: " << argv[6] << "\n";
6666
}
67-
67+
6868
Geocoder geo(argv[1]);
6969
geo.set_max_queries_per_hierarchy(30);
7070
geo.set_max_results(25);
7171

7272
std::vector<Geocoder::GeoResult> result;
7373

7474
std::cout << "Geocoder loaded" << std::endl;
75-
76-
if ( !geo.search_nearby(parsed_name,
77-
type_query,
78-
latitude[0], longitude[0],
79-
radius,
80-
result,
81-
postal) )
75+
76+
if (!geo.search_nearby(parsed_name, type_query, latitude[0], longitude[0], radius, result,
77+
postal))
8278
std::cout << "Failed to search\n";
8379
else
8480
{
8581
std::cout << std::setprecision(8);
8682
std::cout << "Search results: \n\n";
8783
size_t counter = 0;
88-
for (const Geocoder::GeoResult &r: result)
84+
for (const Geocoder::GeoResult &r : result)
8985
{
9086
std::cout << r.title << "\n"
9187
<< r.address << "\n"
9288
<< r.latitude << ", " << r.longitude << ": distance - " << r.distance << "\n"
93-
<< r.type << " / " << r.id << " / " << r.admin_levels << " / " << r.levels_resolved << "\n\n";
89+
<< r.type << " / " << r.id << " / " << r.admin_levels << " / "
90+
<< r.levels_resolved << "\n\n";
9491
counter++;
9592
}
9693

0 commit comments

Comments
 (0)