
By Alexandros Sainidis
We are happy to share with you our first piece of code that you can try out yourself! Artificial Intelligence is catching up with us, humans, and for that reason we must be able to revolutionize the way we are handling technology. Don’t worry, the code will not be random. Rather, it will be code, automations and applications that help you with tasks related to knowledge management and intelligence studies. So, let’s take a look.
The lemon – banana – apple app
This first application is written in Python, one of the simpler languages to start coding with, due to its features making it resemble English. Our app is a program where you enter the text – the app then reads the text to find how many times lemons, bananas and apples are mentioned. It then prints those instances with their immediate context. See the code below.
import re
def find_fruits_context(text, fruit_list):
# Convert text to lowercase for case-insensitive matching
text_lower = text.lower()
# Dictionary to store fruit counts
fruit_counts = {fruit: 0 for fruit in fruit_list}
# Dictionary to store fruit contexts
fruit_contexts = {fruit: [] for fruit in fruit_list}
# Find all occurrences of each fruit
for fruit in fruit_list:
# Find all positions of the fruit in the text
for match in re.finditer(r'\b' + fruit + r'\b', text_lower):
fruit_counts[fruit] += 1
# Get the position of the fruit
start_pos = match.start()
end_pos = match.end()
# Get context (10 words before and after)
# Find the start of context (10 words before)
words_before = text_lower[:start_pos].split()
context_start = " ".join(words_before[-10:] if len(words_before) >= 10 else words_before)
# Find the end of context (10 words after)
words_after = text_lower[end_pos:].split()
context_end = " ".join(words_after[:10] if len(words_after) >= 10 else words_after)
# Get the actual fruit text from the original text (preserving case)
original_fruit = text[start_pos:end_pos]
# Combine the context
context = f"...{context_start} [{original_fruit}] {context_end}..."
fruit_contexts[fruit].append(context)
return fruit_counts, fruit_contexts
def main():
# List of fruits to search for
fruits = ['apple', 'banana', 'lemon']
# Get input text from user
print("Please enter your text (press Enter twice when done):")
lines = []
while True:
line = input()
if line:
lines.append(line)
else:
break
text="\n".join(lines)
# Find fruits and their contexts
counts, contexts = find_fruits_context(text, fruits)
# Print results
print("\nResults:")
print("-" * 50)
# Print counts
print("Fruit counts:")
for fruit, count in counts.items():
print(f"{fruit.capitalize()}: {count} occurrence(s)")
# Print contexts
print("\nContexts where fruits appear:")
for fruit in fruits:
if contexts[fruit]:
print(f"\n{fruit.capitalize()}:")
for i, context in enumerate(contexts[fruit], 1):
print(f"{i}. {context}")
else:
print(f"\n{fruit.capitalize()}: No occurrences found")
if __name__ == "__main__":
main()
You can input this AI generated text to test the code:
“The Great Fruit Escape
In the bustling produce section of Greenville Grocery, three unlikely friends huddled together on a wooden display. There was Zesty, the bright yellow lemon with a sharp tongue and even sharper wit; Sunny, the cheerful banana with a golden disposition; and Pip, the rosy-cheeked apple who was always the most practical of the trio. “We can’t just sit here and wait to be bought!” Zesty proclaimed, his citrusy skin practically vibrating with energy. “There’s a whole world beyond these shelves!” Sunny nodded enthusiastically, his curved smile somehow growing wider. “I’ve heard stories from the traveling fruit trucks. Adventures! Excitement!” Pip rolled her eyes. “We’re produce. We have a job to do. Being eaten is our purpose.” But even as she said it, a tiny spark of curiosity flickered in her core. That night, when the grocery store grew quiet and the fluorescent lights dimmed, something extraordinary happened. A loose shelf board created just enough of a gap for their carefully coordinated escape. Zesty’s acidic wit had been plotting for days, Sunny’s flexible nature helped them wiggle and squeeze, and Pip’s strategic thinking guided their movement. With a soft tumble, they found themselves on the cool tile floor. Freedom! “Now what?” Pip whispered, her practical nature battling with newfound excitement. Zesty grinned. “Now we explore!” Their adventure took them through the quiet aisles. They slid past towering cereal boxes, navigated around mop buckets, and narrowly escaped the night watchman’s flashlight. Sunny told jokes that made Zesty’s sour expression crack into a smile, while Pip mapped out their route with unexpected daring. As dawn approached, they realized their great escape was coming to an end. But something had changed. Zesty wasn’t just a sour lemon anymore. Sunny wasn’t simply a sweet banana. Pip was no longer just a practical apple. They were friends who had discovered that life was about more than just waiting to be chosen. Just before the first morning employee arrived, they nestled back into their original spot on the produce display. To any observer, they looked exactly the same. But their eyes sparkled with a secret: they knew the joy of adventure, the thrill of friendship, and the magic of a single night of unexpected freedom. “Same time tomorrow?” Zesty whispered. Sunny and Pip exchanged a knowing glance and smiled. Some stories are best kept between friends – especially when those friends are a lemon, a banana, and an apple.“
Once you run the code and enter this text, you should be able to see the following results:

But Alexandros, why should I care about an app that helps me with fruit?
The fruits are just an example of how you can achieve some text manipulations with Python. Let’s apply it to a text relevant to international affairs.
Suppose that you are reading a very big PhD dissertation but you only need some information about Greece. The problem with Greece? If you simply do a Ctrl+F search with “Greece” you are missing all of the relevant results that would come up with “Greek”, “Athenian”, “Spartan”, “Hellenic” and any other phrase or keyword relevant to Greece. Instead of fruit, if you update your list with those, you will be able to find everything without being uncertain if you missed something.
Hint: With the current code you would need to add your keywords as lowercase.
Hope you enjoy it, as we will be coming with updates to this code! Who knows – maybe someday we will have our first indie game 🕹️.