Ejemplo n.º 1
0
    def _parse_resource(self, items):

        rtype = ""
        rpath = ""
        rname = ""
        rext  = ""
        lr = LangResource()
        for name,value in items:
            if name == "type":
                rtype = value.encode('utf-8')
            elif name == "path":
                rpath = value.encode('utf-8')
            elif name == "name":
                rname = value.encode('utf-8')
            elif name == "ext":
                rext  = value.encode('utf-8')
        lr.set( rtype, rpath, rname, rext )

        return lr
Ejemplo n.º 2
0
 def setUp(self):
     self.lr = LangResource()
Ejemplo n.º 3
0
class TestLang(unittest.TestCase):

    def setUp(self):
        self.lr = LangResource()

    def test_set(self):
        self.assertEqual(self.lr.get_lang(), "und")

        with self.assertRaises(IOError):
            self.lr.set("file", "wrongpath")

        with self.assertRaises(TypeError):
            self.lr.set("wrongtype", "vocab")

        self.lr.set("file", "vocab")
        langlist = self.lr.get_langlist()
        self.assertEqual(0, len(langlist))

        # Tokenization:
        self.lr.set("file", "vocab", "", ".vocab")
        self.assertEqual(os.path.join(RESOURCES_PATH,"vocab"), self.lr.get_langresource())
        self.lr.set_lang("fra")
        self.assertEqual("fra", self.lr.get_lang())
        self.assertEqual(os.path.join(RESOURCES_PATH,"vocab","fra.vocab"), self.lr.get_langresource())
        with self.assertRaises(ValueError):
            self.lr.set_lang("wrong")

        # Syllabification:
        self.lr.set("file", "syll", "syllConfig-", ".txt")
        self.lr.set_lang("fra")
        self.assertEqual(os.path.join(RESOURCES_PATH,"syll","syllConfig-fra.txt"), self.lr.get_langresource())
        with self.assertRaises(ValueError):
            self.lr.set_lang("wrong")

        # Alignment
        self.lr.set("directory", "models", "models-")
        self.lr.set_lang("fra")
        self.assertEqual(os.path.join(RESOURCES_PATH,"models","models-fra"), self.lr.get_langresource())
        with self.assertRaises(ValueError):
            self.lr.set_lang("wrong")

        self.lr.set("directory", "models", "models-", ".txt")
        self.lr.set_lang("fra")
        self.assertEqual(os.path.join(RESOURCES_PATH,"models","models-fra"), self.lr.get_langresource())
        with self.assertRaises(ValueError):
            self.lr.set_lang("wrong")