Computer Science Canada

making turing find words

Author:  iop [ Sat Jul 17, 2004 11:07 pm ]
Post subject:  making turing find words

i want to create a bot that can talk to people. for that i need turning to get input, then find words in that input that will tell it what to do.

how can i make turning look for words in user input?

Author:  Tony [ Sun Jul 18, 2004 12:23 am ]
Post subject: 

turing test eh?

after you're done reading the very informative link... Laughing

you can separate a sentance into individual words using substrings as in
code:

var text:string := "my name is tony"
put text(4..7)


obviously white spaces are flags and you get individual words between them. To find where " " is located, you use index() function
code:

var text : string := "my name is tony" %string working with
var firstSpace : int := index (text, " ") %first occurance of " "
var tempText : string := text (firstSpace + 1 .. *) %string with first word cut out
var wordLength : int := index (tempText, " ") %occurance of second " "
put text (firstSpace + 1 .. firstSpace + wordLength) %putting it all together

Author:  iop [ Sun Jul 18, 2004 12:46 am ]
Post subject: 

doesnt turing have like a scan command or something that looks over inputed data for whatever its looking for?

Author:  AsianSensation [ Sun Jul 18, 2004 9:02 am ]
Post subject: 

m...........yeah, like tony pointed out above, index is the function you would be using, how well it works would depend on your creativity and skill at string manipulations really.

Author:  Tony [ Sun Jul 18, 2004 9:53 am ]
Post subject: 

yeah... instead of breaking the string up into individual words, you can search for an occurance of the substring directly.
code:

var text:string := "my name is tony"

if index(text,"tony") >0 then
put "did somebody say my name?"
else
put "i only answer to tony"
end if


ofcourse it will result true for any occurance of substring, even if its *tony*

a solution would be to add whitespaces to the search " tony " but that doesn't work for the first and last words inputed. So you'd have to be creative. A solution would be to add such whitespaces yourself.

as AsianSensation said : it comes down to your creativity and skill at string manipulations

Author:  DanShadow [ Mon Jul 26, 2004 6:48 pm ]
Post subject: 

hmm...this is my way of finding a word in a string:
code:

var text:string:="Hello and welcome to bobbys wonder land.."
var input:string:=""
put "Enter a word to search for: "..
get input
var num:int
num:=length(input)
for i:1..length(text)
    if i+num<=length(text) then
        if text(i..i+num)=input then
            put "Found the word ",input," in the text at (",i,",",i+num,")"
        end if
    end if
end for

I dont have Turing on this computer, but I believe that code should work.
But I guess the 'index' command is better...

Author:  Tony [ Mon Jul 26, 2004 7:22 pm ]
Post subject: 

hah, you just rewrote the index function Laughing and it would still find substrings Razz
code:

var text : string := "tony was here"
text := " " + text + " "
if index (text, " tony ") > 0 then
    put "tony was found"
end if

Wink
this way tony and blah_tony_blah are different things Very Happy

Author:  DanShadow [ Fri Jul 30, 2004 8:57 pm ]
Post subject: 

aww! Lol, I didnt even know of the index function before I created that. Well, I guess thats cool. Laughing


: