SHARE
TWEET

Untitled

a guest May 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Parsing;
  2. import static java.util.stream.Collectors.toMap;
  3.  
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.io.UnsupportedEncodingException;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import java.util.Collections;
  12. import java.util.Comparator;
  13. import java.util.HashMap;
  14. import java.util.HashSet;
  15. import java.util.LinkedHashMap;
  16. import java.util.LinkedList;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.Set;
  20.  
  21. import com.github.javaparser.ParseException;
  22.  
  23. import Structures.Attribute;
  24. import Structures.Class;
  25. import Structures.Comment;
  26. import Structures.Method;
  27. import Structures.Package;
  28. import Structures.Variable;
  29.  
  30. public class ApplicationParse {
  31.  
  32.     public static void main(String[] args) throws ParseException, IOException {
  33.  
  34.         String path = "C:\\Users\\THINKPAD W541\\eclipse-workspace\\org.eclipse.acceleo-3.7.8";
  35.         File projectDir = new File(path);
  36.         DB.connect();
  37.         String projectName = new File(path).getName();
  38.         System.out.println("Projet ------- " + projectName);
  39.         ListClassParsed.listClasses(projectDir, projectName);
  40.         String vocabulaire = "";
  41.         StanfordLemmatizer lematizer = new StanfordLemmatizer();
  42.         vocabulaire = Method.extractName(DB.connection);
  43.         /*try {
  44.             vocabulaire = Attribute.extractName(DB.connection);
  45.             PrintWriter writer = new PrintWriter("Vocabulaire_Attributes.txt", "UTF-8");
  46.             writer.print(remDoubleMot(lematizer.lemmatize(vocabulaire)));
  47.             writer.close();
  48.             vocabulaire = Class.extractName(DB.connection);
  49.             writer = new PrintWriter("Vocabulaire_Classes.txt", "UTF-8");
  50.             writer.print(remDoubleMot(lematizer.lemmatize(vocabulaire)));
  51.             writer.close();
  52.             vocabulaire = Comment.extractContent(DB.connection);
  53.             wordCount(vocabulaire);
  54.             writer = new PrintWriter("Vocabulaire_Comments.txt", "UTF-8");
  55.             writer.print(remDoubleMot(lematizer.lemmatize(vocabulaire)));
  56.             writer.close();
  57.             vocabulaire = Method.extractName(DB.connection);
  58.             writer = new PrintWriter("Vocabulaire_Methods.txt", "UTF-8");
  59.             writer.print(remDoubleMot(lematizer.lemmatize(vocabulaire)));
  60.             writer.close();
  61.             vocabulaire = Package.extractName(DB.connection);
  62.             writer = new PrintWriter("Vocabulaire_Packages.txt", "UTF-8");
  63.             writer.print(remDoubleMot(lematizer.lemmatize(vocabulaire)));
  64.             writer.close();
  65.             vocabulaire = Variable.extractName(DB.connection);
  66.             writer = new PrintWriter("Vocabulaire_Variables.txt", "UTF-8");
  67.             writer.print(remDoubleMot(lematizer.lemmatize(vocabulaire)));
  68.             writer.close();
  69.         } catch (FileNotFoundException | UnsupportedEncodingException e1) {
  70.             System.err.println(e1.getMessage());
  71.         }*/
  72.         try {
  73.             DB.connection.close();
  74.         } catch (SQLException e) {
  75.             System.out.println(e.getMessage());
  76.         }
  77.  
  78.     }
  79.  
  80.     public static List remDoubleMot(List<String> list) {
  81.  
  82.         List<String> newlist = new ArrayList();
  83.         Set<String> uniqueWords = new HashSet<String>(list);
  84.         for (String word : uniqueWords) {
  85.  
  86.             if (Collections.frequency(list, word) > 0) {
  87.                 newlist.add(word);
  88.             }
  89.         }
  90.         return newlist;
  91.     }
  92.  
  93.     static void wordCount(String text) {
  94.         String[] b = text.split(" ");
  95.         HashMap<String, Integer> freqMap = new HashMap<String, Integer>();
  96.         for (int i = 0; i < b.length; i++) {
  97.             String key = b[i];
  98.             int freq = freqMap.getOrDefault(key, 0);
  99.             freqMap.put(key, ++freq);
  100.         }
  101.         freqMap = freqMap.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
  102.                 .collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
  103.         System.out.println(freqMap);
  104.         //sortByValue(freqMap);
  105.         /*
  106.          * for (Entry<String, Integer> result : freqMap.entrySet()) {
  107.          * System.out.println(result.getKey() + " " + result.getValue()); }
  108.          */
  109.     }
  110.  
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top