Question

In: Computer Science

Create the infrastructure for building a word cloud application by (1) Reading the content of a...

Create the infrastructure for building a word cloud application by

(1) Reading the content of a text file and creating a binary tree of words in that file. When a duplicate word is encountered. we simply increase the frequency count of that word in its corresponding node. In other words, the nodes in the tree have two parts. One part maintains the word, and the other maintains the frequency count. It should also be noted that words will not be case sensitive, hence three variations of the word (hello, Hello, HELLO), should be stored in the same node in the tree, and it should have a frequency of 3.

(2) Once the binary tree of words (including their frequency) has been created, we need to print the words and their frequency count (one word per line). (Use InOrder() traversal to display the words and their frequency count)

I have additional files,

  • blacklist.txt (Links to an external site.)
  • testfile.txt (Links to an external site.)
  • datafile.txt

if I have the code I can try link the files

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

Points to consider:

  1. Reading the content of the file
  2. Making the count increased at each insert if it is already present
  3. Printing the value and the count as the inorder.

Code

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

// Java program to demonstrate insert operation in binary search tree
public class BinarySearchTree {

   /* Class containing left and right child of current node and key value*/
   class Node {
       String key;
       int count;
       Node left, right;

       public Node(String item) {
           key = item;
           count = 0;
           left = right = null;
       }
   }

   // Root of BST
   Node root;

   // Constructor
   BinarySearchTree() {
       root = null;
   }

   // This method mainly calls insertRec()
   void insert(String key) {
       key = key.toLowerCase();
       root = insertRec(root, key);
   }
  
   /* A recursive function to insert a new key in BST */
   Node insertRec(Node root, String key) {

       /* If the tree is empty, return a new node */
       if (root == null) {
           root = new Node(key);
           root.count = 1;
           return root;
       }

       /* Otherwise, recur down the tree */
       if (key.compareTo(root.key) < 0)
           root.left = insertRec(root.left, key);
       else if (key.compareTo(root.key) > 0)
           root.right = insertRec(root.right, key);
       else
           root.count += 1;
          

       /* return the (unchanged) node pointer */
       return root;
   }

   // This method mainly calls InorderRec()
   void inorder() {
       inorderRec(root);
   }

   // A utility function to do inorder traversal of BST
   void inorderRec(Node root) {
       if (root != null) {
           inorderRec(root.left);
           System.out.println(root.key + " " + root.count);
           inorderRec(root.right);
       }
   }

   // Driver Program to test above functions
   public static void main(String[] args) throws FileNotFoundException {
       BinarySearchTree tree = new BinarySearchTree();

       File file = new File("BSTData.txt");
       Scanner scan = new Scanner(file);
       while(scan.hasNext()) {
           String key = scan.next();
           tree.insert(key);
       }

       // print inorder traversal of the BST
       tree.inorder();
   }
}

Sample File: BSTData.txt

Sample Output:


Related Solutions

This is to done in Java: create the infrastructure for building a word cloud application. We...
This is to done in Java: create the infrastructure for building a word cloud application. We will do so by 1) Reading the content of a text file and creating a binary tree of words in that file. When a duplicate word is encountered. we simply increase the frequency count of that word in its corresponding node. In other words, the nodes in the tree have two parts. One part maintains the word, and the other maintains the frequency count....
What are the three disadvantages of cloud infrastructure?
What are the three disadvantages of cloud infrastructure?
Research the web for an example of a business using a cloud infrastructure. What were the...
Research the web for an example of a business using a cloud infrastructure. What were the main reasons for choosing a cloud infrastructure? What alternatives did the business have?
Discuss briefly your role (e.g. cloud architect, cloud application developer etc.)
Discuss briefly your role (e.g. cloud architect, cloud application developer etc.)
Word Building Build the following terms using word parts. 1. pus in the uterus: word part...
Word Building Build the following terms using word parts. 1. pus in the uterus: word part for pus ________________________ word part for uterus ________________________ term for pus in the uterus ________________________ 2. near the ovary: word part for near ________________________ word part for ovary ________________________ term for near the ovary ________________________ 3. pertaining to the urinary and reproductive systems: word part for urinary ________________________ word part for reproductive system ________________________ word part for pertaining to ________________________ term for pertaining to...
1.In country A, government increases spending on building infrastructure. However, the economic growth of the country...
1.In country A, government increases spending on building infrastructure. However, the economic growth of the country remains slow. Explain why. (Don’t just say that building physical capital is not sufficient for a country to grow.) 2. In country B, political unrests always occur, and these decrease economic growth. Explain why political unrests reduce firms’ investments and human capital of country B?
How can AWS Cloud infrastructure be used by a university to provide remote learning to students...
How can AWS Cloud infrastructure be used by a university to provide remote learning to students enrolled in technical programs/degrees such as CS/IT? Your answer should explain the advantages in terms of AWS Infrastructure. In other words, do not talk about general advantages of Cloud.
Web Server Infrastructure Web application infrastructure includes sub-components and external applications that provide efficiency, scalability, reliability,...
Web Server Infrastructure Web application infrastructure includes sub-components and external applications that provide efficiency, scalability, reliability, robustness, and most critically, security. The same advancements made in web applications that provide users these conveniences are the same components that criminal hackers use to exploit them. Prudent security administrators need to be aware of how to harden such systems. Use the graphic below to answer the following questions: Stage 1 Stage 2 Stage 3 Stage 4 Stage 5 Client Firewall Web Server...
Economic arguments for migrating corporate data centres and computing infrastructure to the cloud have often been...
Economic arguments for migrating corporate data centres and computing infrastructure to the cloud have often been quite persuasive. However, for large-scale business ventures and complex organisational scenarios, careful prior analysis, financial modelling and planning is often needed. Carry out the following tasks: Select any business sector in the country in which you currently reside, and present a reasonably detailed case, based mainly on economic grounds, for why large organisations in that sector would be better off relocating their IT systems...
specify the code to create html with the following content: 1. a paragraph stating, this is...
specify the code to create html with the following content: 1. a paragraph stating, this is an example. 2 image logo.jpg with alternate text ABC Logo below the paragraph created in 1.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT