本文整理汇总了Python中tegaki.character.Character.set_utf8方法的典型用法代码示例。如果您正苦于以下问题:Python Character.set_utf8方法的具体用法?Python Character.set_utf8怎么用?Python Character.set_utf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tegaki.character.Character
的用法示例。
在下文中一共展示了Character.set_utf8方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_stroke_collection
# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import set_utf8 [as 别名]
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
示例2: _getCharacter
# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import set_utf8 [as 别名]
def _getCharacter(self):
writing = self._getWriting()
char = Character()
char.set_writing(writing)
char.set_utf8("A")
return char
示例3: set_writings
# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import set_utf8 [as 别名]
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)
示例4: _end_element
# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import set_utf8 [as 别名]
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
示例5: get_character_collection
# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import set_utf8 [as 别名]
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
示例6: CharacterCollection
# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import set_utf8 [as 别名]
#.........这里部分代码省略.........
newcc.merge([self])
newcc.commit()
del newcc
self.bind(path)
else:
gzip, bz2 = _gzipbz2(path)
self.write(path, gzip=gzip, bz2=bz2)
self.commit()
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
@staticmethod
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: