making turing find words
Author |
Message |
iop
|
Posted: 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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Sun Jul 18, 2004 12:23 am Post subject: (No subject) |
|
|
turing test eh?
after you're done reading the very informative link...
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
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
iop
|
Posted: Sun Jul 18, 2004 12:46 am Post subject: (No subject) |
|
|
doesnt turing have like a scan command or something that looks over inputed data for whatever its looking for? |
|
|
|
|
|
AsianSensation
|
Posted: Sun Jul 18, 2004 9:02 am Post subject: (No 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. |
|
|
|
|
|
Tony
|
Posted: Sun Jul 18, 2004 9:53 am Post subject: (No 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
DanShadow
|
Posted: Mon Jul 26, 2004 6:48 pm Post subject: (No 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... |
|
|
|
|
|
Tony
|
|
|
|
|
DanShadow
|
Posted: Fri Jul 30, 2004 8:57 pm Post subject: (No subject) |
|
|
aww! Lol, I didnt even know of the index function before I created that. Well, I guess thats cool. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|