Accelerated C++ 7.4 生成句子
来源:互联网 发布:java 数组分割 编辑:程序博客网 时间:2024/06/08 07:20
We'll wrap up this chapter with a slightly more complicated example: We can use a map
to write a program that takes a description of a sentence structure—a grammar—and generates random sentences that meet that description. For example, we might describe an English sentence as a noun and a verb, or as a noun, a verb, and an object, and so on.
The sentences that we can construct will be more interesting if we can handle complicated rules. For example, rather than saying merely that a sentence is a noun followed by a verb, we might allow noun phrases, where a noun phrase is either simply a noun or an adjective followed by a noun phrase. As a concrete example, given the following input
Categories Rules <noun> cat<noun> dog<noun> table<noun-phrase> <noun><noun-phrase> <adjective> <noun-phrase><adjective> large<adjective> brown<adjective> absurd<verb> jumps<verb> sits<location> on the stairs<location> under the sky<location> wherever it wants<sentence> the <noun-phrase> <verb> <location>
our program might generate
the table jumps wherever it wants
输入:
<n> cat
<n> dog
<n> pig
<np> <n>
<np> <a> <np>
<a> beautiful
<a> big
<a> small
<v> jumps
<v> sits
<v> runs
<l> under the sky
<l> on the table
<l> in the computer
<sentence> the <np> <v> <l>
^Z
输出:
the beautiful big dog runs in the computer
the pig runs on the table
the cat sits under the sky
the big cat jumps on the table
the big beautiful big cat sits in the computer
the beautiful small small beautiful cat runs under the sky
请按任意键继续. . .
- Accelerated C++ 7.4 生成句子
- 读《Accelerated C++》有感
- 【Accelerated C++】读书笔记(一)
- 【Accelerated C++】读书笔记(二)
- 【Accelerated C++】读书笔记(三)
- 【Accelerated C++】读书笔记(四)
- 【Accelerated C++】读书笔记(五)
- 【Accelerated C++】读书笔记(六)
- 【Accelerated C++】重点回顾
- 《Accelerated C++》 笔记摘录
- 《accelerated c++》---------第六章
- Accelerated C++Exercises' Resolutions
- 【Accelerated C++】重点回顾
- Accelerated C++<3-2>
- Accelerated C++<4-1>
- Accelerated C++<4-2>
- Accelerated C++<4-3>
- Accelerated C++<4-4>
- OGRE 1.7 鼠标非独占使用(鼠标移出当前窗口)
- scanf和printf函数处理不同进制
- scanf和printf函数处理不同进制
- 嵌入式的笔试/面试经典题目
- 排排坐,吃果果
- Accelerated C++ 7.4 生成句子
- QML之使用C++自定义QML类型(一)
- win32 asm Hello World Demo
- Intel Hex文件格式
- Tuscany C++组件平台组成
- 背包问题
- 找零钱
- 花生米(二)
- 装盘子