-
Notifications
You must be signed in to change notification settings - Fork 47
/
suntsu.html
279 lines (221 loc) · 18.3 KB
/
suntsu.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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#2D2D2D" />
<title>NLTK :: nltk.chat.suntsu</title>
<link rel="stylesheet" href="../../../_static/css/nltk_theme.css"/>
<link rel="stylesheet" href="../../../_static/css/custom.css"/>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script type="text/javascript" src="../../../_static/documentation_options.js"></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 src="https://email.tl.fortawesome.com/c/eJxNjUEOgyAQAF8jR7Kw6wIHDh7sP1Cw2mgxgmn6-3JsMqc5zEQfE8dkxOY1KKMUOI3ACFKRJpSW2AAp7ontYIaxI6i7XPJVwyeVfCQ550Os3jLrGSNOLgbdAy6s0PBk2TFNjEbsfq31LB0OnX407pJa5v2faRadwSW63mn5KuLyR9j2tgx3zecanl-55R_-jjPs"></script>
</head>
<body>
<div id="nltk-theme-container">
<header>
<div id="logo-container">
<h1>
<a href="../../../index.html">NLTK</a>
</h1>
</div>
<div id="project-container">
<h1>Documentation</h1>
</div>
<a id="menu-toggle" class="fa fa-bars" aria-hidden="true"></a>
<script type="text/javascript">
$("#menu-toggle").click(function() {
$("#menu-toggle").toggleClass("toggled");
$("#side-menu-container").slideToggle(300);
});
</script>
</header>
<div id="content-container">
<div id="side-menu-container">
<div id="search" role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<div id="side-menu" role="navigation">
<p class="caption" role="heading"><span class="caption-text">NLTK Documentation</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../api/nltk.html">API Reference</a></li>
<li class="toctree-l1"><a class="reference external" href="http://www.nltk.org/howto">Example Usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../py-modindex.html">Module Index</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/nltk/nltk/wiki">Wiki</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/nltk/nltk/wiki/FAQ">FAQ</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Installation</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../install.html">Installing NLTK</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../data.html">Installing NLTK Data</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">More</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../news.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../contribute.html">Contributing to NLTK</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../team.html">NLTK Team</a></li>
</ul>
</div>
</div>
<div id="main-content-container">
<div id="main-content" role="main">
<h1>Source code for nltk.chat.suntsu</h1><div class="highlight"><pre>
<span></span><span class="c1"># Natural Language Toolkit: Sun Tsu-Bot</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2001-2021 NLTK Project</span>
<span class="c1"># Author: Sam Huston 2007</span>
<span class="c1"># URL: <http://nltk.org/></span>
<span class="c1"># For license information, see LICENSE.TXT</span>
<span class="sd">"""</span>
<span class="sd">Tsu bot responds to all queries with a Sun Tsu sayings</span>
<span class="sd">Quoted from Sun Tsu's The Art of War</span>
<span class="sd">Translated by LIONEL GILES, M.A. 1910</span>
<span class="sd">Hosted by the Gutenberg Project</span>
<span class="sd">http://www.gutenberg.org/</span>
<span class="sd">"""</span>
<span class="kn">from</span> <span class="nn">nltk.chat.util</span> <span class="kn">import</span> <span class="n">Chat</span><span class="p">,</span> <span class="n">reflections</span>
<span class="n">pairs</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">(</span><span class="sa">r</span><span class="s2">"quit"</span><span class="p">,</span> <span class="p">(</span><span class="s2">"Good-bye."</span><span class="p">,</span> <span class="s2">"Plan well"</span><span class="p">,</span> <span class="s2">"May victory be your future"</span><span class="p">)),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[^\?]*\?"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"Please consider whether you can answer your own question."</span><span class="p">,</span>
<span class="s2">"Ask me no questions!"</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[0-9]+(.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"It is the rule in war, if our forces are ten to the enemy's one, to surround him; if five to one, to attack him; if twice as numerous, to divide our army into two."</span><span class="p">,</span>
<span class="s2">"There are five essentials for victory"</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[A-Ca-c](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"The art of war is of vital importance to the State."</span><span class="p">,</span>
<span class="s2">"All warfare is based on deception."</span><span class="p">,</span>
<span class="s2">"If your opponent is secure at all points, be prepared for him. If he is in superior strength, evade him."</span><span class="p">,</span>
<span class="s2">"If the campaign is protracted, the resources of the State will not be equal to the strain."</span><span class="p">,</span>
<span class="s2">"Attack him where he is unprepared, appear where you are not expected."</span><span class="p">,</span>
<span class="s2">"There is no instance of a country having benefited from prolonged warfare."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[D-Fd-f](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"The skillful soldier does not raise a second levy, neither are his supply-wagons loaded more than twice."</span><span class="p">,</span>
<span class="s2">"Bring war material with you from home, but forage on the enemy."</span><span class="p">,</span>
<span class="s2">"In war, then, let your great object be victory, not lengthy campaigns."</span><span class="p">,</span>
<span class="s2">"To fight and conquer in all your battles is not supreme excellence; supreme excellence consists in breaking the enemy's resistance without fighting."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[G-Ig-i](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"Heaven signifies night and day, cold and heat, times and seasons."</span><span class="p">,</span>
<span class="s2">"It is the rule in war, if our forces are ten to the enemy's one, to surround him; if five to one, to attack him; if twice as numerous, to divide our army into two."</span><span class="p">,</span>
<span class="s2">"The good fighters of old first put themselves beyond the possibility of defeat, and then waited for an opportunity of defeating the enemy."</span><span class="p">,</span>
<span class="s2">"One may know how to conquer without being able to do it."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[J-Lj-l](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"There are three ways in which a ruler can bring misfortune upon his army."</span><span class="p">,</span>
<span class="s2">"By commanding the army to advance or to retreat, being ignorant of the fact that it cannot obey. This is called hobbling the army."</span><span class="p">,</span>
<span class="s2">"By attempting to govern an army in the same way as he administers a kingdom, being ignorant of the conditions which obtain in an army. This causes restlessness in the soldier's minds."</span><span class="p">,</span>
<span class="s2">"By employing the officers of his army without discrimination, through ignorance of the military principle of adaptation to circumstances. This shakes the confidence of the soldiers."</span><span class="p">,</span>
<span class="s2">"There are five essentials for victory"</span><span class="p">,</span>
<span class="s2">"He will win who knows when to fight and when not to fight."</span><span class="p">,</span>
<span class="s2">"He will win who knows how to handle both superior and inferior forces."</span><span class="p">,</span>
<span class="s2">"He will win whose army is animated by the same spirit throughout all its ranks."</span><span class="p">,</span>
<span class="s2">"He will win who, prepared himself, waits to take the enemy unprepared."</span><span class="p">,</span>
<span class="s2">"He will win who has military capacity and is not interfered with by the sovereign."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[M-Om-o](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"If you know the enemy and know yourself, you need not fear the result of a hundred battles."</span><span class="p">,</span>
<span class="s2">"If you know yourself but not the enemy, for every victory gained you will also suffer a defeat."</span><span class="p">,</span>
<span class="s2">"If you know neither the enemy nor yourself, you will succumb in every battle."</span><span class="p">,</span>
<span class="s2">"The control of a large force is the same principle as the control of a few men: it is merely a question of dividing up their numbers."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[P-Rp-r](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"Security against defeat implies defensive tactics; ability to defeat the enemy means taking the offensive."</span><span class="p">,</span>
<span class="s2">"Standing on the defensive indicates insufficient strength; attacking, a superabundance of strength."</span><span class="p">,</span>
<span class="s2">"He wins his battles by making no mistakes. Making no mistakes is what establishes the certainty of victory, for it means conquering an enemy that is already defeated."</span><span class="p">,</span>
<span class="s2">"A victorious army opposed to a routed one, is as a pound's weight placed in the scale against a single grain."</span><span class="p">,</span>
<span class="s2">"The onrush of a conquering force is like the bursting of pent-up waters into a chasm a thousand fathoms deep."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[S-Us-u](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"What the ancients called a clever fighter is one who not only wins, but excels in winning with ease."</span><span class="p">,</span>
<span class="s2">"Hence his victories bring him neither reputation for wisdom nor credit for courage."</span><span class="p">,</span>
<span class="s2">"Hence the skillful fighter puts himself into a position which makes defeat impossible, and does not miss the moment for defeating the enemy."</span><span class="p">,</span>
<span class="s2">"In war the victorious strategist only seeks battle after the victory has been won, whereas he who is destined to defeat first fights and afterwards looks for victory."</span><span class="p">,</span>
<span class="s2">"There are not more than five musical notes, yet the combinations of these five give rise to more melodies than can ever be heard."</span><span class="p">,</span>
<span class="s2">"Appear at points which the enemy must hasten to defend; march swiftly to places where you are not expected."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span>
<span class="sa">r</span><span class="s2">"[V-Zv-z](.*)"</span><span class="p">,</span>
<span class="p">(</span>
<span class="s2">"It is a matter of life and death, a road either to safety or to ruin."</span><span class="p">,</span>
<span class="s2">"Hold out baits to entice the enemy. Feign disorder, and crush him."</span><span class="p">,</span>
<span class="s2">"All men can see the tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved."</span><span class="p">,</span>
<span class="s2">"Do not repeat the tactics which have gained you one victory, but let your methods be regulated by the infinite variety of circumstances."</span><span class="p">,</span>
<span class="s2">"So in war, the way is to avoid what is strong and to strike at what is weak."</span><span class="p">,</span>
<span class="s2">"Just as water retains no constant shape, so in warfare there are no constant conditions."</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="p">(</span><span class="sa">r</span><span class="s2">"(.*)"</span><span class="p">,</span> <span class="p">(</span><span class="s2">"Your statement insults me."</span><span class="p">,</span> <span class="s2">""</span><span class="p">)),</span>
<span class="p">)</span>
<span class="n">suntsu_chatbot</span> <span class="o">=</span> <span class="n">Chat</span><span class="p">(</span><span class="n">pairs</span><span class="p">,</span> <span class="n">reflections</span><span class="p">)</span>
<div class="viewcode-block" id="suntsu_chat"><a class="viewcode-back" href="../../../api/nltk.chat.suntsu.html#nltk.chat.suntsu.suntsu_chat">[docs]</a><span class="k">def</span> <span class="nf">suntsu_chat</span><span class="p">():</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Talk to the program by typing in plain English, using normal upper-"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'and lower-case letters and punctuation. Enter "quit" when done.'</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"="</span> <span class="o">*</span> <span class="mi">72</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"You seek enlightenment?"</span><span class="p">)</span>
<span class="n">suntsu_chatbot</span><span class="o">.</span><span class="n">converse</span><span class="p">()</span></div>
<div class="viewcode-block" id="demo"><a class="viewcode-back" href="../../../api/nltk.chat.suntsu.html#nltk.chat.suntsu.demo">[docs]</a><span class="k">def</span> <span class="nf">demo</span><span class="p">():</span>
<span class="n">suntsu_chat</span><span class="p">()</span></div>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
<span class="n">demo</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
<footer>
<div id="footer-info">
<ul id="build-details">
<li class="footer-element">
<a href="https://github.com/nltk/nltk/tree/3.6.5">3.6.5</a>
</li>
<li class="footer-element">
Oct 11, 2021
</li>
</ul>
<div id="copyright">
© 2021, NLTK Project
</div>
<div id="credit">
created with <a href="http://sphinx-doc.org/">Sphinx</a> and <a href="https://github.com/tomaarsen/nltk_theme">NLTK Theme</a>
</div>
</div>
</footer>
</div>
</body>
</html>