Jupyter Notebooks and Play
Jup notebooks
import wikipedia
from emoji import emojize
from IPython.display import display, Markdown
from textblob import TextBlob
def analyze_sentiment(text):
analysis = TextBlob(text)
sentiment_score = analysis.sentiment.polarity
if sentiment_score > 0:
return emojize(":grinning_face: This article seems positive!")
elif sentiment_score < 0:
return emojize(":thumbs_down: This article seems negative.")
else:
return emojize(":neutral_face: This article seems neutral.")
def wiki_search_with_feedback():
term = input("Enter a term to search on Wikipedia: ")
try:
result = wikipedia.search(term)
summary = wikipedia.summary(result[0])
display(Markdown(f"### Wikipedia Summary for **{term}**"))
display(Markdown(summary))
sentiment_feedback = analyze_sentiment(summary)
display(Markdown(f"**Sentiment Analysis Result:** {sentiment_feedback}"))
except wikipedia.exceptions.DisambiguationError as e:
display(Markdown(f":warning: **Multiple results found for '{term}', please be more specific:**"))
for option in e.options[:5]:
display(Markdown(f"- {option}"))
except wikipedia.exceptions.PageError:
display(Markdown(f":warning: **No page found for '{term}', please try a different search term.**"))
wiki_search_with_feedback()
Wikipedia Summary for weapons
A weapon, arm, or armament is any implement or device that is used to deter, threaten, inflict physical damage, harm, or kill. Weapons are used to increase the efficacy and efficiency of activities such as hunting, crime (e.g., murder), law enforcement, self-defense, warfare, or suicide. In a broader context, weapons may be construed to include anything used to gain a tactical, strategic, material, or mental advantage over an adversary or enemy target. While ordinary objects such as sticks, rocks, bottles, chairs, and vehicles can be used as weapons, many objects are expressly designed for the purpose; these range from simple implements such as clubs, axes, spears, and swords to complicated modern firearms, tanks, intercontinental ballistic missiles, biological weapons, and cyberweapons. Something that has been repurposed, converted, or enhanced to become a weapon of war is termed weaponized, such as a weaponized virus or weaponized laser.
Sentiment Analysis Result: 👎 This article seems negative.
RANDOM SENTENCE DISPLAY DOWN BELOW HACKS
public class RandomSentenceDisplay {
public static void main(String[] args) {
JFrame frame = new JFrame("Random Sentence Generator");
JLabel sentenceLabel = new JLabel(generateRandomSentence(), JLabel.CENTER);
sentenceLabel.setFont(new Font("Serif", Font.BOLD, 24));
frame.setSize(500, 200);
frame.add(sentenceLabel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static String generateRandomSentence() {
String[] subjects = {"The cat", "A scientist", "An elephant", "My friend", "The robot"};
String[] verbs = {"jumps over", "writes", "eats", "builds", "solves"};
String[] objects = {"a fence", "a computer", "some cookies", "a spaceship", "a puzzle"};
Random random = new Random();
String randomSubject = subjects[random.nextInt(subjects.length)];
String randomVerb = verbs[random.nextInt(verbs.length)];
String randomObject = objects[random.nextInt(objects.length)];
return randomSubject + " " + randomVerb + " " + randomObject + ".";
}
}
RANDOM QUOTE DISPLAY DOWN BELOW HACKS
public class RandomQuoteDisplay {
public static void main(String[] args) {
JFrame frame = new JFrame("Random Motivational Quote");
JLabel quoteLabel = new JLabel(getRandomQuote(), JLabel.CENTER);
quoteLabel.setFont(new Font("Serif", Font.ITALIC, 20));
quoteLabel.setForeground(Color.BLUE);
frame.setSize(600, 200);
frame.add(quoteLabel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static String getRandomQuote() {
String[] quotes = {
"Believe in yourself!",
"Stay positive and happy.",
"The only limit to our realization of tomorrow is our doubts of today.",
"Your limitation—it's only your imagination.",
"Push yourself, because no one else is going to do it for you.",
"Great things never come from comfort zones.",
"Dream it. Wish it. Do it.",
"Success doesn’t just find you. You have to go out and get it."
};
Random random = new Random();
return quotes[random.nextInt(quotes.length)];
}
}