The if-else appear anyway

my web page is to categories the software requirements, so it takes the requirement as input from the user and they should click the button and based on their input it should classify it as bad or good, so in
my case the “good” in the if-else. so if the
why the if-else appear anyway in the web page?

import streamlit as st

st.title(" Tool for detecting defects in software requirement specification")
x=st.text_input("write your Non-funcationl requriment", value="")

weakWords=['fast','quickly', 'easy', 'timely', 'before', 'after', 'user-friendly', 'effective', 'multiple', 'as possible', 'appropriate', 'normal', 'capability', 'reliable', 'state-of-the-art', 'effortless', 'multi']
unboundedList=['at least','more than','less than','not less than','no less than','at the minimum','always']
ambiguity=['should','may','if possible','when','when appropriate','detail','details','analyse','respond','verified']
ambiguityWeakWords=['support','relevant information','needed information']
button=st.button("click",on_click=None)


if button:
    for word in weakWords:
        if (word in x): 
            st.text("The requrement classified as: Bad\nThe wrong word: " +word+"\ncategory: Weak Words")
    for word in unboundedList:
        if (word in x):
            st.text("The requrement classified as: Bad\nThe wrong word: " +word+"\ncategory: Unbounded List")

    for word in ambiguity: 
        if (word in x):
            st.text("The requrement classified as: Bad\nThe wrong word: " +word+"\ncategory: Ambiguity")
    for word in ambiguityWeakWords: 
        if (word in x):
            st.text("The requrement classified as: Bad\nThe wrong word: " +word+"\ncategory: Ambiguity & WeakWords")
        elif(word not in x):
            st.text("The requrement classified as: Good")

It seems that the issue is the IF statements. You can make make the requested functionality work with the following code.



if button:
    if x in weakWords:         
        st.text("The requrement classified as: Bad\nThe wrong word: " +x+"\ncategory: Weak Words")
    elif x in unboundedList:        
        st.text("The requrement classified as: Bad\nThe wrong word: " +x+"\ncategory: Unbounded List")
    elif x in ambiguity:         
        st.text("The requrement classified as: Bad\nThe wrong word: " +x+"\ncategory: Ambiguity")
    elif x in ambiguityWeakWords:         
        st.text("The requrement classified as: Bad\nThe wrong word: " +x+"\ncategory: Ambiguity & WeakWords")
    else :
        st.text("The requrement classified as: Good")

but it must be in a loop cuz it’s a list

Have you tried the inserting the code? The functionality worked on my end.


yes, this is the output that i get, it should says it’s a bad N-FR, but because there is no loop so that list was it like it’s not exist

Because the input will be a sentence not a word

I assumed that the image below is the output that you were looking for:

I was able to accomplish it using a modified code, but there is an issue with the elements in the list with multiple words such as “if possible” and “at the mininum” which I was not able to resolve quickly. You may be able to resolve it with a change on the split option, but this is not streamlit problem. Best of of luck!

if button:
    count=0
    x=x.split(" ")
    for word in x:
        #st.write(word)
        if word in weakWords:         
            st.text("The requirement classified as: Bad\nThe wrong word: " +word+"\ncategory: Weak Words")
            count+=1
        elif word in unboundedList:        
            st.text("The requirement classified as: Bad\nThe wrong word: " +word+"\ncategory: Unbounded List")
            count+=1
        elif word in ambiguity:         
            st.text("The requirement classified as: Bad\nThe wrong word: " +word+"\ncategory: Ambiguity")
            count+=1
        elif word in ambiguityWeakWords:         
            st.text("The requirement classified as: Bad\nThe wrong word: " +word+"\ncategory: Ambiguity & WeakWords")
            count+=1
    if count==0:
        st.text("The requirement classified as: Good")

@lama_Alrweta @cualr Not sure how familiar you are with NLP. You can apply spaCy's rule-based matcher to find phrases and show them highlighted using spaCy’s entity visualizer. Something like this:




It’s very easy so give it a go yourself. Here’s the relevant spaCy doc page. Once you have the basics in place you can build upon it by suggesting tighter, more active and precise phrasing of the requirements.

(If you want the code, I’m happy to share it.)

Happy coding!
Arvindra

2 Likes

thank u so much! that definitely worked

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.