Results 1 to 7 of 7
  1. #1
    BrAD19924 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default Random sentence generator

    Im new to java and i have a program but i have no idea what to do. It needs to be a recursive program to generate random sentences from a given BNF grammar. the user should be able to enter the name of the input file on command line: ex. java Sentences bnf.txt. It should look like this when done.
    Enter number of sentences: (a number)
    Here are the sentences:
    ....
    .....


    can some one help

  2. #2
    BrAD19924 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default

    and the bnf file looks like
    <s>::= <np> <vp>
    <np>::= <dp> <adjp> <n>|<pn>
    <dp>::= the|a
    <adjp>::= <adj>| <adj> <adjp>
    <adj>::= big|fat|green...
    <n>::=dog|cat...
    <pn>::=John|MArry...
    <vp>::=<tv> <np>|<iv>
    <tv>::= hit|honored...
    <iv>::=died|collapsed....
    Quote Originally Posted by BrAD19924 View Post
    Im new to java and i have a program but i have no idea what to do. It needs to be a recursive program to generate random sentences from a given BNF grammar. the user should be able to enter the name of the input file on command line: ex. java Sentences bnf.txt. It should look like this when done.
    Enter number of sentences: (a number)
    Here are the sentences:
    ....
    .....


    can some one help

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    you can start off with this helpful tutorial

    Scanning (The Java™ Tutorials > Essential Classes > Basic I/O)

  4. #4
    BrAD19924 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default

    i no how to use scanner already thanks for the suggestion i just dont no how to read in that txt file make it into an array and then give it random number s then put what it comess up with all together to make a sentence

  5. #5
    Green_Ghoul is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    A hashmap would be a good start

  6. #6
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    regex might be helpful
    String Literals (The Java™ Tutorials > Essential Classes > Regular Expressions)

    also String.replaceAll(String regex, String replacementString)

  7. #7
    BrAD19924 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default

    im just not going to attempt it seems way over my head, but it would be cool to see actually work

Similar Threads

  1. Help with Random Number Generator
    By celtics in forum New To Java
    Replies: 0
    Last Post: 03-07-2011, 08:18 PM
  2. Random number generator
    By zerwik in forum New To Java
    Replies: 3
    Last Post: 12-26-2010, 12:10 PM
  3. Random Generator
    By Learning Java in forum New To Java
    Replies: 9
    Last Post: 05-31-2010, 08:15 PM
  4. Random Numbers generator
    By pinkdreammsss in forum Java Applets
    Replies: 10
    Last Post: 04-08-2010, 03:38 AM
  5. Random Generator
    By padutch2 in forum New To Java
    Replies: 1
    Last Post: 12-03-2007, 06:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •