Skip to content

Instantly share code, notes, and snippets.

@Polsaker
Created April 11, 2016 02:28
Show Gist options
  • Save Polsaker/78caed8bb790f6287838abc914a56b96 to your computer and use it in GitHub Desktop.
Save Polsaker/78caed8bb790f6287838abc914a56b96 to your computer and use it in GitHub Desktop.
Modifica textos intentando no cambiar el significado.
# Instalación:
# 1 - git clone https://github.com/voldmar/conjugation
# 2 - wget https://gist.githubusercontent.com/Polsaker/c9ca458ab9dfcfb570971e8dba9884bb/raw/0fb23322e5d27b58cb1ab83e5d7a5bcae3b4105c/diff -O- && git apply
# 3 - sudo python3 setup.py install
# 4 - git clone https://github.com/mkalinowski/python-mythes
# 5 - make
# 6 - Editar la línea 12 de cmythes.py, reemplazar "libcmythes.so" con "./libcmythes.so"
# 7 - Poner este script en el mismo directorio que cmythes.py
# 8 - wget http://http.us.debian.org/debian/pool/main/libr/libreoffice-dictionaries/mythes-es_5.1.1-1_all.deb
# 9 - Descomprimir th_es_ANY_v2.dat y th_es_ANY_v2.idx en el mismo directorio que este script
# 10 - Eso debería ser todo. Revisar la forma de uso en la última línea de este archivo.
import cmythes
import random
import conjugation
thesaurus = cmythes.MyThes('th_es_ANY_v2.idx', 'th_es_ANY_v2.dat')
encoding = thesaurus.get_th_encoding()
chars = list("abcdefghijklmnñopqrstuvwxyzáéíóúüABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÜ")
def thtext(text):
words = text.split()
final = ""
for word in words:
preword = ""
postword = ""
fword = ""
for l in word:
if l in chars:
break
else:
preword += l
for l in word[::-1]:
if l in chars:
break
else:
postword = l + postword
fword = word.replace(preword, '')
fword = fword.replace(postword, '')
fword = processWord(fword)
#w = thesaurus.lookup(fword.encode(encoding))
# Si la palabra tiene _una sola definición_, se utiliza un sinónimo aleatorio
#if len(w) == 1:
# fword = random.choice(w[0]['syns']).decode(encoding)
# fword = fword.replace(" (NoRAE)", '')
final += preword + fword + postword + " "
return final
def processVerb(word, infi):
w = thesaurus.lookup(word.encode(encoding))
if len(w) == 1:
word2 = random.choice(w[0]['syns']).decode(encoding)
word2 = word2.replace(" (NoRAE)", '')
# obtener conjugacion original
conjs = conjugation.conjugate(infi)
conj = None
for con in conjs:
if conjs['con'] == word:
conj = con
break
if not conj: # no se encontró la conjugacion original
return word
# reconjugar el verbo (?)
conjs2 = conjugation.conjugate(word2)
return conjs2[conj]
def processWord(word):
try:
infi = conjugation.reverse_conjugate(word)[0]
return processVerb(word, infi)
except:
w = thesaurus.lookup(word.encode(encoding))
if len(w) == 1:
word = random.choice(random.choice(w)['syns']).decode(encoding)
word = word.replace(" (NoRAE)", '')
return word
print(thtext('El lenguaje HTML basa su filosofía de desarrollo en la diferenciación. Para añadir un elemento externo a la página (imagen, vídeo, script, entre otros.), este no se incrusta directamente en el código de la página, sino que se hace una referencia a la ubicación de dicho elemento mediante texto. De este modo, la página web contiene solamente texto mientras que recae en el navegador web (interpretador del código) la tarea de unir todos los elementos y visualizar la página final. Al ser un estándar, HTML busca ser un lenguaje que permita que cualquier página web escrita en una determinada versión, pueda ser interpretada de la misma forma (estándar) por cualquier navegador web actualizado.'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment