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


Python Character.get_writing方法代码示例

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


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

示例1: testIsSmall

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import get_writing [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

示例2: UnipenParser

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import get_writing [as 别名]
class UnipenParser(UnipenEventParser):

    def __init__(self):
        UnipenEventParser.__init__(self)
        self._labels = []
        self._characters = []
        self._char = None

    def _handle_SEGMENT(self, args):
        seg_type, delimit, quality, label = args.split(" ")
        if seg_type == "CHARACTER":
            label = label.strip()[1:-1]
            self._labels.append(label)

    def _handle_START_BOX(self, args):
        if self._char:
            self._characters.append(self._char)
        self._char = Character() 

    def _handle_PEN_DOWN(self, args):
        writing = self._char.get_writing()
        points = [[int(p_) for p_ in p.split(" ")] \
                    for p in args.strip().split("\n")]
        stroke = Stroke()
        for x, y in points:
            stroke.append_point(Point(x,y))
        writing.append_stroke(stroke)

    def _handle_INCLUDE(self, args):
        if not self._parsed_file: return

        include_filename = args.upper()
        currdir = os.path.dirname(os.path.abspath(self._parsed_file))

        # FIXME: don't hardcode include paths
        include1 = os.path.join(currdir, "INCLUDE")
        include2 = os.path.join(currdir, "..", "INCLUDE")

        for include in (include1, include2, currdir):   
            path = os.path.join(include, include_filename)
            if os.path.exists(path):
                parser = UnipenProxyParser(self.handle_keyword)
                parser.parse_file(path)
                break

    def handle_keyword(self, keyword, args):
        try:
            func = getattr(self, "_handle_" + keyword)
        except AttributeError:
            pass
        else:
            func(args)

    def get_character_collection(self):
        charcol = CharacterCollection()
        assert(len(self._labels) == len(self._characters))

        # group characters with the same label into sets
        sets = {}
        for i in range(len(self._characters)):
            utf8 = self._labels[i]
            self._characters[i].set_utf8(utf8)
            sets[utf8] = sets.get(utf8, []) + [self._characters[i]]

        charcol.add_sets(sets.keys())

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

        return charcol
开发者ID:Ghost3,项目名称:tegaki,代码行数:72,代码来源:unipen.py

示例3: CharacterCollection

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import get_writing [as 别名]

#.........这里部分代码省略.........
        constructor is used.
        """
        if path is None:
            if self._path is not None:
                # an XML file was provided to constructor
                gzip, bz2 = _gzipbz2(self._path)
                self.write(self._path, gzip=gzip, bz2=bz2)
        else:
            if path.endswith(".chardb"):
                if self._dbpath != path:
                    # the collection changed its database name
                    # FIXME: this can rewritten more efficiently with
                    # the ATTACH command
                    if os.path.exists(path):
                        os.unlink(path)
                    newcc = CharacterCollection(path)
                    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))
开发者ID:Ghost3,项目名称:tegaki,代码行数:70,代码来源:charcol.py

示例4: KuchibueParser

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import get_writing [as 别名]
class KuchibueParser(UnipenParser):

    # The Kuchibue database has three major differences with Tegaki
    #
    # 1) (0, 0) is the left-bottom corner in the former while it's the top-
    #    left corner in the latter.
    # 2) the default screen size is 1280*960 for the former while it's
    #    1000 * 1000 for the latter
    # 3) the screen contains 152 boxes (19 columns, 8 rows) for the former
    #    while it contains only 1 for the latter

    def __init__(self):
        UnipenParser.__init__(self)
        self._labels = []
        self._characters = []
        self._char = None
        self._row = 0
        self._col = 0
        self._screen = None
        self._line = None

    def _handle_SEGMENT(self, args):
        seg_type, delimit, quality, label = args.split(" ")
        if seg_type == "SCREEN":
            self._screen = []
        elif seg_type == "LINE":
            self._screen.append(0) # number of characters in line
        elif seg_type == "CHARACTER":
            label = label.strip()[1:-1]
            if label.startswith("SJIS"):
                charcode = int("0" + label[4:], 16)
                try:
                    label = SHIFT_JIS_TABLE[charcode]
                except KeyError:
                    pass #print "missing character", hex(charcode)
                    
            self._labels.append(label)
            self._screen[-1] += 1

    def _handle_X_DIM(self, args):
        self.FRAME_WIDTH = int(args)

    def _handle_Y_DIM(self, args):
        self.FRAME_HEIGHT = int(args)

    def _get_int_pair_from_line(self, line):
        k, v = line.split(":")
        return [int(val) for val in v.strip().split(" ")]

    def _handle_PAD(self, args):
        lines = [l.strip() for l in args.split("\n")]
        for line in lines:
            if line.startswith("Input Resolution"):
                self.INPUT_RESOLUTION_WIDTH, self.INPUT_RESOLUTION_HEIGHT = \
                    self._get_int_pair_from_line(line)

    def _handle_DATA_INFO(self, args):
        lines = [l.strip() for l in args.split("\n")]
        for line in lines:
            if line.startswith("Frame start"):
                self.FRAME_START_X, self.FRAME_START_Y = \
                    self._get_int_pair_from_line(line)
            elif line.startswith("Frame  step"):
                self.FRAME_STEP_X, self.FRAME_STEP_Y = \
                    self._get_int_pair_from_line(line)  
            elif line.startswith("Frame count"):
                self.FRAME_COUNT_COL, self.FRAME_COUNT_ROW = \
                    self._get_int_pair_from_line(line)    

    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()

    def handle_eof(self):
        if self._char:
            self._characters.append(self._char)

    def _get_coordinates(self, x, y):
        y = abs(y - self.INPUT_RESOLUTION_HEIGHT) # change basis
        x -= self.FRAME_START_X # remove the padding
        x -= self.FRAME_STEP_X * self._col # translate to the left
        x *= float(Writing.WIDTH) / self.FRAME_WIDTH # scale for x = 1000
        y -= (self.INPUT_RESOLUTION_HEIGHT - self.FRAME_START_Y) # padding
        y -= self.FRAME_STEP_Y * self._row # translate to the top
        y *= float(Writing.HEIGHT) / self.FRAME_HEIGHT # scale for y = 1000
        return (int(x), int(y))

    def _handle_PEN_DOWN(self, args):
        writing = self._char.get_writing()
        points = [[int(p_) for p_ in p.split(" ")] \
#.........这里部分代码省略.........
开发者ID:Ghost3,项目名称:tegaki,代码行数:103,代码来源:kuchibue.py

示例5: set_model

# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import get_writing [as 别名]
        """
        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:
        raise Exception, "Not an available model"
开发者ID:Belgabor,项目名称:Tegaki,代码行数:33,代码来源:recognizer.py


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