@@ -41,6 +41,63 @@ def parse_domain(link):
41
41
return link .split ("//" )[- 1 ].split ("/" )[0 ]
42
42
43
43
44
+ # expand commonly used prefixes
45
+ # plt => pyplot
46
+ # sns => seaborn
47
+ # np => numpy
48
+ # pd => pandas
49
+ def expand_args (args ):
50
+ for i , arg in enumerate (args ):
51
+ arg = str (arg ).lower ()
52
+ args [i ] = arg
53
+ if arg == 'plt' :
54
+ args [i ] = 'pyplot'
55
+ continue
56
+
57
+ if arg .startswith ('plt.' ):
58
+ _ , rem = arg .split ('.' )
59
+ args [i ] = 'pyplot.' + rem .lower ()
60
+ continue
61
+
62
+ if arg == 'sns' :
63
+ args [i ] = 'seaborn'
64
+ continue
65
+
66
+ if arg .startswith ('sns.' ):
67
+ _ , rem = arg .split ('.' )
68
+ args [i ] = 'seaborn.' + rem
69
+ continue
70
+
71
+ if arg .lower () == 'np' :
72
+ args [i ] = 'numpy'
73
+ continue
74
+
75
+ if arg .startswith ('np.' ):
76
+ _ , rem = arg .split ('.' )
77
+ args [i ] = 'numpy.' + rem
78
+ continue
79
+
80
+ if arg .lower () == 'pd' :
81
+ args [i ] = 'pandas'
82
+ continue
83
+
84
+ if arg .startswith ('pd.' ):
85
+ _ , rem = arg .split ('.' )
86
+ args [i ] = 'pandas.' + rem
87
+ continue
88
+
89
+ return args
90
+
91
+
92
+ def search (args , keywords ):
93
+ # args is lower case already
94
+ args = expand_args (args )
95
+ for k in args :
96
+ keywords = [i for i in keywords if k in i .lower ()]
97
+ result = sorted (keywords , key = len )
98
+ return result
99
+
100
+
44
101
def main (wf ):
45
102
# The Workflow3 instance will be passed to the function
46
103
# you call from `Workflow3.run`.
@@ -67,15 +124,9 @@ def main(wf):
67
124
ml_data = wf .cached_data ('keywords' , get_ml_docs , max_age = 3600 * 24 * 3 )
68
125
assets = dict (wf .cached_data ('assets' , get_assets , max_age = 3600 * 24 * 7 ))
69
126
asset_keywords = sorted (assets .keys (), key = len )
127
+ result = search (args , ml_data .keys ())
70
128
71
- keywords = ml_data .keys ()
72
-
73
- for k in args :
74
- keywords = [i for i in keywords if k .lower () in i .lower ()]
75
-
76
- result = sorted (keywords , key = len )
77
-
78
- for ml_keyword in result [:20 ]:
129
+ for ml_keyword in result [:30 ]:
79
130
doc_link = ml_data [ml_keyword ]['url' ]
80
131
doc_desc = doc_link # default value
81
132
0 commit comments