OneCompiler

DS22

138

. 1)Create a table student having attributes(rollno, name, class). Using codeigniter, connect to the
database and insert 5 recodes in it. [Marks 15]
CREATE TABLE student (
rollno INT PRIMARY KEY,
name VARCHAR(255),
class VARCHAR(50)
);

<?php class Student_model extends CI_Model { public function __construct() { parent::__construct(); $this->load->database(); // Load the database library } // Function to insert records into the student table public function insert_student($data) { $this->db->insert('student', $data); return $this->db->insert_id(); // Return the auto-generated ID of the inserted record } } ?> <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Student extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('student_model'); // Load the Student_model } // Function to insert 5 records into the student table public function insert_records() { $data = array( array('rollno' => 1, 'name' => 'John', 'class' => 'X'), array('rollno' => 2, 'name' => 'Jane', 'class' => 'XI'), array('rollno' => 3, 'name' => 'Alice', 'class' => 'X'), array('rollno' => 4, 'name' => 'Bob', 'class' => 'XII'), array('rollno' => 5, 'name' => 'Eve', 'class' => 'X') ); foreach ($data as $student) { $this->student_model->insert_student($student); } echo "Records inserted successfully!"; } } ?>

Q. 2)Consider any text paragraph. Remove the stopwords
import nltk
from nltk.corpus import stopwords
nltk.download('stopwords')

Sample text paragraph

text = """Consider any text paragraph. Remove the stopwords."""

Tokenize the text into words

words = nltk.word_tokenize(text)

Remove stopwords

filtered_words = [word for word in words if word.lower() not in stopwords.words('english')]

Join the filtered words back into a paragraph

filtered_text = ' '.join(filtered_words)

print("Original Text:")
print(text)

print("\nText after removing stopwords:")
print(filtered_text)