Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Created November 17, 2017 13:22
Show Gist options
  • Save romainfrancois/0db06fb7f5d0f6543600de9c43ed56be to your computer and use it in GitHub Desktop.
Save romainfrancois/0db06fb7f5d0f6543600de9c43ed56be to your computer and use it in GitHub Desktop.
library(tidyverse)
library(rvest)
library(glue)
inclusivise <- function( mot = "étudiant" ){
url <- glue( "http://www.larousse.fr/dictionnaires/rechercher/?q={mot}&l=francais&culture=" )
mots <- url %>%
read_html() %>%
html_node(".AdresseDefinition") %>%
html_text() %>%
str_split(",") %>%
flatten_chr() %>%
str_trim()
len <- min( nchar(mots) )
ncommon <- str_split( mots, "") %>%
map( head, len ) %>%
pmap(~.x==.y) %>%
flatten_lgl() %>%
sum()
glue( "{prefixe}{m}·{f}",
prefixe = substr(mots[1], 1, ncommon),
m = substr(mots[1], ncommon + 1, nchar(mots[1]) ),
f = substr(mots[2], ncommon + 1, nchar(mots[2]) )
)
}
inclusivise( "étudiant")
inclusivise( "acteur")
@romainfrancois
Copy link
Author

> inclusivise( "étudiant")
étudiant·e
> inclusivise( "acteur")
acteur·rice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment