Solved Batch File A.I. isn't working

September 30, 2018 at 17:57:47
Specs: Windows 10
I'm trying to program an ai. I have it saving the user input into a text document, then searching what the first word is, and going to the correct section, then moving on to the second word, etc. until it has deciphered the entire user input as a question or statement. My only problem, is that I can't seem to get it to search the text document that I saved the user input in. And yes, I only have one ">" sign so that it replaces the old input, rather than adding a new line, and also yes, I am using the /i to try and eliminate it not understanding because of random caps in the middle of the user's input. Can anyone help? I'm trying to use a combination of the for command and the find command:

@echo off
:start
cls
set /p userInput=
echo User: %userInput% > userInput.txt
echo Thinking...
for /f "tokens=1-1*" %%a in ('find /i "User"^<userInput.txt') do(
set userInput= %%a
if /i %userInput%= hello do(
cls
echo Hello, User
)
pause
set userInput= %%b
echo %userInput% > userInput.txt
)
goto start


I have extensive levels of this searching, including almost every possible beginning word for a question searched for as the first word of the user input in the entire program, I simply put this bit in a loop, because the program can't seem to get past the line beginning with for... Someone please help?


See More: Batch File A.I. isnt working

Reply ↓  Report •

✔ Best Answer
October 9, 2018 at 03:21:08
Both,

you are using a for loop with incorrect syntax, which only check for the first word in the .txt file
for the if statement you are also using incorrect syntax.

but even if the if-statement was correct it would still only reply with hello over and over again(with for example userinput set to "hello my name is Rory")
but that is also not true because you keep asking for userinput everytime you jump back to :start with the goto command

so if the if-statment was working correctly and you would use your code, it would still have the same effect as this::

@echo off
:start
set /p userinput=userinput=
if /i "%userinput:~0,5%"=="hello" echo hello
pause
goto start

///
Could you give an example of what would be written in userinput.txt and what kind of answer you would like to get, also an explanation of kind of data set you are using or will be using.

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz



#1
October 1, 2018 at 03:30:04
I'm gonna help you out of the batch A.I. dream before you spend to much time one it like i did.

Batch as a language is just not good enough to do any "A.I." programming, also I can already tell you're just going to daicy-chain a bunch of IF statements in order to find out what the hell the word "dog" means.

meaning if you where to do if statements for every word, you'll be coding for quite some time, writing pre-determined answers for every single word question.

Imagine teaching your program to interpret sentences, it will take forever to code it the way I see you doing it right now

So please don't waste your time on such a project without having experience with a high-level programming language and maby a PHD in the subject.

but hey, i can give you a link to a guy on youtube, who learned it all by himself:
https://www.youtube.com/channel/UC0...

i5-6600K[delid]@4.8GHz/4.3GHz@1.4v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1340Mhz core@1.110v/1865MHz BiosModded


Reply ↓  Report •

#2
October 1, 2018 at 11:29:03
I'm pretty determined, as I have been working on it on and off for about three years... I want an answer, not an "it can't be done, just give up". Just because you can't doesn't mean I can't...

message edited by RorySterling


Reply ↓  Report •

#3
October 1, 2018 at 11:32:22
As I have already stated, I moved on from trying the if command, because I realized it was highly inneficient, whereas the way I'm doing it, I only need to list quite a bit of words, and only need to do it once, not attempt to write an "if" statement for every single phrase possible in the English language...

Reply ↓  Report •

Related Solutions

#4
October 1, 2018 at 13:24:12
What type of questions are you going to ask?
Do you want the answers to a specific question to be the same every time? (randomness?)
Do you want it to learn over time? (so you train it with some kind of data-set and after a while, you let it learn by You the user interacting with it. Also meaning that if you just spam random characters, it can be perceived as "Correct aswell")
Do you want your "A.I." to be all knowing?
Will you be using any other program other than maby cscript, or just plain batch?

I will help you if you want, but I do not have any expertise in this subject, other than being interested in this subject.

"I have been working on it on and off for about three years"
Can you show me some code?
A link perhaps? (since it's probably a lot)

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2800MHz@1.35v
MSI Armor RX 570 4GB@1340Mhz core@1.110v/1865MHz BiosModded


Reply ↓  Report •

#5
October 1, 2018 at 14:11:38
At the very beginning, I have it searching the user input for a specific end-character, to determine the nature of the statement. The main problem is getting the batch file to read what the user wrote, so I need help fixing the for command line I posted in the first question:

for /f "tokens=1-1*" %%a in ('find /i "User"^<userInput.txt') do(

My reasoning for setting up the code like this is because, "delims=" wasn't working, so then I tried using "tokens=1-1*". The asterisk being so that it puts the users input into two seperate token variables, %%a being the first word, and %%b being the rest. just afterwards I have:

set userInput= %%b
echo %username%: %userInput% > userInput.txt
set userInput= %%a

Then it runs the beginning word through some "word banks" to determine more about the user's inputed phrase. Example:
If it finds a question mark at the end of a sentence, it searches my question bank, which includes the following (you can skip by the list if you want):
who, what, when, where, why, how, if, which, can, are, am, do, does, will, is, have, has

I do have each on a separate line to make it easier for the file to read, I'm not sure if it has to be or not. If the file can't find the word in the correct file, it searches all of the word banks.

message edited by RorySterling


Reply ↓  Report •

#6
October 2, 2018 at 01:54:18
I've left some comments in the code below, feel free to edit it and re-post it.

::TheAI.bat
@echo off&setlocal enabledelayedexpansion
::testing only
::set /p input=input=
::gonna hard code it right now...
set "lookuplist=who what when where why how if which can are am do does will is have has"
set "input=What is the biggest country?"
:IsQuestion
::%input% without the char: ? is equal to %input% with the last character removed
if "%input:?=%"=="%input:~,-1%" (
echo call :FirstTwoWords
) else (
echo call :NoQuestion
)
exit/b
:FirstTwoWords
::look for the first 2 words, i.e. what is, who has, when will, etc.
for /f "tokens=1,2,* delims= " %%a in ('echo %input%') do (
::some stuff missing here
call :lookuplist "%%a" "%%b" "%%c"
)
exit/b
:LookupList
::also stuff missing
set "word1=%~1"
set "word2=%~2"
set "allotherwords=%~3"
for /d in (%lookuplist%) do (
if "!word1!"=="%%a" (
call :FindSubject
)
)
:: not sure what to do with word2 and allotherwords at this point
exit/b
:Search
::can be used like this:
::call :Search %%a
::or call :Search %input%
::
::searched through an entire directory, for a string and skips all other directories
::
::if it finds matches they will be categorized like this:
::match1=whatever you searched+some extra stuff on that line
::line1=line number that contains first match
::match2=""
::line2=""
::
::i've also given it a line-number so you can look it up later by line number, which would be faster than doing it by %matchcnt%
set matchcnt=0
set "string=%~1"
for /f "tokens=*" %%a in ('dir/A-D/B') do (
for /f "tokens=*" %%A in ('type "%%a" ^| findstr /L /I /N "%string%"') do (
set matchcnt+=1
set "match!matchcnt!=%%a"
set "line!matchcnt!=%%A"
)
)
exit/b
:FindSubject
::list of subjects needed... and then you can look in a massive data-set what answer could be right
::you will probably get multiple "correct" answers, you could randomly pick an answer, or, train the network(I myself do not know how to do that properly)

exit/b
:DetermineBestAnswer
::Nothing here yet

exit/b
:NoQuestion
::nothing here yet


exit/b
:Randomizer
::0-32767 range

exit/b
:EOF
::just here if you want to kill the entire process instead of exiting a loop

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2800MHz@1.35v
MSI Armor RX 570 4GB@1340Mhz core@1.110v/1865MHz BiosModded

message edited by hidde663


Reply ↓  Report •

#7
October 2, 2018 at 04:07:53
now can you tell me how to explain to the .bat file what the word biggest means? In the sentence:

What is the biggest country?

Also it has to recognize the word "country" somehow and determine the correct meaning(the country, a country, country as in country side or even country as in country music), but at this points we are basically asking elongated if-statements

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2800MHz@1.35v
MSI Armor RX 570 4GB@1340Mhz core@1.110v/1865MHz BiosModded


Reply ↓  Report •

#8
October 2, 2018 at 20:45:29
I understand what you mean, and I'm going to set it up so that at some point the batch file realizes it is unable give a definite answer, and google it. I how ridiculous this sounds, but in this particular scenario, it would suffice. For example, if it reads "What is", then it could search for "the", but also search for "your" or "my" or similar words. And if it reads it as "what is the" then it would simply search for "?" just in case the user had put more than one sentence in, and it would then then search for more words after "?" and if it found some, then it would select everything before the "?" and google it
I know this is flawed, but even siri, alexa, or google home aren't perfect.

Reply ↓  Report •

#9
October 3, 2018 at 00:58:12
Accept that batch can not do a google search, not without an external program/script gathering the information for the .bat file.

I'm telling you Batch has it's limits, one of many.

for instance:

numbers larger than 2147483647 cannot be computed, unless you want to write the arithmetic code yourself

And you can not do any floating point opperations(set/a 3.6+5.4=Missing opperator&set/a 3,6+5,4=4), unless you want to write code yourself that does that.

But these two (there are many more) can be worked-around by piping the math to cscript, and returning the answer.
Tho then it is no longer "Batch only"

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2800MHz@1.35v
MSI Armor RX 570 4GB@1340Mhz core@1.110v/1865MHz BiosModded


Reply ↓  Report •

#10
October 7, 2018 at 09:29:48
As I said previously, at this point I am only asking for help as to why my "for" command isn't working. I will decide for myself weather I can or can't do something. Thank you for your time.

Reply ↓  Report •

#11
October 8, 2018 at 06:05:54
other than that "if /i %userInput%= hello do(" should have been:
if /i "%userInput%"=="hello" do (

for "for", just type for /? in the console, or keep on reading

tokens=1-1* means from 1 till 1 will be put in the first variable (%%a), every tokens after that will be put in the 2nd one (%%b)

example:

set "userinput=1 2 3 4 5"
::default delims are tab & space, im just specifying here that it is only space
for /f "tokens=1-1* delims= " %%a in ('echo %userinput%') do (
echo token1=%%a
echo token2=%%b
echo token3=%%c
)

cmd.exe response:
token1=1
token2=2 3 4 5
token3=

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz


Reply ↓  Report •

#12
October 8, 2018 at 09:41:37
So my problem is with the if statement, not the for statement?

Reply ↓  Report •

#13
October 9, 2018 at 03:21:08
✔ Best Answer
Both,

you are using a for loop with incorrect syntax, which only check for the first word in the .txt file
for the if statement you are also using incorrect syntax.

but even if the if-statement was correct it would still only reply with hello over and over again(with for example userinput set to "hello my name is Rory")
but that is also not true because you keep asking for userinput everytime you jump back to :start with the goto command

so if the if-statment was working correctly and you would use your code, it would still have the same effect as this::

@echo off
:start
set /p userinput=userinput=
if /i "%userinput:~0,5%"=="hello" echo hello
pause
goto start

///
Could you give an example of what would be written in userinput.txt and what kind of answer you would like to get, also an explanation of kind of data set you are using or will be using.

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz


Reply ↓  Report •

Ask Question