Source Code Cross Referenced for plasmaRankingRCIEvaluation.java in  » Search-Engine » yacy » de » anomic » plasma » 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 » yacy » de.anomic.plasma 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // plasmaRCIEvaluation.java
002:        // -----------------------
003:        // part of YaCy
004:        // (C) by Michael Peter Christen; mc@anomic.de
005:        // first published on http://www.anomic.de
006:        // Frankfurt, Germany, 2005
007:        // Created 18.11.2005
008:        //
009:        // $LastChangedDate: 2005-10-22 15:28:04 +0200 (Sat, 22 Oct 2005) $
010:        // $LastChangedRevision: 968 $
011:        // $LastChangedBy: theli $
012:        //
013:        // This program is free software; you can redistribute it and/or modify
014:        // it under the terms of the GNU General Public License as published by
015:        // the Free Software Foundation; either version 2 of the License, or
016:        // (at your option) any later version.
017:        //
018:        // This program is distributed in the hope that it will be useful,
019:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
020:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021:        // GNU General Public License for more details.
022:        //
023:        // You should have received a copy of the GNU General Public License
024:        // along with this program; if not, write to the Free Software
025:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026:        //
027:        // Using this software in any meaning (reading, learning, copying, compiling,
028:        // running) means that you agree that the Author(s) is (are) not responsible
029:        // for cost, loss of data or any harm that may be caused directly or indirectly
030:        // by usage of this softare or this documentation. The usage of this software
031:        // is on your own risk. The installation and usage (starting/running) of this
032:        // software may allow other people or application to access your computer and
033:        // any attached devices and is highly dependent on the configuration of the
034:        // software which must be done by the user of the software; the author(s) is
035:        // (are) also not responsible for proper configuration and usage of the
036:        // software, even if provoked by documentation provided together with
037:        // the software.
038:        //
039:        // Any changes to this file according to the GPL as documented in the file
040:        // gpl.txt aside this file in the shipment you received can be done to the
041:        // lines that follows this copyright notice here, but changes must not be
042:        // done inside the copyright notive above. A re-distribution must contain
043:        // the intact and unchanged copyright notice.
044:        // Contributions and changes to the program code must be marked as such.
045:
046:        package de.anomic.plasma;
047:
048:        import java.io.File;
049:        import java.io.IOException;
050:        import java.net.MalformedURLException;
051:        import java.util.HashMap;
052:        import java.util.HashSet;
053:        import java.util.Iterator;
054:        import java.util.TreeSet;
055:
056:        import de.anomic.kelondro.kelondroAttrSeq;
057:        import de.anomic.kelondro.kelondroBase64Order;
058:        import de.anomic.server.serverCodings;
059:        import de.anomic.server.serverFileUtils;
060:        import de.anomic.yacy.yacyURL;
061:
062:        public class plasmaRankingRCIEvaluation {
063:
064:            public static int[] rcieval(kelondroAttrSeq rci) {
065:                // collect information about which entry has how many references
066:                // the output is a reference-count:occurrences relation
067:                HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
068:                Iterator<String> i = rci.keys();
069:                String key;
070:                kelondroAttrSeq.Entry entry;
071:                Integer count_key, count_count;
072:                int c, maxcount = 0;
073:                while (i.hasNext()) {
074:                    key = i.next();
075:                    entry = rci.getEntry(key);
076:                    c = entry.getSeqSet().size();
077:                    if (c > maxcount)
078:                        maxcount = c;
079:                    count_key = new Integer(c);
080:                    count_count = counts.get(count_key);
081:                    if (count_count == null) {
082:                        count_count = new Integer(1);
083:                    } else {
084:                        count_count = new Integer(count_count.intValue() + 1);
085:                    }
086:                    counts.put(count_key, count_count);
087:                }
088:                int[] ctable = new int[maxcount + 1];
089:                for (int j = 0; j <= maxcount; j++) {
090:                    count_count = counts.get(new Integer(j));
091:                    if (count_count == null) {
092:                        ctable[j] = 0;
093:                    } else {
094:                        ctable[j] = count_count.intValue();
095:                    }
096:                }
097:                return ctable;
098:            }
099:
100:            public static long sum(int[] c) {
101:                long s = 0;
102:                for (int i = 0; i < c.length; i++)
103:                    s += (long) c[i];
104:                return s;
105:            }
106:
107:            public static int[] interval(int[] counts, int parts) {
108:                long limit = sum(counts) / 2;
109:                int[] partition = new int[parts];
110:                int s = 0, p = parts - 1;
111:                for (int i = 1; i < counts.length; i++) {
112:                    s += counts[i];
113:                    if ((s > limit) && (p >= 0)) {
114:                        partition[p--] = i;
115:                        limit = (2 * limit - s) / 2;
116:                        s = 0;
117:                    }
118:                }
119:                partition[0] = counts.length - 1;
120:                for (int i = 1; i < 10; i++)
121:                    partition[i] = (partition[i - 1] + 4 * partition[i]) / 5;
122:                return partition;
123:            }
124:
125:            public static void checkPartitionTable0(int[] counts,
126:                    int[] partition) {
127:                int sumsum = 0;
128:                int sum;
129:                int j = 0;
130:                for (int i = partition.length - 1; i >= 0; i--) {
131:                    sum = 0;
132:                    while (j <= partition[i]) {
133:                        sum += counts[j++];
134:                    }
135:                    System.out.println("sum of YBR-" + i + " entries: " + sum);
136:                    sumsum += sum;
137:                }
138:                System.out.println("complete sum = " + sumsum);
139:            }
140:
141:            public static void checkPartitionTable1(int[] counts,
142:                    int[] partition) {
143:                int sumsum = 0;
144:                int[] sum = new int[partition.length];
145:                for (int i = 0; i < partition.length; i++)
146:                    sum[i] = 0;
147:                for (int i = 0; i < counts.length; i++)
148:                    sum[orderIntoYBI(partition, i)] += counts[i];
149:                for (int i = partition.length - 1; i >= 0; i--) {
150:                    System.out.println("sum of YBR-" + i + " entries: "
151:                            + sum[i]);
152:                    sumsum += sum[i];
153:                }
154:                System.out.println("complete sum = " + sumsum);
155:            }
156:
157:            public static int orderIntoYBI(int[] partition, int count) {
158:                for (int i = 0; i < partition.length - 1; i++) {
159:                    if ((count >= (partition[i + 1] + 1))
160:                            && (count <= partition[i]))
161:                        return i;
162:                }
163:                return partition.length - 1;
164:            }
165:
166:            @SuppressWarnings("unchecked")
167:            public static TreeSet<String>[] genRankingTable(
168:                    kelondroAttrSeq rci, int[] partition) {
169:                TreeSet<String>[] ranked = new TreeSet[partition.length];
170:                for (int i = 0; i < partition.length; i++)
171:                    ranked[i] = new TreeSet<String>(
172:                            kelondroBase64Order.enhancedComparator);
173:                Iterator<String> i = rci.keys();
174:                String key;
175:                kelondroAttrSeq.Entry entry;
176:                while (i.hasNext()) {
177:                    key = (String) i.next();
178:                    entry = rci.getEntry(key);
179:                    ranked[orderIntoYBI(partition, entry.getSeqSet().size())]
180:                            .add(key);
181:                }
182:                return ranked;
183:            }
184:
185:            public static HashMap<String, String> genReverseDomHash(File domlist) {
186:                HashSet<String> domset = serverFileUtils.loadList(domlist);
187:                HashMap<String, String> dommap = new HashMap<String, String>();
188:                Iterator<String> i = domset.iterator();
189:                String dom;
190:                while (i.hasNext()) {
191:                    dom = i.next();
192:                    if (dom.startsWith("www."))
193:                        dom = dom.substring(4);
194:                    try {
195:                        dommap.put((new yacyURL("http://" + dom, null)).hash()
196:                                .substring(6), dom);
197:                        dommap.put((new yacyURL("http://www." + dom, null))
198:                                .hash().substring(6), "www." + dom);
199:                    } catch (MalformedURLException e) {
200:                    }
201:                }
202:                return dommap;
203:            }
204:
205:            public static void storeRankingTable(TreeSet<String>[] ranking,
206:                    File tablePath) throws IOException {
207:                String filename;
208:                if (!(tablePath.exists()))
209:                    tablePath.mkdirs();
210:                for (int i = 0; i < ranking.length - 1; i++) {
211:                    filename = "YBR-4-" + serverCodings.encodeHex(i, 2)
212:                            + ".idx";
213:                    serverFileUtils.saveSet(new File(tablePath, filename),
214:                            "plain", ranking[i], "");
215:                }
216:            }
217:
218:            public static void main(String[] args) {
219:                try {
220:                    if ((args.length == 2) && (args[0].equals("-genybr"))) {
221:                        File root_path = new File(args[1]);
222:                        File rci_file = new File(root_path,
223:                                "DATA/RANKING/GLOBAL/030_rci0/RCI-0.rci.gz");
224:                        long start = System.currentTimeMillis();
225:                        if (!(rci_file.exists()))
226:                            return;
227:
228:                        // create partition table
229:                        final kelondroAttrSeq rci = new kelondroAttrSeq(
230:                                rci_file, false);
231:                        int counts[] = rcieval(rci);
232:                        int[] partition = interval(counts, 16);
233:
234:                        // check the table
235:                        System.out.println("partition position table:");
236:                        for (int i = 0; i < partition.length - 1; i++) {
237:                            System.out.println("YBR-" + i + ": "
238:                                    + (partition[i + 1] + 1) + " - "
239:                                    + partition[i] + " references");
240:                        }
241:                        System.out.println("YBR-" + (partition.length - 1)
242:                                + ": 0 - " + partition[partition.length - 1]
243:                                + " references");
244:                        checkPartitionTable0(counts, partition);
245:                        checkPartitionTable1(counts, partition);
246:                        int sum = 0;
247:                        for (int i = 0; i < counts.length; i++)
248:                            sum += counts[i];
249:                        System.out.println("sum of all references: " + sum);
250:
251:                        // create ranking
252:                        TreeSet<String>[] ranked = genRankingTable(rci,
253:                                partition);
254:                        storeRankingTable(ranked, new File(root_path,
255:                                "ranking/YBR"));
256:                        long seconds = java.lang.Math.max(1, (System
257:                                .currentTimeMillis() - start) / 1000);
258:                        System.out.println("Finished YBR generation in "
259:                                + seconds + " seconds.");
260:                    }
261:                    if ((args.length == 2) && (args[0].equals("-rcieval"))) {
262:                        File root_path = new File(args[1]);
263:
264:                        // load a partition table
265:                        plasmaSearchRankingProcess.loadYBR(new File(root_path,
266:                                "ranking/YBR"), 16);
267:
268:                        // load domain list and generate hash index for domains
269:                        HashMap<String, String> dommap = genReverseDomHash(new File(
270:                                root_path, "domlist.txt"));
271:
272:                        // print out the table
273:                        String hash, dom;
274:                        for (int i = 0; i < 9; i++) {
275:                            System.out.print("YBR-" + i + ": ");
276:                            for (int j = 0; j < plasmaSearchRankingProcess.ybrTables[i]
277:                                    .size(); j++) {
278:                                hash = new String(
279:                                        plasmaSearchRankingProcess.ybrTables[i]
280:                                                .get(j));
281:                                dom = dommap.get(hash);
282:                                if (dom == null)
283:                                    System.out.print("[" + hash + "], ");
284:                                else
285:                                    System.out.print(dom + ", ");
286:                            }
287:                            System.out.println();
288:                        }
289:
290:                    }
291:                } catch (IOException e) {
292:                    e.printStackTrace();
293:                }
294:            }
295:
296:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.