mycroft-core 为技能加载器添加额外的lang文件夹以供查找,

y0u0uwnf  于 2个月前  发布在  其他
关注(0)|答案(9)|浏览(52)

一些技能缺少翻译或者poodle上的翻译尚未合并。同时,在向poodle添加翻译时,几乎无法立即进行测试。

我提议在技能之外添加一个额外的语言文件夹,以便放置其他语言文件。这样就可以本地翻译或从poodle获取翻译并立即使用。

我的建议是在mycroft.comf中添加一个设置,名为additional_language=/opt/mycroft/additional_language/。然后当技能加载器寻找语言文件时,它首先在技能文件夹中查找,如果不存在,则在技能文件夹的additional_language中查找。

然后可以创建一个从poodle获取语言文件并将其放入additional_language文件夹的技能,或者是一个自动翻译并将文件放在那里的技能,或者是两者的组合。

在mycroft-skills.py中,读取语言文件的函数可以从

def load_vocab_files(self, root_directory):
        """ Load vocab files found under root_directory.

        Arguments:
            root_directory (str): root folder to use when loading files
        """
        keywords = []
        vocab_dir = join(root_directory, 'vocab', self.lang)
        locale_dir = join(root_directory, 'locale', self.lang)
        if exists(vocab_dir):
            keywords = load_vocabulary(vocab_dir, self.skill_id)
        elif exists(locale_dir):
            keywords = load_vocabulary(locale_dir, self.skill_id)
        else:
            LOG.debug('No vocab loaded')

        # For each found intent register the default along with any aliases
        for vocab_type in keywords:
            for line in keywords[vocab_type]:
                entity = line[0]
                aliases = line[1:]
                self.intent_service.register_adapt_keyword(vocab_type,
                                                           entity,
                                                           aliases)

    def load_regex_files(self, root_directory):
        """ Load regex files found under the skill directory.

        Arguments:
            root_directory (str): root folder to use when loading files
        """
        regexes = []
        regex_dir = join(root_directory, 'regex', self.lang)
        locale_dir = join(root_directory, 'locale', self.lang)
        if exists(regex_dir):
            regexes = load_regex(regex_dir, self.skill_id)
        elif exists(locale_dir):
            regexes = load_regex(locale_dir, self.skill_id)

        for regex in regexes:
            self.intent_service.register_adapt_regex(regex)

更改为类似这样的内容:

def load_vocab_files(self, root_directory):
        """ Load vocab files found under root_directory.

        Arguments:
            root_directory (str): root folder to use when loading files
        """
        keywords = []
        vocab_dir = join(root_directory, 'vocab', self.lang)
        locale_dir = join(root_directory, 'locale', self.lang)
        if exists(vocab_dir):
            keywords = load_vocabulary(vocab_dir, self.skill_id)
        elif exists(locale_dir):
            keywords = load_vocabulary(locale_dir, self.skill_id)
        else:
            LOG.debug('No vocab loaded')

        # For each found intent register the default along with any aliases
        for vocab_type in keywords:
            for line in keywords[vocab_type]:
                entity = line[0]
                aliases = line[1:]
                self.intent_service.register_adapt_keyword(vocab_type,
                                                           entity,
                                                           aliases)

    def load_regex_files(self, root_directory):
        """ Load regex files found under the skill directory.

        Arguments:
            root_directory (str): root folder to use when loading files
        """
        regexes = []
        regex_dir = join(root_directory, 'regex', self.lang)
        locale_dir = join(root_directory, 'locale', self.lang)
        aditional_dir = join(settings.get("aditional_language", self.lang)
        if exists(regex_dir):
            regexes = load_regex(regex_dir, self.skill_id)
        elif exists(locale_dir):
            regexes = load_regex(locale_dir, self.skill_id)
        elif exists(aditional_dir):
            regexes = load_regex(locale_dir, self.skill_id)

        for regex in regexes:
            self.intent_service.register_adapt_regex(regex)

我已经有一个自动翻译技能了,但如果它将语言文件保存到技能中,那么在已经更改的情况下,技能将不会在以后更新。通过将文件放在技能之外,技能将像往常一样正常更新。

tyg4sfes

tyg4sfes1#

我认为这是一个好主意,如果有人想测试/验证他们在那里完成的翻译,我们也可以创建一个脚本,将翻译从pootle拉到additional_language文件夹。

n8ghc7c1

n8ghc7c12#

我认为技能可以实现这些功能。但是,附加语言文件夹应该存在在哪里,它应该被命名为什么?
附加_language、local_lang还是其他什么?
它应该放在
~/.mycroft/
/opt/mycroft/
还是在第三个地方?
每个具有附加语言的技能是否应该像技能文件夹一样放在文件夹中,或者像.mycroft/skills中的文件夹一样?
它们应该只放在locale/lang文件夹中,还是应该像某些技能一样有词汇、正则表达式和对话文件夹?
我可以按照我找到的正确位置添加它,我之前已经向mycroft.conf添加了注解。但是需要一些设计方向。
此外,它还可以测试语言文件夹中的文件是否与en-us匹配,如果不匹配,则将这些文件添加到附加语言中(无论是从poodle还是自动翻译)。

smdncfj3

smdncfj33#

我找到了一种方法来下载.po文件,多亏了@gras64,他还提供了一种将它们转换为mycroft格式文件的方法。所以这部分已经解决了。
我还没有找到上传的方法:(但那也很好,不过对于这个提案来说并不是问题。

iyzzxitl

iyzzxitl4#

在mycroft-translate仓库中还有一个脚本,用于创建翻译后的mycroft文件。如果你想从技能中实现这个功能,最好使用~/.mycroft/文件夹作为基础,因为无论哪个用户运行核心,都可以保证它存在且可写。我个人建议将翻译文件夹命名为translations

5m1hhzi4

5m1hhzi45#

Then ~/.mycroft/translations it is
Ill look into the mycroft-translate folder and use what I can from that :)
and the setting in mycroft.con should be called ?
translations_folder?
translations_dir?
And shiuld there be a setting for what to use first - skill or translation (if both is present)?
prefear_translations: true/false
I think a skill for pulling translations is the best way to go as it would make smallest impact into core and a flexibale way tat is open to other ways to get translations (

gdrx4gfi

gdrx4gfi6#

我同意技能可能是首选。
看起来配置主要使用_dir,所以translations_dir可能最好。prefere_translations听起来像是配置的好名字👍
我也认为我们应该听取@krisgesling的意见,如果他有任何偏好,因为他正在做很多技能和翻译工作。

thtygnil

thtygnil7#

是的 - 尽快我会在这个上做一些工作,然后我们可以看到它要去哪里。@gras64正在开发一个技能来拉下翻译,这样我就可以在这个文件夹里添加翻译并让这个部分正常工作。
然后我可以改变我的自动翻译技能,让它也使用那个文件夹。
我需要弄清楚如何让我的mycroft-core分支保持最新并重新基于它,这样当我发起PR时就不会出现奇怪的问题。
接下来的下一步可能是反过来同步,这样翻译就可以上传到poodle了。

icomxhvb

icomxhvb8#

我没有什么要补充的,只是说我非常喜欢这个。
再次感谢Andlo的主动!

hs1ihplo

hs1ihplo9#

在我所有的mycroft安装中,我覆盖了mycroft-core/skills/fallback-unknown.mycroftai/dialog/it-it/unknown.dialog,使其只包含一个简短的"non ho capito."。我们能否有一个类似于.config/mycroft/skills/fallback-unknown.mycroftai/dialog/it-it/unknown.dialog的文件来覆盖原始文件,这样我们就不必担心会丢失所有内容?
将来,拥有一个.config/mycroft/skills/文件夹也可能允许覆盖远程配置;)

相关问题