Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 making turing find words
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
iop




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: Sun Jul 18, 2004 12:23 am   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
iop




PostPosted: 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




PostPosted: 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




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DanShadow




PostPosted: 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




PostPosted: Mon Jul 26, 2004 7:22 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DanShadow




PostPosted: 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. Laughing
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: