I have written a basic level program that evaluates if a comment is positive, negative or neutral…
# Comment
word_count = 14
comment = "Positive"
account_age = 33
# Evaluation
comment_length = word_count <= 3 or word_count > 200
useful_post = not comment_length and comment != "Negative"
trusted_acc = account_age >= 30
# Positive Posts
if useful_post and trusted_acc :
print ("Your comment has been put on the fyp!")
# Spam Posts
if comment == "Negative" and account_age < 7:
print('This comment has been flagged as potential spam!')
I was looking for ways to improve the current program and ideas for how I what I can add or how I could make the program good enough to start taking user input…
eg.
comment = input("Comment: ")
Instead of what I have written currently, Thanks.
PS.
If there are any questions about what I mean just ask
I reviewed your script. The way that I am interpreting it is that you are reviewing a list of requirements and determining whether or not they are being satisfied. One potential way of looking at this is that you can assign a 1 to a requirement flag if the test condition has been satisfied and a 0 if it has not. You can then sum the requirements and verify if they are above a predefined pass threshold. Assuming that ALL requirement must be satisfied, you can approach the problem like the example shown below where the pass threshold is the quantity of requirement flags. Since there are five requirements, anything above four will satisfy this per the conditional statement definition.
At the very start, ALL flags are cleared (initialized to 0). They are only set if the condition has been met. Note that I have only shown one test condition but you will have to apply a test condition to all of the requirement flags to determine if they should be set to 1 or not.
# Constants
NOT_SATISFIED = int(False)
PASS_THRESHOLD = 4
# Comment
word_count = 14
comment = "Positive"
account_age = 33
# Initialize flags
comment_length = NOT_SATISFIED
useful_post = NOT_SATISFIED
trusted_acc = NOT_SATISFIED
# comment = NOT_SATISFIED
# account_age = NOT_SATISFIED
if word_count <= 3 or word_count > 200:
comment_length = int(not NOT_SATISFIED)
if sum((comment_length, useful_post, trusted_acc)) > PASS_THRESHOLD:
print('Your comment has been put on the fyp!')
else:
print('This comment has been flagged as potential spam!')
You can also use what you already have regarding the conditional statement as in:
comment_length = int(word_count <= 3 or word_count > 200)
... since this will return either a 'True' or a 'False'
instead of what I have written:
if word_count <= 3 or word_count > 200:
comment_length = int(not NOT_SATISFIED)
In the script, we type cast the conditional test result with the int keyword to convert True to a 1.
Can you please elaborate to fully understand your query. What is shown is a prompt to the user to enter a response. What response or what type of response are you expecting the user to provide? The string Comment is a bit too succinct. You may want to expand on it so that a layman can easily understand what is expected?
From your original post, it seems that you are expecting either: Negative or Positive.
If this is the case, you may want to rewrite it as:
comment = input("Enter 'Positive' for this reason or 'Negative' for this reason.")
Note that you should expand on the reasons to make it clear to the user - there should be no ambiguity.
A simple example that comes to mind is:
comment = input("Would you like to continue? Enter 'Y/y' for yes or 'N/n' for no:")
So basically the idea was to have a space that would act kind of like comments on youtube (or other social media)… the user enters there comment and it is posted.
The difference is with my code they could use it as a way to test if their comments are not appropriate to be posted.
This is more complicated than it appears. I think what you want to do is to make use of some type of artificial intelligence whereby it reads language patterns, and as you stated, determines if what the user has posted is decent enough for publishing. I am sorry, I am not familiar with this.
Is this an exercise for a class? Are you supposed to reinvent the wheel? Because there is a module for this already. The process is called “sentiment analysis”.