Pythong Pickle: How to modify the code?

Thread Starter

zulfi100

Joined Jun 7, 2012
656
Hi,

I am trying to modify the following Python Pickle program. It always starts by generating a ">". I have tried to use "print" statements but it is ignoring them. Kindly guide me how to modify the program:

Python:
import pickle

#trainer program

b=open('war&peace.txt')

text=[]

print("Testing the code")

for line in b:

    for word in line.split():

        text.append (word)

b.close()

textset=list(set(text))

follow={}

print("Testing")

print(text)

for l in range(len(textset)):

    working=[]

    check=textset[l]

    for w in range(len(text)-1):

        if check==text[w] and text[w][-1] not in '(),.?!':

            working.append(str(text[w+1]))

    follow[check]=working

a=open('lexicon-luke','wb')

pickle.dump(follow,a,2)

a.close()
 

Thread Starter

zulfi100

Joined Jun 7, 2012
656
Hi,

I have got some idea. Please guide me what is the meaning of following code:



if check==text[w] and text[w][-1] not in '(),.?!':

I think its checking that 'check' is not equal to (),.?!. Any logic why its checking only 2 substrings of 'text'?



Zulfi.
 

upand_at_them

Joined May 15, 2010
626
I have tried to use "print" statements but it is ignoring them.
You should first assume that you have done something wrong, not that the interpreter is ignoring commands. You tried to use print statements, to do what? You don't say. And you don't show what you tried that didn't work.
 

Thread Starter

zulfi100

Joined Jun 7, 2012
656
Hi,
When you are debugging the code then what is the purpose of "print" statement?

I think you just tried to answer without understanding my code.

But even then I appreciate your response.

God blesses you.

Zulfi.
 

hrs

Joined Jun 13, 2014
270
Are you using this?
https://stackoverflow.com/questions/5306729/how-do-markov-chain-chatbots-work/23901393#23901393

The ">" comes from the bot program, not the trainer. Also, print statements in the trainer program will not be executed if you run the bot program. Looking at your post history you want to make "a chatbot to act as sale agent for grocery items". The example you're working from uses Markov chains which only produce non-sense and are unlikely to be helpfull to customers.
 
Top