Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #233 // Executor for apology generator (unfinished)

Lua code

1  
--[[
2  
Input (grammar) looks like this:
3  
4  
Apology ::= my (cat|mouse|monkey) ate my homework.
5  
Apology ::= our (basement|attic|third floor) collapsed from an overload of school books.
6  
]]
7  
8  
-- Put the grammar into array "rules".
9  
rules = splitIntoLines(getSnippet("#229"))
10  
11  
-- Choose one of the rules (randomly).
12  
rule = chooseOne(rules)
13  
14  
-- Parse rule: Apology ::= <bla>
15  
bla = match(rule, "Apology ::= <bla>")
16  
17  
-- Parse bla into:
18  
--   #1 (...)
19  
--   #2 everything else
20  
21  
i = rule:find("([^)]*)"
22  
23  
With every s in #1 do:
24  
  -- Split inner part of s at "|" into "options".
25  
  options = split(inner, "|")
26  
  -- Choose one of the options (randomly).
27  
  option = chooseOne(options)
28  
  -- Replace s with option.
29  
  
30  
-- Print bla (with the replacements made).
31  
print(join(bla))

Author comment

Began life as a copy of #231

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
688 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
--[[
Input (grammar) looks like this:

Apology ::= my (cat|mouse|monkey) ate my homework.
Apology ::= our (basement|attic|third floor) collapsed from an overload of school books.
]]

-- Put the grammar into array "rules".
rules = splitIntoLines(getSnippet("#229"))

-- Choose one of the rules (randomly).
rule = chooseOne(rules)

-- Parse rule: Apology ::= <bla>
bla = match(rule, "Apology ::= <bla>")

-- Parse bla into:
-- #1 (...)
-- #2 everything else

i = rule:find("([^)]*)"

With every s in #1 do:
-- Split inner part of s at "|" into "options".
options = split(inner, "|")
-- Choose one of the options (randomly).
option = chooseOne(options)
-- Replace s with option.

-- Print bla (with the replacements made).
print(join(bla))
}}
2015-08-19 08:42:32  delete 
686 #1000604 (pitcher) 2015-08-18 00:07:22

add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 782 [visualize]

Snippet ID: #233
Snippet name: Executor for apology generator (unfinished)
Eternal ID of this version: #233/1
Text MD5: 039d1e16fe5c7c1c7926bb407a4a6954
Author: stefan
Category: Apology generators
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2014-02-06 13:54:27
Source code size: 782 bytes / 31 lines
Pitched / IR pitched: Yes / Yes
Views / Downloads: 999 / 212
Referenced in: [show references]