View Javadoc

1   package org.kit.furia;
2   
3   import java.text.DecimalFormat;
4   import java.text.NumberFormat;
5   
6   /*
7    Furia-chan: An Open Source software license violation detector.
8    Copyright (C) 2007 Kyushu Institute of Technology
9   
10   This program is free software: you can redistribute it and/or modify
11   it under the terms of the GNU General Public License as published by
12   the Free Software Foundation, either version 3 of the License, or
13   (at your option) any later version.
14  
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License for more details.
19  
20   You should have received a copy of the GNU General Public License
21   along with this program.  If not, see <http://www.gnu.org/licenses/>.
22   */
23  
24  /**
25   * Result holds a match result. It contains the document name, and some score calculation.
26   * @author Arnoldo Jose Muller Molina
27   * @since 0
28   */
29  /**
30   * @author amuller
31   *
32   */
33  public class ResultCandidate implements Comparable<ResultCandidate>{
34  
35      private static NumberFormat f  = new DecimalFormat("0.000");
36      
37      
38      /**
39       * The name of the document of the result
40       */
41      private String documentName;
42  
43      /**
44       * The score for the given document
45       */
46      private float score;
47        
48      
49      /**
50       * Number of fragments of the DB document (multi-set).
51       */    
52      private int mSetFragmentsCount;
53      
54      /**
55       * Number of words found (multi-set).
56       */
57      private int mSetFoundFragments;
58      
59      /**
60       * Number of fragments of the DB document (set).
61       */    
62      private int setFragmentsCount;
63      
64      /**
65       * Number of words found (set).
66       */
67      private int setFoundFragments;
68  
69      public String getDocumentName() {
70          return documentName;
71      }
72  
73      public float getScore(){
74          return score;
75      }
76   
77      /**
78       * Returns the naive similarity score.
79       * @return naive score.
80       */
81      public float getNaiveScoreMSet(){
82          return ((float)mSetFoundFragments ) / ((float) mSetFragmentsCount);
83      }
84      
85      /**
86       * Returns the naive similarity score.
87       * @return naive score.
88       */
89      public float getNaiveScoreSet(){
90          return ((float)setFoundFragments ) / ((float) setFragmentsCount);
91      }
92  
93      public ResultCandidate(String documentName, float score, int mSetFoundFragments, int mSetFragmentsCount, int setFoundFragments, int setFragmentsCount) {
94          super();
95          this.documentName = documentName;
96          this.score = score;
97          this.mSetFoundFragments = mSetFoundFragments;
98          this.mSetFragmentsCount = mSetFragmentsCount;    
99          this.setFoundFragments = setFoundFragments;
100         this.setFragmentsCount = setFragmentsCount;
101     }
102 
103     public int getMSetFragmentsCount() {
104         return mSetFragmentsCount;
105     }
106 
107     public int getMSetFoundFragments() {
108         return mSetFoundFragments;
109     }
110 
111     public int getSetFoundFragments() {
112         return setFoundFragments;
113     }
114 
115     public int getSetFragmentsCount() {
116         return setFragmentsCount;
117     }
118 
119 
120     public int compareTo(ResultCandidate w) {
121         int res = 0;
122         if (score < w.score) {
123             res = -1;
124         } else if (score > w.score) {
125             res = 1;
126         }// else they are equal
127         return res * -1;// invert the result
128     }
129     
130     public String toString(){
131         return documentName
132         + " " + f.format(getScore())  
133         + " " + f.format(getNaiveScoreMSet())
134         //+ " " + resultCandidate.getMSetFoundFragments()
135         //+ " " + resultCandidate.getMSetFragmentsCount()
136         + " " + f.format(getNaiveScoreSet())
137         //+ " " + resultCandidate.getSetFoundFragments()                            
138         + " " + getMSetFragmentsCount()
139         + " " + getSetFragmentsCount();
140     }
141     
142 }