This is actually an assignment I am stuck with.
Please l appreciate your help and support.
The grammar of natural languages such as
English exhibits a recursive structure. This
structure can be expressed in syntax rules
written in the format known as BNF
(Bachus -Naur Form, named after the people
who invented it ) . You have probably seen
BNF used to specify the syntax of
programming languages . While BNF is
ordinarily used as a guide for parsing ( that
is , determining whether and how a given
string follows the syntax rules ), it can also
be used a guide for generating strings that
follow the syntax rules . An example of this
can be found in the sample program
SimpleRandomSentences. In this example ,
each syntax rule -- except for the most
basic ones -- is represented by a method
that generates strings that follow that rule .
Where one syntax rule refers to another
rule, the method that represents the first
rule calls the method that represents the
second rule .
For the first exercise of the lab, you should write a similar program that implements the
following rules :
< sentence> :: = < simple _sentence>
[ < conjunction > < sentence> ]
< simple _sentence> : := < noun _ phrase >
< verb_ phrase >
< noun _phrase > ::= <proper _ noun > |
< determiner> [ < adjective> ] .
< common_noun > [ who < verb _phrase > ]
< verb_ phrase > : := < intransitive_ verb > |
< transitive_ verb> <noun _ phrase > |
is < adjective> |
believes that < simple_ sentence>
< conjunction > :: = and | or | but | because
< proper _noun > ::= Fred | Jane | Richard
Nixon | Miss America
< common_noun > ::= man | woman | fish |
elephant | unicorn
< determiner> : := a | the | every | some
< adjective> : := big | tiny | pretty | bald
< intransitive_ verb > :: = runs | jumps | talks
< transitive_ verb> ::= loves | hates | sees |
knows | looks for | finds
As in SimpleRandomSentences. java, you can
use arrays to implement the last seven rules
in this list . (You might improve on that
program by writing a single method " void
String randomItem(String  listOfStrings)" for
picking a random item from an array of
strings .) You are welcome to add to or
modify the items in the lists given here .
For each of the first three rules , you should
write a subroutine to represent that rule .
Note that a choice of alternatives
(represented in the rules by "|") can be
implemented using a switch or if . .else
statement ; the various choices don' t
necessarily have to have the same
probability. An optional element
(represented by brackets, "[ xxx ]") can be
implemented by a simple if . And a repeated
optional element ( represented by brackets
with dots, "[ xxx ]. .. ") can be represented by
a while loop. You should implement the first
four rules exactly as stated here . The main
routine should call the <sentence>
subroutine to generate random sentences.
You have to be careful in this program to
avoid infinite recursion in this program .
Since it will use random choices , there is no
guarantee that the recursion will ever end.
If your probabilities of doing recursion and
continuing loops are too high, it is possible
for the program to get lost in recursive calls
forever -- or to produce some finite but
ridiculously long sentences . You should
adjust your probabilities to make sure that
this doesn't happen, but that you still get
some interesting sentences .
I really need help with this. I just need to validate this course.
Thanks for even looking at it.
Don't start thinking about code. Think about the problem first:
- Do you understand what the question is asking?
- Would you be able to carry this out by hand? (e.g. using dice for the randomness)
- Would you be explain to someone else how to carry this out by hand?
Don't write a line of code until the answer to those questions is "yes".
Once it is, break it down into smaller problems. Start with a simplified version and write a program to do this. I'd suggest breaking the rules down into separate methods - pick one of the simplest (e.g. < conjunction >) and try to get that working. Then build up from there.
And welcome to the Ranch!
posted 6 years ago
I will do just that now and hopefully solve this
Once upon a time there were three bears. And they were visted by a golden haired tiny ad: