-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_encoder_S2.py
28 lines (19 loc) · 901 Bytes
/
map_encoder_S2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pandas as pd
from torchtext.vocab import build_vocab_from_iterator
import S2.sphere
def yield_tokens(data):
for index, row in data.iterrows():
cell = S2.sphere.CellId().from_lat_lng(S2.sphere.LatLng.from_degrees(row['latitude'], row['longitude']))
s2_key = cell.parent(16).to_token()
yield [s2_key[4:9]]
# s2_key = s2_key[4:9]
# token = ' '.join([''.join(x) for x in ngrams(s2_key, 3)])
# yield token.split(' ')
def create_location_vocab():
data = pd.read_csv(f"./raw_data/PHO_poi_mapping.csv")
return build_vocab_from_iterator(yield_tokens(data))
def get_location_vector(latitude: float, longitude: float):
cell = S2.sphere.CellId().from_lat_lng(S2.sphere.LatLng.from_degrees(latitude, longitude))
s2_key = cell.parent(16).to_token()
return location_vocab([s2_key[4:9]])
location_vocab = create_location_vocab()