File size: 2,209 Bytes
ec6be24
 
ffabbeb
7791ec9
ec6be24
7791ec9
 
 
 
 
ec6be24
7791ec9
 
 
 
ec6be24
 
 
7791ec9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec6be24
 
7791ec9
ec6be24
 
 
3ccaf35
7791ec9
ec6be24
 
 
3ccaf35
ec6be24
 
 
 
 
 
 
 
 
 
7791ec9
 
ec6be24
7791ec9
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import streamlit as st
import itertools
import nltk
from nltk.corpus import wordnet, words

# Download the necessary resources
nltk.download("wordnet")
nltk.download("words")

def get_related_words(word):
    synonyms = set()
    antonyms = set()
    hypernyms = set()
    hyponyms = set()

    for syn in wordnet.synsets(word):
        for lemma in syn.lemmas():
            synonyms.add(lemma.name())
            if lemma.antonyms():
                antonyms.add(lemma.antonyms()[0].name())

        for hyper in syn.hypernyms():
            hypernyms.update(lemma.name() for lemma in hyper.lemmas())

        for hypo in syn.hyponyms():
            hyponyms.update(lemma.name() for lemma in hypo.lemmas())

    return {
        "synonyms": list(synonyms),
        "antonyms": list(antonyms),
        "hypernyms": list(hypernyms),
        "hyponyms": list(hyponyms),
    }

def generate_words(letters, length=None):
    english_words = set(words.words())
    permutations = set()
    for i in range(1, len(letters) + 1):
        for p in itertools.permutations(letters, i):
            word = "".join(p).lower()  # Convert the word to lowercase
            if (length is None or len(word) == length) and word in english_words:
                permutations.add(word)
    return permutations


st.title("Scrabble Helper")

letters = st.text_input("Enter the letters you have:")
word_length = st.number_input("Enter the word length (optional):", min_value=0, value=0, step=1)

if letters:
    st.header("Generated Words")
    words = generate_words(letters, length=word_length if word_length > 0 else None)
    st.write(words)

    st.header("Thesaurus and Related Words Lookup")
    selected_word = st.selectbox("Select a word to look up related words:", [""] + sorted(words))
    if selected_word:
        related_words = get_related_words(selected_word)
        st.subheader("Synonyms")
        st.write(related_words["synonyms"])
        st.subheader("Antonyms")
        st.write(related_words["antonyms"])
        st.subheader("Hypernyms (more general terms)")
        st.write(related_words["hypernyms"])
        st.subheader("Hyponyms (more specific terms)")
        st.write(related_words["hyponyms"])