How to use the pypinyin.get_pinyin.PyInfo function in pypinyin

To help you get started, we’ve selected a few pypinyin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rainforest32 / pypinyin / pypinyin / get_pinyin.py View on Github external
freq = float(sps[2])
                if word in self.pydict:
                    wordInfoLen = len(self.pydict[word])
                    i = 0
                    dup = False
                    while i < wordInfoLen:
                        if self.pydict[word][i].py == py:
                            if self.pydict[word][i].freq < freq:
                                self.pydict[word][i].freq = freq
                            dup = True
                            break
                        if self.pydict[word][i].freq < freq:
                            break
                        i += 1
                    if not dup:
                        pyInfo = PyInfo()
                        pyInfo.py = py
                        pyInfo.freq = freq
                        self.pydict[word].insert(i, pyInfo)
                        wordInfoLen += 1
                        for j in range(i + 1, wordInfoLen):
                            if self.pydict[word][j].py == py:
                                del self.pydict[word][j]
                                break
                else:
                    pyInfo = PyInfo()
                    pyInfo.py = py
                    pyInfo.freq = freq
                    self.pydict[word] = [ pyInfo ]
        except Exception, e:
            try:
                f.close()
github rainforest32 / pypinyin / pypinyin / get_pinyin.py View on Github external
break
                        if self.pydict[word][i].freq < freq:
                            break
                        i += 1
                    if not dup:
                        pyInfo = PyInfo()
                        pyInfo.py = py
                        pyInfo.freq = freq
                        self.pydict[word].insert(i, pyInfo)
                        wordInfoLen += 1
                        for j in range(i + 1, wordInfoLen):
                            if self.pydict[word][j].py == py:
                                del self.pydict[word][j]
                                break
                else:
                    pyInfo = PyInfo()
                    pyInfo.py = py
                    pyInfo.freq = freq
                    self.pydict[word] = [ pyInfo ]
        except Exception, e:
            try:
                f.close()
            except:
                pass
            return False
        self.is_load = True
        return True
github rainforest32 / pypinyin / pypinyin / get_pinyin.py View on Github external
pyInfos = self.pydict[seg]
                    pyInfoList.append(pyInfos)
                    continue
            pyInfo = PyInfo()
            pyInfo.py = seg
            pyInfo.freq = 1
            pyInfoList.append([ pyInfo ])
            
        results = []
        pyInfoListLen = len(pyInfoList)
        pos = [ 0 for i in range(pyInfoListLen)]
        max_pos = [ len(pyInfoList[i]) - 1 for i in range(pyInfoListLen)]
        
        while True:
            complete = True
            ri = PyInfo()
            ri.freq = 1
            for i in range(pyInfoListLen):
                if ri.py == '':
                    ri.py = pyInfoList[i][pos[i]].py
                else:
                    ri.py += ' ' + pyInfoList[i][pos[i]].py
                ri.freq *= pyInfoList[i][pos[i]].freq
            results.append(ri)
            
            for i in range(pyInfoListLen - 1, -1, -1):
                if pos[i] < max_pos[i]:
                    pos[i] += 1
                    complete = False
                    break
                else:
                    pos[i] = 0