-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.html
More file actions
194 lines (174 loc) · 9.51 KB
/
doc.html
File metadata and controls
194 lines (174 loc) · 9.51 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CFG-utils — CFG-utils 1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</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>
<link rel="top" title="CFG-utils 1 documentation" href="#" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="#">CFG-utils 1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="cfg-utils">
<h1>CFG-utils<a class="headerlink" href="#cfg-utils" title="Permalink to this headline">¶</a></h1>
<p>This script contains some functions to quickly use nltk.grammar.CFG to create and test context-free grammars.</p>
<p>Developped with python 2.7. by Vincent Antaki. Report bugs on the github page : <a class="reference external" href="https://github.com/DjAntaki/CFG-utils">https://github.com/DjAntaki/CFG-utils</a></p>
<p>If you want to use it with python >=3, use 2to3 (<a class="reference external" href="https://docs.python.org/2.7/library/2to3.html">https://docs.python.org/2.7/library/2to3.html</a>) to convert or change manually the call to function “raw_input” to “input”.</p>
<p>To see the functions associated with nltk.grammar.CFG :
<a class="reference external" href="http://www.nltk.org/api/nltk.html#nltk.grammar.CFG">http://www.nltk.org/api/nltk.html#nltk.grammar.CFG</a></p>
</div>
<div class="section" id="module-cfg_utils">
<span id="documentation"></span><h1>Documentation<a class="headerlink" href="#module-cfg_utils" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="cfg_utils._get_terminal_symbols">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">_get_terminal_symbols</tt><big>(</big><em>cfg</em><big>)</big><a class="headerlink" href="#cfg_utils._get_terminal_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a set of all the terminal symbols used in a nltk context-free grammar.</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils._recognizes">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">_recognizes</tt><big>(</big><em>parser</em>, <em>word</em><big>)</big><a class="headerlink" href="#cfg_utils._recognizes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if the CFG accepts that word and False if it doesnt.</p>
<p>parser : a nltk.parser instance for a cfg.
word : a list of tokens</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils._rules_input_prompt">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">_rules_input_prompt</tt><big>(</big><em>nonterminals</em>, <em>terminals</em><big>)</big><a class="headerlink" href="#cfg_utils._rules_input_prompt" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a list of nonterminals and a list of terminals, this function creates a list of rules
(aka grammar.Production instances) and returns it. There must be a whitespace between all terminals and nonterminals symbols. Extra whitespaces are ignored/conside.</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils.accepted_length">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">accepted_length</tt><big>(</big><em>cfg</em>, <em>x</em><big>)</big><a class="headerlink" href="#cfg_utils.accepted_length" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of every accepted word of a context-free grammar with a specific length</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils.accepted_under">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">accepted_under</tt><big>(</big><em>cfg</em>, <em>length</em><big>)</big><a class="headerlink" href="#cfg_utils.accepted_under" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of every accepted word of a context-free grammar under a given length.
cfg : a nltk.grammar.CFG instance.</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils.language_equals_under">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">language_equals_under</tt><big>(</big><em>cfg1</em>, <em>cfg2</em>, <em>length</em><big>)</big><a class="headerlink" href="#cfg_utils.language_equals_under" title="Permalink to this definition">¶</a></dt>
<dd><p>Compares all accepted words under a given length accepted by context-free grammar 1 and context-free grammar 2.</p>
<p>cfg1 & cfg2 : nltk.grammar.CFG instances
:return True if the they accept the same words, False if they do not.</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils.load_grammar">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">load_grammar</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#cfg_utils.load_grammar" title="Permalink to this definition">¶</a></dt>
<dd><p>Loads a nltk.CFG instance previously saved in binary with pickle at given path.</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils.quickprompt">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">quickprompt</tt><big>(</big><big>)</big><a class="headerlink" href="#cfg_utils.quickprompt" title="Permalink to this definition">¶</a></dt>
<dd><p>Interactive prompt to create a context-free grammar.</p>
<p>This prompt assumes that the non-terminal symbols is the uppercase alphabet and that the terminal symbols is lowercase alphabet. You only input rules and starting state.</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils.recognizes">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">recognizes</tt><big>(</big><em>cfg</em>, <em>word</em><big>)</big><a class="headerlink" href="#cfg_utils.recognizes" title="Permalink to this definition">¶</a></dt>
<dd><p>cfg : a nltk.grammar.CFG instance
word : a string with tokens separated with spaces.</p>
<p>A parser is created at every call of this function.</p>
</dd></dl>
<dl class="function">
<dt id="cfg_utils.recognizesAll">
<tt class="descclassname">cfg_utils.</tt><tt class="descname">recognizesAll</tt><big>(</big><em>cfg</em>, <em>words</em><big>)</big><a class="headerlink" href="#cfg_utils.recognizesAll" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of boolean values corresponding to [recognizes(cfg,w) for w in words].
cfg : a nltk.grammar.CFG instance
words must be a list of string with tokens separated with spaces.</p>
</dd></dl>
<div class="toctree-wrapper compound">
<ul class="simple">
</ul>
</div>
</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><a class="reference internal" href="genindex.html"><em>Index</em></a></li>
<li><a class="reference internal" href="py-modindex.html"><em>Module Index</em></a></li>
<li><a class="reference internal" href="search.html"><em>Search Page</em></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="#">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">CFG-utils</a></li>
<li><a class="reference internal" href="#module-cfg_utils">Documentation</a></li>
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/index.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="#">CFG-utils 1 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2015, Vincent Antaki.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
</div>
</body>
</html>