-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoun_stack_example.js
More file actions
166 lines (150 loc) · 3.68 KB
/
noun_stack_example.js
File metadata and controls
166 lines (150 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
function loader() {
srcCode.value = 'story=0 sequence_blocks=4 iterative_depth=2 paragraphs=2 sentences=13 season=0 weapon=0 realization=(+) story_state_machine=[]'
return
}
// function loader ()
function clear_window() {
srcTranslated.value = ''
return
}
// clear_window ()
function MD5() {
srcTranslated.value = Math.md5(srcCode.value)
return
}
// generate_MD5 ()
function Entity(){
this.name = arguments[0]
this.result = []
this.abilities = {
'0,0': Arrive(),
'0,1': Remark(),
'1,0': Interact(),
'1,1': Leave(),
}
this.act = function(){
var p = this.abilities
for(var i in p){
this.result.push(p[i](this))
}
}
this.narrator = function(){
return this.result.join('\n')
}
}
Entity.prototype = new Object()
function Act(){
var N = arguments.length
var s = ''
for(var i=0; i<N; i++){
s += arguments[i]
}
return s
}
function Arrive(){
var obj = function(){
var p = arguments[0]
return Act('I arrive at the ', p.name)
}
return obj
}
//Arrive.prototype = new Object()
function Remark(){
var N = arguments.length
var s = []
for(var i=0; i<N; i++){
s.push(arguments[i])
}
s = s.join(',')
var obj = function(){
var p = arguments[0]
return Act('I issue a few remarks on things I find fascinating at the ', p.name, ':', s)
}
return obj
}
//Remark.prototype = new Object()
function Interact(){
var name = arguments[0]
var obj = function(){
var p = arguments[0]
return Act(name + ': I interact with a few things on the ', p.name)
}
return obj
}
//Interact.prototype = new Object()
function Leave(){
var obj = function(){
var p = arguments[0]
return Act('I decide to leave the ', p.name)
}
return obj
}
//Leave.prototype = new Object()
function Ability(){
var N = arguments.length
var s = []
for(var i=0; i<N; i++){
s.push(arguments[i])
}
var str = s.join(',')
this.push(Arrive())
this.push(Remark(str))
N += 2
for(var i=2; i<N; i++){
try{
this.push(Interact(s[(i-2)]))
} catch (e) {
this.push('Unable to generate new Interaction ('+i+')')
}
}
this.push(Leave())
}
Ability.prototype = new Array()
function SEQ(){
this.name = arguments[0] + ' '
this.index = 0
this.result = []
this.abilities = {}
this.act = function(){
var p = this.abilities
var N = p.length
for(var i=0; i<N; i++){
this.result.push(p[i](this))
}
}
this.narrator = function(){
return this.result.join('\n')
}
}
SEQ.prototype = new Object()
var gIndex = 0
var wordStack = []
var PART_OF_SPEECH = 1
for(var word in mysql_wn_data_synsets_II){
var N = mysql_wn_data_synsets_II[word].length
for(i=0; i<N; i++){
if(
mysql_wn_data_synsets_II[word][i][PART_OF_SPEECH] == 'n' &&
mysql_wn_data_synsets_attributes_IV[word]['sweet'] &&
mysql_wn_data_synsets_attributes_IV[word]['fruit']
){
wordStack.push(word)
break // single DEFS only
}
}
}
function translatorTool() {
var result = []
var beach = new SEQ('beach')
beach.abilities = new Ability(
wordStack[gIndex++],
wordStack[gIndex++],
wordStack[gIndex++],
wordStack[gIndex++],
wordStack[gIndex++])
//beach.abilities = new Ability('boat','anchor','oar','breeze','sand')
beach.act()
result.push(beach.narrator())
srcTranslated.value = result.join('\n\n')
}
// translatorTool ()