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...
in reference to SQL Database, what are some benefits of creating sequences, indexes, and synonyms?
in reference to SQL Database, what are some benefits of creating sequences, indexes, and synonyms?
Use MYSQL to create the set of database tables of the relational database model and complete...
Use MYSQL to create the set of database tables of the relational database model and complete the associated queries given. Procedure: 1) Write all the SQL statements, necessary to create all tables and relationships, with Primary & Foreign keys. 2) Execute each statement in the correct order to create the relational database in MYSQL. 3)Insert some data into each table. 4) Use all your SQL create and Insert statements (from MS Word) to execute in the MYSQL WorkBench 5) Write...
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...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals method to compare two or more objects. Your should use your QC5 as a reference. …………………………...…….. …………………………...……. Instructions LAB5 Instructions Using QC5 as a model, create a Rectangle class and a CompareUsingequalsMethod class that uses an   equals Method to determine if two rectangles are equal if and only if their areas are equal. The Rectangle class should have two instance variables length and width....
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE edu; Create a script which will create the tables listed below: STUDENT(STUDENT_ID, STUDENT_NAME, MAJOR_ID, DOB, PHONE_NUMBER) MAJOR(MAJOR_ID, MAJOR_NAME) ENROLLMENT(STUDENT_ID, COURSE_ID, GRADE) COURSE(COURSE_ID, COURSE_NAME) RESPONSIBILITY(FACULTY_ID, COURSE_ID) TEACHER(FACULTY_ID, DEPT_ID, TEACHER_NAME) DEPARTMENT(DEPT_ID, DEPARTMENT_NAME) Start the script with a series of DROP statements so that as you correct mistakes you will start fresh each time. To avoid referential integrity errors, the table drops should be in the opposite...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT