Download utils.py from jva96160/ggg2: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/jva96160/ggg2/resolve/main/utils.py
- Command line
-
hf download hf://jva96160/ggg2/utils.py
-
curl -L -o utils.py https://huggingface.co/jva96160/ggg2/resolve/main/utils.py
1.8 kB
| ############## 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 |