• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Random sentence generator

Guest
Oct 23, 2010 Oct 23, 2010

Copy link to clipboard

Copied

Hi guys

My Friend and I has to do a project for school, where we have to:

Make a “program” that can generate a random sentence based on:

S ::= N VP

NP ::= N | N who VP | S

VP ::= VT NP | VI

N ::= the bear | the house | Bill | Lisa | Medina | somebody

VT ::= sees | lifted | chased | heard of

VI ::= was hugged | was eaten | was remembered | was lit on fire

(S = sentence, NP = noun phrase, N = noun, VP = verb phrase, VT = transitive verb, VI =

intransitive verb.)

Can anyone help us? We think that we have to use class, but we aren’t sure.

Object:

                                                                                       var Noun = new Array();

                                                                                       var Noun:Array = ["Hat", "Car", "Shoe", "Horse"];

                                                                                       var randomNoun = Noun[Math.floor(Math.random()*Noun.length)];

                                                                                      

                                                                                       var TransitiveVerb = new Array();

                                                                                       var TransitiveVerb:Array = ["lifted", "punished", "give", "traded", "ate"];

                                                                                       var randomTransitiveVerb = TransitiveVerb[Math.floor(Math.random()*TransitiveVerb.length)];

                                                                                      

                                                                                       var IntransitivVerb = new Array();

                                                                                       var IntransitivVerb:Array = ["was very drunk", "was flying", "was gone", "was dead"];

                                                                                       var randomIntransitivVerb = IntransitivVerb[Math.floor(Math.random()*IntransitivVerb.length)];

                                                                                      

                                                                                       var NounPhrase = new Array();

                                                                                       var NounPhrase:Array = [(randomNoun) | (randomNoun) + " who " + (randomVerbPhrase) | (randomSentence)];

                                                                                       var randomNounPhrase = NounPhrase[Math.floor(Math.random()*NounPhrase.length)];

                                                                                      

                                                                                       var VerbPhrase = new Array();

                                                                                       var VerbPhrase:Array = [(randomTransitiveVerb) + (randomNounPhrase) | (randomIntransitivVerb)];

                                                                                       var randomVerbPhrase = VerbPhrase[Math.floor(Math.random()*VerbPhrase.length)];

                                                                                      

                                                                                       var Sentence = new Array();

                                                                                       var Sentence:Array = [(randomNoun) + (randomNounPhrase)];

                                                                                       var randomSentence = Sentence[Math.floor(Math.random()*Sentence.length)];

                                                                                      

                                                                                       trace(randomSentence + " " + randomNounPhrase + " " + randomVerbPhrase + " " + randomNoun + " " + randomTransitiveVerb + " " + randomIntransitivVerb);

Class:

private var Sentence:Array;

                                                                                       private var NounPhrase:Array;

                                                                                       private var Noun:Array;

                                                                                       private var VerbPhrase:Array;

                                                                                       private var TransitiveVerb:Array;

                                                                                       private var IntransitivVerb:Array;

                            

                                                                                       public function Eksamen1class(Sentence:Array; NounPhrase:Array; Noun:Array; VerbPhrase:Array; TransitiveVerb:Array; IntransitivVerb:Array)

                                                                                       {

                                                                                                                   

                                                                                                                    this.Sentence = Sentence

                                                                                                                    this.NounPhrase = NounPhrase

                                                                                                                    this.Noun = Noun

                                                                                                                    this.VerbPhrase = VerbPhrase

                                                                                                                    this.TransitiveVerb = TransitiveVerb

                                                                                                                    this.IntransitivVerb = IntransitivVerb

                                                                                       }

Thanks..

Views

822

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 25, 2010 Oct 25, 2010

Copy link to clipboard

Copied

LATEST

Please try posting it here http://forums.adobe.com/community/flex/flex_general_discussion for better response.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines