Spaces:
Build error
Build error
Shunfeng Zheng
commited on
Upload 83 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +2 -0
- 1_SpatialParse.py +365 -0
- B.geojson +1 -0
- LICENSE +674 -0
- README.md +0 -12
- __pycache__/geospacy.cpython-310.pyc +0 -0
- __pycache__/geospacy.cpython-39.pyc +0 -0
- __pycache__/llm_coding.cpython-310.pyc +0 -0
- __pycache__/llm_ent_extract.cpython-310.pyc +0 -0
- __pycache__/regex_spatial.cpython-310.pyc +0 -0
- __pycache__/regex_spatial.cpython-311.pyc +0 -0
- __pycache__/regex_spatial.cpython-38.pyc +0 -0
- __pycache__/regex_spatial.cpython-39.pyc +0 -0
- db/__pycache__/poly_db_util.cpython-310.pyc +0 -0
- db/__pycache__/poly_db_util.cpython-39.pyc +0 -0
- db/poly_db_util.py +134 -0
- dependencies.txt +102 -0
- disambiguation/__pycache__/disambiguate.cpython-310.pyc +0 -0
- disambiguation/__pycache__/disambiguate.cpython-39.pyc +0 -0
- disambiguation/disambiguate.py +142 -0
- docs/Notes.docx +0 -0
- docs/~$Notes.docx +0 -0
- geocoder/.DS_Store +0 -0
- geocoder/__pycache__/geo_level1.cpython-310.pyc +0 -0
- geocoder/__pycache__/geo_level1.cpython-39.pyc +0 -0
- geocoder/__pycache__/geo_level11.cpython-310.pyc +0 -0
- geocoder/__pycache__/geo_level2.cpython-310.pyc +0 -0
- geocoder/__pycache__/geo_level2.cpython-39.pyc +0 -0
- geocoder/__pycache__/geo_level3.cpython-310.pyc +0 -0
- geocoder/__pycache__/geo_level3.cpython-39.pyc +0 -0
- geocoder/geo_level1.py +158 -0
- geocoder/geo_level2.py +117 -0
- geocoder/geo_level3.py +139 -0
- geospacy.py +256 -0
- pages/.DS_Store +0 -0
- pages/2_Locate.py +0 -0
- regex_spatial.py +72 -0
- requirements.txt +133 -0
- saved_doc.spacy +0 -0
- screen_shot.jpg +3 -0
- utils/.DS_Store +0 -0
- utils/__pycache__/config.cpython-310.pyc +0 -0
- utils/__pycache__/geoutil.cpython-310.pyc +0 -0
- utils/__pycache__/geoutil.cpython-39.pyc +0 -0
- utils/__pycache__/llm_coding.cpython-310.pyc +0 -0
- utils/__pycache__/llm_ent_extract.cpython-310.pyc +0 -0
- utils/config.py +1 -0
- utils/geoutil.py +262 -0
- utils/llm_coding.py +345 -0
- utils/llm_ent_extract.py +145 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
screen_shot.jpg filter=lfs diff=lfs merge=lfs -text
|
37 |
+
未命名文件夹/screen_shot_new.jpg filter=lfs diff=lfs merge=lfs -text
|
1_SpatialParse.py
ADDED
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from spacy import displacy
|
3 |
+
import spacy
|
4 |
+
import geospacy
|
5 |
+
from PIL import Image
|
6 |
+
import base64
|
7 |
+
import sys
|
8 |
+
import pandas as pd
|
9 |
+
import en_core_web_md
|
10 |
+
from spacy.tokens import Span, Doc, Token
|
11 |
+
from utils import geoutil
|
12 |
+
from utils import llm_coding
|
13 |
+
import urllib.parse
|
14 |
+
import json
|
15 |
+
|
16 |
+
colors = {'GPE': "#43c6fc", "LOC": "#fd9720", "RSE":"#a6e22d"}
|
17 |
+
options = {"ents": ['GPE', 'LOC', "RSE"], "colors": colors}
|
18 |
+
|
19 |
+
|
20 |
+
HTML_WRAPPER = """<div style="overflow-x: auto; border: none solid #a6e22d; border-radius: 0.25rem; padding: 1rem">{}</div>"""
|
21 |
+
model = ""
|
22 |
+
|
23 |
+
gpe_selected = "GPE"
|
24 |
+
loc_selected = "LOC"
|
25 |
+
rse_selected = "RSE"
|
26 |
+
|
27 |
+
types = ""
|
28 |
+
|
29 |
+
#BASE_URL = "http://localhost:8080/"
|
30 |
+
BASE_URL = ""
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
def set_header():
|
35 |
+
LOGO_IMAGE = "tetis-1.png"
|
36 |
+
|
37 |
+
st.markdown(
|
38 |
+
"""
|
39 |
+
<style>
|
40 |
+
.container {
|
41 |
+
display: flex;
|
42 |
+
}
|
43 |
+
.logo-text {
|
44 |
+
font-weight:700 !important;
|
45 |
+
font-size:50px !important;
|
46 |
+
color: #f9a01b !important;
|
47 |
+
padding-left: 10px !important;
|
48 |
+
}
|
49 |
+
.logo-img {
|
50 |
+
float:right;
|
51 |
+
width: 28%;
|
52 |
+
height: 28%;
|
53 |
+
}
|
54 |
+
</style>
|
55 |
+
""",
|
56 |
+
unsafe_allow_html=True
|
57 |
+
)
|
58 |
+
st.markdown(
|
59 |
+
f"""
|
60 |
+
<div class="container">
|
61 |
+
<img class="logo-img" src="data:image/png;base64,{base64.b64encode(open(LOGO_IMAGE, "rb").read()).decode()}">
|
62 |
+
<p class="logo-text">GeOspaCy</p>
|
63 |
+
</div>
|
64 |
+
""",
|
65 |
+
unsafe_allow_html=True
|
66 |
+
)
|
67 |
+
|
68 |
+
|
69 |
+
def set_side_menu():
|
70 |
+
global gpe_selected, loc_selected, rse_selected, model, types
|
71 |
+
types =""
|
72 |
+
params = st.query_params
|
73 |
+
st.sidebar.markdown("## Spacy Model")
|
74 |
+
st.sidebar.markdown("You can **select** the values of the *spacy model* from Dropdown.")
|
75 |
+
models = ['en_core_web_sm', 'en_core_web_md', 'en_core_web_lg', 'en_core_web_trf']
|
76 |
+
if "model" in params:
|
77 |
+
default_ix = models.index(params["model"][0])
|
78 |
+
else:
|
79 |
+
default_ix = models.index('en_core_web_sm')
|
80 |
+
model = st.sidebar.selectbox('Spacy Model',models, index=default_ix)
|
81 |
+
|
82 |
+
st.sidebar.markdown("## Spatial Entity Labels")
|
83 |
+
st.sidebar.markdown("**Mark** the Spatial Entities you want to extract?")
|
84 |
+
tpes = ""
|
85 |
+
if "type" in params:
|
86 |
+
tpes = params['type'][0]
|
87 |
+
|
88 |
+
if "g" in tpes:
|
89 |
+
gpe = st.sidebar.checkbox('GPE', value = True)
|
90 |
+
else:
|
91 |
+
gpe = st.sidebar.checkbox('GPE')
|
92 |
+
|
93 |
+
if "l" in tpes:
|
94 |
+
loc = st.sidebar.checkbox('LOC', value = True)
|
95 |
+
else:
|
96 |
+
loc = st.sidebar.checkbox('LOC')
|
97 |
+
if "r" in tpes:
|
98 |
+
rse = st.sidebar.checkbox('RSE', value = True)
|
99 |
+
else:
|
100 |
+
rse = st.sidebar.checkbox('RSE')
|
101 |
+
if(gpe):
|
102 |
+
gpe_selected ="GPE"
|
103 |
+
types+="g"
|
104 |
+
|
105 |
+
if(loc):
|
106 |
+
loc_selected ="LOC"
|
107 |
+
types+="l"
|
108 |
+
|
109 |
+
if(rse):
|
110 |
+
rse_selected ="RSE"
|
111 |
+
types+="r"
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
+
def set_input():
|
116 |
+
params = st.query_params
|
117 |
+
|
118 |
+
# 设置默认文本
|
119 |
+
default_text = params["text"][0] if "text" in params else ""
|
120 |
+
|
121 |
+
# 更友好的提示语
|
122 |
+
# text = st.text_area("Enter a location description to extract spatial entities:", default_text)
|
123 |
+
text = st.text_area("✍️ **Please input your text here:**", default_text)
|
124 |
+
# text = st.text_area("### Please input your text here:", default_text)
|
125 |
+
|
126 |
+
# 提交按钮
|
127 |
+
if st.button("Extract"):
|
128 |
+
return text
|
129 |
+
|
130 |
+
|
131 |
+
def set_selected_entities(doc):
|
132 |
+
global gpe_selected, loc_selected, rse_selected, model
|
133 |
+
ents = [ent for ent in doc.ents if ent.label_ == gpe_selected or ent.label_ == loc_selected or ent.label_ == rse_selected]
|
134 |
+
|
135 |
+
doc.ents = ents
|
136 |
+
return doc
|
137 |
+
|
138 |
+
def extract_spatial_entities(text):
|
139 |
+
nlp = spacy.load("en_core_web_md")
|
140 |
+
nlp.add_pipe("spatial_pipeline", after="ner")
|
141 |
+
doc = nlp(text)
|
142 |
+
|
143 |
+
# 分句处理
|
144 |
+
sent_ents = []
|
145 |
+
sent_texts = []
|
146 |
+
sent_rse_id = []
|
147 |
+
offset = 0
|
148 |
+
sent_start_positions = [0]
|
149 |
+
doc_copy = doc.copy()
|
150 |
+
for sent in doc.sents:
|
151 |
+
|
152 |
+
sent_doc = nlp(sent.text)
|
153 |
+
sent_doc = set_selected_entities(sent_doc)
|
154 |
+
sent_texts.append(sent_doc.text)
|
155 |
+
|
156 |
+
for ent in sent_doc.ents:
|
157 |
+
sent_rse_id.append(ent._.rse_id)
|
158 |
+
for ent in sent_doc.ents:
|
159 |
+
new_ent = Span(doc, ent.start + offset, ent.end + offset, label=ent.label_)
|
160 |
+
sent_ents.append(new_ent)
|
161 |
+
|
162 |
+
offset += len(sent)
|
163 |
+
sent_start_positions.append(sent_start_positions[-1] + len(sent))
|
164 |
+
# **创建新 Doc**
|
165 |
+
final_doc = Doc(nlp.vocab, words=[token.text for token in doc], spaces=[token.whitespace_ for token in doc])
|
166 |
+
for i in sent_start_positions:
|
167 |
+
if i < len(final_doc):
|
168 |
+
final_doc[i].is_sent_start = True
|
169 |
+
|
170 |
+
final_doc.set_ents(sent_ents)
|
171 |
+
|
172 |
+
for i in range(len(sent_rse_id)):
|
173 |
+
final_doc.ents[i]._.rse_id = sent_rse_id[i]
|
174 |
+
doc = final_doc
|
175 |
+
doc.to_disk("saved_doc.spacy")
|
176 |
+
|
177 |
+
highlight_ents = []
|
178 |
+
if 'g' in types:
|
179 |
+
highlight_ents.append('GPE')
|
180 |
+
if 'l' in types:
|
181 |
+
highlight_ents.append('LOC')
|
182 |
+
if 'r' in types:
|
183 |
+
highlight_ents.append('RSE')
|
184 |
+
|
185 |
+
options = {"ents": highlight_ents, "colors": colors}
|
186 |
+
html = displacy.render(doc, style="ent", options=options)
|
187 |
+
html = html.replace("\n","")
|
188 |
+
st.write(HTML_WRAPPER.format(html),unsafe_allow_html=True)
|
189 |
+
show_spatial_ent_table(doc, text)
|
190 |
+
|
191 |
+
show_sentence_selector_table(doc_copy)
|
192 |
+
|
193 |
+
def show_sentence_selector_table(doc_copy):
|
194 |
+
text = doc_copy.text
|
195 |
+
st.markdown("**______________________________________________________________________________________**")
|
196 |
+
st.markdown("**LLM-generated Spatial Composition**")
|
197 |
+
|
198 |
+
|
199 |
+
combo_obj = llm_coding.llmapi(text)
|
200 |
+
|
201 |
+
combo_lines = [json.dumps(item, separators=(", ", ": ")) for item in combo_obj]
|
202 |
+
|
203 |
+
combo_str = json.dumps(combo_obj)
|
204 |
+
combo_encoded = urllib.parse.quote(combo_str)
|
205 |
+
combo_encoded = urllib.parse.quote(combo_str)
|
206 |
+
text_encoded = urllib.parse.quote(text)
|
207 |
+
url = f"{BASE_URL}Locate?mode=geocombo&text={text_encoded}&combo={combo_encoded}"
|
208 |
+
|
209 |
+
rows = [{
|
210 |
+
'LLM Output': f'<pre>{combo_str}</pre>',
|
211 |
+
'Action': f'<a target="_self" href="{url}">Use this spatial composition</a>'
|
212 |
+
}]
|
213 |
+
|
214 |
+
df = pd.DataFrame(rows)
|
215 |
+
custom_style = """
|
216 |
+
<style>
|
217 |
+
table {
|
218 |
+
text-align: left !important;
|
219 |
+
}
|
220 |
+
th, td {
|
221 |
+
text-align: left !important;
|
222 |
+
}
|
223 |
+
</style>
|
224 |
+
"""
|
225 |
+
st.markdown(custom_style, unsafe_allow_html=True)
|
226 |
+
st.write(df.to_html(escape=False, index=False), unsafe_allow_html=True)
|
227 |
+
|
228 |
+
|
229 |
+
def show_spatial_ent_table(doc, text):
|
230 |
+
global types
|
231 |
+
if len(doc.ents) > 0:
|
232 |
+
st.markdown("**______________________________________________________________________________________**")
|
233 |
+
st.markdown("**Spatial Entities List**")
|
234 |
+
|
235 |
+
df = pd.DataFrame(columns=['Sr.', 'entity', 'label', 'Map', 'GEOJson'])
|
236 |
+
rows = [] # 用于存储所有行
|
237 |
+
|
238 |
+
for ent in doc.ents:
|
239 |
+
url_map = BASE_URL + "Locate?map=true&type=" + types + "&model=" + model + "&text=" + text + "&entity=" + ent._.rse_id
|
240 |
+
url_json = BASE_URL + "Locate?geojson=true&type=" + types + "&model=" + model + "&text=" + text + "&entity=" + ent._.rse_id
|
241 |
+
|
242 |
+
new_row = {
|
243 |
+
'Sr.': len(rows) + 1,
|
244 |
+
'entity': ent.text,
|
245 |
+
'label': ent.label_,
|
246 |
+
'Map': f'<a target="_self" href="{url_map}">View</a>',
|
247 |
+
'GEOJson': f'<a target="_self" href="{url_json}">View</a>'
|
248 |
+
}
|
249 |
+
rows.append(new_row)
|
250 |
+
|
251 |
+
df = pd.DataFrame(rows)
|
252 |
+
|
253 |
+
st.write(df.to_html(escape=False, index=False), unsafe_allow_html=True)
|
254 |
+
|
255 |
+
|
256 |
+
def set_header():
|
257 |
+
# LOGO_IMAGE = "title.jpg"
|
258 |
+
|
259 |
+
st.markdown(
|
260 |
+
"""
|
261 |
+
<style>
|
262 |
+
.container {
|
263 |
+
display: flex;
|
264 |
+
}
|
265 |
+
.logo-text {
|
266 |
+
font-weight:700 !important;
|
267 |
+
font-size:50px !important;
|
268 |
+
color: #52aee3 !important;
|
269 |
+
padding-left: 10px !important;
|
270 |
+
}
|
271 |
+
.logo-img {
|
272 |
+
float:right;
|
273 |
+
width: 10%;
|
274 |
+
height: 10%;
|
275 |
+
}
|
276 |
+
</style>
|
277 |
+
""",
|
278 |
+
unsafe_allow_html=True
|
279 |
+
)
|
280 |
+
st.markdown(
|
281 |
+
"""
|
282 |
+
<div class="container">
|
283 |
+
<p class="logo-text">SpatialParse</p>
|
284 |
+
</div>
|
285 |
+
""",
|
286 |
+
unsafe_allow_html=True
|
287 |
+
)
|
288 |
+
|
289 |
+
|
290 |
+
def set_side_menu():
|
291 |
+
global gpe_selected, loc_selected, rse_selected, model, types
|
292 |
+
types = ""
|
293 |
+
params = st.query_params
|
294 |
+
st.sidebar.markdown("## Deployment Method")
|
295 |
+
st.sidebar.markdown("You can select the deployment method for the model.")
|
296 |
+
deployment_options = ["API", "Local deployment"]
|
297 |
+
use_local_model = st.sidebar.radio("Choose deployment method:", deployment_options, index=0) == "Local deployment"
|
298 |
+
|
299 |
+
if use_local_model:
|
300 |
+
local_model_path = st.sidebar.text_input("Enter local model path:", "")
|
301 |
+
|
302 |
+
st.sidebar.markdown("## LLM Model")
|
303 |
+
st.sidebar.markdown("You can **select** different *LLM model* powered by API.")
|
304 |
+
models = ['Llama-3-8B', 'Mistral-7B-0.3', 'Gemma-2-10B', 'GPT-4o', 'Gemini Pro', 'Deepseek-R1', 'en_core_web_sm', 'en_core_web_md', 'en_core_web_lg', 'en_core_web_trf']
|
305 |
+
|
306 |
+
if "model" in params:
|
307 |
+
default_ix = models.index(params["model"][0])
|
308 |
+
else:
|
309 |
+
default_ix = models.index('GPT-4o')
|
310 |
+
|
311 |
+
model = st.sidebar.selectbox('LLM Model', models, index=default_ix)
|
312 |
+
|
313 |
+
st.sidebar.markdown("## Spatial Entity Labels")
|
314 |
+
|
315 |
+
st.sidebar.markdown("Please **Mark** the Spatial Entities you want to extract.")
|
316 |
+
tpes = ""
|
317 |
+
if "type" in params:
|
318 |
+
tpes = params['type'][0]
|
319 |
+
|
320 |
+
# st.sidebar.markdown("### Absolute Spatial Entity:")
|
321 |
+
if "g" in tpes:
|
322 |
+
gpe = st.sidebar.checkbox('GPE', value=True)
|
323 |
+
else:
|
324 |
+
gpe = st.sidebar.checkbox('GPE')
|
325 |
+
|
326 |
+
if "l" in tpes:
|
327 |
+
loc = st.sidebar.checkbox('LOC', value=True)
|
328 |
+
else:
|
329 |
+
loc = st.sidebar.checkbox('LOC')
|
330 |
+
|
331 |
+
st.sidebar.markdown("### Relative Spatial Entity:")
|
332 |
+
|
333 |
+
if "r" in tpes:
|
334 |
+
rse = st.sidebar.checkbox('RSE', value=True)
|
335 |
+
else:
|
336 |
+
rse = st.sidebar.checkbox('RSE')
|
337 |
+
if (gpe):
|
338 |
+
gpe_selected = "GPE"
|
339 |
+
types += "g"
|
340 |
+
|
341 |
+
if (loc):
|
342 |
+
loc_selected = "LOC"
|
343 |
+
types += "l"
|
344 |
+
|
345 |
+
if (rse):
|
346 |
+
rse_selected = "RSE"
|
347 |
+
types += "r"
|
348 |
+
|
349 |
+
|
350 |
+
def main():
|
351 |
+
global gpe_selected, loc_selected, rse_selected, model
|
352 |
+
set_header()
|
353 |
+
set_side_menu()
|
354 |
+
text = set_input()
|
355 |
+
if(text is not None):
|
356 |
+
extract_spatial_entities(text)
|
357 |
+
elif "text" in st.session_state:
|
358 |
+
text = st.session_state.text
|
359 |
+
extract_spatial_entities(text)
|
360 |
+
|
361 |
+
|
362 |
+
if __name__ == '__main__':
|
363 |
+
main()
|
364 |
+
|
365 |
+
|
B.geojson
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"type": "FeatureCollection", "features": [{"type": "Feature", "id": "B", "properties": {"centroid": [150.40522373235163, -33.60974105]}, "geometry": {"type": "Polygon", "coordinates": [[[150.1281731, -33.1789387, 233.36930554542403], [150.1762383, -33.8726954, 135.13976188358015], [150.4714959, -33.9553209, 77.65215095718821], [150.6115716, -33.8875169, 49.58969516619197], [150.6417843, -33.7976938, 34.71703633301888], [150.6599804, -33.6643534, 10.58541940551396], [150.6448742, -33.5551287, 348.76542536774076], [150.6871019, -33.2145622, 309.22595120057736], [150.5411909, -33.2027859, 290.9052966020208], [150.1281731, -33.1789387, 233.36930554542403]]]}}]}
|
LICENSE
ADDED
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 29 June 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works.
|
12 |
+
|
13 |
+
The licenses for most software and other practical works are designed
|
14 |
+
to take away your freedom to share and change the works. By contrast,
|
15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
16 |
+
share and change all versions of a program--to make sure it remains free
|
17 |
+
software for all its users. We, the Free Software Foundation, use the
|
18 |
+
GNU General Public License for most of our software; it applies also to
|
19 |
+
any other work released this way by its authors. You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
them if you wish), that you receive source code or can get it if you
|
26 |
+
want it, that you can change the software or use pieces of it in new
|
27 |
+
free programs, and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to prevent others from denying you
|
30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
31 |
+
certain responsibilities if you distribute copies of the software, or if
|
32 |
+
you modify it: responsibilities to respect the freedom of others.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
36 |
+
freedoms that you received. You must make sure that they, too, receive
|
37 |
+
or can get the source code. And you must show them these terms so they
|
38 |
+
know their rights.
|
39 |
+
|
40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
43 |
+
|
44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
45 |
+
that there is no warranty for this free software. For both users' and
|
46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
47 |
+
changed, so that their problems will not be attributed erroneously to
|
48 |
+
authors of previous versions.
|
49 |
+
|
50 |
+
Some devices are designed to deny users access to install or run
|
51 |
+
modified versions of the software inside them, although the manufacturer
|
52 |
+
can do so. This is fundamentally incompatible with the aim of
|
53 |
+
protecting users' freedom to change the software. The systematic
|
54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
56 |
+
have designed this version of the GPL to prohibit the practice for those
|
57 |
+
products. If such problems arise substantially in other domains, we
|
58 |
+
stand ready to extend this provision to those domains in future versions
|
59 |
+
of the GPL, as needed to protect the freedom of users.
|
60 |
+
|
61 |
+
Finally, every program is threatened constantly by software patents.
|
62 |
+
States should not allow patents to restrict development and use of
|
63 |
+
software on general-purpose computers, but in those that do, we wish to
|
64 |
+
avoid the special danger that patents applied to a free program could
|
65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
66 |
+
patents cannot be used to render the program non-free.
|
67 |
+
|
68 |
+
The precise terms and conditions for copying, distribution and
|
69 |
+
modification follow.
|
70 |
+
|
71 |
+
TERMS AND CONDITIONS
|
72 |
+
|
73 |
+
0. Definitions.
|
74 |
+
|
75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
76 |
+
|
77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
78 |
+
works, such as semiconductor masks.
|
79 |
+
|
80 |
+
"The Program" refers to any copyrightable work licensed under this
|
81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
82 |
+
"recipients" may be individuals or organizations.
|
83 |
+
|
84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
85 |
+
in a fashion requiring copyright permission, other than the making of an
|
86 |
+
exact copy. The resulting work is called a "modified version" of the
|
87 |
+
earlier work or a work "based on" the earlier work.
|
88 |
+
|
89 |
+
A "covered work" means either the unmodified Program or a work based
|
90 |
+
on the Program.
|
91 |
+
|
92 |
+
To "propagate" a work means to do anything with it that, without
|
93 |
+
permission, would make you directly or secondarily liable for
|
94 |
+
infringement under applicable copyright law, except executing it on a
|
95 |
+
computer or modifying a private copy. Propagation includes copying,
|
96 |
+
distribution (with or without modification), making available to the
|
97 |
+
public, and in some countries other activities as well.
|
98 |
+
|
99 |
+
To "convey" a work means any kind of propagation that enables other
|
100 |
+
parties to make or receive copies. Mere interaction with a user through
|
101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
102 |
+
|
103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
104 |
+
to the extent that it includes a convenient and prominently visible
|
105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
106 |
+
tells the user that there is no warranty for the work (except to the
|
107 |
+
extent that warranties are provided), that licensees may convey the
|
108 |
+
work under this License, and how to view a copy of this License. If
|
109 |
+
the interface presents a list of user commands or options, such as a
|
110 |
+
menu, a prominent item in the list meets this criterion.
|
111 |
+
|
112 |
+
1. Source Code.
|
113 |
+
|
114 |
+
The "source code" for a work means the preferred form of the work
|
115 |
+
for making modifications to it. "Object code" means any non-source
|
116 |
+
form of a work.
|
117 |
+
|
118 |
+
A "Standard Interface" means an interface that either is an official
|
119 |
+
standard defined by a recognized standards body, or, in the case of
|
120 |
+
interfaces specified for a particular programming language, one that
|
121 |
+
is widely used among developers working in that language.
|
122 |
+
|
123 |
+
The "System Libraries" of an executable work include anything, other
|
124 |
+
than the work as a whole, that (a) is included in the normal form of
|
125 |
+
packaging a Major Component, but which is not part of that Major
|
126 |
+
Component, and (b) serves only to enable use of the work with that
|
127 |
+
Major Component, or to implement a Standard Interface for which an
|
128 |
+
implementation is available to the public in source code form. A
|
129 |
+
"Major Component", in this context, means a major essential component
|
130 |
+
(kernel, window system, and so on) of the specific operating system
|
131 |
+
(if any) on which the executable work runs, or a compiler used to
|
132 |
+
produce the work, or an object code interpreter used to run it.
|
133 |
+
|
134 |
+
The "Corresponding Source" for a work in object code form means all
|
135 |
+
the source code needed to generate, install, and (for an executable
|
136 |
+
work) run the object code and to modify the work, including scripts to
|
137 |
+
control those activities. However, it does not include the work's
|
138 |
+
System Libraries, or general-purpose tools or generally available free
|
139 |
+
programs which are used unmodified in performing those activities but
|
140 |
+
which are not part of the work. For example, Corresponding Source
|
141 |
+
includes interface definition files associated with source files for
|
142 |
+
the work, and the source code for shared libraries and dynamically
|
143 |
+
linked subprograms that the work is specifically designed to require,
|
144 |
+
such as by intimate data communication or control flow between those
|
145 |
+
subprograms and other parts of the work.
|
146 |
+
|
147 |
+
The Corresponding Source need not include anything that users
|
148 |
+
can regenerate automatically from other parts of the Corresponding
|
149 |
+
Source.
|
150 |
+
|
151 |
+
The Corresponding Source for a work in source code form is that
|
152 |
+
same work.
|
153 |
+
|
154 |
+
2. Basic Permissions.
|
155 |
+
|
156 |
+
All rights granted under this License are granted for the term of
|
157 |
+
copyright on the Program, and are irrevocable provided the stated
|
158 |
+
conditions are met. This License explicitly affirms your unlimited
|
159 |
+
permission to run the unmodified Program. The output from running a
|
160 |
+
covered work is covered by this License only if the output, given its
|
161 |
+
content, constitutes a covered work. This License acknowledges your
|
162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
163 |
+
|
164 |
+
You may make, run and propagate covered works that you do not
|
165 |
+
convey, without conditions so long as your license otherwise remains
|
166 |
+
in force. You may convey covered works to others for the sole purpose
|
167 |
+
of having them make modifications exclusively for you, or provide you
|
168 |
+
with facilities for running those works, provided that you comply with
|
169 |
+
the terms of this License in conveying all material for which you do
|
170 |
+
not control copyright. Those thus making or running the covered works
|
171 |
+
for you must do so exclusively on your behalf, under your direction
|
172 |
+
and control, on terms that prohibit them from making any copies of
|
173 |
+
your copyrighted material outside their relationship with you.
|
174 |
+
|
175 |
+
Conveying under any other circumstances is permitted solely under
|
176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
177 |
+
makes it unnecessary.
|
178 |
+
|
179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
180 |
+
|
181 |
+
No covered work shall be deemed part of an effective technological
|
182 |
+
measure under any applicable law fulfilling obligations under article
|
183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
184 |
+
similar laws prohibiting or restricting circumvention of such
|
185 |
+
measures.
|
186 |
+
|
187 |
+
When you convey a covered work, you waive any legal power to forbid
|
188 |
+
circumvention of technological measures to the extent such circumvention
|
189 |
+
is effected by exercising rights under this License with respect to
|
190 |
+
the covered work, and you disclaim any intention to limit operation or
|
191 |
+
modification of the work as a means of enforcing, against the work's
|
192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
193 |
+
technological measures.
|
194 |
+
|
195 |
+
4. Conveying Verbatim Copies.
|
196 |
+
|
197 |
+
You may convey verbatim copies of the Program's source code as you
|
198 |
+
receive it, in any medium, provided that you conspicuously and
|
199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
200 |
+
keep intact all notices stating that this License and any
|
201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
202 |
+
keep intact all notices of the absence of any warranty; and give all
|
203 |
+
recipients a copy of this License along with the Program.
|
204 |
+
|
205 |
+
You may charge any price or no price for each copy that you convey,
|
206 |
+
and you may offer support or warranty protection for a fee.
|
207 |
+
|
208 |
+
5. Conveying Modified Source Versions.
|
209 |
+
|
210 |
+
You may convey a work based on the Program, or the modifications to
|
211 |
+
produce it from the Program, in the form of source code under the
|
212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
213 |
+
|
214 |
+
a) The work must carry prominent notices stating that you modified
|
215 |
+
it, and giving a relevant date.
|
216 |
+
|
217 |
+
b) The work must carry prominent notices stating that it is
|
218 |
+
released under this License and any conditions added under section
|
219 |
+
7. This requirement modifies the requirement in section 4 to
|
220 |
+
"keep intact all notices".
|
221 |
+
|
222 |
+
c) You must license the entire work, as a whole, under this
|
223 |
+
License to anyone who comes into possession of a copy. This
|
224 |
+
License will therefore apply, along with any applicable section 7
|
225 |
+
additional terms, to the whole of the work, and all its parts,
|
226 |
+
regardless of how they are packaged. This License gives no
|
227 |
+
permission to license the work in any other way, but it does not
|
228 |
+
invalidate such permission if you have separately received it.
|
229 |
+
|
230 |
+
d) If the work has interactive user interfaces, each must display
|
231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
233 |
+
work need not make them do so.
|
234 |
+
|
235 |
+
A compilation of a covered work with other separate and independent
|
236 |
+
works, which are not by their nature extensions of the covered work,
|
237 |
+
and which are not combined with it such as to form a larger program,
|
238 |
+
in or on a volume of a storage or distribution medium, is called an
|
239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
240 |
+
used to limit the access or legal rights of the compilation's users
|
241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
242 |
+
in an aggregate does not cause this License to apply to the other
|
243 |
+
parts of the aggregate.
|
244 |
+
|
245 |
+
6. Conveying Non-Source Forms.
|
246 |
+
|
247 |
+
You may convey a covered work in object code form under the terms
|
248 |
+
of sections 4 and 5, provided that you also convey the
|
249 |
+
machine-readable Corresponding Source under the terms of this License,
|
250 |
+
in one of these ways:
|
251 |
+
|
252 |
+
a) Convey the object code in, or embodied in, a physical product
|
253 |
+
(including a physical distribution medium), accompanied by the
|
254 |
+
Corresponding Source fixed on a durable physical medium
|
255 |
+
customarily used for software interchange.
|
256 |
+
|
257 |
+
b) Convey the object code in, or embodied in, a physical product
|
258 |
+
(including a physical distribution medium), accompanied by a
|
259 |
+
written offer, valid for at least three years and valid for as
|
260 |
+
long as you offer spare parts or customer support for that product
|
261 |
+
model, to give anyone who possesses the object code either (1) a
|
262 |
+
copy of the Corresponding Source for all the software in the
|
263 |
+
product that is covered by this License, on a durable physical
|
264 |
+
medium customarily used for software interchange, for a price no
|
265 |
+
more than your reasonable cost of physically performing this
|
266 |
+
conveying of source, or (2) access to copy the
|
267 |
+
Corresponding Source from a network server at no charge.
|
268 |
+
|
269 |
+
c) Convey individual copies of the object code with a copy of the
|
270 |
+
written offer to provide the Corresponding Source. This
|
271 |
+
alternative is allowed only occasionally and noncommercially, and
|
272 |
+
only if you received the object code with such an offer, in accord
|
273 |
+
with subsection 6b.
|
274 |
+
|
275 |
+
d) Convey the object code by offering access from a designated
|
276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
277 |
+
Corresponding Source in the same way through the same place at no
|
278 |
+
further charge. You need not require recipients to copy the
|
279 |
+
Corresponding Source along with the object code. If the place to
|
280 |
+
copy the object code is a network server, the Corresponding Source
|
281 |
+
may be on a different server (operated by you or a third party)
|
282 |
+
that supports equivalent copying facilities, provided you maintain
|
283 |
+
clear directions next to the object code saying where to find the
|
284 |
+
Corresponding Source. Regardless of what server hosts the
|
285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
286 |
+
available for as long as needed to satisfy these requirements.
|
287 |
+
|
288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
289 |
+
you inform other peers where the object code and Corresponding
|
290 |
+
Source of the work are being offered to the general public at no
|
291 |
+
charge under subsection 6d.
|
292 |
+
|
293 |
+
A separable portion of the object code, whose source code is excluded
|
294 |
+
from the Corresponding Source as a System Library, need not be
|
295 |
+
included in conveying the object code work.
|
296 |
+
|
297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
298 |
+
tangible personal property which is normally used for personal, family,
|
299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
302 |
+
product received by a particular user, "normally used" refers to a
|
303 |
+
typical or common use of that class of product, regardless of the status
|
304 |
+
of the particular user or of the way in which the particular user
|
305 |
+
actually uses, or expects or is expected to use, the product. A product
|
306 |
+
is a consumer product regardless of whether the product has substantial
|
307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
308 |
+
the only significant mode of use of the product.
|
309 |
+
|
310 |
+
"Installation Information" for a User Product means any methods,
|
311 |
+
procedures, authorization keys, or other information required to install
|
312 |
+
and execute modified versions of a covered work in that User Product from
|
313 |
+
a modified version of its Corresponding Source. The information must
|
314 |
+
suffice to ensure that the continued functioning of the modified object
|
315 |
+
code is in no case prevented or interfered with solely because
|
316 |
+
modification has been made.
|
317 |
+
|
318 |
+
If you convey an object code work under this section in, or with, or
|
319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
320 |
+
part of a transaction in which the right of possession and use of the
|
321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
322 |
+
fixed term (regardless of how the transaction is characterized), the
|
323 |
+
Corresponding Source conveyed under this section must be accompanied
|
324 |
+
by the Installation Information. But this requirement does not apply
|
325 |
+
if neither you nor any third party retains the ability to install
|
326 |
+
modified object code on the User Product (for example, the work has
|
327 |
+
been installed in ROM).
|
328 |
+
|
329 |
+
The requirement to provide Installation Information does not include a
|
330 |
+
requirement to continue to provide support service, warranty, or updates
|
331 |
+
for a work that has been modified or installed by the recipient, or for
|
332 |
+
the User Product in which it has been modified or installed. Access to a
|
333 |
+
network may be denied when the modification itself materially and
|
334 |
+
adversely affects the operation of the network or violates the rules and
|
335 |
+
protocols for communication across the network.
|
336 |
+
|
337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
338 |
+
in accord with this section must be in a format that is publicly
|
339 |
+
documented (and with an implementation available to the public in
|
340 |
+
source code form), and must require no special password or key for
|
341 |
+
unpacking, reading or copying.
|
342 |
+
|
343 |
+
7. Additional Terms.
|
344 |
+
|
345 |
+
"Additional permissions" are terms that supplement the terms of this
|
346 |
+
License by making exceptions from one or more of its conditions.
|
347 |
+
Additional permissions that are applicable to the entire Program shall
|
348 |
+
be treated as though they were included in this License, to the extent
|
349 |
+
that they are valid under applicable law. If additional permissions
|
350 |
+
apply only to part of the Program, that part may be used separately
|
351 |
+
under those permissions, but the entire Program remains governed by
|
352 |
+
this License without regard to the additional permissions.
|
353 |
+
|
354 |
+
When you convey a copy of a covered work, you may at your option
|
355 |
+
remove any additional permissions from that copy, or from any part of
|
356 |
+
it. (Additional permissions may be written to require their own
|
357 |
+
removal in certain cases when you modify the work.) You may place
|
358 |
+
additional permissions on material, added by you to a covered work,
|
359 |
+
for which you have or can give appropriate copyright permission.
|
360 |
+
|
361 |
+
Notwithstanding any other provision of this License, for material you
|
362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
363 |
+
that material) supplement the terms of this License with terms:
|
364 |
+
|
365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
366 |
+
terms of sections 15 and 16 of this License; or
|
367 |
+
|
368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
369 |
+
author attributions in that material or in the Appropriate Legal
|
370 |
+
Notices displayed by works containing it; or
|
371 |
+
|
372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
373 |
+
requiring that modified versions of such material be marked in
|
374 |
+
reasonable ways as different from the original version; or
|
375 |
+
|
376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
377 |
+
authors of the material; or
|
378 |
+
|
379 |
+
e) Declining to grant rights under trademark law for use of some
|
380 |
+
trade names, trademarks, or service marks; or
|
381 |
+
|
382 |
+
f) Requiring indemnification of licensors and authors of that
|
383 |
+
material by anyone who conveys the material (or modified versions of
|
384 |
+
it) with contractual assumptions of liability to the recipient, for
|
385 |
+
any liability that these contractual assumptions directly impose on
|
386 |
+
those licensors and authors.
|
387 |
+
|
388 |
+
All other non-permissive additional terms are considered "further
|
389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
390 |
+
received it, or any part of it, contains a notice stating that it is
|
391 |
+
governed by this License along with a term that is a further
|
392 |
+
restriction, you may remove that term. If a license document contains
|
393 |
+
a further restriction but permits relicensing or conveying under this
|
394 |
+
License, you may add to a covered work material governed by the terms
|
395 |
+
of that license document, provided that the further restriction does
|
396 |
+
not survive such relicensing or conveying.
|
397 |
+
|
398 |
+
If you add terms to a covered work in accord with this section, you
|
399 |
+
must place, in the relevant source files, a statement of the
|
400 |
+
additional terms that apply to those files, or a notice indicating
|
401 |
+
where to find the applicable terms.
|
402 |
+
|
403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
404 |
+
form of a separately written license, or stated as exceptions;
|
405 |
+
the above requirements apply either way.
|
406 |
+
|
407 |
+
8. Termination.
|
408 |
+
|
409 |
+
You may not propagate or modify a covered work except as expressly
|
410 |
+
provided under this License. Any attempt otherwise to propagate or
|
411 |
+
modify it is void, and will automatically terminate your rights under
|
412 |
+
this License (including any patent licenses granted under the third
|
413 |
+
paragraph of section 11).
|
414 |
+
|
415 |
+
However, if you cease all violation of this License, then your
|
416 |
+
license from a particular copyright holder is reinstated (a)
|
417 |
+
provisionally, unless and until the copyright holder explicitly and
|
418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
419 |
+
holder fails to notify you of the violation by some reasonable means
|
420 |
+
prior to 60 days after the cessation.
|
421 |
+
|
422 |
+
Moreover, your license from a particular copyright holder is
|
423 |
+
reinstated permanently if the copyright holder notifies you of the
|
424 |
+
violation by some reasonable means, this is the first time you have
|
425 |
+
received notice of violation of this License (for any work) from that
|
426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
427 |
+
your receipt of the notice.
|
428 |
+
|
429 |
+
Termination of your rights under this section does not terminate the
|
430 |
+
licenses of parties who have received copies or rights from you under
|
431 |
+
this License. If your rights have been terminated and not permanently
|
432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
433 |
+
material under section 10.
|
434 |
+
|
435 |
+
9. Acceptance Not Required for Having Copies.
|
436 |
+
|
437 |
+
You are not required to accept this License in order to receive or
|
438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
440 |
+
to receive a copy likewise does not require acceptance. However,
|
441 |
+
nothing other than this License grants you permission to propagate or
|
442 |
+
modify any covered work. These actions infringe copyright if you do
|
443 |
+
not accept this License. Therefore, by modifying or propagating a
|
444 |
+
covered work, you indicate your acceptance of this License to do so.
|
445 |
+
|
446 |
+
10. Automatic Licensing of Downstream Recipients.
|
447 |
+
|
448 |
+
Each time you convey a covered work, the recipient automatically
|
449 |
+
receives a license from the original licensors, to run, modify and
|
450 |
+
propagate that work, subject to this License. You are not responsible
|
451 |
+
for enforcing compliance by third parties with this License.
|
452 |
+
|
453 |
+
An "entity transaction" is a transaction transferring control of an
|
454 |
+
organization, or substantially all assets of one, or subdividing an
|
455 |
+
organization, or merging organizations. If propagation of a covered
|
456 |
+
work results from an entity transaction, each party to that
|
457 |
+
transaction who receives a copy of the work also receives whatever
|
458 |
+
licenses to the work the party's predecessor in interest had or could
|
459 |
+
give under the previous paragraph, plus a right to possession of the
|
460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
461 |
+
the predecessor has it or can get it with reasonable efforts.
|
462 |
+
|
463 |
+
You may not impose any further restrictions on the exercise of the
|
464 |
+
rights granted or affirmed under this License. For example, you may
|
465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
466 |
+
rights granted under this License, and you may not initiate litigation
|
467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
468 |
+
any patent claim is infringed by making, using, selling, offering for
|
469 |
+
sale, or importing the Program or any portion of it.
|
470 |
+
|
471 |
+
11. Patents.
|
472 |
+
|
473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
474 |
+
License of the Program or a work on which the Program is based. The
|
475 |
+
work thus licensed is called the contributor's "contributor version".
|
476 |
+
|
477 |
+
A contributor's "essential patent claims" are all patent claims
|
478 |
+
owned or controlled by the contributor, whether already acquired or
|
479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
480 |
+
by this License, of making, using, or selling its contributor version,
|
481 |
+
but do not include claims that would be infringed only as a
|
482 |
+
consequence of further modification of the contributor version. For
|
483 |
+
purposes of this definition, "control" includes the right to grant
|
484 |
+
patent sublicenses in a manner consistent with the requirements of
|
485 |
+
this License.
|
486 |
+
|
487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
488 |
+
patent license under the contributor's essential patent claims, to
|
489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
490 |
+
propagate the contents of its contributor version.
|
491 |
+
|
492 |
+
In the following three paragraphs, a "patent license" is any express
|
493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
494 |
+
(such as an express permission to practice a patent or covenant not to
|
495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
496 |
+
party means to make such an agreement or commitment not to enforce a
|
497 |
+
patent against the party.
|
498 |
+
|
499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
500 |
+
and the Corresponding Source of the work is not available for anyone
|
501 |
+
to copy, free of charge and under the terms of this License, through a
|
502 |
+
publicly available network server or other readily accessible means,
|
503 |
+
then you must either (1) cause the Corresponding Source to be so
|
504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
506 |
+
consistent with the requirements of this License, to extend the patent
|
507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
508 |
+
actual knowledge that, but for the patent license, your conveying the
|
509 |
+
covered work in a country, or your recipient's use of the covered work
|
510 |
+
in a country, would infringe one or more identifiable patents in that
|
511 |
+
country that you have reason to believe are valid.
|
512 |
+
|
513 |
+
If, pursuant to or in connection with a single transaction or
|
514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
515 |
+
covered work, and grant a patent license to some of the parties
|
516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
517 |
+
or convey a specific copy of the covered work, then the patent license
|
518 |
+
you grant is automatically extended to all recipients of the covered
|
519 |
+
work and works based on it.
|
520 |
+
|
521 |
+
A patent license is "discriminatory" if it does not include within
|
522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
524 |
+
specifically granted under this License. You may not convey a covered
|
525 |
+
work if you are a party to an arrangement with a third party that is
|
526 |
+
in the business of distributing software, under which you make payment
|
527 |
+
to the third party based on the extent of your activity of conveying
|
528 |
+
the work, and under which the third party grants, to any of the
|
529 |
+
parties who would receive the covered work from you, a discriminatory
|
530 |
+
patent license (a) in connection with copies of the covered work
|
531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
532 |
+
for and in connection with specific products or compilations that
|
533 |
+
contain the covered work, unless you entered into that arrangement,
|
534 |
+
or that patent license was granted, prior to 28 March 2007.
|
535 |
+
|
536 |
+
Nothing in this License shall be construed as excluding or limiting
|
537 |
+
any implied license or other defenses to infringement that may
|
538 |
+
otherwise be available to you under applicable patent law.
|
539 |
+
|
540 |
+
12. No Surrender of Others' Freedom.
|
541 |
+
|
542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
543 |
+
otherwise) that contradict the conditions of this License, they do not
|
544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
546 |
+
License and any other pertinent obligations, then as a consequence you may
|
547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
548 |
+
to collect a royalty for further conveying from those to whom you convey
|
549 |
+
the Program, the only way you could satisfy both those terms and this
|
550 |
+
License would be to refrain entirely from conveying the Program.
|
551 |
+
|
552 |
+
13. Use with the GNU Affero General Public License.
|
553 |
+
|
554 |
+
Notwithstanding any other provision of this License, you have
|
555 |
+
permission to link or combine any covered work with a work licensed
|
556 |
+
under version 3 of the GNU Affero General Public License into a single
|
557 |
+
combined work, and to convey the resulting work. The terms of this
|
558 |
+
License will continue to apply to the part which is the covered work,
|
559 |
+
but the special requirements of the GNU Affero General Public License,
|
560 |
+
section 13, concerning interaction through a network will apply to the
|
561 |
+
combination as such.
|
562 |
+
|
563 |
+
14. Revised Versions of this License.
|
564 |
+
|
565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
566 |
+
the GNU General Public License from time to time. Such new versions will
|
567 |
+
be similar in spirit to the present version, but may differ in detail to
|
568 |
+
address new problems or concerns.
|
569 |
+
|
570 |
+
Each version is given a distinguishing version number. If the
|
571 |
+
Program specifies that a certain numbered version of the GNU General
|
572 |
+
Public License "or any later version" applies to it, you have the
|
573 |
+
option of following the terms and conditions either of that numbered
|
574 |
+
version or of any later version published by the Free Software
|
575 |
+
Foundation. If the Program does not specify a version number of the
|
576 |
+
GNU General Public License, you may choose any version ever published
|
577 |
+
by the Free Software Foundation.
|
578 |
+
|
579 |
+
If the Program specifies that a proxy can decide which future
|
580 |
+
versions of the GNU General Public License can be used, that proxy's
|
581 |
+
public statement of acceptance of a version permanently authorizes you
|
582 |
+
to choose that version for the Program.
|
583 |
+
|
584 |
+
Later license versions may give you additional or different
|
585 |
+
permissions. However, no additional obligations are imposed on any
|
586 |
+
author or copyright holder as a result of your choosing to follow a
|
587 |
+
later version.
|
588 |
+
|
589 |
+
15. Disclaimer of Warranty.
|
590 |
+
|
591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
599 |
+
|
600 |
+
16. Limitation of Liability.
|
601 |
+
|
602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
610 |
+
SUCH DAMAGES.
|
611 |
+
|
612 |
+
17. Interpretation of Sections 15 and 16.
|
613 |
+
|
614 |
+
If the disclaimer of warranty and limitation of liability provided
|
615 |
+
above cannot be given local legal effect according to their terms,
|
616 |
+
reviewing courts shall apply local law that most closely approximates
|
617 |
+
an absolute waiver of all civil liability in connection with the
|
618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
619 |
+
copy of the Program in return for a fee.
|
620 |
+
|
621 |
+
END OF TERMS AND CONDITIONS
|
622 |
+
|
623 |
+
How to Apply These Terms to Your New Programs
|
624 |
+
|
625 |
+
If you develop a new program, and you want it to be of the greatest
|
626 |
+
possible use to the public, the best way to achieve this is to make it
|
627 |
+
free software which everyone can redistribute and change under these terms.
|
628 |
+
|
629 |
+
To do so, attach the following notices to the program. It is safest
|
630 |
+
to attach them to the start of each source file to most effectively
|
631 |
+
state the exclusion of warranty; and each file should have at least
|
632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
633 |
+
|
634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
635 |
+
Copyright (C) <year> <name of author>
|
636 |
+
|
637 |
+
This program is free software: you can redistribute it and/or modify
|
638 |
+
it under the terms of the GNU General Public License as published by
|
639 |
+
the Free Software Foundation, either version 3 of the License, or
|
640 |
+
(at your option) any later version.
|
641 |
+
|
642 |
+
This program is distributed in the hope that it will be useful,
|
643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
645 |
+
GNU General Public License for more details.
|
646 |
+
|
647 |
+
You should have received a copy of the GNU General Public License
|
648 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
649 |
+
|
650 |
+
Also add information on how to contact you by electronic and paper mail.
|
651 |
+
|
652 |
+
If the program does terminal interaction, make it output a short
|
653 |
+
notice like this when it starts in an interactive mode:
|
654 |
+
|
655 |
+
<program> Copyright (C) <year> <name of author>
|
656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
657 |
+
This is free software, and you are welcome to redistribute it
|
658 |
+
under certain conditions; type `show c' for details.
|
659 |
+
|
660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
661 |
+
parts of the General Public License. Of course, your program's commands
|
662 |
+
might be different; for a GUI interface, you would use an "about box".
|
663 |
+
|
664 |
+
You should also get your employer (if you work as a programmer) or school,
|
665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
667 |
+
<https://www.gnu.org/licenses/>.
|
668 |
+
|
669 |
+
The GNU General Public License does not permit incorporating your program
|
670 |
+
into proprietary programs. If your program is a subroutine library, you
|
671 |
+
may consider it more useful to permit linking proprietary applications with
|
672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
673 |
+
Public License instead of this License. But first, please read
|
674 |
+
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
README.md
CHANGED
@@ -1,12 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: SpatialParseback
|
3 |
-
emoji: 🏃
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: blue
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.23.3
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__pycache__/geospacy.cpython-310.pyc
ADDED
Binary file (3.18 kB). View file
|
|
__pycache__/geospacy.cpython-39.pyc
ADDED
Binary file (2.43 kB). View file
|
|
__pycache__/llm_coding.cpython-310.pyc
ADDED
Binary file (151 Bytes). View file
|
|
__pycache__/llm_ent_extract.cpython-310.pyc
ADDED
Binary file (6.9 kB). View file
|
|
__pycache__/regex_spatial.cpython-310.pyc
ADDED
Binary file (2.75 kB). View file
|
|
__pycache__/regex_spatial.cpython-311.pyc
ADDED
Binary file (4.43 kB). View file
|
|
__pycache__/regex_spatial.cpython-38.pyc
ADDED
Binary file (2.84 kB). View file
|
|
__pycache__/regex_spatial.cpython-39.pyc
ADDED
Binary file (2.79 kB). View file
|
|
db/__pycache__/poly_db_util.cpython-310.pyc
ADDED
Binary file (3.09 kB). View file
|
|
db/__pycache__/poly_db_util.cpython-39.pyc
ADDED
Binary file (3.1 kB). View file
|
|
db/poly_db_util.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
"""
|
4 |
+
Created on Thu Sep 22 14:38:28 2022
|
5 |
+
|
6 |
+
@author: syed
|
7 |
+
"""
|
8 |
+
|
9 |
+
import mysql.connector as sql_db
|
10 |
+
import json
|
11 |
+
#import mysql.connector
|
12 |
+
|
13 |
+
# Initialize connection.
|
14 |
+
# Uses st.experimental_singleton to only run once.
|
15 |
+
#@st.experimental_singleton
|
16 |
+
def init_connection():
|
17 |
+
#return sql_db.connect(**st.secrets["mysql"])
|
18 |
+
# return sql_db.connect(user='root', password='root1234',
|
19 |
+
# host='127.0.0.1',port=3306,
|
20 |
+
# database='rsi_polygon_schema')
|
21 |
+
return sql_db.connect(user='freedb_root_mehtab', password='b%9bYQ%5TsK%mAD',
|
22 |
+
host='sql.freedb.tech',port=3306,
|
23 |
+
database='freedb_rsi_polygon_schema')
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
query_insert_rating = "insert into rating(shape_id,expert_id, ratings) values(%s,%s,%s)"
|
31 |
+
|
32 |
+
#query_update_rating = "update rating set ratings = %s where shape_id = %s and expert_id = %s"
|
33 |
+
|
34 |
+
|
35 |
+
query_insert_shape = "insert into shape(ase,level_1, level_2, level_3, geojson) values(%s,%s,%s,%s,%s)"
|
36 |
+
|
37 |
+
query_insert_expert = "insert into expert(name,expertise, tools_expert) values(%s,%s,%s)"
|
38 |
+
|
39 |
+
|
40 |
+
def update_rating_query(shape_id, expert_id, ratings):
|
41 |
+
query_rating = "update rating set ratings = '"+str(ratings)+"' where"
|
42 |
+
query_rating += " shape_id = '"+str(shape_id)+"' and expert_id = '"+str(expert_id)+"'"
|
43 |
+
return query_rating
|
44 |
+
|
45 |
+
|
46 |
+
def get_rating_query(shape_id, expert_id):
|
47 |
+
query_rating = "select * from rating where "
|
48 |
+
if shape_id is not None:
|
49 |
+
query_rating += "shape_id = '"+str(shape_id)+"' "
|
50 |
+
if expert_id is not None:
|
51 |
+
query_rating += "and expert_id = '"+str(expert_id)+"' "
|
52 |
+
|
53 |
+
return query_rating
|
54 |
+
|
55 |
+
def get_shape_query(ase, level_1, level_2, level_3):
|
56 |
+
query_shape = "select * from shape where "
|
57 |
+
if ase is not None:
|
58 |
+
query_shape += "ase = '"+ase+"' "
|
59 |
+
if level_1 is not None:
|
60 |
+
query_shape += "and level_1 = '"+level_1+"' "
|
61 |
+
if level_2 is not None:
|
62 |
+
query_shape += "and level_2 = '"+level_2+"' "
|
63 |
+
if level_3 is not None:
|
64 |
+
query_shape += "and level_3 = '"+level_3+"'"
|
65 |
+
return query_shape
|
66 |
+
|
67 |
+
def get_expert_query(name, expertise):
|
68 |
+
query_expert = "select * from expert where "
|
69 |
+
if name is not None:
|
70 |
+
query_expert += "name = '"+name+"' "
|
71 |
+
if expertise is not None:
|
72 |
+
query_expert += "and expertise = '"+expertise+"' "
|
73 |
+
return query_expert
|
74 |
+
|
75 |
+
def apply_rating(name, expertise, tools_selected,
|
76 |
+
rating_selected, ase, level_1, level_2, level_3, geojson):
|
77 |
+
connection = init_connection()
|
78 |
+
cursor = connection.cursor(prepared=True)
|
79 |
+
|
80 |
+
query_shape = get_shape_query(ase, level_1, level_2, level_3)
|
81 |
+
|
82 |
+
#tuple_shape = (ase, level_1, level_2, level_3)
|
83 |
+
tuple_expert = (name, expertise, str(tools_selected)[1:-1])
|
84 |
+
cursor.execute(query_shape)
|
85 |
+
record_shape = cursor.fetchone()
|
86 |
+
print("Record Shape:", record_shape)
|
87 |
+
print("Shape Select Query:", cursor.statement)
|
88 |
+
if record_shape is None:
|
89 |
+
tuple_insert_shape = (ase, level_1, level_2, level_3, json.dumps(geojson))
|
90 |
+
print(len(geojson))
|
91 |
+
cursor.execute(query_insert_shape, tuple_insert_shape)
|
92 |
+
connection.commit()
|
93 |
+
shape_id = cursor.lastrowid
|
94 |
+
print(f"Insert query executed with id : {shape_id}")
|
95 |
+
else:
|
96 |
+
shape_id = record_shape[0]
|
97 |
+
|
98 |
+
query_expert = get_expert_query(name, expertise)
|
99 |
+
|
100 |
+
cursor.execute(query_expert)
|
101 |
+
record_expert = cursor.fetchone()
|
102 |
+
print("Expert Select Query:", cursor.statement)
|
103 |
+
if record_expert is None:
|
104 |
+
cursor.execute(query_insert_expert, tuple_expert)
|
105 |
+
connection.commit()
|
106 |
+
expert_id = cursor.lastrowid
|
107 |
+
else:
|
108 |
+
expert_id = record_expert[0]
|
109 |
+
|
110 |
+
query_rating = get_rating_query(shape_id, expert_id)
|
111 |
+
cursor.execute(query_rating)
|
112 |
+
record_rating = cursor.fetchone()
|
113 |
+
|
114 |
+
print("Ratings Select Query:", cursor.statement)
|
115 |
+
|
116 |
+
|
117 |
+
print("Shape ID", shape_id, "...Expert ID", expert_id)
|
118 |
+
tuple_rating = (shape_id, expert_id, rating_selected)
|
119 |
+
if record_rating is None:
|
120 |
+
cursor.execute(query_insert_rating, tuple_rating)
|
121 |
+
connection.commit()
|
122 |
+
else:
|
123 |
+
cursor.execute(update_rating_query(shape_id, expert_id, rating_selected))
|
124 |
+
connection.commit()
|
125 |
+
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
|
dependencies.txt
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Bottleneck==1.4.2
|
2 |
+
└── numpy [required: Any, installed: 1.26.4]
|
3 |
+
Brotli==1.0.9
|
4 |
+
cffi==1.17.1
|
5 |
+
└── pycparser [required: Any, installed: 2.22]
|
6 |
+
colorama==0.4.6
|
7 |
+
folium==0.19.2
|
8 |
+
├── branca [required: >=0.6.0, installed: 0.8.1]
|
9 |
+
│ └── Jinja2 [required: >=3, installed: 3.1.5]
|
10 |
+
│ └── MarkupSafe [required: >=2.0, installed: 3.0.2]
|
11 |
+
├── Jinja2 [required: >=2.9, installed: 3.1.5]
|
12 |
+
│ └── MarkupSafe [required: >=2.0, installed: 3.0.2]
|
13 |
+
├── numpy [required: Any, installed: 1.26.4]
|
14 |
+
├── requests [required: Any, installed: 2.32.3]
|
15 |
+
│ ├── certifi [required: >=2017.4.17, installed: 2024.12.14]
|
16 |
+
│ ├── charset-normalizer [required: >=2,<4, installed: 3.4.1]
|
17 |
+
│ ├── idna [required: >=2.5,<4, installed: 3.10]
|
18 |
+
│ └── urllib3 [required: >=1.21.1,<3, installed: 2.3.0]
|
19 |
+
└── xyzservices [required: Any, installed: 2024.9.0]
|
20 |
+
GDAL==3.6.2
|
21 |
+
gensim==4.3.3
|
22 |
+
├── numpy [required: >=1.18.5,<2.0, installed: 1.26.4]
|
23 |
+
├── scipy [required: >=1.7.0,<1.14.0, installed: 1.13.1]
|
24 |
+
│ └── numpy [required: >=1.22.4,<2.3, installed: 1.26.4]
|
25 |
+
└── smart-open [required: >=1.8.1, installed: 7.1.0]
|
26 |
+
└── wrapt [required: Any, installed: 1.17.0]
|
27 |
+
geopandas==0.11.1
|
28 |
+
├── fiona [required: >=1.8, installed: 1.10.1]
|
29 |
+
│ ├── attrs [required: >=19.2.0, installed: 24.3.0]
|
30 |
+
│ ├── certifi [required: Any, installed: 2024.12.14]
|
31 |
+
│ ├── click [required: ~=8.0, installed: 8.1.8]
|
32 |
+
│ ├── click-plugins [required: >=1.0, installed: 1.1.1]
|
33 |
+
│ │ └── click [required: >=4.0, installed: 8.1.8]
|
34 |
+
│ └── cligj [required: >=0.5, installed: 0.7.2]
|
35 |
+
│ └── click [required: >=4.0, installed: 8.1.8]
|
36 |
+
├── packaging [required: Any, installed: 24.2]
|
37 |
+
├── pandas [required: >=1.0.0, installed: 2.2.3]
|
38 |
+
│ ├── numpy [required: >=1.22.4, installed: 1.26.4]
|
39 |
+
│ ├── python-dateutil [required: >=2.8.2, installed: 2.9.0.post0]
|
40 |
+
│ │ └── six [required: >=1.5, installed: 1.17.0]
|
41 |
+
│ ├── pytz [required: >=2020.1, installed: 2024.2]
|
42 |
+
│ └── tzdata [required: >=2022.7, installed: 2024.2]
|
43 |
+
├── pyproj [required: >=2.6.1.post1, installed: 3.6.1]
|
44 |
+
│ └── certifi [required: Any, installed: 2024.12.14]
|
45 |
+
└── Shapely [required: >=1.7,<2, installed: 1.8.4]
|
46 |
+
h2==4.1.0
|
47 |
+
├── hpack [required: >=4.0,<5, installed: 4.0.0]
|
48 |
+
└── hyperframe [required: >=6.0,<7, installed: 6.0.1]
|
49 |
+
mapclassify==2.8.1
|
50 |
+
├── networkx [required: >=2.7, installed: 3.4.2]
|
51 |
+
├── numpy [required: >=1.23, installed: 1.26.4]
|
52 |
+
├── pandas [required: >=1.4,!=1.5.0, installed: 2.2.3]
|
53 |
+
│ ├── numpy [required: >=1.22.4, installed: 1.26.4]
|
54 |
+
│ ├── python-dateutil [required: >=2.8.2, installed: 2.9.0.post0]
|
55 |
+
│ │ └── six [required: >=1.5, installed: 1.17.0]
|
56 |
+
│ ├── pytz [required: >=2020.1, installed: 2024.2]
|
57 |
+
│ └── tzdata [required: >=2022.7, installed: 2024.2]
|
58 |
+
├── scikit-learn [required: >=1.0, installed: 1.5.2]
|
59 |
+
│ ├── joblib [required: >=1.2.0, installed: 1.4.2]
|
60 |
+
│ ├── numpy [required: >=1.19.5, installed: 1.26.4]
|
61 |
+
│ ├── scipy [required: >=1.6.0, installed: 1.13.1]
|
62 |
+
│ │ └── numpy [required: >=1.22.4,<2.3, installed: 1.26.4]
|
63 |
+
│ └── threadpoolctl [required: >=3.1.0, installed: 3.5.0]
|
64 |
+
└── scipy [required: >=1.8, installed: 1.13.1]
|
65 |
+
└── numpy [required: >=1.22.4,<2.3, installed: 1.26.4]
|
66 |
+
matplotlib==3.9.2
|
67 |
+
├── contourpy [required: >=1.0.1, installed: 1.3.1]
|
68 |
+
│ └── numpy [required: >=1.23, installed: 1.26.4]
|
69 |
+
├── cycler [required: >=0.10, installed: 0.12.1]
|
70 |
+
├── fonttools [required: >=4.22.0, installed: 4.55.3]
|
71 |
+
├── kiwisolver [required: >=1.3.1, installed: 1.4.4]
|
72 |
+
├── numpy [required: >=1.23, installed: 1.26.4]
|
73 |
+
├── packaging [required: >=20.0, installed: 24.2]
|
74 |
+
├── pillow [required: >=8, installed: 11.0.0]
|
75 |
+
├── pyparsing [required: >=2.3.1, installed: 3.2.0]
|
76 |
+
└── python-dateutil [required: >=2.7, installed: 2.9.0.post0]
|
77 |
+
└── six [required: >=1.5, installed: 1.17.0]
|
78 |
+
munkres==1.1.4
|
79 |
+
numexpr==2.10.1
|
80 |
+
└── numpy [required: >=1.23.0, installed: 1.26.4]
|
81 |
+
pipdeptree==2.24.0
|
82 |
+
├── packaging [required: >=24.1, installed: 24.2]
|
83 |
+
└── pip [required: >=24.2, installed: 24.3.1]
|
84 |
+
PySocks==1.7.1
|
85 |
+
Rtree==1.0.1
|
86 |
+
setuptools==75.1.0
|
87 |
+
tokenizers==0.21.0
|
88 |
+
└── huggingface-hub [required: >=0.16.4,<1.0, installed: 0.27.0]
|
89 |
+
├── filelock [required: Any, installed: 3.16.1]
|
90 |
+
├── fsspec [required: >=2023.5.0, installed: 2024.12.0]
|
91 |
+
├── packaging [required: >=20.9, installed: 24.2]
|
92 |
+
├── PyYAML [required: >=5.1, installed: 6.0.2]
|
93 |
+
├── requests [required: Any, installed: 2.32.3]
|
94 |
+
│ ├── certifi [required: >=2017.4.17, installed: 2024.12.14]
|
95 |
+
│ ├── charset-normalizer [required: >=2,<4, installed: 3.4.1]
|
96 |
+
│ ├── idna [required: >=2.5,<4, installed: 3.10]
|
97 |
+
│ └── urllib3 [required: >=1.21.1,<3, installed: 2.3.0]
|
98 |
+
├── tqdm [required: >=4.42.1, installed: 4.67.1]
|
99 |
+
└── typing_extensions [required: >=3.7.4.3, installed: 4.12.2]
|
100 |
+
unicodedata2==15.1.0
|
101 |
+
wheel==0.44.0
|
102 |
+
zstandard==0.23.0
|
disambiguation/__pycache__/disambiguate.cpython-310.pyc
ADDED
Binary file (3.22 kB). View file
|
|
disambiguation/__pycache__/disambiguate.cpython-39.pyc
ADDED
Binary file (2.2 kB). View file
|
|
disambiguation/disambiguate.py
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
"""
|
4 |
+
Created on Mon Aug 1 13:11:36 2022
|
5 |
+
|
6 |
+
@author: syed
|
7 |
+
"""
|
8 |
+
import requests
|
9 |
+
import urllib3
|
10 |
+
import json
|
11 |
+
from geocoder import geo_level1
|
12 |
+
from geocoder import geo_level2
|
13 |
+
from geocoder import geo_level3
|
14 |
+
|
15 |
+
from utils import geoutil
|
16 |
+
import re
|
17 |
+
import regex_spatial
|
18 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
def dismabiguate_entities(doc, ent, ase, level_1, level_2, level_3, midmid):
|
24 |
+
return get_coordinates(ent, ase, level_1, level_2, level_3, midmid)
|
25 |
+
def get_coordinates(ent, ase, level_1, level_2, level_3, midmid):
|
26 |
+
request_url = 'https://nominatim.openstreetmap.org/search.php?q='+ase+'&polygon_geojson=1&accept-language=en&format=jsonv2'
|
27 |
+
headers = {
|
28 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15"
|
29 |
+
}
|
30 |
+
page = requests.get(request_url, headers=headers, verify=False)
|
31 |
+
# page = requests.get(request_url, verify=False)
|
32 |
+
# print(request_url, '++++++')
|
33 |
+
# print(ent, '++++++')
|
34 |
+
# print(ase, '++++++')
|
35 |
+
# print(level_1, '++++++')
|
36 |
+
# print(level_2, '++++++')
|
37 |
+
# print(level_3, '++++++')
|
38 |
+
# print(midmid, '++++++')
|
39 |
+
|
40 |
+
|
41 |
+
json_content = json.loads(page.content)
|
42 |
+
# json_content = json.loads(aa)
|
43 |
+
print(json_content, 'jjjjj')
|
44 |
+
all_coordinates = json_content[0]['geojson']['coordinates'][0]
|
45 |
+
centroid = (float(json_content[0]['lon']), float(json_content[0]['lat']))
|
46 |
+
for p in all_coordinates:
|
47 |
+
p2 = (p[0], p[1])
|
48 |
+
angle = geoutil.calculate_bearing(centroid, p2)
|
49 |
+
p.append(angle)
|
50 |
+
mid1 = None
|
51 |
+
mid2 = None
|
52 |
+
coordinates = all_coordinates
|
53 |
+
|
54 |
+
if level_3 is not None:
|
55 |
+
all_coordinates, centroid = geo_level3.get_level3_coordinates(coordinates, centroid, level_3, level_1)
|
56 |
+
|
57 |
+
geojson = get_geojson(ent, all_coordinates, centroid)
|
58 |
+
|
59 |
+
return geojson
|
60 |
+
|
61 |
+
|
62 |
+
def dismabiguate_entities_between(doc, ent, ase, level_1, level_2, level_3, midmid):
|
63 |
+
return get_coordinates_between(doc, ent, ase, level_1, level_2, level_3, midmid)
|
64 |
+
|
65 |
+
|
66 |
+
def get_coordinates_between(doc, ent, ase, level_1, level_2, level_3, midmid):
|
67 |
+
|
68 |
+
# first ase
|
69 |
+
request_url = 'https://nominatim.openstreetmap.org/search.php?q=' + doc.ents[0].text + '&polygon_geojson=1&accept-language=en&format=jsonv2'
|
70 |
+
headers = {
|
71 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15"
|
72 |
+
}
|
73 |
+
page1 = requests.get(request_url, headers=headers, verify=False)
|
74 |
+
|
75 |
+
# second ase
|
76 |
+
request_url = 'https://nominatim.openstreetmap.org/search.php?q=' + doc.ents[1].text + '&polygon_geojson=1&accept-language=en&format=jsonv2'
|
77 |
+
headers = {
|
78 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15"
|
79 |
+
}
|
80 |
+
page = requests.get(request_url, headers=headers, verify=False)
|
81 |
+
|
82 |
+
|
83 |
+
request_url = 'https://nominatim.openstreetmap.org/search.php?q=' + ase + '&polygon_geojson=1&accept-language=en&format=jsonv2'
|
84 |
+
headers = {
|
85 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15"
|
86 |
+
}
|
87 |
+
page = requests.get(request_url, headers=headers, verify=False)
|
88 |
+
|
89 |
+
|
90 |
+
json_content = json.loads(page.content)
|
91 |
+
|
92 |
+
all_coordinates = json_content[0]['geojson']['coordinates'][0]
|
93 |
+
centroid = (float(json_content[0]['lon']), float(json_content[0]['lat']))
|
94 |
+
for p in all_coordinates:
|
95 |
+
p2 = (p[0], p[1])
|
96 |
+
angle = geoutil.calculate_bearing(centroid, p2)
|
97 |
+
p.append(angle)
|
98 |
+
mid1 = None
|
99 |
+
mid2 = None
|
100 |
+
coordinates = all_coordinates
|
101 |
+
if level_1 is not None:
|
102 |
+
|
103 |
+
all_coordinates, centroid, mid1, mid2 = geo_level1.get_level1_coordinates(all_coordinates, centroid, level_1, midmid)
|
104 |
+
|
105 |
+
if level_2 is not None:
|
106 |
+
if level_1 is not None and level_1.lower() not in geo_level1.center:
|
107 |
+
all_coordinates, centroid = geo_level2.get_level2_coordinates(coordinates, centroid, level_2, level_1)
|
108 |
+
else:
|
109 |
+
print ("Else executed")
|
110 |
+
all_coordinates, centroid = geo_level2.get_level2_coordinates(all_coordinates, centroid, level_2, level_1)
|
111 |
+
|
112 |
+
if level_3 is not None:
|
113 |
+
all_coordinates, centroid = geo_level3.get_level3_coordinates(coordinates, centroid, level_3, level_1)
|
114 |
+
|
115 |
+
geojson = get_geojson(ent, all_coordinates, centroid)
|
116 |
+
|
117 |
+
return geojson
|
118 |
+
|
119 |
+
def get_geojson(ent, arr, centroid):
|
120 |
+
poly_json = {}
|
121 |
+
poly_json['type'] = 'FeatureCollection'
|
122 |
+
poly_json['features'] = []
|
123 |
+
coordinates= []
|
124 |
+
coordinates.append(arr)
|
125 |
+
poly_json['features'].append({
|
126 |
+
'type':'Feature',
|
127 |
+
'id': ent,
|
128 |
+
'properties': {
|
129 |
+
'centroid': centroid
|
130 |
+
},
|
131 |
+
'geometry': {
|
132 |
+
'type':'Polygon',
|
133 |
+
'coordinates': coordinates
|
134 |
+
}
|
135 |
+
})
|
136 |
+
return poly_json
|
137 |
+
|
138 |
+
def export(ent, poly_json):
|
139 |
+
with open(ent+'.geojson', 'w') as outfile:
|
140 |
+
json.dump(poly_json, outfile)
|
141 |
+
|
142 |
+
|
docs/Notes.docx
ADDED
Binary file (15.6 kB). View file
|
|
docs/~$Notes.docx
ADDED
Binary file (162 Bytes). View file
|
|
geocoder/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
geocoder/__pycache__/geo_level1.cpython-310.pyc
ADDED
Binary file (4.07 kB). View file
|
|
geocoder/__pycache__/geo_level1.cpython-39.pyc
ADDED
Binary file (3.95 kB). View file
|
|
geocoder/__pycache__/geo_level11.cpython-310.pyc
ADDED
Binary file (3.86 kB). View file
|
|
geocoder/__pycache__/geo_level2.cpython-310.pyc
ADDED
Binary file (2.84 kB). View file
|
|
geocoder/__pycache__/geo_level2.cpython-39.pyc
ADDED
Binary file (2.87 kB). View file
|
|
geocoder/__pycache__/geo_level3.cpython-310.pyc
ADDED
Binary file (3.6 kB). View file
|
|
geocoder/__pycache__/geo_level3.cpython-39.pyc
ADDED
Binary file (2.78 kB). View file
|
|
geocoder/geo_level1.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
"""
|
4 |
+
Created on Tue Aug 2 12:38:31 2022
|
5 |
+
|
6 |
+
@author: syed
|
7 |
+
"""
|
8 |
+
import regex_spatial
|
9 |
+
from utils import geoutil
|
10 |
+
|
11 |
+
|
12 |
+
north = ["north", "N'", "North", "NORTH"]
|
13 |
+
south = ["south", "S'", "South", "SOUTH"]
|
14 |
+
east = ["east", "E'", "East", "EAST"]
|
15 |
+
west = ["west", "W'", "West", "WEST"]
|
16 |
+
northeast = ["north-east", "NE'", "north east", "NORTH-EAST", "North East", "NORTH EAST", 'northeast']
|
17 |
+
southeast = ["south-east", "SE'", "south east", "SOUTH-EAST", "South East", "SOUTH EAST", 'southeast']
|
18 |
+
northwest = ["north-west", "NW'", "north west", "NORTH-WEST", "North West", "NORTH WEST", 'northwest']
|
19 |
+
southwest = ["south-west", "SW'", "south west", "SOUTH-WEST", "South West", "SOUTH WEST", 'southwest']
|
20 |
+
center = ["center","central", "downtown","midtown"]
|
21 |
+
def get_min_max(direction):
|
22 |
+
regex = regex_spatial.get_directional_regex()
|
23 |
+
direction_list = regex.split("|")
|
24 |
+
if direction in direction_list:
|
25 |
+
if direction in east:
|
26 |
+
return (337, 22)
|
27 |
+
if direction in northeast:
|
28 |
+
return (22, 67)
|
29 |
+
if direction in north:
|
30 |
+
return (67, 112)
|
31 |
+
if direction in northwest:
|
32 |
+
return (112, 157)
|
33 |
+
if direction in west:
|
34 |
+
return (157, 202)
|
35 |
+
if direction in southwest:
|
36 |
+
return (202, 247)
|
37 |
+
if direction in south:
|
38 |
+
return (247, 292)
|
39 |
+
if direction in southeast:
|
40 |
+
return (292, 337)
|
41 |
+
|
42 |
+
return None
|
43 |
+
|
44 |
+
|
45 |
+
def get_min_max(direction):
|
46 |
+
regex = regex_spatial.get_directional_regex()
|
47 |
+
direction_list = regex.split("|")
|
48 |
+
if direction in direction_list:
|
49 |
+
if direction in east:
|
50 |
+
return (337, 22)
|
51 |
+
if direction in northeast:
|
52 |
+
return (292, 337)
|
53 |
+
if direction in north:
|
54 |
+
return (247, 292)
|
55 |
+
if direction in northwest:
|
56 |
+
return (202, 247)
|
57 |
+
if direction in west:
|
58 |
+
return (157, 202)
|
59 |
+
if direction in southwest:
|
60 |
+
return (112, 157)
|
61 |
+
if direction in south:
|
62 |
+
return (67, 112)
|
63 |
+
if direction in southeast:
|
64 |
+
return (22, 67)
|
65 |
+
|
66 |
+
return None
|
67 |
+
|
68 |
+
|
69 |
+
def get_directional_coordinates_by_angle(coordinates, direction, minimum, maximum):
|
70 |
+
direction_coordinates = []
|
71 |
+
for p in coordinates:
|
72 |
+
if direction in east:
|
73 |
+
if p[2] >= minimum or p[2] <= maximum:
|
74 |
+
direction_coordinates.append(p)
|
75 |
+
|
76 |
+
else:
|
77 |
+
if p[2] >= minimum and p[2] <= maximum:
|
78 |
+
direction_coordinates.append(p)
|
79 |
+
return direction_coordinates
|
80 |
+
|
81 |
+
def get_directional_coordinates(coordinates, direction, centroid , minimum, maximum, is_midmid):
|
82 |
+
direction_coordinates = get_directional_coordinates_by_angle(coordinates, direction, minimum, maximum)
|
83 |
+
midmid1, midmid2= geoutil.get_midmid_point(centroid, direction_coordinates[0],direction_coordinates[-1], is_midmid)
|
84 |
+
if direction in west:
|
85 |
+
maxi = max(p[2] for p in direction_coordinates)
|
86 |
+
mini = min(p[2] for p in direction_coordinates)
|
87 |
+
index_mini = 0
|
88 |
+
index_maxi = 0
|
89 |
+
for idx,p in enumerate(direction_coordinates):
|
90 |
+
if p[2] == mini:
|
91 |
+
index_mini = idx
|
92 |
+
if p[2] == maxi:
|
93 |
+
index_maxi = idx
|
94 |
+
|
95 |
+
direction_coordinates.insert(index_maxi+1, midmid2)
|
96 |
+
direction_coordinates.insert(index_mini+1, midmid1)
|
97 |
+
|
98 |
+
else:
|
99 |
+
direction_coordinates.append(midmid2)
|
100 |
+
direction_coordinates.append(midmid1)
|
101 |
+
|
102 |
+
return direction_coordinates, midmid1, midmid2
|
103 |
+
|
104 |
+
def get_level1_coordinates(coordinates, centroid, direction, is_midmid):
|
105 |
+
min_max = get_min_max(direction)
|
106 |
+
if min_max is not None:
|
107 |
+
coordinates, mid1, mid2 = get_directional_coordinates(coordinates, direction, centroid,
|
108 |
+
min_max[0], min_max[1],is_midmid)
|
109 |
+
|
110 |
+
for idx, p in enumerate(coordinates):
|
111 |
+
print(idx, p)
|
112 |
+
return coordinates, centroid, mid1, mid2
|
113 |
+
elif direction.lower() in center:
|
114 |
+
return get_central(coordinates, centroid, direction, is_midmid), centroid, None, None
|
115 |
+
else :
|
116 |
+
return coordinates, centroid, None, None
|
117 |
+
|
118 |
+
|
119 |
+
def get_central(coordinates, centroid, direction, is_midmid):
|
120 |
+
|
121 |
+
n_min_max = get_min_max("north")
|
122 |
+
n_coordinates=get_directional_coordinates_by_angle(coordinates, "north", n_min_max[0], n_min_max[1])
|
123 |
+
n_mid1, n_mid2 = geoutil.get_midmid_point(centroid,n_coordinates[0],n_coordinates[-1], is_midmid)
|
124 |
+
|
125 |
+
ne_min_max = get_min_max("north east")
|
126 |
+
ne_coordinates=get_directional_coordinates_by_angle(coordinates, "north east", ne_min_max[0], ne_min_max[1])
|
127 |
+
ne_mid1, ne_mid2 = geoutil.get_midmid_point(centroid,ne_coordinates[0],ne_coordinates[-1], is_midmid)
|
128 |
+
|
129 |
+
e_min_max = get_min_max("east")
|
130 |
+
e_coordinates=get_directional_coordinates_by_angle(coordinates, "east", e_min_max[0], e_min_max[1])
|
131 |
+
e_mid1, e_mid2 = geoutil.get_midmid_point(centroid,e_coordinates[0],e_coordinates[-1], is_midmid)
|
132 |
+
|
133 |
+
se_min_max = get_min_max("south east")
|
134 |
+
se_coordinates=get_directional_coordinates_by_angle(coordinates, "south east", se_min_max[0], se_min_max[1])
|
135 |
+
se_mid1, se_mid2 = geoutil.get_midmid_point(centroid,se_coordinates[0],se_coordinates[-1], is_midmid)
|
136 |
+
|
137 |
+
s_min_max = get_min_max("south")
|
138 |
+
s_coordinates=get_directional_coordinates_by_angle(coordinates, "south", s_min_max[0], s_min_max[1])
|
139 |
+
s_mid1, s_mid2 = geoutil.get_midmid_point(centroid,s_coordinates[0],s_coordinates[-1], is_midmid)
|
140 |
+
|
141 |
+
sw_min_max = get_min_max("south west")
|
142 |
+
sw_coordinates=get_directional_coordinates_by_angle(coordinates, "south west", sw_min_max[0], sw_min_max[1])
|
143 |
+
sw_mid1, sw_mid2 = geoutil.get_midmid_point(centroid,sw_coordinates[0],sw_coordinates[-1], is_midmid)
|
144 |
+
|
145 |
+
w_min_max = get_min_max("west")
|
146 |
+
w_coordinates=get_directional_coordinates_by_angle(coordinates, "west", w_min_max[0], w_min_max[1])
|
147 |
+
w_mid1, w_mid2 = geoutil.get_midmid_point(centroid,w_coordinates[0],w_coordinates[-1], is_midmid)
|
148 |
+
|
149 |
+
nw_min_max = get_min_max("north west")
|
150 |
+
nw_coordinates=get_directional_coordinates_by_angle(coordinates, "north west", nw_min_max[0], nw_min_max[1])
|
151 |
+
nw_mid1, nw_mid2 = geoutil.get_midmid_point(centroid,nw_coordinates[0],nw_coordinates[-1], is_midmid)
|
152 |
+
|
153 |
+
central_coordindates =[e_mid1, e_mid2, ne_mid1, ne_mid2, n_mid1, n_mid2,
|
154 |
+
nw_mid1, nw_mid2, w_mid1, w_mid2, sw_mid1, sw_mid2,
|
155 |
+
s_mid1, s_mid2, se_mid1, se_mid2]
|
156 |
+
return central_coordindates
|
157 |
+
|
158 |
+
|
geocoder/geo_level2.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
"""
|
4 |
+
Created on Tue Aug 2 12:38:31 2022
|
5 |
+
|
6 |
+
@author: syed
|
7 |
+
"""
|
8 |
+
import regex_spatial
|
9 |
+
from utils import geoutil
|
10 |
+
import geopandas as gpd
|
11 |
+
import pandas as pd
|
12 |
+
import re
|
13 |
+
from shapely.geometry import Polygon,mapping
|
14 |
+
import numpy as np
|
15 |
+
from shapely.geometry import Polygon, MultiPoint
|
16 |
+
from shapely.geometry.base import geom_factory
|
17 |
+
from shapely.geos import lgeos
|
18 |
+
from geocoder import geo_level1
|
19 |
+
|
20 |
+
#def get_common_coordinates(coordinates, level2):
|
21 |
+
#gdp.
|
22 |
+
|
23 |
+
def get_near(level2):
|
24 |
+
near = re.search(regex_spatial.get_near_regex(), level2)
|
25 |
+
if near is not None:
|
26 |
+
return near.group()
|
27 |
+
return None
|
28 |
+
|
29 |
+
def get_surrounding(level2):
|
30 |
+
surrounding = re.search(regex_spatial.get_surrounding_regex(), level2)
|
31 |
+
if surrounding is not None:
|
32 |
+
return surrounding.group()
|
33 |
+
return None
|
34 |
+
|
35 |
+
|
36 |
+
def sort_west(coords1, poly2, centroid):
|
37 |
+
#coords1 = mapping(poly1)["features"][0]["geometry"]["coordinates"]
|
38 |
+
coords2 = mapping(poly2)["features"][0]["geometry"]["coordinates"]
|
39 |
+
coord1 = []
|
40 |
+
coord2 = []
|
41 |
+
coord = []
|
42 |
+
for c in coords1:
|
43 |
+
pol = list(c[::-1])
|
44 |
+
coord1.extend(pol)
|
45 |
+
for c in coords2:
|
46 |
+
pol = list(c[::-1])
|
47 |
+
coord2.extend(pol)
|
48 |
+
coo1 = []
|
49 |
+
coo2 = []
|
50 |
+
for p in coord1:
|
51 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
52 |
+
if angle >= 157 and angle <= 202:
|
53 |
+
coo1.append((p[0], p[1], angle))
|
54 |
+
for p in coord2:
|
55 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
56 |
+
if angle >= 157 and angle <= 202:
|
57 |
+
coo2.append((p[0], p[1], angle))
|
58 |
+
coo1.extend(coo2)
|
59 |
+
return coo1
|
60 |
+
|
61 |
+
def get_directional_coordinates_by_angle(coordinates, centroid, direction, minimum, maximum):
|
62 |
+
direction_coordinates = []
|
63 |
+
for p in coordinates:
|
64 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
65 |
+
if direction in geo_level1.east:
|
66 |
+
if angle >= minimum or angle <= maximum:
|
67 |
+
direction_coordinates.append(p)
|
68 |
+
|
69 |
+
else:
|
70 |
+
if angle >= minimum and angle <= maximum:
|
71 |
+
direction_coordinates.append(p)
|
72 |
+
#if(direction in geo_level1.west):
|
73 |
+
# direction_coordinates.sort(key=lambda k: k[2], reverse=True)
|
74 |
+
|
75 |
+
return direction_coordinates
|
76 |
+
|
77 |
+
def get_direction_coordinates(coordinates, centroid, level1):
|
78 |
+
min_max = geo_level1.get_min_max(level1)
|
79 |
+
if min_max is not None:
|
80 |
+
coord = get_directional_coordinates_by_angle(coordinates, centroid, level1, min_max[0], min_max[1])
|
81 |
+
return coord
|
82 |
+
return coordinates
|
83 |
+
|
84 |
+
|
85 |
+
def get_level2_coordinates(coordinates, centroid, level_2, level_1):
|
86 |
+
near = get_near(level_2)
|
87 |
+
surrounding = get_surrounding(level_2)
|
88 |
+
|
89 |
+
|
90 |
+
poly1 = Polygon(coordinates)
|
91 |
+
polygon1 = gpd.GeoSeries(poly1)
|
92 |
+
if near is not None:
|
93 |
+
poly2 = polygon1.buffer(0.0095, join_style=2)
|
94 |
+
if surrounding is not None:
|
95 |
+
poly2 = polygon1.buffer(0.012, join_style=2)
|
96 |
+
|
97 |
+
poly = poly2.difference(polygon1)
|
98 |
+
coords = mapping(poly)["features"][0]["geometry"]["coordinates"]
|
99 |
+
|
100 |
+
coord = []
|
101 |
+
for c in coords:
|
102 |
+
pol = list(c[::-1])
|
103 |
+
coord.extend(pol)
|
104 |
+
|
105 |
+
if level_1 is not None and level_1.lower() not in geo_level1.center:
|
106 |
+
coord = get_direction_coordinates(coord, centroid, level_1)
|
107 |
+
if level_1 in geo_level1.west:
|
108 |
+
coord = sort_west(coordinates,poly2, centroid)
|
109 |
+
|
110 |
+
print("Level 2 Coordinates")
|
111 |
+
for idx, p in enumerate(coord):
|
112 |
+
print(idx, p)
|
113 |
+
|
114 |
+
return coord, centroid
|
115 |
+
|
116 |
+
|
117 |
+
|
geocoder/geo_level3.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
"""
|
4 |
+
Created on Tue Aug 2 12:38:31 2022
|
5 |
+
|
6 |
+
@author: syed
|
7 |
+
"""
|
8 |
+
import regex_spatial
|
9 |
+
from utils import geoutil
|
10 |
+
import geopandas as gpd
|
11 |
+
import pandas as pd
|
12 |
+
import re
|
13 |
+
from shapely.geometry import Polygon,mapping
|
14 |
+
import numpy as np
|
15 |
+
from shapely.geometry import Polygon, MultiPoint, LineString, Point
|
16 |
+
from shapely.geometry.base import geom_factory
|
17 |
+
from shapely.geos import lgeos
|
18 |
+
from geocoder import geo_level1
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
def get_level3(level3):
|
23 |
+
digits = re.findall('[0-9]+', level3)[0]
|
24 |
+
unit = re.findall('[A-Za-z]+', level3)[0]
|
25 |
+
return digits, unit
|
26 |
+
|
27 |
+
|
28 |
+
def get_directional_coordinates_by_angle(coordinates, centroid, direction, minimum, maximum):
|
29 |
+
direction_coordinates = []
|
30 |
+
for p in coordinates:
|
31 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
32 |
+
p2= (p[0],p[1],angle)
|
33 |
+
if direction in geo_level1.east:
|
34 |
+
if angle >= minimum or angle <= maximum:
|
35 |
+
direction_coordinates.append(p2)
|
36 |
+
|
37 |
+
else:
|
38 |
+
if angle >= minimum and angle <= maximum:
|
39 |
+
direction_coordinates.append(p2)
|
40 |
+
|
41 |
+
|
42 |
+
return direction_coordinates
|
43 |
+
|
44 |
+
def sort_west(poly1, poly2, centroid):
|
45 |
+
coords1 = mapping(poly1)["features"][0]["geometry"]["coordinates"]
|
46 |
+
coords2 = mapping(poly2)["features"][0]["geometry"]["coordinates"]
|
47 |
+
coord1 = []
|
48 |
+
coord2 = []
|
49 |
+
coord = []
|
50 |
+
for c in coords1:
|
51 |
+
pol = list(c[::-1])
|
52 |
+
coord1.extend(pol)
|
53 |
+
for c in coords2:
|
54 |
+
pol = list(c[::-1])
|
55 |
+
coord2.extend(pol)
|
56 |
+
coo1 = []
|
57 |
+
coo2 = []
|
58 |
+
for p in coord1:
|
59 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
60 |
+
if angle >= 157 and angle <= 202:
|
61 |
+
coo1.append((p[0], p[1], angle))
|
62 |
+
for p in coord2:
|
63 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
64 |
+
if angle >= 157 and angle <= 202:
|
65 |
+
coo2.append((p[0], p[1], angle))
|
66 |
+
coo1.extend(coo2)
|
67 |
+
return coo1
|
68 |
+
|
69 |
+
def get_direction_coordinates(coordinates, centroid, level1):
|
70 |
+
min_max = geo_level1.get_min_max(level1)
|
71 |
+
if min_max is not None:
|
72 |
+
coord = get_directional_coordinates_by_angle(coordinates, centroid, level1, min_max[0], min_max[1])
|
73 |
+
return coord
|
74 |
+
return coordinates
|
75 |
+
|
76 |
+
def get_level3_coordinates(coordinates, centroid, level_3, level1):
|
77 |
+
distance, unit = get_level3(level_3)
|
78 |
+
|
79 |
+
kms = geoutil.get_kilometers(distance, unit)
|
80 |
+
|
81 |
+
|
82 |
+
coord = []
|
83 |
+
|
84 |
+
poly1 = Polygon(coordinates)
|
85 |
+
polygon1 = gpd.GeoSeries(poly1)
|
86 |
+
poly2 = polygon1.buffer(0.0095*kms, join_style=2) # 扩大小面积
|
87 |
+
poly3 = polygon1.buffer(0.013*kms, join_style=2) # 扩大大面积
|
88 |
+
poly = poly3.difference(poly2) # 合二为一成为环状
|
89 |
+
coords = mapping(poly)["features"][0]["geometry"]["coordinates"] # 改为坐标格式
|
90 |
+
|
91 |
+
|
92 |
+
for c in coords:
|
93 |
+
pol = list(c[::-1])
|
94 |
+
coord.extend(pol)
|
95 |
+
if level1 is not None:
|
96 |
+
coord = get_direction_coordinates(coord, centroid, level1)
|
97 |
+
if level1 in geo_level1.west:
|
98 |
+
coord = sort_west(poly3, poly2, centroid)
|
99 |
+
print("Level 3 Coordinates")
|
100 |
+
for idx, p in enumerate(coord):
|
101 |
+
print(idx, p)
|
102 |
+
return coord, centroid
|
103 |
+
|
104 |
+
|
105 |
+
def get_between_coordinates(coordinates1, coordinates2, centroid1, centroid2):
|
106 |
+
poly1 = Polygon(coordinates1)
|
107 |
+
poly2 = Polygon(coordinates2)
|
108 |
+
|
109 |
+
|
110 |
+
center_line = LineString([centroid1, centroid2])
|
111 |
+
|
112 |
+
def max_perpendicular_distance(poly, line):
|
113 |
+
max_dist = 0
|
114 |
+
farthest_points = None
|
115 |
+
|
116 |
+
for point in poly.exterior.coords:
|
117 |
+
p = Point(point)
|
118 |
+
|
119 |
+
dist = p.distance(line)
|
120 |
+
if dist > max_dist:
|
121 |
+
max_dist = dist
|
122 |
+
farthest_points = p
|
123 |
+
|
124 |
+
return max_dist * 2
|
125 |
+
|
126 |
+
diameter1 = max_perpendicular_distance(poly1, center_line)
|
127 |
+
diameter2 = max_perpendicular_distance(poly2, center_line)
|
128 |
+
|
129 |
+
R = (diameter1 + diameter2) / 2
|
130 |
+
|
131 |
+
midpoint = ((centroid1[0] + centroid2[0]) / 2, (centroid1[1] + centroid2[1]) / 2)
|
132 |
+
|
133 |
+
circle = Point(midpoint).buffer(R / 2, resolution=100)
|
134 |
+
|
135 |
+
circle_coords = list(circle.exterior.coords)
|
136 |
+
|
137 |
+
return [circle_coords], midpoint
|
138 |
+
|
139 |
+
|
geospacy.py
ADDED
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from spacy.tokens import Span
|
2 |
+
from spacy.tokens import Doc
|
3 |
+
from spacy.tokens import Token
|
4 |
+
import regex_spatial
|
5 |
+
from spacy.language import Language
|
6 |
+
import re
|
7 |
+
from utils import llm_ent_extract
|
8 |
+
|
9 |
+
id =""
|
10 |
+
rse_id = "rse_id"
|
11 |
+
def set_extension():
|
12 |
+
Span.set_extension(rse_id, default = "",force = True)
|
13 |
+
Doc.set_extension(rse_id, default = "",force = True)
|
14 |
+
Token.set_extension(rse_id, default = "",force = True)
|
15 |
+
|
16 |
+
def get_level1(doc, sentence, ent):
|
17 |
+
return find_ent_by_regex(doc, sentence, ent, regex_spatial.get_level1_regex())
|
18 |
+
|
19 |
+
def get_level2(doc, sentence, ent):
|
20 |
+
return find_ent_by_regex(doc, sentence, ent, regex_spatial.get_level2_regex())
|
21 |
+
|
22 |
+
def get_level3(doc, sentence, ent):
|
23 |
+
return find_ent_by_regex(doc, sentence, ent, regex_spatial.get_level3_regex())
|
24 |
+
|
25 |
+
|
26 |
+
def find_ent_by_regex(doc, sentence, ent, regex):
|
27 |
+
global id
|
28 |
+
|
29 |
+
if id == "":
|
30 |
+
id = ent.text
|
31 |
+
for match in re.finditer(regex, doc.text):
|
32 |
+
start, end = match.span()
|
33 |
+
if(start>= sentence.start_char and start<= sentence.end_char):
|
34 |
+
span = doc.char_span(start, end)
|
35 |
+
if span is not None:
|
36 |
+
id = span.text +"_"+ id
|
37 |
+
if(start > ent.end_char):
|
38 |
+
ent.end_char = end
|
39 |
+
else:
|
40 |
+
ent.start_char = start
|
41 |
+
|
42 |
+
return ent
|
43 |
+
|
44 |
+
return ent
|
45 |
+
|
46 |
+
|
47 |
+
def update_entities(doc, entity_texts, replace=True):
|
48 |
+
"""
|
49 |
+
根据给定的文本内容标注实体,并直接修改 doc.ents。
|
50 |
+
|
51 |
+
:param doc: spaCy 解析后的 Doc 对象
|
52 |
+
:param entity_texts: 字典,键是要标注的实体文本,值是对应的实体类别
|
53 |
+
:param replace: 布尔值,True 则替换现有实体,False 则保留现有实体并添加新的
|
54 |
+
"""
|
55 |
+
new_ents = list(doc.ents) if not replace else [] # 如果 replace=False,保留已有实体
|
56 |
+
|
57 |
+
for ent_text, ent_label in entity_texts.items():
|
58 |
+
start = doc.text.find(ent_text) # 在全文中查找文本位置
|
59 |
+
if start != -1:
|
60 |
+
start_token = len(doc.text[:start].split()) # 计算起始 token 索引
|
61 |
+
end_token = start_token + len(ent_text.split()) # 计算结束 token 索引
|
62 |
+
|
63 |
+
if start_token < len(doc) and end_token <= len(doc): # 确保索引不越界
|
64 |
+
new_ent = Span(doc, start_token, end_token, label=ent_label)
|
65 |
+
new_ents.append(new_ent)
|
66 |
+
|
67 |
+
doc.set_ents(new_ents) # 更新 doc.ents
|
68 |
+
|
69 |
+
|
70 |
+
def get_relative_entity(doc, sentence, ent):
|
71 |
+
global id
|
72 |
+
|
73 |
+
id = ""
|
74 |
+
rel_entity = get_level1(doc, sentence, ent)
|
75 |
+
# print(1111 ,rel_entity)
|
76 |
+
rel_entity = get_level2(doc, sentence, rel_entity)
|
77 |
+
# print(2222 ,rel_entity)
|
78 |
+
rel_entity = get_level3(doc, sentence, rel_entity)
|
79 |
+
# print(3333 ,rel_entity)
|
80 |
+
|
81 |
+
if("_" in id):
|
82 |
+
rel_entity = doc.char_span(rel_entity.start_char, rel_entity.end_char, "RSE")
|
83 |
+
rel_entity._.rse_id = id
|
84 |
+
|
85 |
+
# print(id, 'idid')
|
86 |
+
# print(rel_entity._.rse_id, '._._')
|
87 |
+
|
88 |
+
return rel_entity
|
89 |
+
rel_entity = doc.char_span(ent.start_char, ent.end_char, ent.label_)
|
90 |
+
rel_entity._.rse_id = id
|
91 |
+
# print(4444 ,rel_entity)
|
92 |
+
return rel_entity
|
93 |
+
|
94 |
+
@Language.component("spatial_pipeline")
|
95 |
+
def get_spatial_ent(doc):
|
96 |
+
set_extension()
|
97 |
+
new_ents = []
|
98 |
+
# ents = [ent for ent in doc.ents if ent.label_ == "GPE" or ent.label_ == "LOC"] # 筛选出ase
|
99 |
+
|
100 |
+
|
101 |
+
# LLM 输出
|
102 |
+
# GPE = '[###Pyrmont###, ###Glebe###]' # LLM 输出的实体
|
103 |
+
GPE = llm_ent_extract.extract_GPE(doc.text) # LLM 输出的实体
|
104 |
+
print(doc.text, 'llmin')
|
105 |
+
print(GPE, 'llout')
|
106 |
+
|
107 |
+
GPE = llm_ent_extract.extract(GPE, 'GPE')
|
108 |
+
print(GPE, 'llmout2')
|
109 |
+
update_entities(doc, GPE, True)
|
110 |
+
ents = doc.ents
|
111 |
+
print(ents, 'eee')
|
112 |
+
# print(doc, 'ddd')
|
113 |
+
# print(ents, 'ddd')
|
114 |
+
# GPE = llm_ent_extract.extract(llm_ent_extract.extract_GPE(doc.text), 'gpe')
|
115 |
+
# update_entities(doc, GPE)
|
116 |
+
# LLM 输出完毕
|
117 |
+
|
118 |
+
|
119 |
+
# print(doc.ents, 111)
|
120 |
+
# print(doc.ents[2], 222)
|
121 |
+
# print(type(doc.ents[2]), 222)
|
122 |
+
# print(doc.ents[2].label_, 333)
|
123 |
+
# print('----------')
|
124 |
+
# doc.ents[2] = 'pp'
|
125 |
+
# print(doc.ents[2], 111)
|
126 |
+
# print(doc.ents[2].label_, 222)
|
127 |
+
# print(type(doc.ents), 333)
|
128 |
+
end = None
|
129 |
+
for ent in ents:
|
130 |
+
|
131 |
+
if ent.end != len(doc):
|
132 |
+
next_token = doc[ent.end]
|
133 |
+
if end is not None:
|
134 |
+
start = end
|
135 |
+
else:
|
136 |
+
start = ent.sent.start
|
137 |
+
if next_token.text.lower() in regex_spatial.get_keywords():
|
138 |
+
end = next_token.i
|
139 |
+
else:
|
140 |
+
end = ent.end
|
141 |
+
|
142 |
+
else:
|
143 |
+
start = ent.sent.start
|
144 |
+
end = ent.end
|
145 |
+
|
146 |
+
# print(doc, '//',start, '//', end, 999888)
|
147 |
+
# print(doc[start],'//', doc[end])
|
148 |
+
# print(ents, 999)
|
149 |
+
|
150 |
+
|
151 |
+
rsi_ent = get_relative_entity(doc,Span(doc, start, end), ent)
|
152 |
+
# print(doc.ents[0]._.rse_id, '._._2')
|
153 |
+
|
154 |
+
|
155 |
+
# print(rsi_ent.text, rsi_ent.label_, rsi_ent._.rse_id)
|
156 |
+
new_ents.append(rsi_ent)
|
157 |
+
|
158 |
+
doc.ents = new_ents
|
159 |
+
return doc
|
160 |
+
|
161 |
+
# def update_doc_ents(doc, new_dict):
|
162 |
+
# """
|
163 |
+
# 更新 doc.ents, 将新的实体文本和标签添加到 doc 中。
|
164 |
+
#
|
165 |
+
# 参数:
|
166 |
+
# - doc: spaCy 的 Doc 对象
|
167 |
+
# - new_dict: 一个字典,键是实体文本,值是标签
|
168 |
+
# """
|
169 |
+
# modified_ents = []
|
170 |
+
#
|
171 |
+
# # 遍历字典中的实体文本和标签
|
172 |
+
# for ent_text, label in new_dict.items():
|
173 |
+
# # 将实体文本拆分成单词
|
174 |
+
# ent_words = ent_text.split()
|
175 |
+
#
|
176 |
+
# # 遍历 doc 中的 token 来查找第一个单词
|
177 |
+
# start = None
|
178 |
+
# for i in range(len(doc)):
|
179 |
+
# # 如果当前 token 和实体的第一个单词匹配,确定 start
|
180 |
+
# if doc[i].text == ent_words[0]:
|
181 |
+
# start = i
|
182 |
+
# # 然后检查后续的单词是否都匹配
|
183 |
+
# end = start + len(ent_words) # 计算 end 为 start + 单词数
|
184 |
+
# if all(doc[start + j].text == ent_words[j] for j in range(len(ent_words))):
|
185 |
+
# # 创建 Span 对象
|
186 |
+
# new_ent = Span(doc, start, end, label=label)
|
187 |
+
# modified_ents.append(new_ent)
|
188 |
+
# break # 找到匹配后跳出循环
|
189 |
+
#
|
190 |
+
# # 使用 doc.set_ents() 更新 doc.ents
|
191 |
+
# doc.set_ents(modified_ents)
|
192 |
+
#
|
193 |
+
#
|
194 |
+
# # def llm_extract(doc, model):
|
195 |
+
#
|
196 |
+
# def split_doc_into_sentences(doc):
|
197 |
+
# """
|
198 |
+
# 将 doc 的文本按句子分割,并返回每个句子的字符串列表。
|
199 |
+
# """
|
200 |
+
# sentence_list = [sent.text.strip() for sent in doc.sents]
|
201 |
+
# return sentence_list
|
202 |
+
#
|
203 |
+
#
|
204 |
+
# @Language.component("spatial_pipeline")
|
205 |
+
# def get_spatial_ent(doc):
|
206 |
+
#
|
207 |
+
# set_extension()
|
208 |
+
#
|
209 |
+
# split_sent = split_doc_into_sentences(doc)
|
210 |
+
# for i in range(len(split_sent)):
|
211 |
+
# gpe_dict = llm_ent_extract.extract_GPE(split_sent[i])
|
212 |
+
# loc_dict = llm_ent_extract.extract_LOC(split_sent[i])
|
213 |
+
# new_dict = gpe_dict|loc_dict
|
214 |
+
#
|
215 |
+
#
|
216 |
+
# print(gpe_dict, '111')
|
217 |
+
# print(loc_dict)
|
218 |
+
# print(new_dict)
|
219 |
+
# # new_dict = {'pp': 'ORG', 'France': 'GPE', 'Paris': 'GPE'}
|
220 |
+
#
|
221 |
+
#
|
222 |
+
# # 调用新的函数更新 doc 的实体
|
223 |
+
# update_doc_ents(doc, new_dict)
|
224 |
+
#
|
225 |
+
# # 继续处理 doc.ents
|
226 |
+
# ents = [ent for ent in doc.ents if ent.label_ == "GPE" or ent.label_ == "LOC"]
|
227 |
+
# print(ents[1].label_)
|
228 |
+
#
|
229 |
+
# end = None
|
230 |
+
# new_ents = []
|
231 |
+
#
|
232 |
+
# for ent in ents:
|
233 |
+
# if ent.end != len(doc):
|
234 |
+
# next_token = doc[ent.end + 1]
|
235 |
+
# if end is not None:
|
236 |
+
# start = end
|
237 |
+
# else:
|
238 |
+
# start = ent.sent.start
|
239 |
+
# if next_token.text.lower() in regex_spatial.get_keywords():
|
240 |
+
# end = next_token.i
|
241 |
+
# else:
|
242 |
+
# end = ent.end
|
243 |
+
# else:
|
244 |
+
# start = ent.sent.start
|
245 |
+
# end = ent.end
|
246 |
+
#
|
247 |
+
# # 调用 get_relative_entity 来获得新的实体信息
|
248 |
+
# rsi_ent = get_relative_entity(doc, Span(doc, start, end), ent)
|
249 |
+
#
|
250 |
+
# # 将处理后的实体添加到新的实体列表中
|
251 |
+
# new_ents.append(rsi_ent)
|
252 |
+
#
|
253 |
+
# doc.ents = new_ents # 更新 doc.ents
|
254 |
+
# print(new_ents, '111222')
|
255 |
+
#
|
256 |
+
# return doc
|
pages/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
pages/2_Locate.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
regex_spatial.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
"""
|
4 |
+
Created on Tue Jul 26 14:57:18 2022
|
5 |
+
|
6 |
+
@author: syed
|
7 |
+
"""
|
8 |
+
|
9 |
+
from quantities import units as u
|
10 |
+
from quantities import Quantity
|
11 |
+
|
12 |
+
one_plus = "+"
|
13 |
+
zero_plus = "*"
|
14 |
+
|
15 |
+
|
16 |
+
def get_quantities_regex():
|
17 |
+
# myList = [unit for unit in dir(u.length)
|
18 |
+
# if type(getattr(u.length, unit)) is u.length ]
|
19 |
+
myList = [unit for unit in dir(u.length) if isinstance(getattr(u.length, unit), Quantity)]
|
20 |
+
|
21 |
+
units = [ x for x in myList if "_" not in x ]
|
22 |
+
units_regex = '|'.join(units)
|
23 |
+
return "["+units_regex+"]"
|
24 |
+
def get_number_regex():
|
25 |
+
regex = "[0-9]"
|
26 |
+
return regex
|
27 |
+
def get_space_regex():
|
28 |
+
regex = "\s"
|
29 |
+
return regex
|
30 |
+
|
31 |
+
def get_directional_regex():
|
32 |
+
cardinals_kwds = "north|south|east|west"
|
33 |
+
ordinals_kwds = "north-east|north-west|south-east|south-west|north east|north west|south east|south west|northeast|northwest|southeast|southwest"
|
34 |
+
symbols_kwds = "N'|S'|E'|W'|NE'|NW'|SE'|SW'"
|
35 |
+
return ordinals_kwds+"|"+symbols_kwds+"|"+cardinals_kwds
|
36 |
+
|
37 |
+
def get_center_regex():
|
38 |
+
center_kwds = "center|central|downtown|midtown"
|
39 |
+
return center_kwds
|
40 |
+
|
41 |
+
def get_near_regex():
|
42 |
+
near_kwds = "nearby|near|vicinity|close|beside|next|adjacent|immediate|border"
|
43 |
+
return near_kwds
|
44 |
+
|
45 |
+
def get_surrounding_regex():
|
46 |
+
surrounding_kwds = "surrounding|neigbourhood|proximity|territory|locality"
|
47 |
+
return surrounding_kwds
|
48 |
+
def get_level1_regex():
|
49 |
+
level_1_regex = "(?i)("+get_directional_regex()+"|"+get_center_regex()+")"
|
50 |
+
return level_1_regex
|
51 |
+
|
52 |
+
def get_level2_regex():
|
53 |
+
level_2_regex = "(?i)("+get_near_regex()+"|"+get_surrounding_regex()+")"
|
54 |
+
return level_2_regex
|
55 |
+
|
56 |
+
def get_level3_regex():
|
57 |
+
level_3_regex = "(?i)("+get_number_regex()+one_plus+get_space_regex()+zero_plus+get_quantities_regex()+one_plus+")"
|
58 |
+
return level_3_regex
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
def get_keywords():
|
63 |
+
keywords = []
|
64 |
+
keywords = get_directional_regex().split("|")
|
65 |
+
keywords.extend(get_near_regex().split("|"))
|
66 |
+
keywords.extend(get_surrounding_regex().split("|"))
|
67 |
+
keywords.extend(get_center_regex().split("|"))
|
68 |
+
keywords.append(",")
|
69 |
+
keywords.append("and")
|
70 |
+
keywords.append(".")
|
71 |
+
|
72 |
+
return keywords
|
requirements.txt
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==4.2.2
|
2 |
+
annotated-types==0.7.0
|
3 |
+
anyio==4.8.0
|
4 |
+
attrs @ file:///home/conda/feedstock_root/build_artifacts/attrs_1734348785146/work
|
5 |
+
blinker==1.9.0
|
6 |
+
blis==0.7.11
|
7 |
+
Bottleneck @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_55txi4fy1u/croot/bottleneck_1731058642212/work
|
8 |
+
branca @ file:///home/conda/feedstock_root/build_artifacts/branca_1734433375112/work
|
9 |
+
Brotli @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_27zk0eqdh0/croot/brotli-split_1714483157007/work
|
10 |
+
cachetools==5.5.0
|
11 |
+
catalogue==2.0.10
|
12 |
+
certifi==2024.12.14
|
13 |
+
cffi @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_06ndtibm2c/croot/cffi_1726856446111/work
|
14 |
+
charset-normalizer==3.4.1
|
15 |
+
click==7.1.2
|
16 |
+
click-plugins @ file:///home/conda/feedstock_root/build_artifacts/click-plugins_1733731077999/work
|
17 |
+
cligj @ file:///home/conda/feedstock_root/build_artifacts/cligj_1733749956636/work
|
18 |
+
cloudpathlib==0.20.0
|
19 |
+
colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1733218098505/work
|
20 |
+
confection==0.1.5
|
21 |
+
contourpy @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_2cvjf0v4ux/croot/contourpy_1732540055997/work
|
22 |
+
cycler @ file:///home/conda/feedstock_root/build_artifacts/cycler_1733332471406/work
|
23 |
+
cymem==2.0.10
|
24 |
+
distro==1.9.0
|
25 |
+
en_core_web_md @ https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.0.0/en_core_web_md-3.0.0.tar.gz#sha256=45757583a3c9d15c6895cf4bf9512e86243bab8cda51512c127f5cbdc34ac630
|
26 |
+
en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.0.0/en_core_web_sm-3.0.0.tar.gz#sha256=0673b3ce4a28a19e99dc0fc3f8f7fe67b936c41749e6b70f778ec5f9f78f3a66
|
27 |
+
entrypoints==0.4
|
28 |
+
exceptiongroup==1.2.2
|
29 |
+
filelock==3.16.1
|
30 |
+
fiona @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_10va3k3ghg/croot/fiona_1735554358779/work
|
31 |
+
folium==0.19.4
|
32 |
+
fonttools @ file:///home/conda/feedstock_root/build_artifacts/fonttools_1735335791296/work
|
33 |
+
fsspec==2024.12.0
|
34 |
+
GDAL @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_0at39q0ks3/croot/gdal-split_1704913257208/work/build/swig/python
|
35 |
+
gensim==4.3.3
|
36 |
+
geopandas @ file:///home/conda/feedstock_root/build_artifacts/geopandas_1658688831518/work
|
37 |
+
gitdb==4.0.11
|
38 |
+
GitPython==3.1.43
|
39 |
+
h11==0.14.0
|
40 |
+
h2 @ file:///home/conda/feedstock_root/build_artifacts/h2_1733298745555/work
|
41 |
+
hpack @ file:///home/conda/feedstock_root/build_artifacts/hpack_1733299205993/work
|
42 |
+
httpcore==1.0.7
|
43 |
+
httpx==0.28.1
|
44 |
+
huggingface-hub==0.27.0
|
45 |
+
hyperframe @ file:///home/conda/feedstock_root/build_artifacts/hyperframe_1733298771451/work
|
46 |
+
idna==3.10
|
47 |
+
importlib_metadata==8.5.0
|
48 |
+
Jinja2 @ file:///home/conda/feedstock_root/build_artifacts/jinja2_1734823942230/work
|
49 |
+
jiter==0.8.2
|
50 |
+
joblib @ file:///home/conda/feedstock_root/build_artifacts/joblib_1733736026804/work
|
51 |
+
jsonschema==4.23.0
|
52 |
+
jsonschema-specifications==2024.10.1
|
53 |
+
kiwisolver @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_93o8te804v/croot/kiwisolver_1672387163224/work
|
54 |
+
langcodes==3.5.0
|
55 |
+
language_data==1.3.0
|
56 |
+
mapclassify @ file:///home/conda/feedstock_root/build_artifacts/mapclassify_1733731066416/work
|
57 |
+
marisa-trie==1.2.1
|
58 |
+
markdown-it-py==3.0.0
|
59 |
+
MarkupSafe @ file:///home/conda/feedstock_root/build_artifacts/markupsafe_1733219583522/work
|
60 |
+
matplotlib==3.9.2
|
61 |
+
mdurl==0.1.2
|
62 |
+
munkres==1.1.4
|
63 |
+
murmurhash==1.0.11
|
64 |
+
mysql-connector-python==8.0.30
|
65 |
+
narwhals==1.20.1
|
66 |
+
networkx @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_networkx_1731521053/work
|
67 |
+
numexpr @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_b3kvvt6tc6/croot/numexpr_1730215947700/work
|
68 |
+
numpy @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_a51i_mbs7m/croot/numpy_and_numpy_base_1708638620867/work/dist/numpy-1.26.4-cp310-cp310-macosx_11_0_arm64.whl#sha256=c4b11b3c4d4fdb810039503fe01f311ade06cd1d675fcd6d208800a393f19b69
|
69 |
+
openai==1.61.1
|
70 |
+
packaging==24.2
|
71 |
+
pandas @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_4aifrweohv/croot/pandas_1732735109535/work/dist/pandas-2.2.3-cp310-cp310-macosx_11_0_arm64.whl#sha256=6c5bbde94d3ac89a919939bdecfabca704888cdaf6251a6b101db7024fed27ab
|
72 |
+
pathlib_abc==0.1.1
|
73 |
+
pathy==0.11.0
|
74 |
+
pillow @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_92egn12how/croot/pillow_1731594702114/work
|
75 |
+
pipdeptree==2.24.0
|
76 |
+
preshed==3.0.9
|
77 |
+
protobuf==3.20.1
|
78 |
+
pyarrow==18.1.0
|
79 |
+
pycparser @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_pycparser_1733195786/work
|
80 |
+
pydantic==1.10.0
|
81 |
+
pydantic_core==2.27.2
|
82 |
+
pydeck==0.9.1
|
83 |
+
Pygments==2.18.0
|
84 |
+
Pympler==1.1
|
85 |
+
pyparsing @ file:///home/conda/feedstock_root/build_artifacts/pyparsing_1733222594562/work
|
86 |
+
pyproj @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_acukan6udl/croot/pyproj_1704901274181/work
|
87 |
+
PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1733217236728/work
|
88 |
+
python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1733215673016/work
|
89 |
+
pytz @ file:///home/conda/feedstock_root/build_artifacts/pytz_1733215667876/work
|
90 |
+
PyYAML==6.0.2
|
91 |
+
quantities==0.13.0
|
92 |
+
referencing==0.35.1
|
93 |
+
requests==2.32.3
|
94 |
+
rich==13.9.4
|
95 |
+
rpds-py==0.22.3
|
96 |
+
Rtree @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_a4tjgnr1ag/croot/rtree_1675157863029/work
|
97 |
+
scikit-learn @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_cdv8p6f6u3/croot/scikit-learn_1734547683501/work
|
98 |
+
scipy==1.13.1
|
99 |
+
semver==3.0.2
|
100 |
+
Shapely @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_8arrf7j2ot/croots/recipe/shapely_1664521590671/work
|
101 |
+
shellingham==1.5.4
|
102 |
+
six @ file:///home/conda/feedstock_root/build_artifacts/six_1733380938961/work
|
103 |
+
smart-open==6.4.0
|
104 |
+
smmap==5.0.1
|
105 |
+
sniffio==1.3.1
|
106 |
+
spacy==3.0.9
|
107 |
+
spacy-legacy==3.0.12
|
108 |
+
spacy-loggers==1.0.5
|
109 |
+
spacy-streamlit==1.0.1
|
110 |
+
srsly==2.5.0
|
111 |
+
streamlit==1.41.1
|
112 |
+
streamlit_folium==0.24.0
|
113 |
+
tenacity==9.0.0
|
114 |
+
thinc==8.0.17
|
115 |
+
threadpoolctl @ file:///home/conda/feedstock_root/build_artifacts/threadpoolctl_1714400101435/work
|
116 |
+
tokenizers==0.21.0
|
117 |
+
toml==0.10.2
|
118 |
+
toolz==1.0.0
|
119 |
+
tornado==6.4.2
|
120 |
+
tqdm==4.67.1
|
121 |
+
typer==0.3.2
|
122 |
+
typing_extensions==4.12.2
|
123 |
+
tzdata @ file:///home/conda/feedstock_root/build_artifacts/python-tzdata_1733235305708/work
|
124 |
+
tzlocal==5.2
|
125 |
+
unicodedata2 @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_a3epjto7gs/croot/unicodedata2_1713212955584/work
|
126 |
+
urllib3==2.3.0
|
127 |
+
validators==0.34.0
|
128 |
+
wasabi==0.10.1
|
129 |
+
weasel==0.4.1
|
130 |
+
wrapt==1.17.0
|
131 |
+
xyzservices @ file:///home/conda/feedstock_root/build_artifacts/xyzservices_1733143442470/work
|
132 |
+
zipp==3.21.0
|
133 |
+
zstandard @ file:///private/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_a5_i6g4o6n/croot/zstandard_1731356352787/work
|
saved_doc.spacy
ADDED
Binary file (2.11 kB). View file
|
|
screen_shot.jpg
ADDED
![]() |
Git LFS Details
|
utils/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
utils/__pycache__/config.cpython-310.pyc
ADDED
Binary file (329 Bytes). View file
|
|
utils/__pycache__/geoutil.cpython-310.pyc
ADDED
Binary file (6.4 kB). View file
|
|
utils/__pycache__/geoutil.cpython-39.pyc
ADDED
Binary file (5.95 kB). View file
|
|
utils/__pycache__/llm_coding.cpython-310.pyc
ADDED
Binary file (9.77 kB). View file
|
|
utils/__pycache__/llm_ent_extract.cpython-310.pyc
ADDED
Binary file (6.78 kB). View file
|
|
utils/config.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
api_key = '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'
|
utils/geoutil.py
ADDED
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
"""
|
4 |
+
Created on Tue Aug 2 12:45:21 2022
|
5 |
+
|
6 |
+
@author: syed
|
7 |
+
"""
|
8 |
+
|
9 |
+
import math
|
10 |
+
import re
|
11 |
+
import regex_spatial
|
12 |
+
import quantities as pq
|
13 |
+
from math import radians, cos, sin, asin, sqrt
|
14 |
+
import quantities as pq
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
def get_kilometers(d, unit):
|
19 |
+
q = float(d) * pq.CompoundUnit(unit)
|
20 |
+
q.units = pq.km
|
21 |
+
return q.magnitude
|
22 |
+
|
23 |
+
def ConvertToRadian(input):
|
24 |
+
return input * math.pi / 180
|
25 |
+
|
26 |
+
def get_level1(ent):
|
27 |
+
level_1 = re.search(regex_spatial.get_level1_regex(), ent)
|
28 |
+
if level_1 is not None:
|
29 |
+
return level_1.group()
|
30 |
+
return None
|
31 |
+
def get_level2(ent):
|
32 |
+
level_2 = re.search(regex_spatial.get_level2_regex(), ent)
|
33 |
+
if level_2 is not None:
|
34 |
+
return level_2.group()
|
35 |
+
return None
|
36 |
+
def get_level3(ent):
|
37 |
+
level_3 = re.search(regex_spatial.get_level3_regex(), ent)
|
38 |
+
if level_3 is not None:
|
39 |
+
return level_3.group()
|
40 |
+
return None
|
41 |
+
|
42 |
+
def get_ase(ent):
|
43 |
+
abs_sp = ent.split("_")
|
44 |
+
return abs_sp[len(abs_sp)-1]
|
45 |
+
|
46 |
+
def get_ent(ent):
|
47 |
+
return get_ase(ent), get_level1(ent), get_level2(ent), get_level3(ent)
|
48 |
+
|
49 |
+
def get_centroid(coordinates, centroid, mini, maxi):
|
50 |
+
average = (mini + maxi)/2
|
51 |
+
diff = []
|
52 |
+
ind = 0
|
53 |
+
for p in coordinates:
|
54 |
+
diff.append(abs( p[2] - average))
|
55 |
+
|
56 |
+
ind = diff.index(min(diff))
|
57 |
+
|
58 |
+
return midpoint(centroid[0], centroid[1], coordinates[ind][0], coordinates[ind][1], average)
|
59 |
+
|
60 |
+
|
61 |
+
def calculateArea(coordinates):
|
62 |
+
area = 0
|
63 |
+
if (len(coordinates) > 2):
|
64 |
+
i = 0
|
65 |
+
for i in range(len(coordinates) - 1):
|
66 |
+
p1 = coordinates[i]
|
67 |
+
p2 = coordinates[i + 1]
|
68 |
+
area += math.radians(p2[0] - p1[0]) * (2 + math.sin(ConvertToRadian(p1[1])) + math.sin(math.radians(p2[0])))
|
69 |
+
|
70 |
+
|
71 |
+
area = area * 6378137 * 6378137 / 1000000
|
72 |
+
|
73 |
+
area = abs(round(area, 2)) + 2
|
74 |
+
|
75 |
+
return area
|
76 |
+
|
77 |
+
def get_midmid_point(centroid, point1, point2, is_midmid):
|
78 |
+
mid1 = midpoint(centroid[0], centroid[1],
|
79 |
+
point1[0], point1[1]
|
80 |
+
, point1[2])
|
81 |
+
mid2 = midpoint(centroid[0], centroid[1],
|
82 |
+
point2[0], point2[1],
|
83 |
+
point2[2])
|
84 |
+
midmid1 = midpoint(centroid[0], centroid[1],
|
85 |
+
mid1[0], mid1[1]
|
86 |
+
, mid1[2])
|
87 |
+
midmid2 = midpoint(centroid[0], centroid[1],
|
88 |
+
mid2[0], mid2[1],
|
89 |
+
mid2[2])
|
90 |
+
if is_midmid:
|
91 |
+
return midmid1, midmid2
|
92 |
+
else:
|
93 |
+
return mid1, mid2
|
94 |
+
|
95 |
+
def getPointByDistanceAngle(lat, ln, angle, distanceInKm):
|
96 |
+
|
97 |
+
R = 6378.1 #Radius of the Earth
|
98 |
+
brng = angle * math.pi /180 #Bearing is 90 degrees converted to radians.
|
99 |
+
d = distanceInKm #Distance in km
|
100 |
+
|
101 |
+
#lat2 52.20444 - the lat result I'm hoping for
|
102 |
+
#lon2 0.36056 - the long result I'm hoping for.
|
103 |
+
|
104 |
+
lat1 = math.radians(lat) #Current lat point converted to radians
|
105 |
+
lon1 = math.radians(ln) #Current long point converted to radians
|
106 |
+
|
107 |
+
lat2 = math.asin( math.sin(lat1)*math.cos(d/R) +
|
108 |
+
math.cos(lat1)*math.sin(d/R)*math.cos(brng))
|
109 |
+
|
110 |
+
lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1),
|
111 |
+
math.cos(d/R)-math.sin(lat1)*math.sin(lat2))
|
112 |
+
|
113 |
+
lat2 = math.degrees(lat2)
|
114 |
+
lon2 = math.degrees(lon2)
|
115 |
+
|
116 |
+
return [lon2, lat2, angle]
|
117 |
+
|
118 |
+
def midpoint(x1, y1, x2, y2, angle):
|
119 |
+
|
120 |
+
lonA = math.radians(y1)
|
121 |
+
lonB = math.radians(y2)
|
122 |
+
latA = math.radians(x1)
|
123 |
+
latB = math.radians(x2)
|
124 |
+
|
125 |
+
dLon = lonB - lonA
|
126 |
+
|
127 |
+
Bx = math.cos(latB) * math.cos(dLon)
|
128 |
+
By = math.cos(latB) * math.sin(dLon)
|
129 |
+
|
130 |
+
latC = math.atan2(math.sin(latA) + math.sin(latB),
|
131 |
+
math.sqrt((math.cos(latA) + Bx) * (math.cos(latA) + Bx) + By * By))
|
132 |
+
lonC = lonA + math.atan2(By, math.cos(latA) + Bx)
|
133 |
+
lonC = (lonC + 3 * math.pi) % (2 * math.pi) - math.pi
|
134 |
+
latitude = round(math.degrees(latC), 8)
|
135 |
+
longitude = round(math.degrees(lonC),8)
|
136 |
+
return [latitude, longitude, angle]
|
137 |
+
|
138 |
+
def midpoint(y1, x1, y2, x2, angle):
|
139 |
+
|
140 |
+
lonA = math.radians(y1)
|
141 |
+
lonB = math.radians(y2)
|
142 |
+
latA = math.radians(x1)
|
143 |
+
latB = math.radians(x2)
|
144 |
+
|
145 |
+
dLon = lonB - lonA
|
146 |
+
|
147 |
+
Bx = math.cos(latB) * math.cos(dLon)
|
148 |
+
By = math.cos(latB) * math.sin(dLon)
|
149 |
+
|
150 |
+
latC = math.atan2(math.sin(latA) + math.sin(latB),
|
151 |
+
math.sqrt((math.cos(latA) + Bx) * (math.cos(latA) + Bx) + By * By))
|
152 |
+
lonC = lonA + math.atan2(By, math.cos(latA) + Bx)
|
153 |
+
lonC = (lonC + 3 * math.pi) % (2 * math.pi) - math.pi
|
154 |
+
latitude = round(math.degrees(latC), 8)
|
155 |
+
longitude = round(math.degrees(lonC) ,8)
|
156 |
+
print([longitude, latitude, angle], 'midmid')
|
157 |
+
return [longitude, latitude, angle
|
158 |
+
|
159 |
+
]
|
160 |
+
|
161 |
+
def calculate_bearing(pointA, pointB):
|
162 |
+
|
163 |
+
if (type(pointA) != tuple) or (type(pointB) != tuple):
|
164 |
+
return 400
|
165 |
+
if (type(pointB[0]) != float) or (type(pointB[0]) != float):
|
166 |
+
return 400
|
167 |
+
|
168 |
+
lat1 = math.radians(pointA[0])
|
169 |
+
lat2 = math.radians(pointB[0])
|
170 |
+
|
171 |
+
diffLong = math.radians(pointB[1] - pointA[1])
|
172 |
+
|
173 |
+
x = math.sin(diffLong) * math.cos(lat2)
|
174 |
+
y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1)
|
175 |
+
* math.cos(lat2) * math.cos(diffLong))
|
176 |
+
|
177 |
+
initial_bearing = math.atan2(x, y)
|
178 |
+
|
179 |
+
|
180 |
+
initial_bearing = math.degrees(initial_bearing)
|
181 |
+
compass_bearing = (initial_bearing + 360) % 360
|
182 |
+
|
183 |
+
return compass_bearing
|
184 |
+
|
185 |
+
def getPointByDistanceAngle(lat, ln, angle, distance, unit):
|
186 |
+
|
187 |
+
#distanceInKm = distance
|
188 |
+
R = 6378.1 #Radius of the Earth
|
189 |
+
brng = float(angle) * math.pi /180 #Bearing is 90 degrees converted to radians.
|
190 |
+
d = get_kilometers(distance, unit) #Distance in km
|
191 |
+
|
192 |
+
|
193 |
+
lat1 = math.radians(lat) #Current lat point converted to radians
|
194 |
+
lon1 = math.radians(ln) #Current long point converted to radians
|
195 |
+
|
196 |
+
lat2 = math.asin( math.sin(lat1)*math.cos(d/R) +
|
197 |
+
math.cos(lat1)*math.sin(d/R)*math.cos(brng))
|
198 |
+
|
199 |
+
lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1),
|
200 |
+
math.cos(d/R)-math.sin(lat1)*math.sin(lat2))
|
201 |
+
|
202 |
+
lat2 = math.degrees(lat2)
|
203 |
+
lon2 = math.degrees(lon2)
|
204 |
+
|
205 |
+
return (round(lon2,8), round(lat2,8), angle)
|
206 |
+
|
207 |
+
|
208 |
+
def calculatePointByDistance(lat, ln, angle, distance, unit):
|
209 |
+
coff = 100/(6378*1.56)
|
210 |
+
kms = get_kilometers(distance, unit)
|
211 |
+
|
212 |
+
d = kms * coff
|
213 |
+
|
214 |
+
angle_x = math.cos( angle ) # * math.pi/180
|
215 |
+
angle_y = math.sin( angle) # * math.pi/180
|
216 |
+
lat_new = lat + (d * angle_x)
|
217 |
+
ln_new = ln + (d * angle_y)
|
218 |
+
|
219 |
+
return (round(ln_new,8), round(lat_new,8), angle)
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
def pointByAngle(lat, ln, angle, distance, unit):
|
224 |
+
|
225 |
+
R = 6378.1 #Radius of the Earth
|
226 |
+
brng = angle * math.pi /180 #Bearing is 90 degrees converted to radians.
|
227 |
+
d = get_kilometers(distance, unit) #Distance in km
|
228 |
+
|
229 |
+
#lat2 52.20444 - the lat result I'm hoping for
|
230 |
+
#lon2 0.36056 - the long result I'm hoping for.
|
231 |
+
|
232 |
+
lat1 = math.radians(lat) #Current lat point converted to radians
|
233 |
+
lon1 = math.radians(ln) #Current long point converted to radians
|
234 |
+
|
235 |
+
lat2 = math.asin( math.sin(lat1)*math.cos(d/R) +
|
236 |
+
math.cos(lat1)*math.sin(d/R)*math.cos(brng))
|
237 |
+
|
238 |
+
lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1),
|
239 |
+
math.cos(d/R)-math.sin(lat1)*math.sin(lat2))
|
240 |
+
|
241 |
+
lat2 = math.degrees(lat2)
|
242 |
+
lon2 = math.degrees(lon2)
|
243 |
+
|
244 |
+
return (lon2, lat2, angle)
|
245 |
+
|
246 |
+
|
247 |
+
def getPointByDistance(lat, ln, angle, distance, unit):
|
248 |
+
kms = get_kilometers(distance, unit)
|
249 |
+
coef = kms / 111.32
|
250 |
+
new_lat = lat + coef
|
251 |
+
new_long = ln + coef / math.cos(lat * 0.01745)
|
252 |
+
return (round(new_lat,8), round(new_long,8), angle)
|
253 |
+
|
254 |
+
def haversine(lon1, lat1, lon2, lat2):
|
255 |
+
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
|
256 |
+
dlon = lon2 - lon1
|
257 |
+
dlat = lat2 - lat1
|
258 |
+
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
|
259 |
+
c = 2 * asin(sqrt(a))
|
260 |
+
km = 6371* c
|
261 |
+
return km
|
262 |
+
|
utils/llm_coding.py
ADDED
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import urllib3
|
3 |
+
import json
|
4 |
+
from utils import geoutil
|
5 |
+
import regex_spatial
|
6 |
+
from shapely.geometry import Polygon, MultiPoint, LineString, Point, mapping
|
7 |
+
import re
|
8 |
+
import geopandas as gpd
|
9 |
+
from geocoder import geo_level1
|
10 |
+
from openai import OpenAI
|
11 |
+
from utils.config import api_key
|
12 |
+
import numpy as np
|
13 |
+
|
14 |
+
|
15 |
+
client = OpenAI(
|
16 |
+
api_key=api_key
|
17 |
+
)
|
18 |
+
|
19 |
+
|
20 |
+
model = "gpt-4o"
|
21 |
+
|
22 |
+
north = ["north", "N'", "North", "NORTH"]
|
23 |
+
south = ["south", "S'", "South", "SOUTH"]
|
24 |
+
east = ["east", "E'", "East", "EAST"]
|
25 |
+
west = ["west", "W'", "West", "WEST"]
|
26 |
+
northeast = ["north-east", "NE'", "north east", "NORTH-EAST", "North East", "NORTH EAST"]
|
27 |
+
southeast = ["south-east", "SE'", "south east", "SOUTH-EAST", "South East", "SOUTH EAST"]
|
28 |
+
northwest = ["north-west", "NW'", "north west", "NORTH-WEST", "North West", "NORTH WEST"]
|
29 |
+
southwest = ["south-west", "SW'", "south west", "SOUTH-WEST", "South West", "SOUTH WEST"]
|
30 |
+
center = ["center","central", "downtown","midtown"]
|
31 |
+
|
32 |
+
|
33 |
+
def to_standard_2d_list(data):
|
34 |
+
arr = np.array(data)
|
35 |
+
flat = arr.flatten()
|
36 |
+
if flat.size % 2 != 0:
|
37 |
+
raise ValueError("元素个数不是2的倍数,不能 reshape 成 [N, 2] 格式")
|
38 |
+
|
39 |
+
return flat.reshape(-1, 2).tolist()
|
40 |
+
|
41 |
+
|
42 |
+
def get_geojson(ent, arr, centroid):
|
43 |
+
poly_json = {}
|
44 |
+
poly_json['type'] = 'FeatureCollection'
|
45 |
+
poly_json['features'] = []
|
46 |
+
coordinates= []
|
47 |
+
coordinates.append(arr)
|
48 |
+
poly_json['features'].append({
|
49 |
+
'type':'Feature',
|
50 |
+
'id': ent,
|
51 |
+
'properties': {
|
52 |
+
'centroid': centroid
|
53 |
+
},
|
54 |
+
'geometry': {
|
55 |
+
'type':'Polygon',
|
56 |
+
'coordinates': coordinates
|
57 |
+
}
|
58 |
+
})
|
59 |
+
return poly_json
|
60 |
+
|
61 |
+
|
62 |
+
def get_coordinates(ent):
|
63 |
+
request_url = 'https://nominatim.openstreetmap.org/search.php?q= ' +ent +'&polygon_geojson=1&accept-language=en&format=jsonv2'
|
64 |
+
headers = {
|
65 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15"
|
66 |
+
}
|
67 |
+
page = requests.get(request_url, headers=headers, verify=False)
|
68 |
+
json_content = json.loads(page.content)
|
69 |
+
all_coordinates = json_content[0]['geojson']['coordinates'][0]
|
70 |
+
centroid = (float(json_content[0]['lon']), float(json_content[0]['lat']))
|
71 |
+
for p in all_coordinates:
|
72 |
+
p2 = (p[0], p[1])
|
73 |
+
angle = geoutil.calculate_bearing(centroid, p2)
|
74 |
+
p.append(angle)
|
75 |
+
|
76 |
+
geojson = get_geojson(ent, all_coordinates, centroid)
|
77 |
+
|
78 |
+
return geojson['features'][0]['geometry']['coordinates'][0], geojson['features'][0]['properties']['centroid']
|
79 |
+
|
80 |
+
def get_coordinates(location):
|
81 |
+
request_url = f'https://nominatim.openstreetmap.org/search.php?q={location}&polygon_geojson=1&accept-language=en&format=jsonv2'
|
82 |
+
|
83 |
+
print(request_url)
|
84 |
+
headers = {"User-Agent": "Mozilla/5.0"}
|
85 |
+
response = requests.get(request_url, headers=headers, verify=False)
|
86 |
+
json_content = json.loads(response.content)
|
87 |
+
if json_content[0]['geojson']['type'] == 'Polygon':
|
88 |
+
coordinates = json_content[0]['geojson']['coordinates'][0]
|
89 |
+
elif json_content[0]['geojson']['type'] == 'Point':
|
90 |
+
coordinates = json_content[0]['geojson']['coordinates']
|
91 |
+
else:
|
92 |
+
print(json_content[0]['geojson']['type'])
|
93 |
+
centroid = (float(json_content[0]['lon']), float(json_content[0]['lat']))
|
94 |
+
return (coordinates, centroid)
|
95 |
+
|
96 |
+
|
97 |
+
# level3
|
98 |
+
def get_directional_coordinates_by_angle(coordinates, centroid, direction, minimum, maximum):
|
99 |
+
direction_coordinates = []
|
100 |
+
for p in coordinates:
|
101 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
102 |
+
p2 = (p[0], p[1], angle)
|
103 |
+
if direction in geo_level1.east:
|
104 |
+
if angle >= minimum or angle <= maximum:
|
105 |
+
direction_coordinates.append(p2)
|
106 |
+
|
107 |
+
else:
|
108 |
+
if angle >= minimum and angle <= maximum:
|
109 |
+
direction_coordinates.append(p2)
|
110 |
+
return direction_coordinates
|
111 |
+
def get_level3(level3):
|
112 |
+
digits = re.findall('[0-9]+', level3)[0]
|
113 |
+
unit = re.findall('[A-Za-z]+', level3)[0]
|
114 |
+
return digits, unit
|
115 |
+
|
116 |
+
def get_direction_coordinates(coordinates, centroid, level1):
|
117 |
+
min_max = geo_level1.get_min_max(level1)
|
118 |
+
if min_max is not None:
|
119 |
+
coord = get_directional_coordinates_by_angle(coordinates, centroid, level1, min_max[0], min_max[1])
|
120 |
+
return coord
|
121 |
+
return coordinates
|
122 |
+
def sort_west(poly1, poly2, centroid):
|
123 |
+
coords1 = mapping(poly1)["features"][0]["geometry"]["coordinates"]
|
124 |
+
coords2 = mapping(poly2)["features"][0]["geometry"]["coordinates"]
|
125 |
+
coord1 = []
|
126 |
+
coord2 = []
|
127 |
+
coord = []
|
128 |
+
for c in coords1:
|
129 |
+
pol = list(c[::-1])
|
130 |
+
coord1.extend(pol)
|
131 |
+
for c in coords2:
|
132 |
+
pol = list(c[::-1])
|
133 |
+
coord2.extend(pol)
|
134 |
+
coo1 = []
|
135 |
+
coo2 = []
|
136 |
+
for p in coord1:
|
137 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
138 |
+
if angle >= 157 and angle <= 202:
|
139 |
+
coo1.append((p[0], p[1], angle))
|
140 |
+
for p in coord2:
|
141 |
+
angle = geoutil.calculate_bearing(centroid, p)
|
142 |
+
if angle >= 157 and angle <= 202:
|
143 |
+
coo2.append((p[0], p[1], angle))
|
144 |
+
coo1.extend(coo2)
|
145 |
+
return coo1
|
146 |
+
|
147 |
+
|
148 |
+
def get_level3_coordinates(coordinates, level_3, level1):
|
149 |
+
distance, unit = get_level3(level_3)
|
150 |
+
kms = geoutil.get_kilometers(distance, unit)
|
151 |
+
coord = []
|
152 |
+
|
153 |
+
coords0, center = coordinates
|
154 |
+
|
155 |
+
if not isinstance(coords0, list) or len(coords0) < 3:
|
156 |
+
lat_km = 111.32
|
157 |
+
lon_km = 111.32 * np.cos(np.radians(center[1]))
|
158 |
+
|
159 |
+
dx = dy = 0
|
160 |
+
|
161 |
+
if level1 is not None:
|
162 |
+
if level1 in geo_level1.east:
|
163 |
+
dx = kms / lon_km
|
164 |
+
elif level1 in geo_level1.west:
|
165 |
+
dx = -kms / lon_km
|
166 |
+
elif level1 in geo_level1.north:
|
167 |
+
dy = kms / lat_km
|
168 |
+
elif level1 in geo_level1.south:
|
169 |
+
dy = -kms / lat_km
|
170 |
+
new_center = (center[0] + dx, center[1] + dy)
|
171 |
+
r_km = 1
|
172 |
+
|
173 |
+
circle_points = []
|
174 |
+
for theta in np.linspace(0, 360, num=100):
|
175 |
+
theta_rad = np.radians(theta)
|
176 |
+
d_lat = (np.sin(theta_rad) * r_km) / lat_km
|
177 |
+
d_lon = (np.cos(theta_rad) * r_km) / lon_km
|
178 |
+
circle_points.append((new_center[0] + d_lon, new_center[1] + d_lat))
|
179 |
+
|
180 |
+
if circle_points:
|
181 |
+
center_point = MultiPoint(circle_points).centroid
|
182 |
+
center = (center_point.x, center_point.y)
|
183 |
+
else:
|
184 |
+
center = new_center
|
185 |
+
|
186 |
+
return circle_points, center
|
187 |
+
|
188 |
+
poly1 = Polygon(coords0)
|
189 |
+
polygon1 = gpd.GeoSeries(poly1)
|
190 |
+
|
191 |
+
poly2 = polygon1.buffer(0.0095 * kms, join_style=2)
|
192 |
+
poly3 = polygon1.buffer(0.013 * kms, join_style=2)
|
193 |
+
poly = poly3.difference(poly2)
|
194 |
+
|
195 |
+
coords = mapping(poly)["features"][0]["geometry"]["coordinates"]
|
196 |
+
for c in coords:
|
197 |
+
pol = list(c[::-1])
|
198 |
+
coord.extend(pol)
|
199 |
+
|
200 |
+
if level1 is not None:
|
201 |
+
coord = get_direction_coordinates(coord, coordinates[1], level1)
|
202 |
+
if level1 in geo_level1.west:
|
203 |
+
coord = sort_west(poly3, poly2, coordinates[1])
|
204 |
+
|
205 |
+
if coord:
|
206 |
+
center_point = MultiPoint(coord).centroid
|
207 |
+
center = (center_point.x, center_point.y)
|
208 |
+
else:
|
209 |
+
center = coordinates[1]
|
210 |
+
|
211 |
+
return coord, center
|
212 |
+
|
213 |
+
# between
|
214 |
+
def get_between_coordinates(coordinates1, coordinates2):
|
215 |
+
|
216 |
+
def is_valid_polygon(coords):
|
217 |
+
return isinstance(coords, list) and len(coords) >= 3
|
218 |
+
|
219 |
+
coords1, center1 = coordinates1
|
220 |
+
coords2, center2 = coordinates2
|
221 |
+
|
222 |
+
if is_valid_polygon(coords1):
|
223 |
+
poly1 = Polygon(coords1)
|
224 |
+
area1 = poly1.area
|
225 |
+
else:
|
226 |
+
area1 = 0
|
227 |
+
|
228 |
+
if is_valid_polygon(coords2):
|
229 |
+
poly2 = Polygon(coords2)
|
230 |
+
area2 = poly2.area
|
231 |
+
else:
|
232 |
+
area2 = 0
|
233 |
+
|
234 |
+
midpoint = (
|
235 |
+
(center1[0] + center2[0]) / 2,
|
236 |
+
(center1[1] + center2[1]) / 2
|
237 |
+
)
|
238 |
+
|
239 |
+
if area1 == 0 and area2 == 0:
|
240 |
+
r_km = 2
|
241 |
+
else:
|
242 |
+
avg_area = (area1 + area2) / 2
|
243 |
+
r_km = np.sqrt(avg_area / np.pi) * 111.32 # 近似 km 半径
|
244 |
+
|
245 |
+
lat_km = 111.32
|
246 |
+
lon_km = 111.32 * np.cos(np.radians(midpoint[1]))
|
247 |
+
|
248 |
+
circle_points = []
|
249 |
+
for theta in np.linspace(0, 360, num=100):
|
250 |
+
theta_rad = np.radians(theta)
|
251 |
+
d_lat = (np.sin(theta_rad) * r_km) / lat_km
|
252 |
+
d_lon = (np.cos(theta_rad) * r_km) / lon_km
|
253 |
+
circle_points.append((midpoint[0] + d_lon, midpoint[1] + d_lat))
|
254 |
+
|
255 |
+
return circle_points, midpoint
|
256 |
+
|
257 |
+
|
258 |
+
def llmapi(text):
|
259 |
+
system_prompt = (
|
260 |
+
"You are an experienced geographer. Your task is to determine the correct sequence of positioning functions and their inputs based on a given piece of natural language.\n"
|
261 |
+
"The positioning functions you can choose from are:\n"
|
262 |
+
"1. Relative Positioning: Inputs is (location coordinate or location name, direction, and distance). Outputs the coordinates that are in the given 'direction' and 'distance' from the input location.\n"
|
263 |
+
"2. Between Positioning: Inputs is (location 1 coordinates or location 1 name, location 2 coordinates or location 2 name). Outputs the midpoint coordinate between the two locations.\n"
|
264 |
+
"You can only use the given functions, and the inputs to the functions must obey the above properties. The given functions can be combined to solve complex situations."
|
265 |
+
"First, perform chain-of-thought (CoT) reasoning, and finally output your answer in JSON format, wrapped between `<<<JSON>>>` and `<<<END>>>`.\n"
|
266 |
+
"Make sure all inputs only include: location names (strings), step indices (integers), directions (strings, must be in English), or distances (strings with units). Do not return expressions like 'the coordinate 4 km south of Chatswood'.\n"
|
267 |
+
"Each step must have an 'id'. If the input of a step is the output of a previous step, use that step’s 'id' as the input.\n"
|
268 |
+
"All directions must be in English (e.g., south, west, northeast, etc.).\n"
|
269 |
+
"Example output:\n"
|
270 |
+
"<<<JSON>>>\n"
|
271 |
+
"[{\"id\": 1, \"function\": \"Relative\", \"inputs\": [\"Chatswood\", \"south\", \"4 km\"]},"
|
272 |
+
"{\"id\": 2, \"function\": \"Relative\", \"inputs\": [\"North Sydney\", \"west\", \"2 km\"]},"
|
273 |
+
"{\"id\": 3, \"function\": \"Between\", \"inputs\": [1, 2]},"
|
274 |
+
"{\"id\": 4, \"function\": \"Relative\", \"inputs\": [3, \"southwest\", \"5 km\"]}]\n"
|
275 |
+
"<<<END>>>")
|
276 |
+
|
277 |
+
messages = [
|
278 |
+
{"role": "system", "content": system_prompt},
|
279 |
+
{"role": "user", "content": text},
|
280 |
+
]
|
281 |
+
|
282 |
+
chat_completion = client.chat.completions.create(
|
283 |
+
messages=messages,
|
284 |
+
model=model,
|
285 |
+
)
|
286 |
+
|
287 |
+
result = chat_completion.choices[0].message.content
|
288 |
+
|
289 |
+
json_match = re.search(r'<<<JSON>>>\n(.*?)\n<<<END>>>', result, re.DOTALL)
|
290 |
+
|
291 |
+
if json_match:
|
292 |
+
return json.loads(json_match.group(1))
|
293 |
+
else:
|
294 |
+
raise ValueError("The LLM output does not contain the expected JSON formatted data. Please try again.")
|
295 |
+
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
|
300 |
+
def execute_steps(steps):
|
301 |
+
data = {}
|
302 |
+
locations_history = []
|
303 |
+
for step in steps:
|
304 |
+
step_id = step['id']
|
305 |
+
function = step['function']
|
306 |
+
inputs = step['inputs']
|
307 |
+
resolved_inputs = []
|
308 |
+
for inp in inputs:
|
309 |
+
if isinstance(inp, int):
|
310 |
+
resolved_inputs.append(data[inp])
|
311 |
+
else:
|
312 |
+
resolved_inputs.append(inp)
|
313 |
+
if function == "Relative":
|
314 |
+
location, direction, distance = resolved_inputs
|
315 |
+
if isinstance(location, str):
|
316 |
+
location = get_coordinates(location)
|
317 |
+
locations_history.append(location)
|
318 |
+
location = [to_standard_2d_list(location[0])] + list(location[1:])
|
319 |
+
result = get_level3_coordinates(location, distance, direction)
|
320 |
+
locations_history.append(result)
|
321 |
+
data[step_id] = result
|
322 |
+
elif function == "Between":
|
323 |
+
location1, location2 = resolved_inputs
|
324 |
+
|
325 |
+
if isinstance(location1, str):
|
326 |
+
location1 = get_coordinates(location1)
|
327 |
+
locations_history.append(location1)
|
328 |
+
location1 = [to_standard_2d_list(location1[0])] + list(location1[1:])
|
329 |
+
if isinstance(location2, str):
|
330 |
+
|
331 |
+
location2 = get_coordinates(location2)
|
332 |
+
locations_history.append(location2)
|
333 |
+
location2 = [to_standard_2d_list(location2[0])] + list(location2[1:])
|
334 |
+
result = get_between_coordinates(location1, location2)
|
335 |
+
locations_history.append(result)
|
336 |
+
data[step_id] = result
|
337 |
+
|
338 |
+
return [data, locations_history]
|
339 |
+
|
340 |
+
|
341 |
+
|
342 |
+
if __name__ == '__main__':
|
343 |
+
parsed_steps = []
|
344 |
+
step_loc = execute_steps(parsed_steps)
|
345 |
+
result = step_loc[0]
|
utils/llm_ent_extract.py
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
import re
|
3 |
+
from utils.config import api_key
|
4 |
+
|
5 |
+
client = OpenAI(
|
6 |
+
api_key=api_key
|
7 |
+
)
|
8 |
+
|
9 |
+
model = "gpt-3.5-turbo"
|
10 |
+
model = "gpt-4o"
|
11 |
+
|
12 |
+
def extract_GPE(text):
|
13 |
+
system_prompt = '''You are a professional geographer. Your task is to extract all geopolitical entities from a given text. Geopolitical entities can include countries, regions, cities, autonomous regions, or other administrative divisions. For each geopolitical entity, wrap the name in a unique character sequence, such as [###ENTITY###]. If there are multiple entities, output them in the following format:\n[###ENTITY1###, ###ENTITY2###, ###ENTITY3###]\nHere is an example:\n Example:\n\nText:\n"China and India are two of the most populous countries in Asia."\n\nExpected Output:\n[###China###, ###India###]'''
|
14 |
+
sent = 'Where is France?'
|
15 |
+
|
16 |
+
math_bot_messages = [
|
17 |
+
{"role": "system",
|
18 |
+
"content": system_prompt},
|
19 |
+
{"role": "user", "content": text},
|
20 |
+
]
|
21 |
+
|
22 |
+
chat_completion = client.chat.completions.create(
|
23 |
+
messages=math_bot_messages,
|
24 |
+
model=model,
|
25 |
+
)
|
26 |
+
|
27 |
+
result = chat_completion.choices[0].message.content
|
28 |
+
return result
|
29 |
+
|
30 |
+
|
31 |
+
def extract_LOC(text):
|
32 |
+
system_prompt = '''You are a professional geographer. Your task is to extract all location entities (LOC) from a given text. Location entities can include physical locations such as landmarks, geographical features, mountains, rivers, oceans, and places, but do not include political or administrative divisions such as countries or cities (these are considered geopolitical entities). For each location entity, wrap the name in a unique character sequence, such as [###ENTITY###]. If there are multiple entities, output them in the following format:\n[###ENTITY1###, ###ENTITY2###, ###ENTITY3###]\nHere is an example:\n Example:\n\nText:\n"China and India are two of the most populous countries in Asia."\n\nExpected Output:\n[###China###, ###India###]'''
|
33 |
+
sent = 'The Grand Canyon is one of the most spectacular natural wonders in the world, located in the state of Arizona. Nearby, the Colorado River flows through the canyon, carving its way through the rugged terrain. In the north, the Rocky Mountains stretch across several states, including Colorado and Wyoming.'
|
34 |
+
|
35 |
+
math_bot_messages = [
|
36 |
+
{"role": "system",
|
37 |
+
"content": system_prompt},
|
38 |
+
{"role": "user", "content": text},
|
39 |
+
]
|
40 |
+
|
41 |
+
chat_completion = client.chat.completions.create(
|
42 |
+
messages=math_bot_messages,
|
43 |
+
model=model,
|
44 |
+
)
|
45 |
+
|
46 |
+
result = chat_completion.choices[0].message.content
|
47 |
+
return result
|
48 |
+
|
49 |
+
|
50 |
+
def extract_RSE_1(text):
|
51 |
+
system_prompt = '''You are a professional geographer. Your task is to extract all spatial entities (directional keywords) from a given text. Spatial entities can include directional keywords such as north, south, east, west, and more specific terms like northeast, northwest, southeast, southwest, as well as terms indicating locations like center, central, downtown, and midtown. For each spatial entity, wrap the name in a unique character sequence, such as [###ENTITY###]. If there are multiple entities, output them in the following format:\n[###ENTITY1###, ###ENTITY2###, ###ENTITY3###]\nHere is an example:\n Example:\n\nText:\n"The hotel is located in the downtown area of New York, just south of Central Park, with a beautiful view of the southeast corner."\n\nExpected Output:\n[###downtown###, ###south###, ###southeast###]'''
|
52 |
+
sent = 'The train station is situated in the central part of the city, just north of the river and east of the main square.'
|
53 |
+
|
54 |
+
math_bot_messages = [
|
55 |
+
{"role": "system",
|
56 |
+
"content": system_prompt},
|
57 |
+
{"role": "user", "content": text},
|
58 |
+
]
|
59 |
+
|
60 |
+
chat_completion = client.chat.completions.create(
|
61 |
+
messages=math_bot_messages,
|
62 |
+
model=model,
|
63 |
+
)
|
64 |
+
|
65 |
+
result = chat_completion.choices[0].message.content
|
66 |
+
return result
|
67 |
+
|
68 |
+
|
69 |
+
def extract_RSE_2(text):
|
70 |
+
system_prompt = '''You are a professional geographer. Your task is to extract all fuzzy spatial entities (keywords) from a given text. Fuzzy spatial keywords can include terms like nearby, near, vicinity, close, beside, next, adjacent, immediate, border, surrounding, neighbourhood, proximity, territory, locality, and similar terms. For each fuzzy spatial keyword, wrap the name in a unique character sequence, such as [###ENTITY###]. If there are multiple entities, output them in the following format:\n[###ENTITY1###, ###ENTITY2###, ###ENTITY3###]\nHere is an example:\n Example:\n\nText:\n"The park is located nearby the lake, with several cafes close to the walking paths, and a small garden adjacent to the main entrance."\n\nExpected Output:\n[###nearby###, ###close###, ###adjacent###]'''
|
71 |
+
sent = 'The village is situated in the vicinity of the mountain range, with a small river flowing beside the houses and several farms next to the road.'
|
72 |
+
|
73 |
+
math_bot_messages = [
|
74 |
+
{"role": "system",
|
75 |
+
"content": system_prompt},
|
76 |
+
{"role": "user", "content": text},
|
77 |
+
]
|
78 |
+
|
79 |
+
chat_completion = client.chat.completions.create(
|
80 |
+
messages=math_bot_messages,
|
81 |
+
model=model,
|
82 |
+
)
|
83 |
+
|
84 |
+
result = chat_completion.choices[0].message.content
|
85 |
+
return result
|
86 |
+
|
87 |
+
|
88 |
+
def extract_RSE_3(text):
|
89 |
+
system_prompt = '''You are a professional geographer. Your task is to extract all fuzzy distance keywords from a given text. Fuzzy distance keywords include numeric values followed by distance units such as kilometer, mile, meter, foot, inch, centimeter, and other related units. The distance units can be in different formats, such as km, m, mi, ft, yd, cm, mm, or even in full words like kilometer, mile, or inch. For each fuzzy distance keyword, wrap the entire expression (number and unit) in a unique character sequence, such as [###ENTITY###]. If there are multiple entities, output them in the following format:\n[###ENTITY1###, ###ENTITY2###, ###ENTITY3###]\nHere is an example:\n Example:\n\nText:\n"The park is located 3 km away from the city center, while the nearest supermarket is only 500 meters from here, and the lake is about 1 mile further down the road."\n\nExpected Output:\n[###3 km###, ###500 meters###, ###1 mile###]'''
|
90 |
+
sent = 'The school is located approximately 2 miles from the station, while the nearest bus stop is 200 meters away. The hiking trail is about 5 kilometers east of the town center.'
|
91 |
+
|
92 |
+
math_bot_messages = [
|
93 |
+
{"role": "system",
|
94 |
+
"content": system_prompt},
|
95 |
+
{"role": "user", "content": text},
|
96 |
+
]
|
97 |
+
|
98 |
+
chat_completion = client.chat.completions.create(
|
99 |
+
messages=math_bot_messages,
|
100 |
+
model=model,
|
101 |
+
)
|
102 |
+
|
103 |
+
result = chat_completion.choices[0].message.content
|
104 |
+
return result
|
105 |
+
|
106 |
+
|
107 |
+
def extract(respond, entity_type):
|
108 |
+
"""
|
109 |
+
从输入字符串中提取被 ### 包裹的实体,并将其映射到给定的实体类型。
|
110 |
+
|
111 |
+
:param respond: 包含实体的字符串,例如 '[###2 miles###, ###200 meters###, ###5 kilometers###]'
|
112 |
+
:param entity_type: 给所有提取的实体赋予的类型(字符串)
|
113 |
+
:return: 一个字典,键是提取出的实体,值是相同的 entity_type
|
114 |
+
"""
|
115 |
+
# 提取被 ### 包裹的内容
|
116 |
+
extracted_entities = re.findall(r'###(.*?)###', respond)
|
117 |
+
|
118 |
+
# 生成字典,将所有实体映射到同一个类型
|
119 |
+
entity_dict = {entity.strip(): entity_type for entity in extracted_entities}
|
120 |
+
|
121 |
+
return entity_dict
|
122 |
+
|
123 |
+
|
124 |
+
def llmapi(text):
|
125 |
+
system_prompt = '请你填入需要的提示'
|
126 |
+
math_bot_messages = [
|
127 |
+
{"role": "system",
|
128 |
+
"content": system_prompt},
|
129 |
+
{"role": "user", "content": text},
|
130 |
+
]
|
131 |
+
|
132 |
+
chat_completion = client.chat.completions.create(
|
133 |
+
messages=math_bot_messages,
|
134 |
+
model=model,
|
135 |
+
)
|
136 |
+
|
137 |
+
result = chat_completion.choices[0].message.content
|
138 |
+
return result
|
139 |
+
|
140 |
+
|
141 |
+
# print(extract('[###2 miles###, ###200 meters###, ###5 kilometers###]', 'rse'))
|
142 |
+
# print(extract(extract_GPE('Between Burwood and Glebe.'), 'gpe'))
|
143 |
+
|
144 |
+
|
145 |
+
|