예제 #1
0
 def add_relation(name, first, second):
     from text_indexer.orm.word import Word
     from text_indexer.orm.base import session
     db_first = Word.add_word(first)
     db_second = Word.add_word(first)
     
     relation = Relation(name)
     session.add(relation)
     
     session.commit()
     
     word_relation = WordRelationAssociation(relation, db_first, db_second)
     session.add(word_relation)
     session.commit()
     
     
예제 #2
0
 def onRemoveWordFromGroup(self, evt):
     selection = self.group_words.GetSelection()
     word = self.group_words.Items[selection]
     db_word = Word.get_words(word)[0]
     db_group = Group.get_groups(self.select_group.Items[self.select_group.Selection])[0]
     self.group_words.Delete(selection)
     db_wga = session.query(WordGroupAssociation).filter_by(group_id=db_group.id, word_id=db_word.id).first()
     session.delete(db_wga)
     session.commit()
예제 #3
0
 def OnAddWordToGroupFromList(self, evt):
     selections = self.lb1.GetSelections()
     db_group = Group.get_groups(self.select_group.Items[self.select_group.Selection])[0]
     for selection in selections: 
         db_word = Word.get_words(word=self.lb1.Items[selection])[0]
         word_group = WordGroupAssociation(word_id=db_word.id, group_id=db_group.id)
         session.add(word_group)
         session.commit()
         self.group_words.Append(db_word.word)
예제 #4
0
    def onAddWordToGroup(self, evt):
        name = self.select_group.Items[self.select_group.Selection]
        group = Group.get_groups(name)[0]
        dlg = wx.TextEntryDialog(
                self, 'Please enter the word to add:')


        if dlg.ShowModal() == wx.ID_OK:
            word = dlg.GetValue()
            db_word = Word.add_word(word)
            word_group = WordGroupAssociation(word_id=db_word.id, group_id=group.id)
            session.add(word_group)
            session.commit()
            self.group_words.Append(word)
        dlg.Destroy()
예제 #5
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)
        self.words = Word.get_words()
        self.songs = []
        
        song_text = wx.StaticText(self, -1, "Select Song", (100, 30))
        songList = [s.name for s in Song.get_songs()]
        self.lb1 = wx.ListBox(self, 60, (100, 50), (200, 200), songList, wx.LB_EXTENDED)
        self.lb1.SetSelection(0)
        
#        btn1 = wx.Button(self, -1, "Show words", (330, 120))
#        self.Bind(wx.EVT_BUTTON, self.songChosen, btn1) 
        
        words_text = wx.StaticText(self, -1, "Select Word", (450, 30))
        self.lb2 = wx.ListBox(self, 70, (450, 50), (90, 200), [], wx.LB_SINGLE)
        
        words = self.words
        for word in words:
            self.lb2.Append(word.word)
        
        btn2 = wx.Button(self, -1, "Search Word", (450, 280))
        self.Bind(wx.EVT_BUTTON, self.wordChosen, btn2) 
        
        occurrences_text = wx.StaticText(self, -1, "Occurrences", (750, 30))
        self.t3 = wx.TextCtrl(self, -1,
                        "", (750, 50),
                       size=(400, 400), style=wx.TE_MULTILINE|wx.TE_RICH2)
        
        group_text = wx.StaticText(self, -1, "Select Group", (100, 380))
        self.groups_list = [g.name for g in Group.get_groups(type='group')]
        
        self.select_group = wx.ComboBox(self, 500, "", (100, 400), 
                                        (160, -1), self.groups_list, wx.CB_DROPDOWN)
        
        btn4 = wx.Button(self, -1, "Search Group", (100, 500))
        self.Bind(wx.EVT_BUTTON, self.groupChosen, btn4)
        
        btn2 = wx.Button(self, -1, "Search Phrase", (750, 500))
        self.Bind(wx.EVT_BUTTON, self.phraseChosen, btn2)
        
        expression_text = wx.StaticText(self, -1, "Select Expression", (450, 380))
        
        expression_list = [e.name for e in Expression.get_expressions()]
        self.lb3 = wx.ListBox(self, 70, (450, 410), (90, 50), expression_list, wx.LB_SINGLE)
        
        btn3 = wx.Button(self, -1, "Search Expression", (450, 500))
        self.Bind(wx.EVT_BUTTON, self.expressionChosen, btn3)
예제 #6
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        exp_sizer = wx.BoxSizer(wx.VERTICAL)
        
        relation_sizer = wx.BoxSizer(wx.HORIZONTAL)
        relation_grid_sizer = wx.BoxSizer(wx.VERTICAL)
        relation_buttons_sizer = wx.BoxSizer(wx.VERTICAL)
        
        word_list_sizer = wx.BoxSizer(wx.VERTICAL)
        
        
        group_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        select_group_sizer = wx.BoxSizer(wx.VERTICAL)
        
        buttons_group_sizer = wx.BoxSizer(wx.VERTICAL)
        
        
        self.groups_list = [g.name for g in Group.get_groups(type='group')]
        
        self.select_group = wx.ComboBox(self, 500, "", (90, 50), 
                                        (160, -1), self.groups_list, wx.CB_DROPDOWN)
        self.Bind(wx.EVT_COMBOBOX, self.onGroupChosen, self.select_group)
        
        group_text = wx.StaticText(self, -1, "Manage Group", (20, 20)) 
        
        self.group_words = wx.ListBox(self, 60, (100, 100), (150, 200), [], wx.LB_SINGLE)
        
        self.create_group_button = wx.Button(self, -1, "Create New Group", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onCreateGroup, self.create_group_button) 
        
        self.add_word_to_group_button = wx.Button(self, -1, "Add Word", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onAddWordToGroup, self.add_word_to_group_button)
        
        self.add_word_to_group_from_list_button = wx.Button(self, -1, "Add Words From List", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.OnAddWordToGroupFromList, self.add_word_to_group_from_list_button)

        self.remove_word_button = wx.Button(self, -1, "Remove Word", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onRemoveWordFromGroup, self.remove_word_button)
        
        self.remove_group_button = wx.Button(self, -1, "Remove Group", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onRemoveGroup, self.remove_group_button)
        
        
        
        select_group_sizer.Add(group_text)
        select_group_sizer.Add(self.select_group)
        select_group_sizer.Add(self.group_words)
        
        buttons_group_sizer.AddSpacer(100)
        buttons_group_sizer.Add(self.create_group_button)
        buttons_group_sizer.Add(self.add_word_to_group_button)
        buttons_group_sizer.Add(self.add_word_to_group_from_list_button)
        buttons_group_sizer.Add(self.remove_word_button)
        buttons_group_sizer.Add(self.remove_group_button)
        
        group_sizer.Add(select_group_sizer)
        group_sizer.Add(buttons_group_sizer)
        
        
        expressions_sizer = wx.BoxSizer(wx.HORIZONTAL)
        buttons_expressions_sizer = wx.BoxSizer(wx.VERTICAL)
        select_expressions_sizer = wx.BoxSizer(wx.VERTICAL)
        
        expression_text = wx.StaticText(self, -1, "Manage Expressions", (20, 20))
        self.expressions_list = [e.name for e in Expression.get_expressions()] 
        
        self.expressions = wx.ListBox(self, 60, (100, 100), (150, 200), self.expressions_list, wx.LB_EXTENDED)
        
        self.add_expression_button = wx.Button(self, -1, "Add Expression", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onAddExpression, self.add_expression_button) 

        self.remove_expressions_button = wx.Button(self, -1, "Remove Expressions", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onRemoveExpressions, self.remove_expressions_button) 
        
        select_expressions_sizer.Add(expression_text)
        select_expressions_sizer.Add(self.expressions)
        
        buttons_expressions_sizer.AddSpacer(100)
        buttons_expressions_sizer.Add(self.add_expression_button)
        buttons_expressions_sizer.Add(self.remove_expressions_button)
        
        
        expressions_sizer.Add(select_expressions_sizer)
        expressions_sizer.Add(buttons_expressions_sizer)
        
        exp_sizer.AddSpacer(50)
        exp_sizer.Add(group_sizer)
        exp_sizer.AddSpacer(50)
        exp_sizer.Add(expressions_sizer)
        
        
        
        expression_text = wx.StaticText(self, -1, "Manage relations", (20, 20))
        
        self.relations = Group.get_groups(type='relation')
        
        self.relations_grid = wx.grid.Grid(self, -1, size=(380, 250))
        
        self.relations_grid.CreateGrid(len(self.relations), 3)
        
        self.relations_grid.SetColSize(0, 100)
        self.relations_grid.SetColSize(1, 100)
        self.relations_grid.SetColSize(2, 100)

        
        self.relations_grid.SetColLabelValue(0, "Word 1")
        self.relations_grid.SetColLabelValue(1, "Word 2")
        self.relations_grid.SetColLabelValue(2, "Relation Name")
        
        i=0
        for relation in self.relations:
            self.relations_grid.SetCellValue(i, 0, relation.first_word.word)
            self.relations_grid.SetCellValue(i, 1, relation.second_word.word)
            self.relations_grid.SetCellValue(i, 2, relation.name)
            i+=1
        
        
        relation_grid_sizer.AddSpacer(50)
        relation_grid_sizer.Add(expression_text)
        relation_grid_sizer.AddSpacer(10)
        relation_grid_sizer.Add(self.relations_grid)
        
        
        
        self.add_relation_button = wx.Button(self, -1, "Add Relation", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onAddRelation, self.add_relation_button) 
        
        self.add_relation_with_words_button = wx.Button(self, -1, "Add Relation With Selected Words", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onAddRelationWithWords, self.add_relation_with_words_button) 

        self.remove_relation_button = wx.Button(self, -1, "Remove Relation", (300, 150))
        self.Bind(wx.EVT_BUTTON, self.onRemoveRelations, self.remove_relation_button) 
        
        relation_buttons_sizer.AddSpacer(100)
        relation_buttons_sizer.Add(self.add_relation_button)
        relation_buttons_sizer.Add(self.add_relation_with_words_button)
        relation_buttons_sizer.Add(self.remove_relation_button)
        
        relation_sizer.Add(relation_grid_sizer)
        relation_sizer.AddSpacer(20)
        relation_sizer.Add(relation_buttons_sizer)
        
        word_list_text = wx.StaticText(self, -1, "Words List", (20, 20)) 
        word_list = [w.word for w in Word.get_words()]
        self.lb1 = wx.ListBox(self, 60, (100, 50), (200, 400), word_list, wx.LB_EXTENDED)
        
        word_list_sizer.AddSpacer(100)
        word_list_sizer.Add(word_list_text)
        word_list_sizer.Add(self.lb1)
        
        
        sizer.AddSpacer(50)
        sizer.Add(exp_sizer)
        sizer.AddSpacer(50)
        sizer.Add(relation_sizer)        
        sizer.AddSpacer(100)        
        sizer.Add(word_list_sizer)
        
        self.SetSizer(sizer)