Programming

Programming Questions? Ask a Programmer for Answers ASAP

Ask a Computer Expert,
Get an Answer ASAP!

Programming

How does this website work? Python - I am trying to figure

Customer Question
Hi, how does this website...
Hi, how does this website work?
JA: What programs and versions are you using?
Customer: Python - I am trying to figure out how to remove a record in my json file based on a certain condition
JA: What is your ideal outcome? How can we solve this for you?
Customer: Remove the record in json file based on the conditions
JA: Anything else you want the programmer to know before I connect you?
Customer: Nope, but I do have a bunch of codes, trying to figure out what they do
Submitted: 3 months ago.Category: Programming
Show More
Show Less
Ask Your Own Programming Question
Customer reply replied 3 months ago
def remove(self, statement_text):
"""
Removes the statement that matches the input text.
Removes any responses from statements if the response text matches the
input text.
"""
for statement in self.filter(in_response_to__contains=statement_text):
statement.remove_response(statement_text)
self.update(statement)self.database.delete(statement_text)
Customer reply replied 3 months ago
I am trying to remove any statement text that has no response that comes from the json file. Something like this: {" you are bad": {"in_response_to": []}
Customer reply replied 3 months ago
as you can see, it should pass the statement of something like, if in_response_to is blank, delete the statement
Customer reply replied 3 months ago
but not sure what is the correct syntax to do this
Customer reply replied 3 months ago
Also for your reference what the filter function dodef filter(self, **kwargs):
"""
Returns a list of statements in the database
that match the parameters specified.
"""
from operator import attrgetterresults = []order_by = kwargs.pop('order_by', None)for key in self._keys():
values = self.database.data(key=key)
# Add the text attribute to the values
values['text'] = key
if self._all_kwargs_match_values(kwargs, values):
results.append(self.json_to_object(values))if order_by:# Sort so that newer datetimes appear first
is_reverse = order_by == 'created_at'# Do an in place sort of the results
results.sort(key=attrgetter(order_by), reverse=is_reverse)
return results
Customer reply replied 3 months ago
https://github.com/gunthercox/ChatterBot/tree/master/chatterbot - this is the complete source code
Customer reply replied 3 months ago
Do let me know if more details are required
Answered in 4 hours by:
7/25/2017
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago
George Sibiya
George Sibiya, Computer Hardware Engineer
Category: Programming
Satisfied Customers: 228
Experience: PhD in Computer Science
Verified

Hi,

Welcome to JustAnswer and thank you for utilizing our services.

I can look at your code in 5 hours after work if that would be fine.

Regards,

G

Ask Your Own Programming Question
Customer reply replied 3 months ago
Sure thanks.
Customer reply replied 3 months ago
Hi George - maybe you can troubleshoot with the codes first. If I can't solve it, happy to do a remote connection with the additional amounts. Let me know if you need additional/complete information. Thanks.
Customer reply replied 3 months ago
Also, the remove function is to be run after trainer function...
Customer reply replied 3 months ago
class ListTrainer(Trainer):
"""
Allows a chat bot to be trained using a list of strings
where the list represents a conversation.
"""def train(self, conversation):previous_statement_text = Nonefor text in conversation:
statement = self.get_or_create(text)if previous_statement_text:
statement.add_response(
Response(previous_statement_text)
)previous_statement_text = statement.textself.storage.update(statement)
self.storage.remove(statement)
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Alright, I am back on it now.

Ask Your Own Programming Question
Customer reply replied 3 months ago
Are you able to answer?
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

I got distracted yesterday let me look at it quickly

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hello - roughly when you will come back?
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Ok I was looking at the git project to see if you are extending jsonfile.py or you are implementing a component which uses the package.

I'll send a premium offer shortly so you can demonstrate it

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hmm i just want to use thr remove function to remove anything in the json file thar has empty response
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Ok. Please send me and example of the json file and the I haven't managed to generate one from the git project

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hi - can you let me know what you have managed to get so far? Sorry i am using this website for the first time so just a bit wary carrying it further without any result yet
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

I have just cloned the git project, installed its dependencies and checked in the example in the examples folder.

The only file file I could see it which has some of your code snippets is jsonfile.py

Now I was trying to understand you issue better and now I see you only need a function which discards ones with responses.

If you can paste a snippet of the json file I can write the function which does this. I just need to see the attributes of the json objects in the responses array

Ask Your Own Programming Question
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Ok, my response will be delayed by about 30 min from now

Ask Your Own Programming Question
Customer reply replied 3 months ago
Sure give me a minute
Customer reply replied 3 months ago
The database.rar is the result of the Listrainer function
Customer reply replied 3 months ago
I have also included the trainers.rar that produces the database. The function I am using is class(list trainer)
Customer reply replied 3 months ago
no worries, thank you for your help
Customer reply replied 3 months ago
I am trying use the remove function to remove anything with "in_response_to": [], but so far no luck.
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Ok thank you so much. I'll update you it should be done by today

Ask Your Own Programming Question
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Ok just 4 more hours. for now I need a rest

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hi hi - roughly when you can get back? Thanks.
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Ok I just got back to it from the office. I'll update you

Ask Your Own Programming Question
Customer reply replied 3 months ago
Thanks - will you be able to finish by today?
Customer reply replied 3 months ago
Hi any update?
Customer reply replied 3 months ago
Hi got a message from just answer. Did you attach somethinf fore review?
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Sorry for the poor communication I am still on it

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hi George - will you be able to get back to me by Monday? If not i will move on to other experts. Thanks.
Programmer: George Sibiya, Computer Hardware Engineer replied 3 months ago

Humble apologies for poor communication and the time taken. I'll throw in a towel for now

Ask Your Own Programming Question
Customer reply replied 3 months ago
Thanks - appreciate your honesty.
Programmer: JJesus Perez Gonzale,
 replied 3 months ago
JJesus Perez Gonzale
Category: Programming
Satisfied Customers: 42
Experience: Level II Technician at 49erShops Inc.
Verified

Hi, did you still need further assistance with your concern?

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hi, yes, JJesus - are you familiar with python?
Customer reply replied 3 months ago
You can look at the exchanges I have done with the previous expert and see if you can take it up... thanks.
Programmer: JJesus Perez Gonzale,
 replied 3 months ago

I apologize I am not familiar with python

Ask Your Own Programming Question
Programmer: amortensen, Computer Hardware Engineer replied 3 months ago
amortensen
amortensen, Computer Hardware Engineer
Category: Programming
Satisfied Customers: 99
Experience: Over 10 years in Information Systems including tech support, programming, design and installation.
Verified

I am currently reviewing the previous comments.

Ask Your Own Programming Question
Programmer: amortensen, Computer Hardware Engineer replied 3 months ago

To remove a statement if it matches use the remove attribute:

See below where the first example just checks for matches.

Test for presence using the in operator, then apply the remove method.

if thing in some_list: some_list.remove(thing)

The remove method will remove only the first occurrence of thing, in order to remove all occurrences you can use while instead of if.

while thing in some_list: some_list.remove(thing)

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hi Amortensen - have tried the method you mention. The problem lies with the fact that once j did the remove, i have to reload the json file, which causes an issue. I will try to give you a clear illustration later.
Programmer: amortensen, Computer Hardware Engineer replied 3 months ago

Store the JSON data in a variable.

Then edit the data as the variable

Then load the variable as the data stream/source.

This way you are working off a dynamic data load and not needing to get the external data. Should you want to compare you can then load a new JSON data stream as a variable and compare the two. You can then do what you need with the data.

Ask Your Own Programming Question
Customer reply replied 3 months ago
Hi Amortensen - maybe the question was not very clear. My code is here, https://github.com/Pythonbotty/chatterbot
Customer reply replied 3 months ago
Under storage-jsonfile, you will see the function I am trying to run to remove the statement in the json database. It is called remove2.def remove2(self, statement_text):
"""
Removes the statement that matches the input text.
Removes any responses from statements if the response text matches the
input text.
"""
import json
obj = json.load(open("database.db"))# Iterate through the objects in the JSON and pop (remove)
# the obj once we find it.
keep = []
for i in obj:
for j in obj[i]:
if len(obj[i][j])==0:
keep.append(i)
for i in keep:
obj.pop(i)
with open('database.db', 'w') as f:
f.write(json.dumps(obj))
Customer reply replied 3 months ago
The issue I am facing now is, once the json.dumps is done, although it has given the results I want (i.e. it removes all questions without responses), it loses the class it inherits under storage.update. Basically the bot no longer can find the answer to the question. Below is the database it creates.Is there something wrong with this code - does json.dumps actually changes the data type (string etc.)? Or is there something else that I miss and there is a better method to do this than remove2 as stated? Thanks.
Ask amortensen Your Own Question
amortensen
amortensen
amortensen, Computer Hardware Engineer
Category: Programming
Satisfied Customers: 99
99 Satisfied Customers
Experience: Over 10 years in Information Systems including tech support, programming, design and installation.

amortensen is online now

A new question is answered every 9 seconds

How JustAnswer works:

  • Ask an ExpertExperts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional AnswerVia email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction GuaranteeRate the answer you receive.

JustAnswer in the News:

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

What Customers are Saying:

My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed.

One Happy CustomerNew York

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Mary C.Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

AlexLos Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

EstherWoodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

RobinElkton, Maryland

< Previous | Next >

Meet the Experts:

ATLPROG

ATLPROG

Computer Software Engineer

7,677 satisfied customers

MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

LogicPro

LogicPro

Computer Software Engineer

7,109 satisfied customers

Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

unvadim

unvadim

Computer Software Engineer

1,168 satisfied customers

Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.

lifesaver

lifesaver

Computer Software Engineer

950 satisfied customers

Several years of intensive programming and application development experience in various platforms.

ehabtutor

ehabtutor

Computer Software Engineer

936 satisfied customers

Bachelor of computer science, 5+ years experience in software development, software company owner

TheDoctor

TheDoctor

Software Engineer

893 satisfied customers

M.S. in Internet Information Systems

The-PC-Guy

The-PC-Guy

Software Engineer

789 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

< Previous | Next >

Related Programming Questions
Do you know PowerPivot for Excel? Office 2013 for now, I
Office 2013 for now, I have a 2016 license as well … read more
Kris R
Kris R
IT Manager
Computing
2,263 satisfied customers
OKPR923211 Expert in VB code editing? I have a short VB code
OKPR923211 Expert in VB code editing? I have a short VB code that does indenting of source code. I need help in revising it.… read more
Bhavik Joshi
Bhavik Joshi
Computer Science and Engineering
582 satisfied customers
When accessing Excel, I receive the following message:
When accessing Excel, I receive the following message: "Microsoft Office cannot verify the license for this product." I cannot get past this message. What do I need to do. … read more
Bryan
Bryan
IT Consultant
8,745 satisfied customers
A program that considers a class that keeps track of the
a program that considers a class that keeps track of the sales of an item. An object of this class will have the following attributes: •Number sold •Total sales •Total discounts •Cost per item •Bulk q… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I received this error message when creating a program for a
Hello. I received this error message when creating a program for a clock in netbeans. Can you help? … read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I need STM32Cube_FW based example source C code to program
I need STM32Cube_FW based example source C code to program STM32F411 MCU as USB HID host to access (communicate with) customized HID device (not keyboard nor mouse)… read more
Kris R
Kris R
IT Manager
Computing
2,263 satisfied customers
It's an excel question. Microsoft Excel Office 2016, I am
I am having trouble creating a formula and I am unsure how to go about it. The formula help within Excel is not understanding my question. … read more
Richard
Richard
IT Manager
IT Manager, Consultant
3,208 satisfied customers
I am programming for years mostly in vbScript having the
I am programming for years mostly in vbScript having the vbScript-Editor, but codes get very long and I seek one Editor, which can have classes on different pages and procedures be closed, that only t… read more
Steve
Steve
Consultant
Bachelor
69 satisfied customers
I have an assignment I need done today and I don't have time
I have an assignment I need done today and I don't have time to work on it. Can you help please? … read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Excel is not responding and will not open, Office 365 2016,
Excel is not responding and will not open JA: What programs and versions are you using? Customer: Office 365 2016 JA: What is your ideal outcome? How can we solve this for you? Customer: how can I get… read more
Cody
Cody
Computer Science
1,462 satisfied customers
Java blocks me from getting online to my office computer,
Java blocks me from getting online to my office computer … read more
jeffreybongers
jeffreybongers
ICT Support 1/2/3/ Line
Information Technology
145 satisfied customers
Question for LogicPro Sheriff Office Booking System
Question for LogicProSheriff Office Booking SystemOverview: This system is a desktop JavaFX GUI application to support the sheriff's deputies in their duties to maintain accurate information of inmate… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
The local Driver's License Office has asked you to write a
The local Driver's License Office has asked you to write a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
It is an Excel question.. 2010, Microsoft Office, I am
I am looking for assistance in figuring out a formula for a report… read more
Richard
Richard
IT Manager
IT Manager, Consultant
3,208 satisfied customers
We recently fired our office person handling critical files.
We recently fired our office person handling critical files. On his list is info for Wordpress. However, the info is not valid for log in. Can you help me determine if we still have an active account … read more
Peter GJ
Peter GJ
Senior IT Governance Project Manager
Bachelor Science and Education
17 satisfied customers
Assignment 3 Please start with this source code. Write a
Assignment 3 Please start with this source code.Write a program that opens the following text file and processes it contents. The program should display the following per store: The total sales for ea… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Problem sending the command to the program" Microsoft office
I receive excel files by e-mail: the program suddenly will not open the files from the e-mail. It will open files that I have saved and opened previously … read more
Viet - Computer Tech
Viet - Computer Tech
Computer Technican
Bachelor\u0027s Degree
952 satisfied customers
To C expert: How to convert my C source code to standard C
To C expert: How to convert my C source code to standard C source code so that it includes only standard C header files? My C source coding includes "CB.h", which is not an ANSI C standard C header fi… read more
Steve
Steve
Consultant
Bachelor
69 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less

Ask Your Question

x