কবি হওয়ার সহজ উপায়

Clifford A.Pickover নামে একজন ভদ্রলোক একবার চেষ্টা করেছিলেন কবিতাকে কমন একটা প্যাটার্নে ফেলতে। তার মতে, ইংরেজী ব্যকরণের Parts of Speech গুলোকে যদি এমনভাবে সাজানো যেত যাতে প্রতিবার কবিতা লিখতে গেলে এই সাজানো সিষ্টেমের মাঝে ফেললেই কবিতা বের হয়ে আসত !

তার দেওয়া “৩ লাইনের কবিতা লেখা”র ছোট্ট একটা সিষ্টেম হচ্ছেঃ

1 {A/An} {adjective1} {noun1}
2
3 {A/An} {adjective1} {noun1} {verb1} {preposition1} the {adjective2}
{noun2}
4 {adverb1}, the {noun1} {verb2}
5 the {noun2} {verb3} {preposition2} a {adjective3} {noun3}

এখানে Parts of Speech গুলোতে randomly সংশ্লিষ্ট শব্দগুলো বসিয়ে দিলেই চলবে।

এই সিষ্টেমের উপর ভিত্তি করে কবিতা লেখার একটা পাইথন কোড শেয়ার করছিঃ

  1. from random import choice
  2. # decalring parts of speech
    Nouns= [“fossil”,”horse”,”aardvark”,”judge”,”chef”,”mango”,”extrovert”,”gorilla”]
    Verbs = [“kicks”,”jingles”,”bounces”,”slurps”,”meows”,”explodes”,”curdles”]
    Adjectives = [“furry”,”balding”,”incredulous”,”fragrant”,”exuberant”,”glistening”]
    Prepositions = [“against”,”after”,”into”,”beneath”,”upon”,”for”,”in”,”like”,”over”,”within”]
    Adverbs = [“curiously”,”extravagantly”,”tantalizingly”,”furiously”,”sensuously”]# Choosing 3 nouns, 3 adjectives, 3 verbs, 1 adverb and 2 prepositions

    noun1 = choice(Nouns)
    while True:
    a = choice(Nouns)
    if a != noun1:
    noun2 = a
    break
    while True:
    b = choice(Nouns)
    if b!= noun1 and b!= noun2:
    noun3 = b
    break

    verb1 = choice(Verbs)
    while True:
    a = choice(Verbs)
    if a != verb1:
    verb2 = a
    break
    while True:
    b = choice(Verbs)
    if b!= verb1 and b!= verb2:
    verb3 = b
    break

    adj1 = choice(Adjectives)
    while True:
    a = choice(Adjectives)
    if a != adj1:
    adj2 = a
    break
    while True:
    b = choice(Adjectives)
    if b!= adj1 and b!= adj2:
    adj3 = b
    break

    adverb1 = choice(Adverbs)

    prep1 = choice(Prepositions)
    while True:
    a = choice(Prepositions)
    if a != noun1:
    prep2 = a
    break

    # Generating lines of the poem according to the theory
    poem_line_one = “{} {} {}”.format(‘A’,adj1,noun1)
    poem_line_two = “\n”
    poem_line_three = “{0} {1} {2} {3} {4} the {5} {6}”.format(‘A’,adj1,noun1,verb1,prep1,adj2,noun2)
    poem_line_four = “{}, the {} {}”.format(adverb1,noun1,verb2)
    poem_line_five = “the {0} {1} {2} a {3} {4}”.format(noun2,verb3,prep2,adj3,noun3)

    # checking for the vowels
    vowels = [‘a’,’e’,’i’,’o’,’u’]
    if poem_line_one[2] in vowels:
    poem_line_one = “{} {} {}”.format(‘An’,adj1,noun1)
    poem_line_three = “{0} {1} {2} {3} {4} the {5} {6}”.format(‘An’,adj1,noun1,verb1,prep1,adj2,noun2)

    # Generating the poem
    print poem_line_one + “\n” + poem_line_two + “\n” + poem_line_three + “\n” + poem_line_four + “\n” + poem_line_five

 

এই কোড রান করে জেনারেট হওয়া কিছু কবিতার Screenshot:

Capture

 

 কোড রান করার জন্য কোডটা “code_name.py” আকারে যে ফোল্ডারে পাইথন ইনষ্টল করা আছে সেই ফোল্ডারে রেখে কমান্ড লাইন থেকে অথবা Python IDLE দিয়ে ওপেন করে রান করাতে হবে। পাইথন ২.৭.৮ ভার্সনে কোডটা লেখা হয়েছে।

Md. Noor Faizur Reza
Author: Md. Noor Faizur Reza

আমার যে কাজ ভালো লাগে তা নিয়ে সারাদিন পরে থাকি !

Permanent link to this article: https://www.borgomul.com/rezanur/3394/


মন্তব্য করুন আপনার ফেসবুক প্রোফাইল ব্যবহার করে

4 comments

Skip to comment form

  1. ভাই, একটা বাংলা কবিতা লেখার কিছু বানানো যায় না??? Matlab এ বাংলা কবিতা লেখার এরকম একটা কোড দেখছিলাম।
    %% Automatic Poem Generator

    clc
    close all
    clear all
    Poem_Key={'Tumi '; 'Ami '; 'Nodi '; 'Surjo '; 'Sondha '; 'Godhuli ';'Somudro '; 'Akash '; 'Megh '; 'Bristi '; 'Shimana '; 'Hridoy ';'Jol ' ;'Kolpona '; 'Protikkha '; 'Pronoy '};

    Poem_Line_No=4;
    Poem_Word_No=4;
    for i=1:Poem_Line_No
    Poem_Index=randperm(length(Poem_Key));

    Poem_Line=[];
    for j=1:Poem_Word_No
    Poem_Line=[Poem_Line Poem_Key{Poem_Index(j)}];
    end
    Poem{i}=Poem_Line;
    end
    sprintf('%s\n',Poem{:})

    আউটপুটঃ

    Ami Shimana Akash Tumi
    Akash Kolpona Godhuli Tumi
    Protikkha Ami Bristi Megh
    Ami Hridoy Somudro Pronoy

    1. হা হা হা হা হা। অদ্ভুত 😛

      সিরিয়াসলী বললে, এমন একটা অ্যাপ বানানো যায় যেটা কবিতা জেনারেট করবে। প্রোগ্রামিং ভাষা যেকোন একটা হলেই চলবে। মুল সমস্যাটা হচ্ছে একটা এফেক্টিভ অ্যালগরিদম দাড় করানো।

    2. এই পোস্টের শিরোনাম দেখে আমারো সবার আগে চরম উদাসের ওই কবিতা পোস্টের কথাই মাথায় আসছে 😀

  2. আহ কি দুনিয়া আইলো ভাই, কবিতাও এখন কোড দিয়ে লেখা হয়

মন্তব্য করুন