Question

In: Computer Science

A concordance is a table that tells how often a word appears in a text (or...

A concordance is a table that tells how often a word appears in a text (or where in a text it appears; but we are not using this definition).

You are going to write a program for a concordance that:

  • reads a text
  • separates it into words (any collection of letters appearing between non-alphabetic characters)
  • places them into a table (if they are not already there with an initial count of 1)
  • or adds one to its count in the table (if it's already there).

The next step in writing this program is to write the Concordance class with:

  1. the necessary constructor that initializes the number of installed words to zero (0)
  2. Installs additional words, by placing them at the end of the array, incrementing the count and then sorting them into order.:
  3. searches the array for a word, returning the index if the word is there and return -1 if it isn't
  4. Prints the lsit of words and the number of occurences in the text.
Your program should be modular, with separate classes for handling input/output and for the concordance.

To simplify the assignment, assume that a word is any collection of consecutive characters separated by white space.

Your input should be a text file (or equivalent) and your output should be a listing of the words (in alphabetical order) and the number of times that they appear in the input.

You will submit a program listing (properly commented), your sample document (at least 40 lines of text) and the print-out.



it is about java

i need to make a programming to read my input text file. input can be any word. output should contains a list of occurences of all text file’s words.

Solutions

Expert Solution

Program

import java.util.*;
import java.io.*;

public class Concordance
{
   int count;
   String words[] = new String[200];
   int countwords[] = new int[1200];
  
   //constructor
   public Concordance()
   {
       this.count = 0;
   }
  
   public void addWords(String s)
   {
       s = s.toLowerCase();
       int n = s.length();
       char c = s.charAt(n-1);
       if (c < 97 || c > 122)
           s = s.substring(0,n-1);
      
       int i = search(s);
       if(i==-1)
       {
           words[count] = s;
           countwords[count] = 1;
           count++;
       }
       else
       {
           countwords[i]++;
       }
   }
   //method ti\o sort the words
   public void sort()
   {
       for(int i=0; i<count-1; i++)
       {
           for(int j=i+1; j<count; j++)
           {
               if(words[i].compareTo(words[j])>0)
               {
                   String t = words[i];
                   words[i] = words[j];
                   words[j] = t;
                   int k = countwords[i];
                   countwords[i] = countwords[j];
                   countwords[j] = k;
               }
           }
       }
       }
   //method to search a word
   public int search(String s)
   {
       for(int i=0; i<count; i++)
       {
           if(words[i].equals(s)==true)
           {
               return i;
           }
       }
       return -1;
   }
  
   //method to print the list of words and the number of occurences
   public void print()
   {
       System.out.println("Words\tNumber of occurences");
      System.out.println("---------------------------");
       for(int i=0; i<count; i++)
       {
           System.out.printf("%-15s\t%d\n",words[i],countwords[i]);
       }
   }
}


class Driver
{
   public static void main(String args[]) throws IOException
   {
       Scanner in = new Scanner(System.in);
      
       System.out.print("Enter input Text File: ");
  
       String textfile = in.nextLine();
      
       File file = new File(textfile);
      
       Scanner sc = new Scanner(file);
      
       Concordance cc = new Concordance();
      
       while(sc.hasNext())
       {
       String s = sc.next();
      
       cc.addWords(s);
       }
      
       cc.sort();
      
       cc.print();
   }
}

Sample output:

Enter input Text File: inputdata.txt


Words Number of Occurences
-----------------------------------------
a 5
about 2
afterwards 1
again 1
all 3
and 3
appropiate 1
as 3
at 1
basis 1
be 2
begin 1
being 1
but 1
comes 1
could 1
daily 1
day 1
delete 1
developer 1
dream 1
embrace 1
end 1
enough 1
experience 1
feel 1
figured 1
first 1
for 2
forgive 1
fortunate 1
free 1
graduated 1
guess 1
have 1
i 7
i'm 1
if 2
insecurities 1
is 2
it 4
it's 1
job 1
junior 2
just 1
know 1
land 1
low 1
me 3
more 1
much 2
my 2
need 3
not 2
noted 1
of 4
on 1
one 1
only 1
personal 1
please 2
position 1
post 1
potentially 1
pretty 1
really 2
redirect 1
right 1
second 1
seeing 1
should 1
show 1
stress 1
stresses 1
sub 3
summer 1
that 2
the 3
this 7
to 9
tolerance 1
too 1
vent 2
was 1
which 1
with 1


Related Solutions

Word Frequencies (Concordance)    1. Use a text editor to create a text file (ex: myPaper.txt)...
Word Frequencies (Concordance)    1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt)...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE:...
I have a Python code that reads the text file, creates word list then calculates word...
I have a Python code that reads the text file, creates word list then calculates word frequency of each word. Please see below: #Open file f = open('example.txt', 'r') #list created with all words data=f.read().lower() list1=data.split() #empty dictionary d={} # Adding all elements of the list to a dictionary and assigning it's value as zero for i in set(list1):     d[i]=0 # checking and counting the values for i in list1:     for j in d.keys():        if i==j:           d[i]=d[i]+1 #Return all non-overlapping...
Our course text tells us that understanding cultural differences is critical to the success of firms...
Our course text tells us that understanding cultural differences is critical to the success of firms engaging in international business. We have learned that Hall and Hall developed the low-context-high-context classification scheme, which focuses on the importance of context within a culture. Based on what you have read, please describe the difference between high-context and low-context cultures and explain why understanding this difference is important for managers who are trying to develop business opportunities internationally.
What is the word length effect? include references and in text citations.
What is the word length effect? include references and in text citations.
Jim Young/Reuters Screw the passengers. That appears all too often to be the governing philosophy of...
Jim Young/Reuters Screw the passengers. That appears all too often to be the governing philosophy of the airline business. Take the case of a United Airlines flight from Chicago to London last weekend. A technical problem forced the plane to abort its trans-Atlantic route and divert to Goose Bay in Canada. The 176 passengers were marooned there for more than 20 hours, sleeping in unheated military barracks at near-freezing temperatures. “There was nobody from United Airlines to be seen anywhere,”...
Word Match: From the list of words provided, enter in the table below the word that...
Word Match: From the list of words provided, enter in the table below the word that best describes each of the listed meanings Alveoli Congestion Pleura Anthracosis Exudate Pneumocytes Bronchiole Fibrin Sequelae Bronchus Metamyelocytes Suppuration Term Meaning The process of forming puss that can occur during the process of eliminating stimulus of inflammation. Abnormal accumulation of blood or other fluids in blood vessel or body part. Cells and fluids that has seeped out of blood vessels or an organ. Small...
Word Match: From the list of words provided, enter in the table below the word that...
Word Match: From the list of words provided, enter in the table below the word that best describes each of the listed meanings Alveoli Congestion Pleura Anthracosis Exudate Pneumocytes Bronchiole Fibrin Sequelae Bronchus Metamyelocytes Suppuration Term Meaning The process of forming puss that can occur during the process of eliminating stimulus of inflammation. Abnormal accumulation of blood or other fluids in blood vessel or body part. Cells and fluids that has seeped out of blood vessels or an organ. Small...
12. (Equilibrium) Assume the market for corn is depicted as in the table that appears below....
12. (Equilibrium) Assume the market for corn is depicted as in the table that appears below. Complete the table below. What market pressure occurs when quantity demanded exceeds quantity supplied? Explain. What market pressure occurs when quantity supplied exceeds quantity demanded? Explain. What is the equilibrium price? What could change the equilibrium price? At each price in the first column of the table below, how much is sold? Price per Bushel Quantity Demanded (millions of bushels) Quantity Supplied (millions of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT