MRivas

NewMethods

Apr 5th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.03 KB | None | 0 0
  1. public static long doFreq(int n, long df, long tf){
  2.         long returnValue = (long) (1+Math.log(tf)*Math.log(n/df));
  3.         return returnValue;
  4.     }
  5.    
  6.     public static void midTerms2 (Document doc, IndexReader reader, String field, int min, int max){
  7.         ArrayList <DocInfo> docsInfo = new ArrayList<>();
  8.         int i = 0;
  9.         long freq = 0;
  10.         long tf;
  11.         long df;
  12.         String [] content = doc.getValues(field);
  13.         for (String term : content){
  14.             Term termToSearch = new Term(field, term);
  15.             try {
  16.                 tf = TermFreqInDoc(doc,field, term);
  17.                 df = reader.totalTermFreq(termToSearch);
  18.                 freq = doFreq(reader.maxDoc(),tf,df);
  19.             } catch (IOException e) {
  20.                 e.printStackTrace();
  21.             }
  22.             docsInfo.add(new DocInfo(term,i,freq));
  23.             content = remove(content,term);
  24.         }
  25.        
  26.        
  27.         Arrays.sort((DocInfo [])docsInfo.toArray(), new Comparator<DocInfo>() {
  28.  
  29.             @Override
  30.             public int compare(DocInfo o1, DocInfo o2) {
  31.                 return Long.compare(o1.getTermFreq(), o2.getTermFreq());
  32.             }
  33.         });
  34.        
  35.        
  36.         for (i = min; i<docsInfo.size() && i < max; i++){
  37.             System.out.println("Termino "+docsInfo.get(i).getTerm()+" en el documento "+docsInfo.get(i).getDocId()+" con frecuencia "+docsInfo.get(i).getTermFreq());
  38.         }
  39.     }
  40.    
  41.    
  42.    
  43.     public static void midTerms (Document[] docs, IndexReader reader, String field, int min, int max){
  44.         ArrayList <DocInfo> docsInfo = new ArrayList<>();
  45.         int i = 0;
  46.         long freq = 0;
  47.         long tf;
  48.         long df;
  49.         for (Document doc : docs ){
  50.             String [] content = doc.getValues(field);
  51.             for (String term : content){
  52.                 Term termToSearch = new Term(field, term);
  53.                 try {
  54.                     tf = TermFreqInDoc(doc,field, term);
  55.                     df = reader.totalTermFreq(termToSearch);
  56.                     freq = doFreq(reader.maxDoc(),tf,df);
  57.                 } catch (IOException e) {
  58.                     e.printStackTrace();
  59.                 }
  60.                 docsInfo.add(new DocInfo(term,i,freq));
  61.                 content = remove(content,term);
  62.             }
  63.         }
  64.        
  65.        
  66.         Arrays.sort((DocInfo [])docsInfo.toArray(), new Comparator<DocInfo>() {
  67.  
  68.             @Override
  69.             public int compare(DocInfo o1, DocInfo o2) {
  70.                 return Long.compare(o1.getTermFreq(), o2.getTermFreq());
  71.             }
  72.         });
  73.        
  74.        
  75.         for (i = min; i<docsInfo.size() && i < max; i++){
  76.             System.out.println("Termino "+docsInfo.get(i).getTerm()+" en el documento "+docsInfo.get(i).getDocId()+" con frecuencia "+docsInfo.get(i).getTermFreq());
  77.         }
  78.     }
  79.    
  80.     public static void bottomTerms2 (Document doc, IndexReader reader,String field, int number){
  81.         ArrayList <DocInfo> docsInfo = new ArrayList<>();
  82.         int i = 0;
  83.         long freq = 0;
  84.         long tf;
  85.         long df;
  86.         String [] content = doc.getValues(field);
  87.         for (String term : content){
  88.             Term termToSearch = new Term(field, term);
  89.             try {
  90.                 tf = TermFreqInDoc(doc,field, term);
  91.                 df = reader.totalTermFreq(termToSearch);
  92.                 freq = doFreq(reader.maxDoc(),tf,df);
  93.             } catch (IOException e) {
  94.                 e.printStackTrace();
  95.             }
  96.             docsInfo.add(new DocInfo(term,i,freq));
  97.             content = remove(content,term);
  98.         }
  99.        
  100.         Arrays.sort((DocInfo [])docsInfo.toArray(), new Comparator<DocInfo>() {
  101.  
  102.             @Override
  103.             public int compare(DocInfo o1, DocInfo o2) {
  104.                 return Long.compare(o1.getTermFreq(), o2.getTermFreq());
  105.             }
  106.         });
  107.        
  108.        
  109.         for (i = 0; i<docsInfo.size() && i < number; i++){
  110.             System.out.println("Termino "+docsInfo.get(i).getTerm()+" en el documento "+docsInfo.get(i).getDocId()+" con frecuencia "+docsInfo.get(i).getTermFreq());
  111.         }
  112.     }
  113.    
  114.     public static void bottomTerms (Document[] docs, IndexReader reader,String field, int number){
  115.         ArrayList <DocInfo> docsInfo = new ArrayList<>();
  116.         int i = 0;
  117.         long freq = 0;
  118.         long tf;
  119.         long df;
  120.         for (Document doc : docs ){
  121.             String [] content = doc.getValues(field);
  122.             for (String term : content){
  123.                 Term termToSearch = new Term(field, term);
  124.                 try {
  125.                     tf = TermFreqInDoc(doc,field, term);
  126.                     df = reader.totalTermFreq(termToSearch);
  127.                     freq = doFreq(reader.maxDoc(),tf,df);
  128.                 } catch (IOException e) {
  129.                     e.printStackTrace();
  130.                 }
  131.                 docsInfo.add(new DocInfo(term,i,freq));
  132.                 content = remove(content,term);
  133.             }
  134.         }
Advertisement
Add Comment
Please, Sign In to add comment