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