MCPcopy Create free account
hub / github.com/baidu/lac / load_customization

Method load_customization

python/LAC/custom.py:76–107  ·  view source on GitHub ↗

装载人工干预词典

(self, filename, sep=None)

Source from the content-addressed store, hash-verified

74 self.ac.add_word(phrase)
75
76 def load_customization(self, filename, sep=None):
77 """装载人工干预词典"""
78 self.ac = TriedTree()
79 with open(filename, 'r', encoding='utf8') as f:
80 for line in f:
81 if sep == None:
82 words = line.strip().split()
83 else:
84 sep = strdecode(sep)
85 words = line.strip().split(sep)
86
87 if len(words) == 0:
88 continue
89
90 phrase = ""
91 tags = []
92 offset = []
93 for word in words:
94 if word.rfind('/') < 1:
95 phrase += word
96 tags.append('')
97 else:
98 phrase += word[:word.rfind('/')]
99 tags.append(word[word.rfind('/') + 1:])
100 offset.append(len(phrase))
101
102 if len(phrase) < 2 and tags[0] == '':
103 continue
104
105 self.dictitem[phrase] = (tags, offset)
106 self.ac.add_word(phrase)
107 self.ac.make()
108
109 def parse_customization(self, query, lac_tags):
110 """使用人工干预词典修正lac模型的输出"""

Callers 1

custom.pyFile · 0.45

Calls 4

TriedTreeClass · 0.90
strdecodeFunction · 0.90
add_wordMethod · 0.45
makeMethod · 0.45

Tested by

no test coverage detected