home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR22 / JORF21_2.ZIP / HAIKU.J < prev    next >
Text File  |  1993-07-05  |  5KB  |  154 lines

  1. Class:Haiku
  2.   Index:Key     | A "Key" to store this structure
  3.   Text          | Current Haiku Text
  4.   Arts          | Sentence articles
  5.   Adjs          | Adjectives
  6.   Nouns         | Nouns
  7.   Verbs         | Verbs
  8.   Preps         | Preps
  9.  
  10. Haiku:Start
  11.   New (Haiku:Haiku)
  12.   Jorf:File ("Haiku", Here)
  13.   Haiku=Haiku:GetStructure()
  14.   Haiku:Thinkup(Haiku)
  15.   Event:Add()
  16.   Win:Add("Haiku Generator", 4, 15, 10, 50, Here)
  17.     Menu:"&File"
  18.       Menu:"E&xit" Action:"Return Null"
  19.     Menu:"&Print"
  20.       Action:"Haiku:Print(Haiku)"
  21.  
  22.     Group:"" Row:2 Col:5 Len:3 Wid:40   | Group box border
  23.     Text:"" Field:"Haiku->Text"         | Text to show
  24.       Before:"Null"                     | Never any input here
  25.  
  26.     Button:"&Generate" Row:8, Col:5 Wid:20 Action:"Haiku:Thinkup(Haiku)"
  27.     Button:"E&xit"     Row:8, Col:27 Wid:20 Action:"Return Null"
  28.   Return (Ok)
  29.  
  30. Haiku:Array (Text)
  31.   | This routine loads words into an array.  Double words must be quoted.
  32.   | The Array is written to the current file (HAIKU.JRF).
  33.   New (WordCount, Arr, ArrCount, Spaces)
  34.   Spaces = Str:Ind(Text)                | Indent level
  35.   While (Text And Spaces <= Str:Ind(Text))
  36.     For (WordCount = 1 thru Word:Len (Text))    | For each word
  37.       ++ArrCount                                | Add word to
  38.       Arr[ArrCount]=Word:At (Text, WordCount)   |   word array
  39.     Text = Text:Next (Text)             | Next line
  40.   Jorf:Write (Arr)                      | Write to current file
  41.   Return (Arr)
  42.  
  43. Haiku:Generate (Haiku, Text)
  44.   New (Spaces, CurWord, Pos)
  45.   New (NewWord, NewLine, NewText)
  46.   Spaces = Str:Ind (Text)
  47.   While (Text And Spaces <= Str:Ind(Text))
  48.     | Step backwards - so we can switch "A" to "AN" when necessary
  49.     For (Pos = Word:Len (Text) thru 1 Step -1)
  50.       CurWord = Word:At (Text, Pos)
  51.       Switch (CurWord)
  52.         Case 'Art'
  53.           NewWord = Haiku:GetWord (Haiku->Arts)
  54.           If NewWord = "a"
  55.             If (Str:Aft (NewLine,"aeiou") < 2)
  56.               NewWord = "an"
  57.         Case 'Noun'
  58.           NewWord = Haiku:GetWord (Haiku->Nouns)
  59.         Case 'Adj'
  60.           NewWord = Haiku:GetWord (Haiku->Adjs)
  61.         Case 'Verb'
  62.           NewWord = Haiku:GetWord (Haiku->Verbs)
  63.         Case 'Prep'
  64.           NewWord = Haiku:GetWord (Haiku->Preps)
  65.         Else
  66.           NewWord = CurWord
  67.       If (Pos = 1)
  68.         NewWord = To:Caps (NewWord)
  69.       NewLine = NewWord + NewLine
  70.     NewText = Text:Add (NewLine, NewText)
  71.     NewLine = Null
  72.     Text = Text:Next (Text)
  73.   Haiku->Text = NewText
  74.   Return (Ok)
  75.  
  76. Haiku:GetStructure
  77.   | Get Haiku structure from file.  If not found in file, generate
  78.   |  it from the word lists.
  79.   New (Haiku:Haiku)
  80.   Haiku = Struct:Find("Haiku","Key",Null)
  81.   If (Haiku == Null)
  82.     Haiku->Arts = Haiku:Array()
  83.       a the
  84.     Haiku->Adjs = Haiku:Array()
  85.       autumn hidden bitter misty silent empty
  86.       dry dark sighing delicate quiet
  87.       white cool frigid winter dappled
  88.       twilight afternoon crimson wispy azure
  89.       blue billowing broken cold damp falling
  90.       frosty tawny long late lingering
  91.       little morning leafy billowing
  92.       still small sparkling cloudy
  93.       wandering withered wild black young
  94.     Haiku->Nouns = Haiku:Array()
  95.       waterfall mist breeze moon
  96.       rain wind sea morning snow glitter forest
  97.       Josephine cloud meadow sun glade bird brook
  98.       butterfly tove dew savannah meadow
  99.       flower firefly feather grass haze mountain
  100.       night goat shade snowflake
  101.       silence lily sky shape surf thunder
  102.       violet water wildflower wave
  103.     Haiku->Verbs = Haiku:Array()
  104.       drifts "has stopped" blusters blows
  105.       races "did gimble" stretches
  106.       flutters has risen "is drifting" "is trickling"
  107.       murmers "is floating" "is wafting"
  108.     Haiku->Preps = Haiku:Array()
  109.       on in beneath over near of
  110.     Haiku->Key = "Key"
  111.     Jorf:Write (Haiku)
  112.   Return (Haiku)
  113.  
  114. Haiku:GetWord (Arr)
  115.   New (Word, Off)
  116.   Off = Num:Rand (1, Word:Len (Arr))
  117.   Word = Arr[Off]
  118.   Return Word + " "
  119.  
  120. Haiku:Print(Haiku)
  121.   New (Dest)
  122.   Dest=Jorf:Printer()
  123.   If (Dest!=Null)
  124.     File:Save("JREPORT.LST",Haiku->Text)
  125.     File:Append("JREPORT.LST")
  126.     File:Print("JREPORT.LST",Dest,TRUE)
  127.   Return (Ok)
  128.  
  129. Haiku:Thinkup(Haiku)
  130.   Switch Num:Rand (1, 4)
  131.     Case 1
  132.       Haiku:Generate (Haiku)
  133.         Art Adj Noun . . .
  134.         Art noun verb prep art noun
  135.         Adj Adj Noun
  136.     Case 2
  137.       Haiku:Generate (Haiku)
  138.         Noun Prep Art Noun
  139.         Art Adj Noun Prep Art Noun
  140.         Adj Noun
  141.     Case 3
  142.       Haiku:Generate (Haiku)
  143.         Art Adj Noun
  144.         Art Adj Noun
  145.         Art Noun Verb
  146.     Case 4
  147.       Haiku:Generate (Haiku)
  148.         Art Adj Noun Verb
  149.         Art Adj Noun
  150.         Prep Art Adj Noun
  151.   Win:Dsp
  152.   Return(Ok)
  153.  
  154.