-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcy.rule_based.dictionary.html
445 lines (301 loc) · 18.9 KB
/
pcy.rule_based.dictionary.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pcy.rule_based.dictionary package — PCY: Python Completes You 0.0.1 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
<link rel="top" title="PCY: Python Completes You 0.0.1 documentation" href="index.html"/>
<link rel="up" title="pcy.rule_based package" href="pcy.rule_based.html"/>
<link rel="prev" title="pcy.rule_based package" href="pcy.rule_based.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> PCY: Python Completes You
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">pcy</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="pcy.html">pcy package</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="pcy.html#subpackages">Subpackages</a><ul class="current">
<li class="toctree-l4 current"><a class="reference internal" href="pcy.rule_based.html">pcy.rule_based package</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pcy.html#module-pcy">Module contents</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">PCY: Python Completes You</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li><a href="modules.html">pcy</a> »</li>
<li><a href="pcy.html">pcy package</a> »</li>
<li><a href="pcy.rule_based.html">pcy.rule_based package</a> »</li>
<li>pcy.rule_based.dictionary package</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/pcy.rule_based.dictionary.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="pcy-rule-based-dictionary-package">
<h1>pcy.rule_based.dictionary package<a class="headerlink" href="#pcy-rule-based-dictionary-package" title="Permalink to this headline">¶</a></h1>
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="module-pcy.rule_based.dictionary.autocomplete">
<span id="pcy-rule-based-dictionary-autocomplete-module"></span><h2>pcy.rule_based.dictionary.autocomplete module<a class="headerlink" href="#module-pcy.rule_based.dictionary.autocomplete" title="Permalink to this headline">¶</a></h2>
<p>Make an Autocomplete class to autocomplete incomplete words using a dictionary tree.</p>
<dl class="py class">
<dt id="pcy.rule_based.dictionary.autocomplete.Autocomplete">
<em class="property"><span class="pre">class</span> </em><code class="sig-prename descclassname"><span class="pre">pcy.rule_based.dictionary.autocomplete.</span></code><code class="sig-name descname"><span class="pre">Autocomplete</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dictionary</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pcy.rule_based.dictionary.autocomplete.Autocomplete" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Make an Autocomplete class to autocomplete incomplete words using a dictionary tree.</p>
<p>The Autocomplete class receives a Dictionary tree in its __init__ method. To get the Dictionary tree,
we need to use the DictionaryGenerator class.</p>
<p>To generate word suggestions, you need to call the .autocomplete method. Look at the example below to
understand everything.</p>
<dl>
<dt>Code Example:</dt><dd><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pcy.rule_based.dictionary</span> <span class="kn">import</span> <span class="n">Autocomplete</span>
<span class="c1"># here the tree is the dictionary</span>
<span class="n">auto</span> <span class="o">=</span> <span class="n">Autocomplete</span><span class="p">(</span><span class="n">tree</span><span class="p">)</span>
<span class="c1"># calling the method to get complete words based on the incomplete word</span>
<span class="c1"># here the word "hous" is the incomplete word and 10 is the number of suggestions to return</span>
<span class="n">words</span> <span class="o">=</span> <span class="n">auto</span><span class="o">.</span><span class="n">autocomplete</span><span class="p">(</span><span class="s2">"hous"</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="c1"># printing the words</span>
<span class="nb">print</span><span class="p">(</span><span class="n">words</span><span class="p">)</span>
<span class="c1"># --> ['housage', 'housal', 'housatonic', 'house', 'houseball', 'houseboat', 'houseboating', 'houseboats',</span>
<span class="c1"># 'houseboy', 'houseboys', 'housebote']</span>
</pre></div>
</div>
</dd>
</dl>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dictionary</strong> (<em>node</em>) – Instance of the node class. It can be created using the DictionaryGenerator class.</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ValueError</strong> – When the provided dictionary is not valid</p>
</dd>
</dl>
<dl class="py method">
<dt id="pcy.rule_based.dictionary.autocomplete.Autocomplete.autocomplete">
<code class="sig-name descname"><span class="pre">autocomplete</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">incomplete_word</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">no_of_suggestions</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pcy.rule_based.dictionary.autocomplete.Autocomplete.autocomplete" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an array of suggestions.</p>
<p>It returns the suggestions based on incomplete_word and no_of_suggestions.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>incomplete_word</strong> (<em>str</em>) – Incomplete word to autocomplete</p></li>
<li><p><strong>no_of_suggestions</strong> (<em>int</em>) – Number of suggestions (words) to provide</p></li>
</ul>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><ul class="simple">
<li><p><strong>ValueError</strong> – When the incomplete_word is not valid string</p></li>
<li><p><strong>ValueError</strong> – When incomplete_word is empty</p></li>
<li><p><strong>ValueError</strong> – When the no_of_suggestions is less than zero</p></li>
</ul>
</dd>
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>An array of strings containing suggestions</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>str[]</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pcy.rule_based.dictionary.dictionary_generator">
<span id="pcy-rule-based-dictionary-dictionary-generator-module"></span><h2>pcy.rule_based.dictionary.dictionary_generator module<a class="headerlink" href="#module-pcy.rule_based.dictionary.dictionary_generator" title="Permalink to this headline">¶</a></h2>
<p>Generate a dictionary tree based on words.</p>
<dl class="py class">
<dt id="pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator">
<em class="property"><span class="pre">class</span> </em><code class="sig-prename descclassname"><span class="pre">pcy.rule_based.dictionary.dictionary_generator.</span></code><code class="sig-name descname"><span class="pre">DictionaryGenerator</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">words</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Generate a dictionary tree based on words.</p>
<p>The DictionaryGenerator class generates a dictionary tree that can be used by the Autocomplete class to
autocomplete incomplete words.</p>
<dl>
<dt>Code Example:</dt><dd><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pcy.rule_based.dictionary</span> <span class="kn">import</span> <span class="n">DictionaryGenerator</span>
<span class="c1"># words list</span>
<span class="n">words</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">"words"</span><span class="p">:</span> <span class="s2">"Apple"</span><span class="p">,</span> <span class="s2">"data"</span><span class="p">:</span> <span class="p">{</span><span class="s2">"color"</span><span class="p">:</span> <span class="s2">"red"</span><span class="p">}},</span> <span class="p">{</span><span class="s2">"words"</span><span class="p">:</span> <span class="s2">"Anaconda"</span><span class="p">,</span> <span class="s2">"data"</span><span class="p">:</span> <span class="p">{</span><span class="s2">"color"</span><span class="p">:</span> <span class="s2">"black"</span><span class="p">}}]</span>
<span class="c1"># initializing the DictionaryGenerator class</span>
<span class="n">gen</span> <span class="o">=</span> <span class="n">DictionaryGenerator</span><span class="p">(</span><span class="n">words</span><span class="p">)</span>
<span class="c1"># generating the tree</span>
<span class="n">tree</span> <span class="o">=</span> <span class="n">gen</span><span class="o">.</span><span class="n">generate_dictionary</span><span class="p">()</span>
</pre></div>
</div>
</dd>
</dl>
<dl class="field-list simple">
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>ValueError</strong> – When the words are not a valid list</p></li>
<li><p><strong>ValueError</strong> – When there are no words in the words list</p></li>
<li><p><strong>ValueError</strong> – When the word is not a valid string</p></li>
<li><p><strong>ValueError</strong> – When the word is not a valid</p></li>
<li><p><strong>ValueError</strong> – When there is no dictionary tree</p></li>
<li><p><strong>ValueError</strong> – When the path to save the tree is not valid</p></li>
<li><p><strong>ValueError</strong> – When the path to save the tree is not valid</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Returns the tree</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>Node</p>
</dd>
</dl>
<dl class="py method">
<dt id="pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.add_word_to_dictionary">
<code class="sig-name descname"><span class="pre">add_word_to_dictionary</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">word</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.add_word_to_dictionary" title="Permalink to this definition">¶</a></dt>
<dd><p>Add word to generated dictionary.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>word</strong> (<em>any</em>) – Word that needed to be added</p></li>
<li><p><strong>data</strong> – Data that needed to be added with the word</p></li>
</ul>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><ul class="simple">
<li><p><strong>ValueError</strong> – When the word is not valid string</p></li>
<li><p><strong>ValueError</strong> – When the word is not a valid word</p></li>
<li><p><strong>ValueError</strong> – When there is no dictionary generated.</p></li>
</ul>
</dd>
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>New dictionary tree</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Node</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.generate_dictionary">
<code class="sig-name descname"><span class="pre">generate_dictionary</span></code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.generate_dictionary" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a new dictionary based on the words list.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>New dictionary tree</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Node</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.load_dictionary">
<em class="property"><span class="pre">classmethod</span> </em><code class="sig-name descname"><span class="pre">load_dictionary</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.load_dictionary" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a dictionary from the local file.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>path</strong> (<em>str</em>) – Path where the dictionary stored in the filesystem</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ValueError</strong> – When the path to the saved dictionary is not valid</p>
</dd>
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>Returns a new dictionary tree</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Node</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.save_dictionary">
<code class="sig-name descname"><span class="pre">save_dictionary</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pcy.rule_based.dictionary.dictionary_generator.DictionaryGenerator.save_dictionary" title="Permalink to this definition">¶</a></dt>
<dd><p>Save dictionary to the local filesystem.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>path</strong> (<em>str</em>) – Path to store the dictionary</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ValueError</strong> – When the path is not valid</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pcy.rule_based.dictionary">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-pcy.rule_based.dictionary" title="Permalink to this headline">¶</a></h2>
<p>Autocomplete incomplete words based on generated dictionary tree.</p>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="pcy.rule_based.html" class="btn btn-neutral" title="pcy.rule_based package" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2021, Abhishek Chatterjee.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'0.0.1',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>