Question

In: Computer Science

Can you please check for the error in my code?: #data object is created text_data =...

Can you please check for the error in my code?:

#data object is created
text_data = {"the_final_output": [{"abs": ""}, {"abs": ""}, ..., {"abs": ""}]}

#a list is created
main_terms = []
#iterating every data in the_final_output
for i in range(len(text_data["the_final_output"]):
blob = TextBlob(text_data["the_final_output"][i]["abs"])
main_terms.append(blob.polarity)
  
#sentiment analysis sorts the text into positive, neutral, and negative.
tp = sum(main_terms)
#if tp is less than 0, it's negative
if tp < 0:
print("Negative")
#if tp is greater than 0, it's positive
elif tp > 0:
print("Positive")
#if neither positive nor negative, it's neutral
else:
print("Neutral")

Solutions

Expert Solution

Code:

from textblob import TextBlob
#data object is created
text_data = {"the_final_output": [{"abs": ""}, {"abs": ""}, {"abs": ""}]}

#a list is created
main_terms = []
#iterating every data in the_final_output
for i in range(len(text_data["the_final_output"])):
  blob = TextBlob(text_data["the_final_output"][i]["abs"])
  main_terms.append(blob.polarity)

  #sentiment analysis sorts the text into positive, neutral, and negative.
  tp = sum(main_terms)
  #if tp is less than 0, it's negative
  if tp < 0:
    print("Negative")
  #if tp is greater than 0, it's positive
  elif tp > 0:
    print("Positive")
  #if neither positive nor negative, it's neutral
  else:
    print("Neutral")

Code screenshot:

Code output:

===========================

Following errors were in your code:

1) for i in range(len(text_data["the_final_output"])

Here the ending parentheses were not present. So updated code:

for i in range(len(text_data["the_final_output"])):

2) The data you mentioned

text_data = {"the_final_output": [{"abs": ""}, {"abs": ""}, ..., {"abs": ""}]}

Here ... in between is not valid. So I removed them.

On Making above changes the code runs as shown above.

===================

For any query comment.


Related Solutions

I have a problem with my code. It does not run. Please can someone check the...
I have a problem with my code. It does not run. Please can someone check the code and tell me where I went wrong? This is the question: Program Specification: Write a C program that takes the length and width of a rectangular yard, and the length and width of a rectangular house (that must be completely contained in the yard specified) as input values. Assuming that the yard has grass growing every where that the house is not covering,...
can you check if my answers are correct and can you please type the correct answers...
can you check if my answers are correct and can you please type the correct answers for each question 5 points) Trevor is interested in purchasing the local hardware/electronic goods store in a small town in South Ohio. After examining accounting records for the past several years, he found that the store has been grossing over $850 per day about 60% of the business days it is open. Estimate the probability that the store will gross over $850 at least...
this code still shows that it still has an syntax error in it can you please...
this code still shows that it still has an syntax error in it can you please fix it. I will put an error message next to the line that is wrong and needs fixed, other than that the other lines seems to be ok. public static void main() { /** * main method - makes this an executable program. */ public static void main("String[]args"); this is the error line that I get and needs fixed // create a client with...
Can you please check my answers and if I am wrong correct me. Thank you! A....
Can you please check my answers and if I am wrong correct me. Thank you! A. In today's interconnected world, many central banks communicate regularly and frequently with the public about the state of the economy, the economic outlook, and the likely future course of monetary policy. Communication about the likely future course of monetary policy is known as "forward guidance.". If the central bank increases the reserve ratio, as the market has perfectly expected, which of the following will...
Hi! Thanks for taking the time to check out my problem. If you can please answer...
Hi! Thanks for taking the time to check out my problem. If you can please answer as many as possible and I really appreciate your help. Question 6 2 pts In an agricultural study, the average amount of corn yield is normally distributed with a mean of 189.3 bushels of corn per acre, with a standard deviation of 23.5 bushels of corn. If a study included 1200 acres, about how many would be expected to yield more than 180 bushels...
can someone finish and check my code on main. cpp? Its not working for me even...
can someone finish and check my code on main. cpp? Its not working for me even though im sure my code make sense is it possible to output each function to show they work. this is supposed to be a vector class library made from allocated memory i have included templated functions in the class file to help create the rest of the functions. Thank you so much note: i did not include main.cpp because it  was empty- im hoping someone...
Error detection/correction C Objective: To check a Hamming code for a single-bit error, and to report...
Error detection/correction C Objective: To check a Hamming code for a single-bit error, and to report and correct the error(if any) Inputs: 1.The maximum length of a Hamming code 2.The parity of the check bits (even=0, odd=1) 3.The Hamming code as a binary string of 0’s and 1’s Outputs: 1.The original parity bits (highest index to lowest index, left to right) 2.The new parity bits (highest index to lowest index, left to right) 3.The bit-wise difference between the original parity...
Please assist with getting my code to correctly check to validate input. Everything else works fine,...
Please assist with getting my code to correctly check to validate input. Everything else works fine, but when I enter a character, it should say Invalid entry. Everything else should also work. It should not allow more or less than 9 digits, and it should ask again for input if it doesn't like the input. Please help my code and explain how it is working. I also need to keep the recursive function. #include <stdio.h> #include <ctype.h > int SecNumSum(long...
Can you please check my work? I used R but it's very basic. I searched for...
Can you please check my work? I used R but it's very basic. I searched for this question on Chegg to check my answer but my numbers are slightly different. What did I do wrong? Question: Calculate confidence intervals for population variance and standard deviation. Assume that samples are simple random samples and taken from a normal population. α=0.05, sample size=30,s=3.5 stdev =3.5 df = 29 n = 30 alpha = 0.05 qchisq(0.05,df,lower.tail = FALSE) onechi <- 42.55679 #[1] 42.55697...
can someone please check the code below? Thank you Hunterville College Tuition Design a program for...
can someone please check the code below? Thank you Hunterville College Tuition Design a program for Hunterville College. The current tuition is $20,000 per year. Allow the user to enter the rate the tuition increases each year. Display the tuition each year for the next 10 years. For the programming problem, create the pseudocode and enter it below. Enter pseudocode here start     Declarations             num tuition             num year                         num TOTAL_YEARS = 10             num INCREASE_RATE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT