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

Method parse_customization

python/LAC/custom.py:109–135  ·  view source on GitHub ↗

使用人工干预词典修正lac模型的输出

(self, query, lac_tags)

Source from the content-addressed store, hash-verified

107 self.ac.make()
108
109 def parse_customization(self, query, lac_tags):
110 """使用人工干预词典修正lac模型的输出"""
111 if not self.ac:
112 logging.warning("customization dict is not load")
113 return
114
115 # FMM前向最大匹配
116 ac_res = self.ac.search(query)
117
118 for begin, end in ac_res:
119 phrase = query[begin:end]
120 index = begin
121
122 tags, offsets = self.dictitem[phrase]
123 for tag, offset in zip(tags, offsets):
124 while index < begin + offset:
125 if len(tag) == 0:
126 lac_tags[index] = lac_tags[index][:-1] + 'I'
127 else:
128 lac_tags[index] = tag + "-I"
129 index += 1
130
131 lac_tags[begin] = lac_tags[begin][:-1] + 'B'
132 for offset in offsets:
133 index = begin + offset
134 if index < len(lac_tags):
135 lac_tags[index] = lac_tags[index][:-1] + 'B'
136
137
138if __name__ == '__main__':

Callers 3

custom.pyFile · 0.45
parse_resultMethod · 0.45
parse_resultMethod · 0.45

Calls 1

searchMethod · 0.45

Tested by

no test coverage detected