當前位置: 首頁>>代碼示例>>Python>>正文


Python character.Character類代碼示例

本文整理匯總了Python中tegaki.character.Character的典型用法代碼示例。如果您正苦於以下問題:Python Character類的具體用法?Python Character怎麽用?Python Character使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Character類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: to_stroke_collection

    def to_stroke_collection(self, dictionary, silent=True):
        """
        @type dictionary: L{CharacterStrokeDictionary
        """
        strokecol = CharacterCollection()
        for char in self.get_all_characters_gen():
            stroke_labels = dictionary.get_strokes(char.get_unicode())[0]
            strokes = char.get_writing().get_strokes(full=True)

            if len(strokes) != len(stroke_labels):
                if silent:
                    continue
                else:
                    raise ValueError, "The number of strokes doesn't " \
                                      "match with reference character"

            for stroke, label in zip(strokes, stroke_labels):
                utf8 = label.encode("utf-8")
                strokecol.add_set(utf8)
                writing = Writing()
                writing.append_stroke(stroke)
                writing.normalize_position()
                schar = Character()
                schar.set_utf8(utf8)
                schar.set_writing(writing)
                strokecol.append_character(utf8, schar)

        return strokecol
開發者ID:Ghost3,項目名稱:tegaki,代碼行數:28,代碼來源:charcol.py

示例2: _getCharacter

    def _getCharacter(self):
        writing = self._getWriting()

        char = Character()
        char.set_writing(writing)
        char.set_utf8("A")

        return char
開發者ID:cburgmer,項目名稱:tegaki,代碼行數:8,代碼來源:test_character.py

示例3: testToSexp

 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,代碼行數:8,代碼來源:test_character.py

示例4: testReadXMLBZ2String

    def testReadXMLBZ2String(self):
        file = os.path.join(self.currdir, "data", "character.xml.bz2")
        file = open(file)
        string = file.read()
        file.close()
        
        char = Character()
        char.read_string(string, bz2=True)

        self._testReadXML(char)
開發者ID:cburgmer,項目名稱:tegaki,代碼行數:10,代碼來源:test_character.py

示例5: testWriteXMLFile

    def testWriteXMLFile(self):
        char = self._getCharacter()

        io = StringIO.StringIO()
        char.write(io)

        new_char = Character()
        new_char.read_string(io.getvalue())

        self.assertEquals(char, new_char)
開發者ID:cburgmer,項目名稱:tegaki,代碼行數:10,代碼來源:test_character.py

示例6: testIsSmall

 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,代碼行數:11,代碼來源:test_character.py

示例7: testReadXMLString

    def testReadXMLString(self):
        file = os.path.join(self.currdir, "data", "character.xml")
        
        f = open(file)
        buf = f.read()
        f.close()
        
        char = Character()
        char.read_string(buf)

        self._testReadXML(char)
開發者ID:cburgmer,項目名稱:tegaki,代碼行數:11,代碼來源:test_character.py

示例8: set_writings

 def set_writings(self, writings):
     """
     writings: a list of tegaki.Writing objects.
     """
     self._model.clear()
     characters = []
     for writing in writings:
         char = Character()
         char.set_writing(writing)
         char.set_utf8("?")
         characters.append(char)
     self.set_characters(characters)
開發者ID:Belgabor,項目名稱:Tegaki,代碼行數:12,代碼來源:iconview.py

示例9: _end_element

    def _end_element(self, name):
        if name == "kanji":
            char = Character()
            char.set_utf8(self._utf8)
            char.set_writing(self._writing)
            self._charcol.add_set(self._utf8)
            self._charcol.append_character(self._utf8, char)
            for s in ["_tag", "_stroke"]:
                if s in self.__dict__:
                    del self.__dict__[s]

        if name == "stroke":
            self._writing.append_stroke(self._stroke)
            self._stroke = None

        self._tag = None
開發者ID:rogerbraun,項目名稱:Project-Tegaki,代碼行數:16,代碼來源:kvg.py

示例10: setUp

 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)
開發者ID:Ghost3,項目名稱:tegaki,代碼行數:8,代碼來源:test_charcol.py

示例11: testConstructorAndSave

    def testConstructorAndSave(self):
        file_ = os.path.join(self.currdir, "data", "character.xml")

        for f in (file_, file_ + ".gzip", file_ + ".bz2", None):
            char = Character(f)
            if f:
                self._testReadXML(char) # check that it is correctly loaded

            files = map(tempfile.mkstemp, (".xml", ".xml.gz", ".xml.bz2"))
            output_paths = [path for fd,path in files]
            
            for path in output_paths:                
                try:
                    # check that save with a path argument works
                    char.save(path)
                    newchar = Character(path)
                    self.assertEquals(char, newchar)
                finally:
                    os.unlink(path)

                try:
                    # check that save with a path argument works
                    newchar.save()
                    newchar2 = Character(path)
                    self.assertEquals(char, newchar2)
                finally:
                    os.unlink(path)

        char = Character()
        self.assertRaises(ValueError, char.save)
開發者ID:cburgmer,項目名稱:tegaki,代碼行數:30,代碼來源:test_character.py

示例12: get_character_collection

	def get_character_collection(self):
		charcol = CharacterCollection()

		# group characters with the same label into sets
		sets = {}
		for i in range(len(self._labels)):
			# Create Character
			writing = Writing()
			if self.height and self.width:
				writing.set_height(self.height)
				writing.set_width(self.width)

			for delin_range in self._delineations[i]:
				if delin_range.start_comp == (delin_range.end_comp - 1):
					stroke_points = self._strokes[delin_range.start_comp][delin_range.start_point:delin_range.end_point]
					writing.append_stroke(Stroke.from_list(stroke_points))
				else:
					# add first stroke to writing
					start_stroke_points = self._strokes[delin_range.start_comp][delin_range.start_point:-1]
					if len(start_stroke_points) > 0:
						writing.append_stroke(Stroke.from_list(start_stroke_points))

					# add last stroke to writing
					end_stroke_points = self._strokes[delin_range.end_comp - 1][0:delin_range.end_point]
					if len(end_stroke_points) > 0:
						writing.append_stroke(Stroke.from_list(end_stroke_points))

					# add the remaining strokes to writing
					for stroke in self._strokes[delin_range.start_comp + 1:delin_range.end_comp - 1]:
						writing.append_stroke(stroke)

			character = Character()
			character.set_writing(writing)

			utf8 = self._labels[i]
			character.set_utf8(utf8)

			sets[utf8] = sets.get(utf8, []) + [character]

		charcol.add_sets(sets.keys())

		for set_name, characters in sets.items():
			charcol.append_characters(set_name, characters)

		return charcol
開發者ID:titeipa,項目名稱:CharacterClassifier,代碼行數:45,代碼來源:unipen.py

示例13: _handle_START_BOX

    def _handle_START_BOX(self, args):
        if self._char:
            self._characters.append(self._char)
            if self._col == self.FRAME_COUNT_COL - 1:
                self._col = 0
                if self._row == self.FRAME_COUNT_ROW - 1:
                    self._row = 0
                else:
                    self._row += 1
            else:
                self._col += 1

        self._char = Character()
開發者ID:Ghost3,項目名稱:tegaki,代碼行數:13,代碼來源:kuchibue.py

示例14: from_character_directory

	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,代碼行數:37,代碼來源:charcol.py

示例15: testValidate

    def testValidate(self):
        path = os.path.join(self.currdir, "data", "character.xml")
        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>
    <utf8>防</utf8>
    <strokes>
      <stroke>
      </stroke>
    </strokes>
"""

        try:
            self.assertTrue(Character.validate(buf))
            self.assertFalse(Character.validate(invalid))
            self.assertFalse(Character.validate(malformed))
        except NotImplementedError:
            sys.stderr.write("lxml missing!\n")
            pass
開發者ID:cburgmer,項目名稱:tegaki,代碼行數:36,代碼來源:test_character.py


注:本文中的tegaki.character.Character類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。