Last active
February 19, 2016 11:54
-
-
Save gagliardetto/d2e599f10608e4cd46fc to your computer and use it in GitHub Desktop.
Terminal comands to download and clean Google ngram datasets with a set of regular expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| cat lista.txt | while read -r file; do wget "$file" && gzip -dc "${file##*/}" | \ | |
| tr '[:upper:]' '[:lower:]' | sed \ | |
| -e 's/\(_\?noun_\?\)\|\(_\?adp_\?\)\|\(_\?adv_\?\)\|\(_\?det_\?\)\|\(_\?verb_\?\)\|\(_\?adj_\?\)\|\(_\?end_\?\)\|\(_\?conj_\?\)\|\(S\?_\?pron_\?\)\|\(_\?num_\?\)/ /g' \ | |
| -e "s/\([^a-zàéèìòù '.]\)/ /g" \ | |
| -e "s/\s\{2,\}/ /g" \ | |
| -e "s/\.\{2,\}/./g" \ | |
| -e "s/[^a-zàéèìòù.]\{1,\}\.\{1,\}//g" \ | |
| -e "s/\s\{2,\}/ /g" \ | |
| -e "s/'/' /g" \ | |
| -e "s/\s'/' /g" \ | |
| -e "s/\(\s\{0,\}[^a-zàéèìòù']\.$\)//g" \ | |
| -e "s/\(^\.\{1,\}[^a-zàéèìòù']\{0,\}\s\{0,\}\)//g" \ | |
| -e "s/\s\{2,\}/ /g" \ | |
| -e 's/\(^\s\{1,\}\)\|\(\s\{1,\}$\)//g' \ | |
| | sort | uniq > "${file##*/}_cleaned.txt" && rm "${file##*/}"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment