Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Toponym Geocoding
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jacques Fize
Toponym Geocoding
Commits
d83be71f
Commit
d83be71f
authored
4 years ago
by
Ludovic Moncla
Browse files
Options
Downloads
Patches
Plain Diff
Update generate_dataset.py remove duplicates from pairs
parent
d3c5e2b4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
generate_dataset.py
+19
-2
19 additions, 2 deletions
generate_dataset.py
with
19 additions
and
2 deletions
generate_dataset.py
+
19
−
2
View file @
d83be71f
...
@@ -28,6 +28,7 @@ PREFIX = PREFIX + "_" + args.split_method
...
@@ -28,6 +28,7 @@ PREFIX = PREFIX + "_" + args.split_method
# LOAD DATA
# LOAD DATA
geonames_data
=
read_geonames
(
args
.
geonames_dataset
)
geonames_data
=
read_geonames
(
args
.
geonames_dataset
)
geonames_data
=
geonames_data
[
geonames_data
.
feature_class
.
isin
(
"
A P
"
.
split
())]
# filter populated places and areas
wikipedia_data
=
pd
.
read_csv
(
args
.
wikipedia_dataset
,
sep
=
"
\t
"
)
wikipedia_data
=
pd
.
read_csv
(
args
.
wikipedia_dataset
,
sep
=
"
\t
"
)
geonames_hierarchy_data
=
pd
.
read_csv
(
args
.
geonames_hierarchy_data
,
sep
=
"
\t
"
,
header
=
None
,
geonames_hierarchy_data
=
pd
.
read_csv
(
args
.
geonames_hierarchy_data
,
sep
=
"
\t
"
,
header
=
None
,
names
=
"
parentId,childId,type
"
.
split
(
"
,
"
)).
fillna
(
""
)
names
=
"
parentId,childId,type
"
.
split
(
"
,
"
)).
fillna
(
""
)
...
@@ -69,6 +70,15 @@ def get_adjacent_pairs(dataframe, sampling_nb=4,no_sampling=False):
...
@@ -69,6 +70,15 @@ def get_adjacent_pairs(dataframe, sampling_nb=4,no_sampling=False):
new_pairs
.
extend
([[
row
.
geonameid
,
topo_prin
,
sel
,
lat
,
lon
]
for
sel
in
selected
])
new_pairs
.
extend
([[
row
.
geonameid
,
topo_prin
,
sel
,
lat
,
lon
]
for
sel
in
selected
])
return
new_pairs
return
new_pairs
def
random_sample
(
values
,
m
):
res
=
[]
if
len
(
values
)
==
1
:
values
.
append
(
values
[
0
])
for
i
in
range
(
min
(
max
(
len
(
values
),
2
),
m
)):
pos
=
np
.
random
.
randint
(
len
(
values
))
res
.
append
(
values
[
pos
])
values
.
pop
(
pos
)
return
res
def
get_cooccurrence_pairs
(
dataframe
,
sampling_nb
=
4
,
no_sampling
=
False
):
def
get_cooccurrence_pairs
(
dataframe
,
sampling_nb
=
4
,
no_sampling
=
False
):
"""
"""
...
@@ -87,7 +97,8 @@ def get_cooccurrence_pairs(dataframe, sampling_nb=4,no_sampling=False):
...
@@ -87,7 +97,8 @@ def get_cooccurrence_pairs(dataframe, sampling_nb=4,no_sampling=False):
"""
"""
new_pairs
=
[]
new_pairs
=
[]
if
not
no_sampling
:
if
not
no_sampling
:
dataframe
[
"
interlinks
"
]
=
dataframe
.
interlinks
.
apply
(
lambda
x
:
np
.
random
.
choice
(
x
.
split
(
"
|
"
),
sampling_nb
))
#dataframe["interlinks"] = dataframe.interlinks.apply(lambda x: np.random.choice(x.split("|"), sampling_nb))
dataframe
[
"
interlinks
"
]
=
dataframe
.
interlinks
.
apply
(
lambda
x
:
random_sample
(
x
.
split
(
"
|
"
),
sampling_nb
))
else
:
else
:
dataframe
[
"
interlinks
"
]
=
dataframe
.
interlinks
.
apply
(
lambda
x
:
x
.
split
(
"
|
"
))
dataframe
[
"
interlinks
"
]
=
dataframe
.
interlinks
.
apply
(
lambda
x
:
x
.
split
(
"
|
"
))
for
ix
,
row
in
tqdm
(
dataframe
.
iterrows
(),
total
=
len
(
dataframe
),
desc
=
"
Get Cooccurrent Toponym Pairs
"
):
for
ix
,
row
in
tqdm
(
dataframe
.
iterrows
(),
total
=
len
(
dataframe
),
desc
=
"
Get Cooccurrent Toponym Pairs
"
):
...
@@ -149,7 +160,13 @@ inc_train, _ = train_test_split(inclusion_pairs, test_size=0.33)
...
@@ -149,7 +160,13 @@ inc_train, _ = train_test_split(inclusion_pairs, test_size=0.33)
inclusion_pairs
[
"
split
"
]
=
"
test
"
inclusion_pairs
[
"
split
"
]
=
"
test
"
inclusion_pairs
.
loc
[
inc_train
.
index
.
values
,
"
split
"
]
=
"
train
"
inclusion_pairs
.
loc
[
inc_train
.
index
.
values
,
"
split
"
]
=
"
train
"
# SAVE DATA
# PRINT NB PAIRS
print
(
'
# cooc_pairs:
'
,
len
(
cooc_pairs
))
print
(
'
# adjacent_pairs:
'
,
len
(
adjacent_pairs
))
print
(
'
# inclusion_pairs:
'
,
len
(
inclusion_pairs
))
# SAVE DATA
inclusion_pairs
.
to_csv
(
"
{0}_inclusion.csv
"
.
format
(
PREFIX
),
sep
=
"
\t
"
)
inclusion_pairs
.
to_csv
(
"
{0}_inclusion.csv
"
.
format
(
PREFIX
),
sep
=
"
\t
"
)
adjacent_pairs
.
to_csv
(
"
{0}_adjacent.csv
"
.
format
(
PREFIX
),
sep
=
"
\t
"
)
adjacent_pairs
.
to_csv
(
"
{0}_adjacent.csv
"
.
format
(
PREFIX
),
sep
=
"
\t
"
)
cooc_pairs
.
to_csv
(
"
{0}_cooc.csv
"
.
format
(
PREFIX
),
sep
=
"
\t
"
)
cooc_pairs
.
to_csv
(
"
{0}_cooc.csv
"
.
format
(
PREFIX
),
sep
=
"
\t
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment