Exemplo n.º 1
0
 def sample_with_template(self, num, prime):
     # create template
     tm = TemplateManager()
     tm.generate_template(length=num + len(prime.split()))
     while not tm.match(sentence=prime):
         print("The prime won't work with the template! Generating new template...")
         tm.generate_template(length=num)
     # sample words
     probs = self.sample_probs(num, prime)
     ret = prime
     for p in probs:
         valid = False
         while not valid:
             sample = np.random.choice(self.vocab_size, p=p)
             word = self.data_loader.vocab_list[sample]
             temp_ret = ret + " " + word
             valid = tm.match_latest(sentence=temp_ret)
             # renormalize
             p[sample] = 0.0
             p /= np.sum(p)
         ret = temp_ret
     return tm.format_sentence(ret)
Exemplo n.º 2
0
    def __init__(self, parent):
        super(CopyVerseDialog, self).__init__(parent)
        self.tm = TemplateManager(self)
        self.is_custom = False
        self.based_on = ""

        # fill up the list of templates
        self.fill_templates()

        fields = None

        settings = config_manager["BPBible"]["copy_verse"]

        # if we are a tuple, we represent based_on, fields
        # otherwise we are a template name
        copy_formatted = False
        if isinstance(settings, tuple):
            if len(settings) == 2:
                # old style
                based_on, fields = settings
                self.is_custom = True
            else:
                based_on, fields, copy_formatted = settings
                self.is_custom = fields != None

        else:
            # old style
            based_on = settings

        if self.is_custom:
            self.make_custom(based_on)

        else:
            item_id = 0
            for idx, item in enumerate(self.tm.templates):
                if item.name == based_on:
                    item_id = idx
                    break

                # remember default, but keep on looking
                if item.name == "Default":
                    item_id = idx

            self.tm.change_template(item_id)
            self.gui_template_list.SetStringSelection(self.tm.template.name)

            fields = self.tm.template

        # put the template panel in
        self.template_panel = TemplatePanel(self.tp_holder, fields, False)
        self.tp_holder.Sizer.Add(self.template_panel, 1, wx.GROW)
        self.tp_holder.Fit()
        self.tp_holder.Parent.Parent.Label = _("Edit Template...")
        self.Fit()
        self.SetMinSize(self.Size)

        # do binding
        for event in [wx.EVT_KILL_FOCUS, wx.EVT_TEXT_ENTER]:
            self.reference.Bind(event, self.update)

        self.copy_formatted.SetValue(copy_formatted)
        self.copy_formatted.Bind(wx.EVT_CHECKBOX, self.update)

        for item in self.template_panel.fields:
            for event in [wx.EVT_KILL_FOCUS]:  #, stc.EVT_STC_MODIFIED]:
                item.Bind(event, self.update)
            item.Bind(stc.EVT_STC_MODIFIED, self.on_text_changed)

            colour, text_colour = guiconfig.get_window_colours()
            for style in stc.STC_STYLE_DEFAULT, 0:
                item.StyleSetBackground(style, colour)
                item.StyleSetForeground(style, text_colour)

            item.SetCaretForeground(text_colour)

        self.wxID_CANCEL.Bind(wx.EVT_BUTTON, lambda x: self.Destroy())
        self.wxID_OK.Bind(wx.EVT_BUTTON, self.ok_button_clicked)

        self.gui_save_template.Bind(wx.EVT_BUTTON, self.save_template)
        self.gui_load_template.Bind(wx.EVT_BUTTON, self.load_template)
        self.gui_template_list.Bind(wx.EVT_CHOICE, self.on_template_choice)

        self.preview.book = biblemgr.bible
        self.has_preview_been_loaded = False