I need help with this assignment. Please use Java language only and please compile, test and run the code. Please give t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

I need help with this assignment. Please use Java language only and please compile, test and run the code. Please give t

Post by answerhappygod »

I need help with this assignment. Please use Java
language only and please compile, test and run the code.
Please give the output and make sure the code works. Here's the
question:
4-map
Implement constructor and lookupBigram according to
todos
Here's the given code:
import java.util.*;
public class Bigrams {
public static class Pair {
public T1 first;
public T2 second;
public Pair(T1 first, T2 second)
{
this.first =
first;
this.second =
second;
}
}
protected Map, Float> bigramCounts;
protected Map unigramCounts;
// TODO: Given filename fn, read in the file word
by word
// For each word:
// 1. call process(word)
// 2. increment count of that word in
unigramCounts
// 3. increment count of new Pair(prevword, word) in
bigramCounts
public Bigrams(String fn) {
}
// TODO: Given words w1 and w2,
// 1. replace w1 and w2 with process(w1) and
process(w2)
// 2. print the words
// 3. if bigram(w1, w2) is not found, print "Bigram
not found"
// 4. print how many times w1 appears
// 5. print how many times (w1, w2) appears
// 6. print count(w1, w2)/count(w1)
public float lookupBigram(String w1, String w2)
{
return (float) 0.0;
}
protected String process(String str) {
return
str.toLowerCase().replaceAll("[^a-z]", "");
}
public static void main(String[] args) {
if (args.length != 1) {

System.out.println("Usage: java Bigrams ");

System.out.println(args.length);
return;
}
Bigrams bg = new
Bigrams(args[0]);
List> wordpairs =
Arrays.asList(
new Pair("with",
"me"),
new Pair("the",
"grass"),
new Pair("the",
"king"),
new Pair("to",
"you")
);
for (Pair p : wordpairs) {

bg.lookupBigram(p.first, p.second);
}
System.out.println(bg.process("adddaWEFEF38234---+"));
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply