File size: 1,797 Bytes
a3914b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d6949c
a2d5d51
5d6949c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
############## help functions (will move to utils.py later) ###############################
import numpy as np
from NER.poi_processing import filter_poi_list

def find_nearest(array, a):
    array = np.array(array)
    if type(a) in [float,int] or len(a)==1:
        distances = np.abs(array - a)
    else:
        distances = np.linalg.norm(array - a, axis=1)
    min_index = np.argmin(distances)
    return min_index

def sec2gps(video_csv,sec=0):
    # video_name = shini or sec17
    idx = find_nearest(video_csv['video_tps'],sec)
    return video_csv.iloc[idx]['latitude'],video_csv.iloc[idx]['longitude']


def get_video_location_and_poi_data(task, xinyi_csv, sec17_csv, xinyi_poi_data, zhongxiao_poi_data):
    """
    根據 task 決定使用的 video_location_data 和 poi_data
    """
    # 判斷 video_location_data
    if task == 'xinyi':
        video_location_data = xinyi_csv
        poi_data = xinyi_poi_data
    elif task == 'zhongxiao':
        video_location_data = sec17_csv
        poi_data = zhongxiao_poi_data
    
    poi_data = filter_poi_list(poi_data)
    return video_location_data, poi_data


def get_ner_coordinates(task, timestamp, xinyi_csv, sec17_csv):
    """
    計算 NER 座標位置並將 timestamp 減去 1 秒
    """
    # 確保 timestamp 不低於 5,且根據任務不同有不同的上限
    if task == 'xinyi':
        timestamp = min(max(5, timestamp - 1), 1494)
        ner_cur_pos = sec2gps(xinyi_csv, timestamp)
    elif task == 'zhongxiao':
        timestamp = min(max(5, timestamp - 1), 2514)
        ner_cur_pos = sec2gps(sec17_csv, timestamp)
    return ner_cur_pos

import re
def remove_chinese_characters(text):
  tmp = re.sub(r'[\u4E00-\u9FFF\u3400-\u4DBF]+','', text)
  return tmp
  return re.sub(r'\[.*?\]', '', tmp) # remove_brackets