Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kivy
- from kivy.app import App
- from kivy.uix.gridlayout import GridLayout
- from kivy.uix.label import Label
- from kivy.uix.textinput import TextInput
- from kivy.uix.button import Button
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.screenmanager import ScreenManager, Screen
- # --- data ---
- you_shall_not_pass = ['de', 'o','a', 'do', 'da', 'em', 'e', 'que', 'ser', 'um', 'uns', 'uma', 'umas', 'por','para', 'nao', 'com', 'se', 'ter', 'seu', 'sua', 'seus', 'suas','como',
- 'estar','sim', '-', 'os', 'as', 'no', 'ao', 'na', '.', 'mas', 'era', 'lhe', 'ele', 'mais','dos', 'ela', 'ele', 'muito','ja','eu','sobre','das','tinha','quando','sem','la','num',
- 'depois','entao','nos','esta','ainda','numa','onde','foi','tao','estava','entre','dum','so','grande','disse','todo','pela','agora','pelo','me','toda', 'havia', 'tudo', 'ou','ate',
- 'ha','nem','logo','ia','sempre','duas','tambem','mesmo','ali','aos','tem','fora','aquele','tu','meu','duma','aquela','e,','outra','essa','outro','isto','esse','assim','quem','ele,',
- 'apenas','todos','pouco','nas','diante','ai','sob','tinham','coisas','aqui','pois','porque','ir','te','nunca','depois','lado','tres','mao','vez','sim,','desde','isso','fazer','este']
- # --- classes ---
- from kivy.uix.scrollview import ScrollView
- from kivy.properties import StringProperty
- from kivy.lang import Builder
- Builder.load_string('''
- <ScrollableLabel>:
- Label:
- size_hint_y: None
- height: self.texture_size[1]
- text_size: self.width, None
- text: root.text
- ''')
- class ScrollableLabel(ScrollView):
- text = StringProperty('')
- # --- classes ---
- class LoginScreen(GridLayout):
- def __init__(self, **kwargs):
- super(LoginScreen, self).__init__(**kwargs)
- self.cols = 2
- self.add_widget(Label(text='Livro1:'))
- self.bookone = TextInput(multiline=False)
- self.add_widget(self.bookone)
- self.add_widget(Label(text='Livro2:'))
- self.booktwo = TextInput(multiline=False)
- self.add_widget(self.booktwo)
- self.add_widget(Button(text='Submit1', on_press=self.callback))
- self.add_widget(Button(text='Submit2', on_press=self.callback))
- self.debug_label = ScrollableLabel()
- self.add_widget(self.debug_label)
- # --- class object ---
- self.total = 0
- self.livro1 = 'erro'
- self.livro2 = 'batata.txt'
- self.dicionario = {}
- self.dicionario2 = {}
- def callback(self, args):
- print('[DEBUG] args:', args)
- print('[DEBUG] args.text:', args.text)
- if args.text == 'Submit1':
- self.livro1 = self.bookone.text + '.txt'
- self.debug_label.text += 'livro1: {}\n'.format(self.livro1)
- self.palavras_repetidas()
- elif args.text == 'Submit2':
- self.livro1 = self.bookone.text + '.txt'
- self.livro2 = self.booktwo.text + '.txt'
- self.debug_label.text += 'livro1: {}\n'.format(self.livro1)
- self.debug_label.text += 'livro2: {}\n'.format(self.livro2)
- self.palavras_repetidas()
- self.comparar()
- else:
- txt = '???'
- def comparar(self):
- lista2 = open(self.livro2, 'r').read().split()
- for word in lista2:
- if word in you_shall_not_pass:
- continue
- if word in self.dicionario2:
- self.dicionario2[word] += 1
- else:
- self.dicionario2[word] = 1
- #for key in dicionario.keys():
- # if key in dicionario2.keys():
- # if (dicionario[key]>10 and dicionario2[key]>10):
- # print(key, dicionario[key], dicionario2[key])######################################################
- common_keys = set(self.dicionario.keys()) & set(self.dicionario2.keys())
- print(common_keys)
- for key in common_keys:
- a = self.dicionario[key]
- b = self.dicionario2[key]
- if a > 10 and b > 10:
- #print(key, a, b)
- self.debug_label.text += '{}: {}, {}\n'.format(key, a, b)
- self.debug_label.text += '{}: {}, {}\n'.format(key, a, b)
- def palavras_repetidas(self):
- lista = open(self.livro1, 'r').read().split()
- for word in lista:
- if word in you_shall_not_pass:
- continue
- if word in self.dicionario:
- self.dicionario[word]+=1
- else:
- self.dicionario[word] = 1
- #sorted_dict = [(k,v) for v,k in sorted([(v,k) for k,v in dicionario.items()],reverse=True)]
- sorted_dict = sorted(self.dicionario.items(), reverse=True, key=lambda d:d[1])
- print(sorted_dict)
- #with open('teste.txt', 'w') as f:##############################################################################
- # for item in sorted_dict:
- # f.write(str(item))
- for item in sorted_dict:
- self.debug_label.text += '{}: {}\n'.format(*item)
- def palavras_totais(self):
- f = open(self.livro1, 'r').read().split()
- for word in f:
- self.total += 1
- self.debug_label.text += 'total: {}\n'.format(self.total)
- class MyApp(App):
- def build(self):
- return LoginScreen()
- MyApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement