jtyoui.algorithm package¶
Submodules¶
jtyoui.algorithm.MatchingAlgorithm module¶
匹配算法
-
class
jtyoui.algorithm.MatchingAlgorithm.
FMMA
(ls, sort=False)[源代码]¶ 基类:
object
FMMA(Forward Maximum Matching Algorithms)正向最大匹配算法
>>> r = FMMA(ls=['我们', '野生', '动物园', '在野'], sort=True) >>> print(r.cut('我们在野生动物园玩', 3)) >>> # ['我们', '在野', '生', '动物园', '玩']
-
class
jtyoui.algorithm.MatchingAlgorithm.
RMMA
(ls, sort=False)[源代码]¶ 基类:
object
RMMA(Reverse Maximum Matching Algorithms)逆向最大匹配算法
>>> r = RMMA(ls=['我们', '野生', '动物园', '在野'], sort=True) >>> print(r.cut('我们在野生动物园玩', 3)) >>> # ['我们', '在', '野生', '动物园', '玩']
jtyoui.algorithm.ReplaceAlgorithm module¶
-
jtyoui.algorithm.ReplaceAlgorithm.
map_replace
(str_: str, key: [<class 'list'>, <class 'str'>] = None, value: [<class 'list'>, <class 'str'>] = None, maps: dict = None) → str[源代码]¶ 映射替换,最好使用maps字典映射
>>> print(map_replace('[中国]', '[]', '【】')) #【中国】 >>> print(map_replace('[中国]', maps={'[': '【', ']': '】'})) #【中国】
参数: - str – 字符串
- key – 替换字符
- value – 被替换的字符
- maps – 字符映射
返回: 替换完毕的字符串
jtyoui.algorithm.SearchAlgorithm module¶
搜索算法
jtyoui.algorithm.SortAlgorithm module¶
排序算法
jtyoui.algorithm.TreeAlgorithm module¶
-
class
jtyoui.algorithm.TreeAlgorithm.
Tree
(value=None, parent=None)[源代码]¶ 基类:
object
创建一颗树
>>> tree = Tree(value='Root') >>> for d in data: t = Tree(value=d, parent=tree) tree.add_child(t)
-
jtyoui.algorithm.TreeAlgorithm.
dict_create_tree
(data: dict, tree: jtyoui.algorithm.TreeAlgorithm.Tree = <jtyoui.algorithm.TreeAlgorithm.Tree object>)[源代码]¶ - 创建下面的树结构
- a
b c d
e f g |g h| k m
>>> ds = {'a': {'b': ['e', 'f', 'g'], 'c': ['g', 'h'], 'd': ['k', 'm']}} >>> ts = dict_create_tree(ds) >>> print(ts)
参数: - data – 创建树型结构,对照上面,例如:ds = {‘a’: {‘b’: [‘e’, ‘f’, ‘g’], ‘c’: [‘g’, ‘h’], ‘d’: [‘k’, ‘m’]}}
- tree – 默认为上一层树结构,不需要传入
返回: 一颗自动带有root根目录的树结构