• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python character.Character类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Character类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: _start_element

    def _start_element(self, name, attrs):
        self._tag = name

        if self._first_tag:
            self._first_tag = False
            if self._tag != "character-collection":
                raise ValueError, \
                      "The very first tag should be <character-collection>"

        if self._tag == "set":
            if not attrs.has_key("name"):
                raise ValueError, "<set> should have a name attribute"

            self._curr_set_name = attrs["name"].encode("UTF-8")
            self.add_set(self._curr_set_name)

        if self._tag == "character":
            self._curr_char = Character()
            self._curr_writing = self._curr_char.get_writing()
            self._curr_width = None
            self._curr_height = None
            self._curr_utf8 = None

        if self._tag == "stroke":
            self._curr_stroke = Stroke()

        elif self._tag == "point":
            point = Point()

            for key in ("x", "y", "pressure", "xtilt", "ytilt", "timestamp"):
                if attrs.has_key(key):
                    value = attrs[key].encode("UTF-8")
                    if key in ("pressure", "xtilt", "ytilt"):
                        value = float(value)
                    else:
                        value = int(float(value))
                else:
                    value = None

                setattr(point, key, value)

            self._curr_stroke.append_point(point)
开发者ID:Ghost3,项目名称:tegaki,代码行数:42,代码来源:charcol.py


示例17: testReadXMLBZ2File

    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,代码行数:6,代码来源:test_character.py


示例18: WritingIconView

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,代码行数:30,代码来源:iconview.py


示例19: CharacterCollection

class CharacterCollection(_XmlBase):
    """
    A collection of L{Characters<Character>}.

    A CharacterCollection is composed of sets.
    Each set can be composed of zero, one, or more characters.

    /!\ Sets do not necessarily contain only characters of the same class
    / utf8 value. Sets may also be used to group characters in other fashions
    (e.g. by number of strokes, by handwriting quality, etc...).
    Therefore the set name is not guaranteed to contain the utf8 value of
    the characters of that set. The utf8 value must be retrieved from each
    character individually.

    Building character collection objects
    =====================================

    A character collection can be built from scratch progmatically:


    >>> char = Character()
    >>> charcol = CharacterCollection()
    >>> charcol.add_set("my set")
    >>> charcol.append_character("my set", char)

    Reading XML files
    =================

    A character collection can be read from an XML file:

    >>> charcol = CharacterCollection()
    >>> charcol.read("myfile")

    Gzip-compressed and bzip2-compressed XML files can also be read:

    >>> charcol = CharacterCollection()
    >>> charcol.read("myfilegz", gzip=True)

    >>> charcol = Character()
    >>> charcol.read("myfilebz", bz2=True)

    A similar method read_string exists to read the XML from a string
    instead of a file.

    For convenience, you can directly load a character collection by passing it
    the file to load. In that case, compression is automatically detected based
    on file extension (.gz, .bz2).

    >>> charcol = Character("myfile.xml.gz")

    The recommended extension for XML character collection files is .charcol.

    Writing XML files
    =================

    A character collection can be saved to an XML file by using the write()
    method.

    >>> charcol.write("myfile")

    The write method has gzip and bz2 arguments just like read(). In addition,
    there is a write_string method which generates a string instead of a file.

    For convenience, you can save a character collection with the save() method.
    It automatically detects compression based on the file extension.

    >>> charcol.save("mynewfile.xml.bz2")

    If the CharacterCollection object was passed a file when it was constructed,
    the path can ce omitted.

    >>> charcol = Character("myfile.gz")
    >>> charcol.save()

    Using .chardb files
    ===================

    XML files allow to retain human-readability and are ideal for small
    character collections. However, they force the whole database to be kept
    in memory. For larger collections, it's recommended to use .chardb files
    instead. Their loading is faster and the whole collection doesn't
    need be kept entirely in memory. However human-readability ist lost.

    >>> charcol = CharacterCollection("charcol.chardb")
    [...]
    >>> charcol.save()

    The .chardb extension is required.
    """

    #: With WRITE_BACK set to True, proxy objects are returned in place of
    #: character, writing, stroke and point objects in order to automatically
    #: reflect changes to these objects back to the sqlite db.
    #: However, there is probably overhead usigng them.
    WRITE_BACK = True

    def get_auto_commit(self):
        return True if self._con.isolation_level is None else False

    def set_auto_commit(self, auto):
#.........这里部分代码省略.........
开发者ID:Ghost3,项目名称:tegaki,代码行数:101,代码来源:charcol.py


示例20: _convert_character

def _convert_character(data):
    # converts a BLOB into an object
    char = Character()
    char.read_string(base64.b64decode(data), gzip=True)
    return char
开发者ID:Ghost3,项目名称:tegaki,代码行数:5,代码来源:charcol.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python router.to_path函数代码示例发布时间:2022-05-27
下一篇:
Python messages.TeamcityServiceMessages类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap