Question

In: Computer Science

in this assignment you will create and use a database to find meanings and synonyms for...

in this assignment you will create and use a database to find meanings and synonyms for given phrases. To do so you will use tables of synsets -- sets of one or more synonyms (specific phrases) that share the same meaning.

Your program should:

  1. Display a message stating its goal
  2. Create a database file using SQLite using your name (i.e. use your name as a file name - for example, my database will be named "nimdvir")
  3. In your database, create a table named "synsets" with the columns "SynsetID" and "Definition", and populate it with values from the attached text file "Synsets" (also available to download here - https://drive.google.com/file/d/1qmj518lIjTFn6xifnd_PCl6AadY_JeG8/view?usp=sharing)
  4. In your database, create a table named "phrases" with the columns "SynsetID" and "phrase", and populate it with values from the attached text file "Phrases" (also available to download here - https://drive.google.com/file/d/1r-JZrF_Ei7a2_FPhXJqo9b-i8nvpqMbc/view?usp=sharing)
  5. Hint 1: make sure the encoding is correct (see previous readings)
  6. Hint 2: make sure you parse the text files correctly
  7. Hint 3: it is recommended not to import all the data while you are still working on the program. Use just a few values to make sure your program runs correctly, and them change it to import all the values from the files.
  8. Ask the user to enter a phrase and check if it's in the database (not case sensitive)
  9. If it's not in the database display a message and prompt the user to try again
  10. If it is in the database, return as output:
  11. How many meanings the phrase has? (in how many synsets it appear)
  12. How many unique synonyms the phrase has? (how many other phrases share the same synsets? Make sure to not count the phrase itself or the same phrase twice)
  13. Display all the meanings (definitions) the phrase has, including their corresponding Synset ID
  14. Below each definition out the correlating synonyms

For example, for the phrase "jail"

there are 2 meanings and 11 unique synonyms

Meaning 1:

lock up or confine, in or as in a jail

Synset ID:

2494356

Synonyms:

gaol

  • immure
  • jailed
  • jug
  • lag
  • laggin
  • remand

Meaning 2:

A correctional institution used to detain persons who are in the lawful custody of the government (either accused persons awaiting trial or convicted persons serving a sentence)

Synset ID:

3592245

Synonyms:

clink

  • gaol
  • pokey
  • poky
  • slammer
  • Remember:

Only use the material covered in this module -- do not use more advanced functions not covered yet in the course

  • Make sure to include comments that explain all your steps (starts with #). Also use a comment to sign your name at the beginning of the program!
  • Work individually and only submit original work

Submit a .py file!

Solutions

Expert Solution

import sqlite3
import pandas as pd
conn = sqlite3.connect('nimdvir.db')
c = conn.cursor()
c.execute('''CREATE TABLE synsets([SynsetID] INTEGER,[Definition] text)''')
c.execute('''CREATE TABLE phrases([SynsetID] INTEGER,[phrase] text)''')
conn.commit()
with open('/content/synsets.txt', 'r') as f:
    for line in f:
        data = line.split('\t')
        c.execute('INSERT INTO synsets (SynsetID, Definition) VALUES (?, ?)', (data[0], data[1].strip()))

with open('/content/phrases.txt', 'r') as f:
    for line in f:
        data = line.split('\t')
        c.execute('INSERT INTO phrases (SynsetID, phrase) VALUES (?, ?)', (data[0], data[1].strip()))

word = str(input("Enter the phrase: "))
query = 'SELECT * FROM phrases WHERE phrase=' + "'"+ word.lower() + "'"
df = pd.read_sql_query(query, conn)
if df.empty:
  print("please try again!")
else:
  result_query = 'SELECT DISTINCT s.SynsetID,Definition FROM phrases p INNER JOIN synsets s ON s.SynsetID=p.SynsetID WHERE phrase=' + "'"+ word.lower() + "'"
  result_df = pd.read_sql_query(result_query, conn)
  lst = result_df['SynsetID'].values.tolist()
  query = 'SELECT DISTINCT phrase,SynsetID FROM phrases WHERE SynsetID IN (SELECT DISTINCT s.SynsetID FROM phrases p INNER JOIN synsets s ON s.SynsetID=p.SynsetID WHERE phrase=' + "'"+ word.lower() + "') AND phrase<>"+ "'"+ word.lower() + "'"
  df = pd.read_sql_query(query, conn)
  syn = df['phrase'].values.tolist()
  print("There are "+ str(len(lst)) +" meanings and "+ str(len(syn)) +" unique synonyms")
  j=1
  for i in lst:
    print("Meaning - ",j)
    print(result_df[result_df['SynsetID']==i]['Definition'].values[0])
    print("Synset ID: ")
    print(i)
    print("Synonyms:")
    words = df[df['SynsetID']==i]['phrase'].values.tolist()
    for w in words:
      if w!=word.lower():
        print(w)
    j=j+1

ANy query you can ask in the comment. Thanks.


Related Solutions

Assignment Requirements: 1. Find a workout or create a workout and perform it. If you use...
Assignment Requirements: 1. Find a workout or create a workout and perform it. If you use an online workout/video please reference it so I know what you've done. If you create one yourself, make sure to include your written workout in the assignment. 2. Write about each component/part of the workout and how it related to the health-related components of physical fitness. Answer in detail.
All questions in this assignment refer to the “om” database (or Schema) that you will find...
All questions in this assignment refer to the “om” database (or Schema) that you will find in your MySQL Workbench program if you have run the sample database install script. Please save all of your answers in one script (.sql) or type all your answers into Notepad++ and submit them as a single .sql file. You are encouraged to test your SQL statements in Workbench, and please use the ‘tidy’ tool to properly format your SQL before you save it...
For this assignment, you will use the provided database in the Unit 5 script file. You...
For this assignment, you will use the provided database in the Unit 5 script file. You will add statements to this file to query the database tables. For your reference, below is a screenshot of the enhanced entity relationship diagram (ERD) as a reference when you write your queries. With the data types listed in the diagram, this will help you identify the types of operators that you can use for particular queries. Use paiza.io for MySQL to execute and...
Database Application Development Project/Assignment Milestone 1 (part 1) Objective: In this assignment, you create a simple...
Database Application Development Project/Assignment Milestone 1 (part 1) Objective: In this assignment, you create a simple HR application using the C++ programming language and Oracle server. This assignment helps students learn a basic understanding of application development using C++ programming and an Oracle database Submission: This Milestone is a new project that simply uses what was learned in the SETUP. Your submission will be a single text-based .cpp file including your C++ program for the Database Application project/assignment. The file...
Information on the following Database: create database Sales_Co use Sales_Co create table Vendor (v_code integer, v_name...
Information on the following Database: create database Sales_Co use Sales_Co create table Vendor (v_code integer, v_name varchar(35) not null, v_contact varchar(15) not null, v_areacode char(3) not null, v_phone char(8) not null, v_state char(2) not null, v_order char(1) not null, primary key (v_code)); create table product (p_code varchar(10) constraint product_p_code_pk primary key, p_descript varchar(35) not null, p_indate datetime not null, p_qoh integer not null, p_min integer not null, p_price numeric (8,2) not null, p_discount numeric (4,2) not null, v_code integer, constraint...
Use Visual Basic Language In this assignment you will need to create a program that will...
Use Visual Basic Language In this assignment you will need to create a program that will have both a “for statement” and an “if statement”. Your program will read 2 numbers from the input screen and it will determine which is the larger of the 2 numbers. It will do this 10 times. It will also keep track of both the largest and smallest numbers throughout the entire 10 times through the loop. An example of the program would be...
For this assignment, you are to use the business model canvas to create four (4) canvases...
For this assignment, you are to use the business model canvas to create four (4) canvases on different business concepts Make sure to include the following in the margins as per the video. 1)Key Trends 2) Industry Trends 3) Market Forces 4) Marco-economic forces
In this assignment you will use pointers and structures to create Single and double link list....
In this assignment you will use pointers and structures to create Single and double link list. Write a menu driven program with the menu options: 1. Insert in Linked List       1. Insert in Single linked list              1. Insert at front(head)              2. Insert at Index              3. Insert at end(tail)       2. Insert in double linked list              1. Insert at front(head)              2. Insert at Index              3. Insert at end(tail) 2. Print       1. Print linked...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class (CIN int PRIMARY KEY, FirstName varchar(255), LastName varchar(255), Gender varchar(1), EyeColor varchar(50), HairColor varchar(50), HeightInches int,CurrentGrade varchar(1));CREATE TABLE Student (SSN int PRIMARY KEY,FirstName varchar(255),LastName varchar(255), Age int,BirthMonth varchar(255),HeightInches int,Address varchar(255),City varchar(255),PhoneNumber varchar(12),Email varchar(255),FavColor varchar(255),FavNumber int);INSERT INTO Class VALUES(1, "David", "San", "M", "BRN", "BLK", 72, "-");INSERT INTO Class VALUES(2, "Jeff", "Gonzales", "M", "BRN", "BLK", 68, "B");INSERT INTO Class VALUES(3, "Anna", "Grayson", "F", "BRN", "BRN", 62,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT