Skip to content

Instantly share code, notes, and snippets.

@marsimaria
Last active August 29, 2015 14:18
Show Gist options
  • Save marsimaria/bb6811a3c8e234e41fb5 to your computer and use it in GitHub Desktop.
Save marsimaria/bb6811a3c8e234e41fb5 to your computer and use it in GitHub Desktop.
Sunflower module 2 - Execute my midterm project in two lines of code
import goslate
def generate(text):
gs = goslate.Goslate()
with open(text, 'r') as f:
text = f.read()
l = []
for i in range(100):
if i==0:
trans1 = gs.translate(text, 'en')
l.append(trans1)
elif i%2==0:
transC = gs.translate(l[-1], 'zh-tw')
l.append(transC)
else:
transE = gs.translate(l[-1], 'en')
l.append(transE)
text1 = l[1]
text2 = l[-1]
def wordsincommon(t1, t2):
t1 = t1.split(',')
t2 = t2.split(',')
output = []
for word in t1:
if word in t2:
word = word.strip()
word = word.replace(' Af', 'Af')
output.append(word)
return output
a = wordsincommon(text1, text2)
p = '\n'.join(a)
p = p.replace('.', '\n')
return p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment