Пример #1
0
    def initialize(self):
        try:
            import gio
        except:
            sys.path.append("/usr/lib/python2.7/dist-packages")
            try:
                import gio
            except:
                logger.error("Could not import gio")
                return

        tokenizer = EnglishTokenizer()

        for app in gio.app_info_get_all():
            name = app.get_name().lower()
            entry = [app]
            tokenized_name = tokenizer.tokenize(name)[0]

            if name in self.appmap:
                self.appmap[name] += entry
            else:
                self.appmap[name] = entry

            self.register_vocabulary(name, "Application")
            if name != tokenized_name:
                self.register_vocabulary(tokenized_name, "Application")
                if tokenized_name in self.appmap:
                    self.appmap[tokenized_name] += entry
                else:
                    self.appmap[tokenized_name] = entry

        launch_intent = IntentBuilder(
            "LaunchDesktopApplicationIntent").require("LaunchKeyword").require(
            "Application").build()
        self.register_intent(launch_intent, self.handle_launch_desktop_app)

        close_intent = IntentBuilder(
            "CloseDesktopApplicationIntent").require("CloseKeyword").require(
            "Application").build()
        self.register_intent(close_intent, self.handle_close_desktop_app)

        launch_website_intent = IntentBuilder(
            "LaunchWebsiteIntent").require("LaunchKeyword").require(
            "Website").build()
        self.register_intent(launch_website_intent, self.handle_launch_website)

        search_website = IntentBuilder("SearchWebsiteIntent").require(
            "SearchKeyword").require("Website").require(
            "SearchTerms").build()
        self.register_intent(search_website, self.handle_search_website)

        launch_playlist_intent = IntentBuilder(
            "LaunchPlaylistIntent").require("LaunchKeyword").require(
            "Playlist").build()
        self.register_intent(launch_playlist_intent, self.handle_launch_playlist)
Пример #2
0
class TokenizerTest(unittest.TestCase):
    def setUp(self):
        self.tokenizer = EnglishTokenizer()

    def test_basic_tokenizer(self):
        s = "hello, world, I'm a happy camper. I don't have any friends?"
        result = self.tokenizer.tokenize(s)
        assert (result == [
            'hello', ',', 'world', ',', 'I', "'m", 'a', 'happy', 'camper', '.',
            'I', 'do', "n't", 'have', 'any', 'friends', '?'
        ])
Пример #3
0
    def initialize(self):
        try:
            import gio
        except:
            sys.path.append("/usr/lib/python2.7/dist-packages")
            try:
                import gio
            except:
                logger.error("Could not import gio")
                return

        vocab_dir = os.path.join(os.path.dirname(__file__), 'vocab', 'en-us')

        self.load_vocab_files(vocab_dir)
        tokenizer = EnglishTokenizer()

        for app in gio.app_info_get_all():
            name = app.get_name().lower()
            entry = [app]
            tokenized_name = tokenizer.tokenize(name)[0]

            if name in self.appmap:
                self.appmap[name] += entry
            else:
                self.appmap[name] = entry

            self.register_vocabulary(name, "Application")
            if name != tokenized_name:
                self.register_vocabulary(tokenized_name, "Application")
                if tokenized_name in self.appmap:
                    self.appmap[tokenized_name] += entry
                else:
                    self.appmap[tokenized_name] = entry

        self.register_regex("for (?P<SearchTerms>.*)")
        self.register_regex("for (?P<SearchTerms>.*) on")
        self.register_regex("(?P<SearchTerms>.*) on")

        launch_intent = IntentBuilder(
            "LaunchDesktopApplication").require("LaunchKeyword").require(
                "Application").build()
        self.register_intent(launch_intent, self.handle_launch_desktop_app)

        launch_website_intent = IntentBuilder(
            "LaunchWebsiteIntent").require("LaunchKeyword").require(
                "Website").build()
        self.register_intent(launch_website_intent, self.handle_launch_website)

        search_website = IntentBuilder("SearchWebsiteIntent").require(
            "SearchKeyword").require("Website").require(
                "SearchTerms").build()
        self.register_intent(search_website, self.handle_search_website)
    def initialize(self):
        tokenizer = EnglishTokenizer()

        for app in gio.app_info_get_all():
            name = app.get_name().lower()
            entry = [app]
            tokenized_name = tokenizer.tokenize(name)[0]

            if name in self.appmap:
                self.appmap[name] += entry
            else:
                self.appmap[name] = entry

            self.register_vocabulary(name, "Application")
            if name != tokenized_name:
                self.register_vocabulary(tokenized_name, "Application")
                if tokenized_name in self.appmap:
                    self.appmap[tokenized_name] += entry
                else:
                    self.appmap[tokenized_name] = entry

        launch_intent = IntentBuilder(
            "LaunchDesktopApplicationIntent").require("LaunchKeyword").require(
            "Application").build()
        self.register_intent(launch_intent, self.handle_launch_desktop_app)

        close_intent = IntentBuilder(
            "CloseDesktopApplicationIntent").require("CloseKeyword").require(
            "Application").build()
        self.register_intent(close_intent, self.handle_close_desktop_app)

        launch_website_intent = IntentBuilder(
            "LaunchWebsiteIntent").require("LaunchKeyword").require(
            "Website").build()
        self.register_intent(launch_website_intent, self.handle_launch_website)

        search_website = IntentBuilder("SearchWebsiteIntent").require(
            "SearchKeyword").require("Website").require(
            "SearchTerms").build()
        self.register_intent(search_website, self.handle_search_website)
Пример #5
0
    def initialize(self):
        tokenizer = EnglishTokenizer()
        for app_command in subprocess.check_output(['{}/get_apps'.format(dir_path)]).splitlines():
            name = app_command.decode('ascii').lower()
            entry = [App(app_command)]
            tokenized_name = tokenizer.tokenize(name)[0]

            if name in self.appmap:
                self.appmap[name] += entry
            else:
                self.appmap[name] = entry

            self.register_vocabulary(name, "Application")
            if name != tokenized_name:
                self.register_vocabulary(tokenized_name, "Application")
                if tokenized_name in self.appmap:
                    self.appmap[tokenized_name] += entry
                else:
                    self.appmap[tokenized_name] = entry

        launch_intent = IntentBuilder(
            "LaunchDesktopApplicationIntent").require("LaunchKeyword").require(
            "Application").build()
        self.register_intent(launch_intent, self.handle_launch_desktop_app)

        close_intent = IntentBuilder(
            "CloseDesktopApplicationIntent").require("CloseKeyword").require(
            "Application").build()
        self.register_intent(close_intent, self.handle_close_desktop_app)

        launch_website_intent = IntentBuilder(
            "LaunchWebsiteIntent").require("LaunchKeyword").require(
            "Website").build()
        self.register_intent(launch_website_intent, self.handle_launch_website)

        search_website = IntentBuilder("SearchWebsiteIntent").require(
            "SearchKeyword").require("Website").require(
            "SearchTerms").build()
        self.register_intent(search_website, self.handle_search_website)