Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1. (WordNet Data Type) Implement an immutable data type called WordNet with the following API: WordNet(String synsets, String hypernyms) constructs a WordNet object given

Problem 1. (WordNet Data Type) Implement an immutable data type called WordNet with the following API:

WordNet(String synsets, String hypernyms) constructs a WordNet object given the names of the input (synset and hypernym) files Iterable nouns() returns all WordNet nouns boolean isNoun(String word) returns true if the given word is a WordNet noun, and false otherwise String sca(String noun1, String noun2) returns a synset that is a shortest common ancestor of noun1 and noun2 int distance(String noun1, String noun2) returns the length of the shortest ancestral path between noun1 and noun2

and the output for the problem is : 

$ java WordNet data/synsets.txt data/hypernyms.txt worm bird

# of nouns = 119188

isNoun(worm)? true 

isNoun(bird)? true 

isNoun(worm bird)? false 

sca(worm, bird) = animal animate_being beast brute creature fauna 

distance(worm, bird) = 5
 

here is the writeup for the code:

 import stdlib.StdIn;

 import stdlib.StdOut;

 public class Outcast {

 ... 

// Constructs a WordNet object given the names of the input (synset and hypernym) files.

public Outcast(WordNet wordnet) {

...

}

// Returns all WordNet nouns. 

public Iterable nouns() {

 ...

 }
 

// Returns true if the given word is a WordNet noun, and false otherwise.

 public boolean isNoun(String word) {

 ... 

}
 

// Returns a synset that is a shortest common ancestor of noun1 and noun2. 

public String sca(String noun1, String noun2) {

 ...

 }
 

// Returns the length of the shortest ancestral path between noun1 and noun2. 

public int distance(String noun1, String noun2) { 

...

}

 

// Unit tests the data type. [DO NOT EDIT] 

public static void main(String[] args) { 

WordNet wordnet = new WordNet(args[0], args[1]);

 String word1 = args[2]; 

String word2 = args[3]; 

int nouns = 0; 

for (String noun : wordnet.nouns()) { 

nouns++;

 }

StdOut.printf("# of nouns = %d", nouns); StdOut.printf("isNoun(%s)? %s", word1, wordnet.isNoun(word1)); StdOut.printf("isNoun(%s)? %s", word2, wordnet.isNoun(word2)); StdOut.printf("isNoun(%s %s)? %s", word1, word2, wordnet.isNoun(word1 + " " + word2)); StdOut.printf("sca(%s, %s) = %s", word1, word2, wordnet.sca(word1, word2)); StdOut.printf("distance(%s, %s) = %s", word1, word2, wordnet.distance(word1, word2)); } 

}

 

and here is the direction for the code: Directions: Instance variables: - A symbol table that maps a synset noun to a set of synset IDs (a synset noun can belong to multiple synsets), RedBlackBST> st . - A symbol table that maps a synset ID to the corresponding synset string, RedBlackBST rst. - For shortest common ancestor computations, ShortestCommonAncestor sca. WordNet(String synsets, String hypernyms) - Initialize instance variables st and rst appropriately using the synset file. - Construct a DiGraph object G (representing a rooted DAG) with V vertices (equal to the number of entries in the synset file), and add edges to it, read in from the hypernyms file. - Initialize sca using G. Iterable nouns() - Return all WordNet nouns. boolean isNoun(String word) - Return true if the given word is a synset noun, and false otherwise. String sca(String noun1, String noun2) - Use sca to compute and return a synset that is a shortest common ancestor of the given nouns. int distance(String noun1, String noun2) - Use sca to compute and return the length of the shortest ancestral path between the given nouns.
 

Note - Use these two import statements only :

import stdlib.StdIn;

import stdlib.StdOut;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Introduction The question is asking for the implementation of an immutable data type called WordNet which represents a lexical database of words organized as a directed acyclic graph DAG The WordNet c... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions