test2.rb
RubyMud/test2.rb · 1.6 KB
From the archive rbmud-0.1rc2.tar.gz
Download the archive « Back to the archive contents
# daar is 3 moontlikhede
# verb
# verb directobject
# verb directobject preposition indirect-object
$preposition = [ 'with','using',
'at','to',
'in front of',
'in','inside','into',
'on top of','on','onto','upon',
'out of','from inside','from',
'over',
'through',
'under','underneath','beneath',
'begind','beside',
'for','about',
'is',
'as',
'off of','off']
def parse(str)
# first word is the verb
# eintlik moet ons " " ook handle
words = str.split(' ')
verb = words[0]
directobject = words[1]
index = 2
for prep in $preposition:
prepwords = prep.split(' ')
found = false
if prepwords[0] == words[index]
found = true
i = index+1
for k in 1...prepwords.size
if prepwords[k]!=words[i]
found = false
break
end
i += 1
end
if found
preposition = prep
break
end
end
end
indirectobject = words[-1]
puts "verb = #{verb}"
puts "direct object = #{directobject}"
puts "prep = #{preposition}"
puts "indirect object = #{indirectobject}"
end
parse("throw cd off of shelf")