Source Code Cross Referenced for ClarkeCormackScorer.java in  » Search-Engine » mg4j » it » unimi » dsi » mg4j » search » score » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » mg4j » it.unimi.dsi.mg4j.search.score 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package it.unimi.dsi.mg4j.search.score;
002:
003:        /*		 
004:         * MG4J: Managing Gigabytes for Java
005:         *
006:         * Copyright (C) 2004-2007 Paolo Boldi
007:         *
008:         *  This library is free software; you can redistribute it and/or modify it
009:         *  under the terms of the GNU Lesser General Public License as published by the Free
010:         *  Software Foundation; either version 2.1 of the License, or (at your option)
011:         *  any later version.
012:         *
013:         *  This library is distributed in the hope that it will be useful, but
014:         *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
015:         *  or FITfNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
016:         *  for more details.
017:         *
018:         *  You should have received a copy of the GNU Lesser General Public License
019:         *  along with this program; if not, write to the Free Software
020:         *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021:         *
022:         */
023:
024:        import java.io.IOException;
025:
026:        import it.unimi.dsi.mg4j.index.Index;
027:        import it.unimi.dsi.util.Interval;
028:        import it.unimi.dsi.mg4j.search.IntervalIterator;
029:        import it.unimi.dsi.mg4j.search.IntervalIterators;
030:
031:        /** Computes the Clarke–Cormack score of all interval iterators of a document.
032:         *  This score function is defined in Charles L.A. Clarke and Gordon V. Cormack, “Shortest-Substring
033:         *  Retrieval and Ranking&rdquo;, <i>ACM Transactions on Information Systems</i>, 18(1):44&minus;78, 2000, 
034:         *  at page 65.
035:         * 
036:         *  <p>The score for each index depends on two parameters: an integer <var>h</var> and a double &alpha;.
037:         *  The score is obtained summing up a certain score assigned to all intervals in the interval iterator
038:         *  under examination. The score assigned to an interval is 1 if the interval
039:         *  has length smaller than <var>h</var>; otherwise, it is obtained by dividing <var>h</var> by
040:         *  the interval length, and raising the result to the power of &alpha;.
041:         * 
042:         *  <p>Note that the score assigned to each interval is between 0 and 1 (highest scores corresponding
043:         *  to best intervals). The score assigned to an interval iterator is thus bounded from above by the
044:         *  number of intervals; an alternative version allows one to have normalized scores (in this case, the resulting 
045:         *  value is an average instead of a sum). A scorer with similar relative ranks, but inherently (almost) normalised
046:         *  is provided by {@link it.unimi.dsi.mg4j.search.score.VignaScorer}. 
047:         * 
048:         *  <p>Typically, one sets <var>h</var>=16 (or a bit larger) and &alpha;=1 (or a bit smaller),
049:         *  but the authors say that the method is rather stable w.r.t. changes in the values of parameters.
050:         *  
051:         */
052:        public class ClarkeCormackScorer extends AbstractWeightedScorer
053:                implements  DelegatingScorer {
054:            /** The default value for <var>h</var>. */
055:            public static final int DEFAULT_H = 16;
056:            /** The parameter h. */
057:            public final int h;
058:            /** The parameter alpha. */
059:            public final double alpha;
060:            /** Whether the result should be normalized (i.e., between 0 and 1). */
061:            public final boolean normalize;
062:
063:            /** Creates a Clarke&ndash;Cormack scorer.
064:             * 
065:             * @param h the parameter <var>h</var>.
066:             * @param alpha the parameter &alpha;.
067:             * @param normalize whether the result should be normalized.
068:             */
069:            public ClarkeCormackScorer(final int h, final double alpha,
070:                    final boolean normalize) {
071:                this .h = h;
072:                this .alpha = alpha;
073:                this .normalize = normalize;
074:            }
075:
076:            /** Creates a Clarke&ndash;Cormack scorer.
077:             * 
078:             * @param h the parameter <var>h</var>.
079:             * @param alpha the parameter &alpha;.
080:             * @param normalize whether the result should be normalized.
081:             */
082:            public ClarkeCormackScorer(final String h, final String alpha,
083:                    final String normalize) {
084:                this (Integer.parseInt(h), Double.parseDouble(alpha), Boolean
085:                        .parseBoolean(normalize));
086:            }
087:
088:            /** Default constructor, assigning the default values (<var>h</var>={@link #DEFAULT_H}, &alpha;=1) to the
089:             *  parameters; the resulting scorer is normalized.
090:             */
091:            public ClarkeCormackScorer() {
092:                this (DEFAULT_H, 1, true);
093:            }
094:
095:            public synchronized ClarkeCormackScorer copy() {
096:                final ClarkeCormackScorer scorer = new ClarkeCormackScorer(h,
097:                        alpha, normalize);
098:                scorer.setWeights(index2Weight);
099:                return scorer;
100:            }
101:
102:            public double score(final Index index) throws IOException {
103:                final IntervalIterator it = documentIterator
104:                        .intervalIterator(index);
105:                if (it == IntervalIterators.TRUE
106:                        || it == IntervalIterators.FALSE)
107:                    return 0;
108:                double result = 0;
109:                int lt, count = 0;
110:                Interval interval;
111:                while ((interval = it.nextInterval()) != null) {
112:                    count++;
113:                    lt = interval.length();
114:                    if (lt < h)
115:                        result += 1;
116:                    else
117:                        result += Math.pow(h / (double) lt, alpha);
118:                }
119:                return normalize ? result / count : result;
120:            }
121:
122:            public String toString() {
123:                return "Clarke-Cormack(" + h + ", " + alpha + ", " + normalize
124:                        + ')';
125:            }
126:
127:            /** Returns true.
128:             * @return true.
129:             */
130:            public boolean usesIntervals() {
131:                return true;
132:            }
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.