Skip to content

Commit

Permalink
mudancas e testes na padronizar_logradouros()
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Feb 7, 2024
1 parent 17697f8 commit 2e0e9fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
34 changes: 28 additions & 6 deletions R/padronizar_logradouro.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#' 4. adição de espaços após abreviações sinalizadas por pontos.
#'
#' @examples
#' bairros <- c("PRQ IND", "NSA SEN DE FATIMA", "ILHA DO GOV")
#' padronizar_bairros(bairros)
#' logradouros <- c("r. gen.. glicério")
#' padronizar_logradouros(logradouros)
#'
#' @export
padronizar_logradouros <- function(logradouros) {
Expand All @@ -30,7 +30,7 @@ padronizar_logradouros <- function(logradouros) {
# identificamos o indice dos logradouros vazios para "reesvazia-los" ao final,
# ja que a sequencia de operacoes abaixo acabaria atribuindo um valor a eles

indice_logradouro_vazio <- which(logradouros == "" | is.na(logradouros))
indice_logradouro_vazio <- which(is.na(logradouros))

logradouros_padrao <- stringr::str_squish(logradouros)
logradouros_padrao <- toupper(logradouros_padrao)
Expand Down Expand Up @@ -100,14 +100,31 @@ padronizar_logradouros <- function(logradouros) {
"^(LOCALIDADE|RUA) LOC\\b(\\.|,)?" = "LOCALIDADE",
"^LOCALIDADE?\\b(-|,|\\.) *" = "LOCALIDADE ",

"^VL\\b(\\.|,)?" = "VILA",
"^VILA VILA\\b(\\.|,)?" = "VILA",
"^VILA?\\b(-|,|\\.) *" = "VILA ",

"^LAD\\b(\\.|,)?" = "LADEIRA",
"^LADEIRA LADEIRA\\b(\\.|,)?" = "LADEIRA",
"^LADEIRA?\\b(-|,|\\.) *" = "LADEIRA ",

"^DT\\b(\\.|,)?" = "DISTRITO",
"\\bDISTR?\\b\\.?" = "DISTRITO",
"^DISTRITO DISTRITO\\b(\\.|,)?" = "DISTRITO",
"^DISTRITO?\\b(-|,|\\.) *" = "DISTRITO ",

"^NUC\\b(\\.|,)?" = "NUCLEO",
"^NUCLEO NUCLEO\\b(\\.|,)?" = "NUCLEO",
"^NUCLEO?\\b(-|,|\\.) *" = "NUCLEO ",

"^L(RG|GO)\\b(\\.|,)?" = "LARGO",
"^LARGO L(RG|GO)\\b(\\.|,)?" = "LARGO",
"^LARGO?\\b(-|,|\\.) *" = "LARGO ",

# estabelecimentos
"^AER\\b(\\.|,)?" = "AEROPORTO", # sera que vale? tem uns casos estranhos aqui, e.g. "AER GUANANDY, 1", "AER WASHINGTON LUIZ, 3318"
"^AER(OP)?\\b(\\.|,)?" = "AEROPORTO", # sera que vale? tem uns casos estranhos aqui, e.g. "AER GUANANDY, 1", "AER WASHINGTON LUIZ, 3318"
"^AEROPORTO (AEROPORTO|AER)\\b(\\.|,)?" = "AEROPORTO",
"^AEROPORTO (INT|INTER)\\b(\\.|,)?" = "AEROPORTO INTERNACIONAL",
"^AEROPORTO INT(ERN?)?\\b(\\.|,)?" = "AEROPORTO INTERNACIONAL",

"^COND\\b(\\.|,)?" = "CONDOMINIO",
"^(CONDOMINIO|RODOVIA) (CONDOMINIO|COND)\\b(\\.|,)?" = "CONDOMINIO",
Expand Down Expand Up @@ -147,6 +164,7 @@ padronizar_logradouros <- function(logradouros) {
"\\b(PRIMEIRO|PRIM\\.?) TENENTE\\b" = "PRIMEIRO-TENENTE",
"\\b(SEGUNDO|SEG\\.?) TENENTE\\b" = "SEGUNDO-TENENTE",
"\\bSOLD\\b\\.?" = "SOLDADO",
"\\bMAJ\\b\\.?" = "MAJOR",

"\\bPROF\\b\\.?" = "PROFESSOR",
"\\bPROFA\\b\\.?" = "PROFESSORA",
Expand All @@ -163,14 +181,15 @@ padronizar_logradouros <- function(logradouros) {
"\\bPREF\\b\\.?" = "PREFEITO",
"\\bDEP\\b\\.?" = "DEPUTADO",
"\\bVER\\b\\.?[^$ ]" = "VEREADOR",
"\\bESPL?\\.? (DOS )?MIN(IST(ERIOS?)?)?\\b\\.?" = "ESPLANADA DOS MINISTERIOS",
"\\bMIN\\b\\.?[^$ ]" = "MINISTRO",

# abreviacoes
"\\bUNID\\b\\.?" = "UNIDADE",
"\\b(CJ|CONJ)\\b\\.?" = "CONJUNTO",
"\\bLT\\b\\.?" = "LOTE",
"\\bLTS\\b\\.?" = "LOTES",
"\\bQD\\b\\.?" = "QUADRA",
"\\bQDA?\\b\\.?" = "QUADRA",
"\\bLJ\\b\\.?" = "LOJA",
"\\bLJS\\b\\.?" = "LOJAS",
"\\bAPTO?\\b\\.?" = "APARTAMENTO",
Expand All @@ -180,6 +199,7 @@ padronizar_logradouros <- function(logradouros) {
"\\bEDI?F\\b\\.?" = "EDIFICIO",
"\\bCOND\\b\\.?" = "CONDOMINIO", # apareceu antes mas como tipo de logradouro
"\\bKM\\b\\." = "KM",
"\\bS\\.? ?N\\b\\.?" = "S/N",
# SL pode ser sobreloja ou sala

# intersecao entre nomes e titulos
Expand Down Expand Up @@ -219,5 +239,7 @@ padronizar_logradouros <- function(logradouros) {
)
)

logradouros_padrao[indice_logradouro_vazio] <- ""

return(logradouros_padrao)
}
4 changes: 2 additions & 2 deletions man/padronizar_logradouros.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/test-padronizar_logradouros.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_that("da erro com inputs != de caracteres", {
expect_error(padronizar_logradouros(12))
})

test_that("padroniza corretamente", {
# complicado fazer um teste pra cada uma das regexs usadas. testando só um
# basiquinho da manipulação, depois pensamos melhor se vale a pena fazer um
# teste pra cada regex ou não

expect_equal(padronizar_logradouros("r. gen.. glicério"), "RUA GENERAL GLICERIO")
expect_equal(padronizar_logradouros(NA_character_), "")
})

test_that("lida com vetores vazios corretamente", {
expect_equal(padronizar_logradouros(character(0)), character(0))
})

0 comments on commit 2e0e9fe

Please sign in to comment.