Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Problem: k-Grams

In computational linguistics, a k-gram is a series of k consecutive words taken out of a piece of text. For example, in the text

                                         Mr. Owl ate my metal worm
there are four 3-grams, each of which is given below:

Mr. Owl ate

Owl ate my

ate my metal

my metal worm

k-grams are used extensively in computer science - especially in artificial intelligence and computational linguistics - and are at the heart of many techniques in machine translation.

Your job in this problem is to write a method

private ArrayList kGramsIn(ArrayList text, int k)

This method accepts two parameters - an ArrayList representing a piece of text and a num¬ber k. It should then return an Ar ray List (that is, an ArrayList of arrays of Strings) con¬taining all the k-grams in the text.

The text parameter to this method consists of an ArrayList containing all the words in the source text in the order in which they appear. For example, if the input text was "Mr. Owl ate my metal worm," the text parameter would be this ArrayList:

Mr. Owl ate my metal worm

Calling the above method on this text with k= 2 would produce an ArrayList containing the following 2-grams, each of which would be represented by a St ring [ ] of length two:

Mr. Owl
Owl ate
ate my
my metal
metal worm

Calling this method with k = 4 would produce an ArrayList containing these 4-grams, each of which would be represented by a St ring [] of length four:

Mr. Owl ate my
Owl ate my metal
ate my metal worm

In implementing this method, you can assume that the value of k will be greater than zero and no greater than the number of words in text.

Problem: Andy Warhol Paintings

The artist Andy Warhol produced a series of famous portraits made with only a small number of colors. Even with a limited color palette, the portraits are immediately recognizable and have since become iconic. In this problem, we'd like you to write a method that transforms a source image in the style of these prints.

Write a method

private Glmage andyWarholtze(GImage source, int[] palette) that accepts as input two parameters. The first parameter, source, will be an ordinary GImage. The sec¬ond parameter, palette, is an array of ints, each of which represents a color value (in the same way that each pixel in a G Image has its color represented by an int value).

This method should work as follows. For each pixel in the source image, you will change the color of that pixel to the color from palette that is "closest" to the original color. To help you determine which palette color is closest to a given pixel color, you can assume you have access to the following method:

private double stmtlarity0f(int colorl, int color2)

This method accepts as input two int values representing colors and returns a double between 0 and 1 that determines how similar those colors are. The higher the value returned, the more similar the colors are. When you're trying to figure out which color from the palette you should use to replace some pixel from the original image, you'll want to use the palette color that's most similar to the original pixel. (If two or more colors are tied for highest similarity, you can use any one of them.)

In implementing this method, you can assume that the palette has at least one color in it, but you should make no other assumptions about the image or the palette colors. There is no special significance to the order in which the colon appear in the palette array.

Write your answer to this problem on the next page, and feel free to tear out this page as a reference. Just for fim, here's the output of the method given as input a picture of a puppy:

Problem: Finding Coworkers

Suppose you have the organizational hierarchies of various companies showing who reports to who. For example, across three different companies, you might have this hierarchy information:

307_Artificial intelligence and computational linguistics.png

In this diagram, person e reports directly to person b, who reports directly to person a, who is the CEO of her company and therefore doesn't report to anyone.

This hierarchical information can be represented as a HashMapcSt ring , St ring> associating each per¬son with their direct superior (that is, the person one level above them in the hierarchy). As an excep¬tion, the heads of each organization are not present in the HashMap, since they don't report to anyone. For example, in the above picture, the key h would have value g, the key g would have value d, the key d would have value a, and a would not be a key in the map.

Given two different people you can tell whether they work for the same company by tracing from those people all the way up to their companies' CEOs, then seeing whether those CEOs are the same person. For example, in the above diagram, person e and person j work in the same company because both of them report (indirectly) to a. Similarly, person n and person k are in the same organization, as are per¬son c and person d. However, person j and person in are not in the same company, since person fs com¬pany is headed by person a and person m's company is headed by person k. Along similar lines, person and person b are in different companies, since person ar runs her own company (she doesn't report to anyone) and person b works at a company headed by person a.

Your job is to write a method

private boolean areAtSameCompany(String p1, String p2,
HashMap bosses)

that accepts as input two people and a HashMap associating each person with their boss, then reports whether pl and p2 work at the same company. You can assume the following:

• For simplicity, assume that everyone has just one boss, that each company has just one CEO, and that no person works at two or more companies.

• Everyone, except for the heads of companies, appear as keys in the HashMap. Therefore, if someone doesn't appear in the HashMap, you can assume that they are the head of a company.

• Names are case-sensitive, so "Karel" and "KAREL" are considered different people.

• pl and p2 may be the same person.

• There can be any number of levels of management between pl and her CEO and between p2 and his CEO, including 0, and that number of levels doesn't have to be the same.

Java, Programming

  • Category:- Java
  • Reference No.:- M91221537
  • Price:- $70

Priced at Now at $70, Verified Solution

Have any Question?


Related Questions in Java

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As