【发布时间】:2021-07-03 00:06:37
【问题描述】:
我有很长的地址,其中一些只是在我试图提取的各个位置的一般建筑物名称。我已经确定如何提取地址中更标准化的部分,但我一直在试图找出通用名称。
示例数据。
addresses<-c("big fake plaza, 12 this street, district, city",
"Green mansion, district, city",
"Block 7c of orange building district, city",
"98 main street block a blue plaza, city",
"tower 10, caribbean coast, district",
"block 3a, the latitude, city",
"blue red mansion, 46 pearl street, city"
"dorsett hotel, city"
"block 9, Willowland, disctrict, city",
tower 2, the coronation, 1 fake street, district")
目标是提取非特定的建筑物名称,并且只提取它们。代码中的计划是提取前面没有通用建筑物名称的单词,以及忽略任何块或塔名称。
我有什么
df$add.gen<-str_extract(df$address,""^[^block|^tower](([a-z]+\\s+[a-z]*\\s*[a-z]*\\s*[a-z]*\\s*[a-z]*))(?!building)(?!mansion)(?!garden)(?!house)")
But its not working clearly
我的目标是什么
df$add.gen<-
(NA,
NA,
NA,
NA,
"caribbean coast",
"the latitude",
"dorsett hotel"
"Willowland",
"the coronation")
提前致谢!!
【问题讨论】:
-
试试
trimws(str_extract(df$address, "(?i)(?<=,|^)(?:(?!\\b(?:city|disc?trict|street|plaza|square|tower|block|mansion|garden|house|building)\\b)[^,])*(?=,|$)"))
标签: r regex string extract stringr