Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.lang.String;
  2. import java.util.Scanner;
  3. public class Learn {
  4. public static void BOWVocabulary(String [] words,String [] uniquewords,int [] frequency){
  5.  
  6.     uniquewords[0]=words[0];frequency[0]=1;
  7.  
  8.     for (int i = 0; i < words.length; i++) { {if(i==0){continue;};
  9.  
  10.  
  11.         for (int j = 0; j < words.length; j++) {
  12.             if(words[i].equals(uniquewords[j]))
  13.             frequency[j]=frequency[j]+1;
  14.  
  15.         }
  16.  
  17.        uniquewords[i]=words[i];
  18.      frequency[i]++;
  19.     }
  20.  
  21.  
  22.     }
  23.  
  24.  
  25.   }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. public static void main(String [] args){
  37. Scanner input = new Scanner(System.in);
  38. System.out.print("Enter a text (press enter to stop): ");
  39. String text=input.nextLine();
  40. String[] words = text.split("\\s+");
  41. int len=words.length;
  42. String[] uniquewords = new String[len];
  43. //array to save frequency
  44. int [] frequency = new int[len];
  45. BOWVocabulary(words,uniquewords,frequency);
  46.     for (int i = 0; i <len; i++) {
  47.  
  48.         System.out.println(uniquewords[i]+" "+frequency[i]);
  49.     }
  50.  
  51.  
  52.  
  53. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement