We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
# 更加简洁(more pythonic)的IMM算法(可用OOP) _dictionary = {'南京', '南京市', '南京市长', '市长', '长江', '长江大桥', '江大桥', '大桥', '桥'} def imm(text, maxlen=4): # inverse maximum matching method dictionary = _dictionary result = [] index = len(text) while index > 0: m = min((index, maxlen)) # dictionary = {e for e in _dictionary if e.endswith(text[index-1])} # for speeding up for size in range(m, 0, -1): piece = text[(index-size):index] if piece in dictionary: result.insert(0, piece) index -= size break else: index -= 1 return result result = imm('南京市长江大桥') print(result)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: