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:...
how to count the word of occurance in the text file example input text file :...
how to count the word of occurance in the text file example input text file : "test1.txt hello : 1 good : 1 morning: 1 how : 1 are : 2 you : 2 good : 1 example output text file : "test2.txt" 1 : 4 2 : 2 3 : 0 4 : 0 5 : 0
Write a program in structured text that tells a butterfly valve to open for 10seconds and...
Write a program in structured text that tells a butterfly valve to open for 10seconds and close thereafter.
Create a program that reports whether each word in a set of words appears in a...
Create a program that reports whether each word in a set of words appears in a paragraph. Here are the requirements: a. Ask the user to enter a set of words, one at a time. Use an appropriate prompt to keep asking for words until a blank line is entered. The set of words should be in a dictionary, where the word is the key, and “yes” or “no” is the value. The value represents whether the word appears in...
Our text tells us that the behavior of group members is shaped by the workgroups, which...
Our text tells us that the behavior of group members is shaped by the workgroups, which " help explain individual behaviors as well as the performance of the group." ( Robbins & Judge, p.139) There are several defining group properties including roles, norms, status, size, cohesiveness, and diversity. Pick three and give a brief explanation of how each might affects the workgroup positively and/or negatively.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT