-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_discussion.Rmd
283 lines (216 loc) · 7.44 KB
/
map_discussion.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
---
title: "Harmonizing cartographic language data"
author: "Niko Partanen"
date: "1/22/2018"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Notes
- All data used shared by CC-BY
- [SKN, Samples of Spoken Finnish](http://metashare.csc.fi/repository/browse/samples-of-spoken-finnish/642b58defccc11e18b49005056be118e3444ea5bb1dd46a5a4ca4829e93da406/)
- [Murreaineistot](https://avaa.tdata.fi/web/kotus/aineistot) by KOTUS
- Some credits missing, some code copy-pasted from [lingtypology](https://github.com/ropensci/lingtypology)
- I have got my version through [Korp](https://korp.csc.fi/#?corpus=skn) API (is obviously allowed, not maybe recommended)
## Data harmonization and linguistic mapping
At least three data types:
- Typological data (lingtypology!)
- Dialect atlas data
- Corpus data
## Typology
```{r}
library(lingtypology)
library(tidyverse)
library(leaflet)
library(leaflet.minicharts)
library(sf)
library(glue)
```
```{r}
uralic <- lingtypology::lang.aff("Uralic")
wals_85A <- wals.feature("85A")
wals_85A_scandinavia <- wals_85A %>% filter(language %in% c("Finnish", "Russian", "Swedish"))
map.feature(languages = wals_85A_scandinavia$language,
features = wals_85A_scandinavia$`85A`,
label = wals_85A_scandinavia$language,
shape = c("➡", "⬅"))
```
## Extends to linguistic area maps
```{r}
map.feature(languages = circassian$language,
features = circassian$dialect,
label = circassian$village,
latitude = circassian$latitude,
longitude = circassian$longitude)
```

```{r}
kpv <- read_csv("https://raw.githubusercontent.com/langdoc/kpv-geography/master/kpv.csv")
map.feature(languages = kpv$language,
features = kpv$dialect,
label = kpv$village,
latitude = kpv$latitude,
longitude = kpv$longitude)
```
## Comments
- Should the `village` be changed to `name` and `settlement_type`, or some equivalents?
- People live in cities (basically anywhere)
- We want to maintain only one database of place info
- How we make sure these identifiers connect to other databases?
- Is this realistic to start with?
## Dialect atlas

Map source: [http://kettunen.fnhost.org/html/kett117.html](http://kettunen.fnhost.org/html/kett117.html)
```{r}
sfc_as_cols <- function(x, names = c("longitude","latitude")) {
stopifnot(inherits(x,"sf") && inherits(sf::st_geometry(x),"sfc_POINT"))
ret <- sf::st_coordinates(x)
ret <- tibble::as_tibble(ret)
stopifnot(length(names) == ncol(ret))
x <- x[ , !names(x) %in% names]
ret <- setNames(ret,names)
dplyr::bind_cols(x,ret)
}
kettunen <- st_read('data/kettunen.shp') %>% st_transform("+proj=longlat +datum=WGS84") %>% sfc_as_cols()
map_finnic <- function(data, map = "Kartta 151"){
my_colors <-
c(
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#d62728",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#17becf",
sample(grDevices::colors()[!grepl("ivory|azure|white|gray|grey|black|pink|1",
grDevices::colors())])
)
corpus <- data
current_selection <- corpus %>% filter(map_id == map)
pal <- colorFactor({my_colors[1:length(unique(current_selection$feature_value))]},
domain = current_selection$feature_value)
title_text <- current_selection$feature_description[1] %>% as.character()
leaflet(data = current_selection) %>%
addTiles() %>%
addCircleMarkers(color = ~pal(feature_value),
radius = 4,
stroke = FALSE, fillOpacity = 0.5,
popup = ~feature_value) %>%
addLegend("bottomleft", pal = pal, values = ~feature_value,
title = title_text,
opacity = 1
)
}
kettunen_names <- names(kettunen)
kettunen <- kettunen %>% mutate(ilmio = as.character(ilmio)) %>%
rename(feature_id = ilmio_id,
feature_value = ilmio,
feature_description = kuvaus,
location = paikka_nim) %>%
mutate(map_id = str_extract(alaryhma_n, "^[^:]+(?=:)"))
map_finnic(kettunen, "Kartta 117")
```
## Data for these maps
Features used in my variants of Finnic dialect maps:
- map_name
- feature_id
- feature_description
- feature_value
- location
- longitude
- latitude
```{r}
names(kettunen_names)
```
## Using dialect corpus
```{r}
skn <- read_rds("data/skn_df.rds") %>%
left_join(read_csv("data/skn_paikat.csv"))
skn_names <- names(skn)
```
```{r}
leaflet(skn %>% distinct(paikka, lat, lon)) %>%
addTiles() %>%
addCircleMarkers()
```
Structure here:
- original token
- normalized token
- morphological analysis
- dependency structure
- place name
- parish
- …
**Note! Some annotations automatically created! Quality is good, but this is crucial to remember.**
```{r}
names(skn)
```
```{r}
skn %>% arrange(position) %>% slice(1:10) %>% knitr::kable()
```
```{r}
skn_kanssa <- skn %>% mutate(id = as.numeric(id)) %>%
arrange(id, position) %>%
filter(rooli == "haastateltava") %>%
# mutate(context = glue("{lag(sane)} {sane} {lead(sane)}")) %>%
filter(pos == "Adp") %>%
filter(deprel == "adpos") %>%# View
mutate(type = ifelse(dephead > ref, "pre", "post")) %>%
filter(lemma == "kanssa") %>%
add_count(paikka) %>%
rename(count_adpos = n) %>%
group_by(paikka, type) %>%
mutate(freq_adpos = n() / count_adpos) %>%
ungroup() %>%
distinct(paikka, lat, lon, freq_adpos, type) %>%
spread(type, freq_adpos) %>%
replace(is.na(.), 0)
# skn_kanssa_hits %>% slice(1) %>% pull(url) %>% browseURL()
```
You end up with something like this (in this case, for different scenarios with different structures):
```{r}
skn_kanssa %>% slice(1:10) %>% knitr::kable()
```
```{r}
leaflet() %>%
leaflet::addTiles() %>%
addMinicharts(lng = skn_kanssa$lon,
lat = skn_kanssa$lat,
type = "pie", width = 20,
chartdata = skn_kanssa[, c("pre", "post")]) %>%
map.feature(pipe.data = .,
languages = wals_85A_scandinavia$language,
features = wals_85A_scandinavia$`85A`,
label = wals_85A_scandinavia$language,
shape = c("➡", "⬅"))
```
## Fake news!
- These are almost all mistakes in the corpus annotations :(
- Still a good research topic!
- Data also surely useful
- [Example](https://lat.csc.fi/ds/annex/runLoader?nodeid=MPI7571%23&time=32725&duration=7529&tiername=RJ-original)
- Rare features and dialectal lexicon a challenging combination
More realistic workflow:
- Explore
- Visualize
- Explore
- Visualize
- Find more coarsely what you want, categorize manually
- Fix your morphological analysator
- Fix your dependency parser
- …
## Current situation
```{r}
kettunen_names
skn_names
```
- Can we have more uniform ways to represent this kind of data?
- Or connect some conventions to one another
- There is a need for interactive workflow that it is effortless to move between different data types
- Conceptually similar methods to explore and visualize variables, whether we are having dialect data or corpus data with spatial metadata in our hands
- Preferably within R