示例#1
0
    def __init__(self, exec_by_ibus):
        engine_name = "bogo"
        long_engine_name = "BoGo"
        author = "BoGo Development Team <*****@*****.**>"
        description = "ibus-bogo for IBus"
        version = "0.4"
        license = "GPLv3"

        self.component = \
            IBus.Component.new("org.freedesktop.IBus.BoGo",
                               description,
                               version,
                               license,
                               author,
                               "https://github.com/BoGoEngine/ibus-bogo",
                               "/usr/bin/exec",
                               "ibus-bogo")

        engine = IBus.EngineDesc(
            name=engine_name,
            longname=long_engine_name,
            description=description,
            language="vi",
            license=license,
            author=author,
            icon=current_path + "/data/ibus-bogo-dev.svg",
            # icon = "ibus-bogo",
            layout="default")

        self.component.add_engine(engine)
        self.mainloop = GObject.MainLoop()
        self.bus = IBus.Bus()
        self.bus.connect("disconnected", self.bus_disconnected_cb)

        self.engine_count = 0
        self.factory = IBus.Factory.new(self.bus.get_connection())
        self.factory.connect("create-engine", self.create_engine)

        CONFIG_DIR = os.path.expanduser("~/.config/ibus-bogo/")
        self.config = Config()
        self.abbr_expander = AbbreviationExpander(config=self.config)
        self.abbr_expander.watch_file(CONFIG_DIR + "/abbr_rules.json")

        if exec_by_ibus:
            self.bus.request_name("org.freedesktop.IBus.BoGo", 0)
        else:
            self.bus.register_component(self.component)
            self.bus.set_global_engine_async("bogo", -1, None, None, None)
        custom_broker = enchant.Broker()
        custom_broker.set_param('enchant.myspell.dictionary.path', DICT_PATH)

        spellchecker = enchant.DictWithPWL('vi_VN_telex',
                                           pwl=PWL_PATH,
                                           broker=custom_broker)

        # FIXME: Catch enchant.errors.DictNotFoundError exception here.
        english_spellchecker = enchant.Dict('en_US')

        self.auto_corrector = AutoCorrector(self.config, spellchecker,
                                            english_spellchecker)
示例#2
0
    def setup(self):
        self.spellchecker = Mock()
        self.english_spellchecker = Mock()
        self.config = {"typo-correction-level": 2}

        self.corrector = AutoCorrector(
            config=self.config,
            spellchecker=self.spellchecker,
            english_spellchecker=self.english_spellchecker)
    def test_auto_corrector(self):
        auto_corrector = AutoCorrector()
        for page in self.pages:
            with open(page[3].replace('.txt','_nc.json')) as f:
                responses = json.load(f)
            for result in responses['results']:
                result['corrected_content'] =\
                                            auto_corrector.auto_correct(result)

            for c in responses['results']:
                self.assertIsNotNone(c.get('corrected_content'))

            '''
 def setUp(self):
     self.test_correcton_files = {
         'ca-ES': [
             '3422059e057636482a2230c3aa87dfeb.json',
             '36b63320f3a0e3be9fb5db9f6977ff2d.json',
             '4640bc501a5249d012cd8fa1db31bd77.json',
             'ef4f48c7860cba1910edafe6c7dbd332.json'
         ],
         'en-US': [
             '3c0b0033e4ae2e8182451a22159badea.json',
             '9e1b1202e55d4add7e376d451e3afa64.json'
         ]
     }
     self.test_corrector = AutoCorrector()
示例#5
0
 def __init__(self, botname, host = 'teixidora', languagetool = LT_URL):
     # initializes the connection to teixidora semantic wiki
     if host not in HOSTS:
         msg = 'given host %s not in defined hosts: %s'%(host, str(HOSTS))
         logging.error(msg)
         raise ValueError(msg)
     self.site = pywikibot.Site('ca', host)
     self.botname = botname
     self.languagetool = LT_URL
     self.online = False
     self.params = {"bot import": None, 
                    "bot correction": None,
                    "human review": None}
     self.outname = None
     self.declared_language = None
     self.local_corpus = set()
     self.get_global_corpus()
     self.auto_corrector = AutoCorrector()
示例#6
0
    def __init__(self, config, abbr_expander):
        super().__init__()

        self.caps = 0
        self.vietnameseMode = True

        self.config = config
        self.ui_delegate = UiDelegate(engine=self)

        custom_broker = enchant.Broker()
        custom_broker.set_param('enchant.myspell.dictionary.path', DICT_PATH)

        spellchecker = enchant.DictWithPWL('vi_VN_telex',
                                           pwl=PWL_PATH,
                                           broker=custom_broker)

        # FIXME: Catch enchant.errors.DictNotFoundError exception here.
        english_spellchecker = enchant.Dict('en_US')

        auto_corrector = AutoCorrector(config, spellchecker,
                                       english_spellchecker)

        self.preedit_backend = PreeditBackend(engine=self,
                                              config=config,
                                              abbr_expander=abbr_expander,
                                              auto_corrector=auto_corrector)

        self.surrounding_text_backend = SurroundingTextBackend(
            engine=self,
            config=config,
            abbr_expander=abbr_expander,
            auto_corrector=auto_corrector)

        # The preedit backend is the default
        self.backend = self.preedit_backend
        self.reset()