suntsu.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # Natural Language Toolkit: Sun Tsu-Bot
  2. #
  3. # Copyright (C) 2001-2019 NLTK Project
  4. # Author: Sam Huston 2007
  5. # URL: <http://nltk.org/>
  6. # For license information, see LICENSE.TXT
  7. """
  8. Tsu bot responds to all queries with a Sun Tsu sayings
  9. Quoted from Sun Tsu's The Art of War
  10. Translated by LIONEL GILES, M.A. 1910
  11. Hosted by the Gutenberg Project
  12. http://www.gutenberg.org/
  13. """
  14. from __future__ import print_function
  15. from nltk.chat.util import Chat, reflections
  16. pairs = (
  17. (r'quit', ("Good-bye.", "Plan well", "May victory be your future")),
  18. (
  19. r'[^\?]*\?',
  20. (
  21. "Please consider whether you can answer your own question.",
  22. "Ask me no questions!",
  23. ),
  24. ),
  25. (
  26. r'[0-9]+(.*)',
  27. (
  28. "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.",
  29. "There are five essentials for victory",
  30. ),
  31. ),
  32. (
  33. r'[A-Ca-c](.*)',
  34. (
  35. "The art of war is of vital importance to the State.",
  36. "All warfare is based on deception.",
  37. "If your opponent is secure at all points, be prepared for him. If he is in superior strength, evade him.",
  38. "If the campaign is protracted, the resources of the State will not be equal to the strain.",
  39. "Attack him where he is unprepared, appear where you are not expected.",
  40. "There is no instance of a country having benefited from prolonged warfare.",
  41. ),
  42. ),
  43. (
  44. r'[D-Fd-f](.*)',
  45. (
  46. "The skillful soldier does not raise a second levy, neither are his supply-wagons loaded more than twice.",
  47. "Bring war material with you from home, but forage on the enemy.",
  48. "In war, then, let your great object be victory, not lengthy campaigns.",
  49. "To fight and conquer in all your battles is not supreme excellence; supreme excellence consists in breaking the enemy's resistance without fighting.",
  50. ),
  51. ),
  52. (
  53. r'[G-Ig-i](.*)',
  54. (
  55. "Heaven signifies night and day, cold and heat, times and seasons.",
  56. "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.",
  57. "The good fighters of old first put themselves beyond the possibility of defeat, and then waited for an opportunity of defeating the enemy.",
  58. "One may know how to conquer without being able to do it.",
  59. ),
  60. ),
  61. (
  62. r'[J-Lj-l](.*)',
  63. (
  64. "There are three ways in which a ruler can bring misfortune upon his army.",
  65. "By commanding the army to advance or to retreat, being ignorant of the fact that it cannot obey. This is called hobbling the army.",
  66. "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.",
  67. "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.",
  68. "There are five essentials for victory",
  69. "He will win who knows when to fight and when not to fight.",
  70. "He will win who knows how to handle both superior and inferior forces.",
  71. "He will win whose army is animated by the same spirit throughout all its ranks.",
  72. "He will win who, prepared himself, waits to take the enemy unprepared.",
  73. "He will win who has military capacity and is not interfered with by the sovereign.",
  74. ),
  75. ),
  76. (
  77. r'[M-Om-o](.*)',
  78. (
  79. "If you know the enemy and know yourself, you need not fear the result of a hundred battles.",
  80. "If you know yourself but not the enemy, for every victory gained you will also suffer a defeat.",
  81. "If you know neither the enemy nor yourself, you will succumb in every battle.",
  82. "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.",
  83. ),
  84. ),
  85. (
  86. r'[P-Rp-r](.*)',
  87. (
  88. "Security against defeat implies defensive tactics; ability to defeat the enemy means taking the offensive.",
  89. "Standing on the defensive indicates insufficient strength; attacking, a superabundance of strength.",
  90. "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.",
  91. "A victorious army opposed to a routed one, is as a pound's weight placed in the scale against a single grain.",
  92. "The onrush of a conquering force is like the bursting of pent-up waters into a chasm a thousand fathoms deep.",
  93. ),
  94. ),
  95. (
  96. r'[S-Us-u](.*)',
  97. (
  98. "What the ancients called a clever fighter is one who not only wins, but excels in winning with ease.",
  99. "Hence his victories bring him neither reputation for wisdom nor credit for courage.",
  100. "Hence the skillful fighter puts himself into a position which makes defeat impossible, and does not miss the moment for defeating the enemy.",
  101. "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.",
  102. "There are not more than five musical notes, yet the combinations of these five give rise to more melodies than can ever be heard.",
  103. "Appear at points which the enemy must hasten to defend; march swiftly to places where you are not expected.",
  104. ),
  105. ),
  106. (
  107. r'[V-Zv-z](.*)',
  108. (
  109. "It is a matter of life and death, a road either to safety or to ruin.",
  110. "Hold out baits to entice the enemy. Feign disorder, and crush him.",
  111. "All men can see the tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved.",
  112. "Do not repeat the tactics which have gained you one victory, but let your methods be regulated by the infinite variety of circumstances.",
  113. "So in war, the way is to avoid what is strong and to strike at what is weak.",
  114. "Just as water retains no constant shape, so in warfare there are no constant conditions.",
  115. ),
  116. ),
  117. (r'(.*)', ("Your statement insults me.", "")),
  118. )
  119. suntsu_chatbot = Chat(pairs, reflections)
  120. def suntsu_chat():
  121. print("Talk to the program by typing in plain English, using normal upper-")
  122. print('and lower-case letters and punctuation. Enter "quit" when done.')
  123. print('=' * 72)
  124. print("You seek enlightenment?")
  125. suntsu_chatbot.converse()
  126. def demo():
  127. suntsu_chat()
  128. if __name__ == "__main__":
  129. demo()