使用人工干预词典修正lac模型的输出
(self, query, lac_tags)
| 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 | |
| 138 | if __name__ == '__main__': |
no test coverage detected