当前位置: 首页>>代码示例>>Python>>正文


Python Character.read方法代码示例

本文整理汇总了Python中tegaki.character.Character.read方法的典型用法代码示例。如果您正苦于以下问题:Python Character.read方法的具体用法?Python Character.read怎么用?Python Character.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tegaki.character.Character的用法示例。


在下文中一共展示了Character.read方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testToSexp

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
 def testToSexp(self):
     f = os.path.join(self.currdir, "data", "character.xml")
     char = Character()
     char.read(f)
     f = open(os.path.join(self.currdir, "data", "character.sexp"))
     sexp = f.read().strip()
     f.close()
     self.assertEquals(char.to_sexp(), sexp)
开发者ID:cburgmer,项目名称:tegaki,代码行数:10,代码来源:test_character.py

示例2: testIsSmall

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
 def testIsSmall(self):
     for filename, res in (("small.xml", True),
                           ("small2.xml", True),
                           ("small3.xml", True),
                           ("small4.xml", True),
                           ("small5.xml", True),
                           ("non-small.xml", False)):
         f = os.path.join(self.currdir, "data", "small", filename)
         char = Character()
         char.read(f)
         self.assertEquals(char.get_writing().is_small(), res)
开发者ID:Ghost3,项目名称:tegaki,代码行数:13,代码来源:test_character.py

示例3: from_character_directory

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
	def from_character_directory(directory,
	                             extensions=["xml", "bz2", "gz"],
	                             recursive=True,
	                             check_duplicate=False):
		"""
		Creates a character collection from a directory containing
		individual character files.
		"""
		regexp = re.compile("\.(%s)$" % "|".join(extensions))
		charcol = CharacterCollection()

		for name in os.listdir(directory):
			full_path = os.path.join(directory, name)
			if os.path.isdir(full_path) and recursive:
				charcol += CharacterCollection.from_character_directory(
					full_path, extensions)
			elif regexp.search(full_path):
				char = Character()
				gzip = False;
				bz2 = False
				if full_path.endswith(".gz"): gzip = True
				if full_path.endswith(".bz2"): bz2 = True

				try:
					char.read(full_path, gzip=gzip, bz2=bz2)
				except ValueError:
					continue  # ignore malformed XML files

				utf8 = char.get_utf8()
				if utf8 is None: utf8 = "Unknown"

				charcol.add_set(utf8)
				if not check_duplicate or \
						not char in charcol.get_characters(utf8):
					charcol.append_character(utf8, char)

		return charcol
开发者ID:titeipa,项目名称:CharacterClassifier,代码行数:39,代码来源:charcol.py

示例4: CharacterCollectionTest

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
class CharacterCollectionTest(unittest.TestCase):

    def setUp(self):
        self.currdir = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(self.currdir, "data", "collection", "test.charcol")
        self.cc = CharacterCollection()
        self.cc.read(path)
        f = os.path.join(self.currdir, "data", "character.xml")
        self.c = Character()
        self.c.read(f)

    def testValidate(self):
        path = os.path.join(self.currdir, "data", "collection", "test.charcol")
        f = open(path)
        buf = f.read()
        f.close()

        invalid = \
"""
<?xml version="1.0" encoding="UTF-8"?>
  <character>
    <utf8>防</utf8>
    <strokes>
      <stroke>
      </stroke>
    </strokes>
  </character>
"""

        malformed = \
"""
<?xml version="1.0" encoding="UTF-8"?>
  <character>
"""

        try:
            self.assertTrue(CharacterCollection.validate(buf))
            self.assertFalse(CharacterCollection.validate(invalid))
            self.assertFalse(CharacterCollection.validate(malformed))
        except NotImplementedError:
            sys.stderr.write("lxml missing!\n")
            pass

    def _testReadXML(self, charcol):
        self.assertEquals(charcol.get_set_list(), ["一", "三", "二", "四"])

        c = {}
        for k in ["19968_1", "19968_2", "19968_3", "19977_1", "19977_2",
                 "20108_1"]:
            c[k] = Character()
            c[k].read(os.path.join(self.currdir, "data", "collection",
                      k + ".xml"))

        self.assertEquals(charcol.get_characters("一"),
                          [c["19968_1"], c["19968_2"], c["19968_3"]])
        self.assertEquals(charcol.get_characters("三"),
                          [c["19977_1"], c["19977_2"]])
        self.assertEquals(charcol.get_characters("二"),
                          [c["20108_1"]])
        self.assertEquals(charcol.get_characters("四"), [])
        self.assertEquals(charcol.get_all_characters(),
                          [c["19968_1"], c["19968_2"], c["19968_3"],
                           c["19977_1"], c["19977_2"], c["20108_1"]])

    def testReadXMLFile(self):
        self._testReadXML(self.cc)

    def testToXML(self):
        charcol2 = CharacterCollection()
        charcol2.read_string(self.cc.to_xml())
        self.assertEquals(self.cc.get_set_list(), charcol2.get_set_list())
        self.assertEquals(self.cc.get_all_characters(),
                          charcol2.get_all_characters())

    def testWriteGzipString(self):
        charcol2 = CharacterCollection()
        charcol2.read_string(self.cc.write_string(gzip=True), gzip=True)
        self.assertEquals(self.cc.get_set_list(), charcol2.get_set_list())
        self.assertEquals(self.cc.get_all_characters(),
                          charcol2.get_all_characters())

    def testWriteBz2String(self):
        charcol2 = CharacterCollection()
        charcol2.read_string(self.cc.write_string(bz2=True), bz2=True)
        self.assertEquals(self.cc.get_set_list(), charcol2.get_set_list())
        self.assertEquals(self.cc.get_all_characters(),
                          charcol2.get_all_characters())

    def testAddSame(self):
        path = os.path.join(self.currdir, "data", "collection", "test.charcol")
        charcol = CharacterCollection()
        charcol.read(path)
        charcol2 = CharacterCollection()
        charcol2.read(path)
        charcol3 = charcol.concatenate(charcol2, check_duplicate=True)
        self.assertEquals(charcol3.get_set_list(), ["一", "三", "二", "四"])
        self.assertEquals(len(charcol3.get_characters("一")), 3)
        self.assertEquals(len(charcol3.get_characters("三")), 2)
        self.assertEquals(len(charcol3.get_characters("二")), 1)
        self.assertEquals(len(charcol3.get_characters("四")), 0)
#.........这里部分代码省略.........
开发者ID:Ghost3,项目名称:tegaki,代码行数:103,代码来源:test_charcol.py

示例5: recognize

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
    def recognize(self, writing, n=10):
        """
        Recognizes writing and returns n candidates.
        A model must be set with set_model() beforehand.
        """
        raise NotImplementedError


if __name__ == "__main__":
    import sys
    from tegaki.character import Character

    recognizer = sys.argv[1] # name of recognizer
    model = sys.argv[2] # name of model file
    char = Character()
    char.read(sys.argv[3]) # path of .xml file
    writing = char.get_writing() 

    recognizers = Recognizer.get_available_recognizers()
    print "Available recognizers", recognizers

    if not recognizer in recognizers:
        raise Exception, "Not an available recognizer"

    recognizer_klass = recognizers[recognizer]
    recognizer = recognizer_klass()

    models = recognizer_klass.get_available_models()
    print "Available models", models

    if not model in models:
开发者ID:Belgabor,项目名称:Tegaki,代码行数:33,代码来源:recognizer.py

示例6: testReadXMLBZ2File

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
    def testReadXMLBZ2File(self):
        file = os.path.join(self.currdir, "data", "character.xml.bz2")
        char = Character()
        char.read(file, bz2=True)

        self._testReadXML(char)
开发者ID:cburgmer,项目名称:tegaki,代码行数:8,代码来源:test_character.py

示例7: testReadXMLGzipFile

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
    def testReadXMLGzipFile(self):
        file = os.path.join(self.currdir, "data", "character.xml.gzip")
        char = Character()
        char.read(file, gzip=True)

        self._testReadXML(char)
开发者ID:cburgmer,项目名称:tegaki,代码行数:8,代码来源:test_character.py

示例8: testReadXMLFile

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
    def testReadXMLFile(self):
        file = os.path.join(self.currdir, "data", "character.xml")
        char = Character()
        char.read(file)

        self._testReadXML(char)
开发者ID:cburgmer,项目名称:tegaki,代码行数:8,代码来源:test_character.py

示例9: WritingIconView

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import read [as 别名]
if __name__ == "__main__":
    import sys
    from glob import glob
    import os.path

    from tegaki.character import Character

    folder = sys.argv[1] # a folder contains XML character files

    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_default_size(500, 500)
    iconview = WritingIconView()
    scrolledwindow = gtk.ScrolledWindow()
    scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  
    characters = []
    for path in glob(os.path.join(folder, "*.xml")):
        char = Character()
        char.read(path)
        characters.append(char)

    iconview.set_item_width(80)
    iconview.set_characters(characters)
    iconview.hide_icon_text()

    scrolledwindow.add(iconview)
    window.add(scrolledwindow)
    window.show_all()

    gtk.main()
开发者ID:Belgabor,项目名称:Tegaki,代码行数:32,代码来源:iconview.py


注:本文中的tegaki.character.Character.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。