Artificial intelligence and computational linguistics

Assignment Help JAVA Programming
Reference no: EM13681812

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<String[]> kGramsIn(ArrayList<String> text, int k)

This method accepts two parameters - an ArrayList<St ring> representing a piece of text and a num¬ber k. It should then return an Ar ray List<St ring [ ]> (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<String, String> 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.

Reference no: EM13681812

Questions Cloud

What is the maximum height reached by the frog : A leaping frog leaves the ground with a speed of 4 m/s heading straight upward. The frog's mass is 100 g (so its weight is 1 N). What is the maximum height reached by the frog through this leap? Look back at the formulas for gravitational potential e..
Calculate wavelength of the resulting wave on the cable : A steel cable with total length 58 m and mass 110 kg is connected to two poles. The tension in the cable is 2,116 N, and the wind makes the cable vibrate with a frequency of 2 Hz. Compute the wavelength of the resulting wave on the cable.
What are the size and the direction of the net force on it : A juniper-wood plank measuring 0.15 ft by 1 ft by 17 ft is totally submerged in water. What is its weight? (Ib) What is the buoyant force acting on it? (Ib) What are the size and the direction of the net force on it? (Ib)
How much gravitational potential energy is stored with dam : Hoover Dam produces electricity for residents of Nevada, Arizona, and California. The dam is 200 meters tall. Lake Mead sits at the top of the dam and contains about 10 billion cubic meters of water. Estimate how much gravitational potential energy i..
Artificial intelligence and computational linguistics : Artificial intelligence and computational linguistics - Andy Warhol Paintings - 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 p..
Acts on a square access hatch at the bottom of the tank : A storage tank 25 m high is filled with pure water. (Suppose the tank is open and exposed to the atmosphere at the top. Compute the magnitude of the net force that acts on a square access hatch at the bottom of the tank that measures 0.8 m by 0.8 m. ..
Box of mass slides down a rough vertical wall : A box of mass 3.06kg slides down a rough vertical wall. The gravitational force on the box is 30N. When the box reaches a speed of 2.5m/s, you start pushing on one edge of the box at a 45? Angle (utilize degrees in your calculations throughout this p..
What is the speed of sound in hydrogen : A 380-Hz sound travels during pure hydrogen. The wavelength of the sound is gauged to be 3.38 m. What is the speed of sound in hydrogen?
Is the process reversible or irreversible : A 12.0L gas tank containing 3.40 moles of ideal He gas at 30.0C is placed inside a completely evacuated insulated bell jar of volume 37.0L. A small hole in the tank allows the He to leak out into the jar until the gas reaches a final equilibrium stat..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Problem aa savings account object holds a nonnegative

problem aa savings account object holds a nonnegative balance and provides depositk and withdrawk methods where

  Mutant bacterium-synthesize the amino acid tyrosine

Consider a mutant bacterium you have isolated which is unable to synthesize the amino acid tyrosine. You grow it in the presence of a chemical mutagen and isolate a single revertant, which is now able to grow in the absence of tyrosine

  Determine the purpose of using javascriptreg on a website

what is the purpose of using javascriptreg on a website? what is a specific example of a javascriptreg application that

  Determine the example of a javascriptr framework in the

what is an example of a javascriptr framework? in the framework you have described what is an example of an application

  All your code should be in the main method

Write a Java test program, all your code should be in the main method, that asks the user for two numbers representing an investment value and interest rate

  You need to train for 10 weeks

You are preparing for a marathon. In order to prepare, you need to train for 10 weeks, running an increasing number of miles per week, starting at running at least 2 miles your first week up to 26 miles by week 10.

  Write a java program in a netbeans project that reads a

write a java program in a netbeans project that reads a text file containing the names and addresses of several people

  Create an application that demonstrates the use of the class

Create an application that demonstrates the use of the classes. Save the files as Player.java, Child.java, Actor.java, Musician.java, and UsePlayer.java.

  We will simulate a very simple network by having a process

we will simulate a very simple network by having a process correspond to a node in the network and files correspond to

  Traditionally-nutrition programs were targeted to indigent

Traditionally, nutrition programs were targeted to the indigent and poor populations in developing countries. Many of today's Americans are malnourished also, but they are glutted with a wealth of unhealthy foods and require a multidisciplinary appro..

  Consider a typical certification hierarchy

Why might Bob still not trust that the certificate for Alice truly establishes Alice as the owner of the public key in the certificate?

  To translate infix mathematical expression

Write a program in java to translate infix mathematical expression into postfix expression and a program to evaluate the postfix expression

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd