]> gitweb.factorcode.org Git - factor.git/blob - extra/geobytes/geobytes.factor
Switch to https urls
[factor.git] / extra / geobytes / geobytes.factor
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: combinators combinators.smart csv io.encodings.latin1
4 kernel math.parser memoize money sequences unicode ;
5 IN: geobytes
6
7 ! GeoBytes is not free software.
8 ! Please read their license should you choose to use it.
9 ! This is just a binding to the GeoBytes CSV files.
10 ! Download and install GeoBytes yourself should you wish to use it.
11 ! https://www.geobytes.com/GeoWorldMap.zip
12
13 CONSTANT: geobytes-cities-path "resource:GeoWorldMap/Cities.txt"
14 CONSTANT: geobytes-countries-path "resource:GeoWorldMap/Countries.txt"
15 CONSTANT: geobytes-regions-path "resource:GeoWorldMap/Regions.txt"
16 CONSTANT: geobytes-version-path "resource:GeoWorldMap/version.txt"
17
18 TUPLE: country country-id country fips104 iso2 iso3 ison internet capital map-reference
19 nationality-singular nationality-plural currency currency-code population title
20 comment ;
21
22 TUPLE: region region-id country-id region code adm1-code ;
23
24 TUPLE: city city-id country-id region-id city longitude latitude timezone code ;
25
26 TUPLE: version component version rows ;
27
28 MEMO: load-countries ( -- seq )
29     geobytes-countries-path latin1 file>csv rest-slice [
30         [
31             {
32                 [ string>number ]
33                 [ ]
34                 [ ]
35                 [ ]
36                 [ ]
37                 [ ]
38                 [ ]
39                 [ ]
40                 [ ]
41                 [ ]
42                 [ ]
43                 [ ]
44                 [ ]
45                 [ string>number ]
46                 [ ]
47                 [ ]
48             } spread country boa
49         ] input<sequence
50     ] map ;
51
52 MEMO: load-regions ( -- seq )
53     geobytes-regions-path latin1 file>csv rest-slice [
54         [
55             {
56                 [ string>number ]
57                 [ string>number ]
58                 [ ]
59                 [ ]
60                 [ [ blank? ] trim ]
61             } spread region boa
62         ] input<sequence
63     ] map ;
64
65 MEMO: load-cities ( -- seq )
66     geobytes-cities-path latin1 file>csv rest-slice [
67         [
68             {
69                 [ string>number ]
70                 [ string>number ]
71                 [ string>number ]
72                 [ ]
73                 [ parse-decimal ]
74                 [ parse-decimal ]
75                 [ ]
76                 [ string>number ]
77             } spread city boa
78         ] input<sequence
79     ] map ;
80
81 MEMO: load-version ( -- seq )
82     geobytes-version-path latin1 file>csv rest-slice [
83         [
84             {
85                 [ ]
86                 [ ]
87                 [ string>number ]
88             } spread version boa
89         ] input<sequence
90     ] map ;