From ca738ac92433d67f0f6f22d65449c169fab52489 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 15 Oct 2010 22:01:39 +0000 Subject: [PATCH] - added a tag cloud to search results (using the topics) - some refactoring of score classes - added default package for new classes add_ymark and delete_ymark git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7251 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .classpath | 5 ++- htroot/Supporter.java | 8 ++-- htroot/Surftips.java | 8 ++-- htroot/yacy/ui/js/jquery.tagcloud.min.js | 8 ++++ htroot/yacy/ui/js/jquery.tinysort.min.js | 8 ++++ htroot/yacysearch.html | 5 ++- htroot/yacysearchtrailer.html | 17 ++++----- htroot/yacysearchtrailer.java | 6 ++- source/de/anomic/crawler/ResultURLs.java | 8 ++-- source/de/anomic/data/DidYouMean.java | 6 +-- source/de/anomic/data/DidYouMeanLibrary.java | 2 +- .../de/anomic/search/MetadataRepository.java | 6 +-- source/de/anomic/search/RankingProcess.java | 2 +- source/de/anomic/search/ReferenceOrder.java | 4 +- source/de/anomic/yacy/dht/PeerSelection.java | 6 +-- source/de/anomic/yacy/yacySearch.java | 8 ++-- .../net/yacy/cora/storage/DynamicScore.java | 8 ++-- source/net/yacy/cora/storage/IntScore.java | 3 +- .../net/yacy/cora/storage/ScoreCluster.java | 38 ++++++++++--------- source/net/yacy/cora/storage/ScoreMap.java | 24 +++++++----- source/net/yacy/cora/storage/StaticScore.java | 14 +++---- .../net/yacy/kelondro/blob/MapDataMining.java | 8 ++-- source/net/yacy/yacy.java | 6 +-- 23 files changed, 118 insertions(+), 90 deletions(-) create mode 100755 htroot/yacy/ui/js/jquery.tagcloud.min.js create mode 100755 htroot/yacy/ui/js/jquery.tinysort.min.js diff --git a/.classpath b/.classpath index af32e65e5..2ae043609 100644 --- a/.classpath +++ b/.classpath @@ -1,17 +1,18 @@ - + - + + diff --git a/htroot/Supporter.java b/htroot/Supporter.java index f011379e8..a1b0998dc 100644 --- a/htroot/Supporter.java +++ b/htroot/Supporter.java @@ -113,7 +113,7 @@ public class Supporter { //accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB); // read out surftipp array and create property entries - final Iterator k = ranking.scores(false); + final Iterator k = ranking.keys(false); int i = 0; Row.Entry row; String url, urlhash, refid, title, description; @@ -150,7 +150,7 @@ public class Supporter { prop.put("supporter_results_" + i + "_url", url); prop.put("supporter_results_" + i + "_urlname", nxTools.shortenURLString(url, 60)); prop.put("supporter_results_" + i + "_urlhash", urlhash); - prop.putHTML("supporter_results_" + i + "_title", (showScore) ? ("(" + ranking.getScore(urlhash) + ") " + title) : title); + prop.putHTML("supporter_results_" + i + "_title", (showScore) ? ("(" + ranking.get(urlhash) + ") " + title) : title); prop.putHTML("supporter_results_" + i + "_description", description); i++; @@ -265,9 +265,9 @@ public class Supporter { } // consider double-entries if (Supporter.containsKey(urlhash)) { - ranking.addScore(urlhash, score); + ranking.inc(urlhash, score); } else { - ranking.setScore(urlhash, score); + ranking.set(urlhash, score); Supporter.put(urlhash, entry); } } diff --git a/htroot/Surftips.java b/htroot/Surftips.java index 865520a95..f0fb7f446 100644 --- a/htroot/Surftips.java +++ b/htroot/Surftips.java @@ -121,7 +121,7 @@ public class Surftips { //accumulateSurftips(surftips, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB); // read out surftipp array and create property entries - final Iterator k = ranking.scores(false); + final Iterator k = ranking.keys(false); int i = 0; Row.Entry row; String url, urlhash, refid, title, description; @@ -159,7 +159,7 @@ public class Surftips { prop.putXML("surftips_results_" + i + "_url", url); prop.putXML("surftips_results_" + i + "_urlname", nxTools.shortenURLString(url, 60)); prop.putXML("surftips_results_" + i + "_urlhash", urlhash); - prop.putXML("surftips_results_" + i + "_title", (showScore) ? ("(" + ranking.getScore(urlhash) + ") " + title) : title); + prop.putXML("surftips_results_" + i + "_title", (showScore) ? ("(" + ranking.get(urlhash) + ") " + title) : title); prop.putHTML("surftips_results_" + i + "_description", description); i++; @@ -327,9 +327,9 @@ public class Surftips { } // consider double-entries if (surftips.containsKey(urlhash)) { - ranking.addScore(urlhash, score); + ranking.inc(urlhash, score); } else { - ranking.setScore(urlhash, score); + ranking.set(urlhash, score); surftips.put(urlhash, entry); } } diff --git a/htroot/yacy/ui/js/jquery.tagcloud.min.js b/htroot/yacy/ui/js/jquery.tagcloud.min.js new file mode 100755 index 000000000..7f799470d --- /dev/null +++ b/htroot/yacy/ui/js/jquery.tagcloud.min.js @@ -0,0 +1,8 @@ +/* +* jQuery TagCloud 0.5.0 +* Copyright (c) 2008 Ron Valstar +* Dual licensed under the MIT and GPL licenses: +* http://www.opensource.org/licenses/mit-license.php +* http://www.gnu.org/licenses/gpl.html +*/ +(function(F){var C;var A={};var G={};var L=2.399963;F.tagcloud={id:"TagCloud",version:"0.5.0",defaults:{height:null,type:"cloud",sizemax:20,sizemin:10,colormax:"00F",colormin:"B4D2FF",seed:null,power:0.5}};F.fn.extend({tagcloud:function(M){C=F.extend({},F.tagcloud.defaults,M);if(C.seed===null){C.seed=Math.ceil(Math.random()*45309714203)}switch(C.type){case"sphere":case"cloud":A={position:"relative"};G={position:"absolute",display:"block"};break;case"list":A={height:"auto"};G={position:"static",display:"inline"};break}B.setSeed(C.seed+123456);return this.each(function(f,a){var q=F(a);var R=q.find(">li");var S=R.length;var Z=q.width();var l=C.height===null?(0.004*Z*S):C.height;q.css({width:Z,height:l,listStyle:"none",margin:0,padding:0});q.css(A);var e=-2147483647;var r=2147483648;var T=-1;for(var d=0;de){e=n}if(n0?0:this.M);return(this.seed*this.oneOverM)};B.rand=function(N,M){return Math.floor((M-N+1)*this.next()+N)};function I(M){return M.toString(16)}function K(M){return parseInt(M,16)}function H(Q){var M=Q.length==3;var O=[];for(var N=0;N<3;N++){var P=Q.substring(N*(M?1:2),(N+1)*(M?1:2));O.push(K(M?P+P:P))}return O}function J(M){var O="";for(var N=0;N<3;N++){var P=I(M[N]);if(P.length==1){P="0"+P}O+=P}return O}function D(R,S,P){var Q=H(R);var M=H(S);var O=[];for(var N=0;N<3;N++){O.push(Q[N]+Math.floor(P*(M[N]-Q[N])))}return J(O)}function E(M){if(window.console&&window.console.log){if(typeof (M)=="string"){window.console.log(M)}else{for(var N in M){window.console.log(N+": "+M[N])}}}}F.fn.TagCloud=F.fn.Tagcloud=F.fn.tagcloud})(jQuery); \ No newline at end of file diff --git a/htroot/yacy/ui/js/jquery.tinysort.min.js b/htroot/yacy/ui/js/jquery.tinysort.min.js new file mode 100755 index 000000000..a12fb1989 --- /dev/null +++ b/htroot/yacy/ui/js/jquery.tinysort.min.js @@ -0,0 +1,8 @@ +/* +* jQuery TinySort 1.0.1 +* Copyright (c) 2008 Ron Valstar +* Dual licensed under the MIT and GPL licenses: +* http://www.opensource.org/licenses/mit-license.php +* http://www.gnu.org/licenses/gpl.html +*/ +(function(C){C.tinysort={id:"TinySort",version:"1.0.1",defaults:{order:"asc",attr:"",place:"start",returns:false}};C.fn.extend({tinysort:function(I,J){if(I&&typeof (I)!="string"){J=I;I=null}var F=C.extend({},C.tinysort.defaults,J);var P={};this.each(function(T){var V=(!I||I=="")?C(this):C(this).find(I);var U=F.order=="rand"?""+Math.random():(F.attr==""?V.text():V.attr(F.attr));var S=C(this).parent();if(!P[S]){P[S]={s:[],n:[]}}if(V.length>0){P[S].s.push({s:U,e:C(this),n:T})}else{P[S].n.push({e:C(this),n:T})}});for(var H in P){var E=P[H];E.s.sort(function K(U,T){var S=U.s.toLowerCase?U.s.toLowerCase():U.s;var V=T.s.toLowerCase?T.s.toLowerCase():T.s;if(D(U.s)&&D(T.s)){S=parseFloat(U.s);V=parseFloat(T.s)}return(F.order=="asc"?1:-1)*(SV?1:0))})}var M=[];for(var H in P){var E=P[H];var N=[];var G=C(this).length;switch(F.place){case"first":C.each(E.s,function(S,T){G=Math.min(G,T.n)});break;case"org":C.each(E.s,function(S,T){N.push(T.n)});break;case"end":G=E.n.length;break;default:G=0}var Q=[0,0];for(var L=0;L=G&&Lhs.outlineType = 'rounded-white'; + + @@ -94,8 +96,7 @@ $(function() { $("#sidebar2").accordion({}); $("#sidebar3").accordion({}); $("#sidebar3").accordion('activate', false); - $("#sidebar4").accordion({}); - $("#sidebar4").accordion('activate', false); + $("#sidebar4").tagcloud({seed:0,sizemin:10,sizemax:20,height:60}).find("li").tsort(); $("#sidebarAbout").accordion({}); $("#search").focus(); }); diff --git a/htroot/yacysearchtrailer.html b/htroot/yacysearchtrailer.html index 840114e3d..aefe85bb7 100644 --- a/htroot/yacysearchtrailer.html +++ b/htroot/yacysearchtrailer.html @@ -8,6 +8,14 @@ #(/cat-location)# +#(nav-topics)#:: +
+
    #{element}# +
  • #[url]#
  • +#{/element}#
+
+#(/nav-topics)# + #(nav-domains)#::

Domain Navigator

@@ -35,15 +43,6 @@
#(/nav-authors)# -#(nav-topics)#:: -
-

Topic Navigator

-
    #{element}# -
  • #[url]#
  • -#{/element}#
-
-#(/nav-topics)# - #(nav-about)#::

#[headline]#

diff --git a/htroot/yacysearchtrailer.java b/htroot/yacysearchtrailer.java index 79204b396..93c5cb50c 100644 --- a/htroot/yacysearchtrailer.java +++ b/htroot/yacysearchtrailer.java @@ -130,7 +130,7 @@ public class yacysearchtrailer { } // topics navigator - List topicNavigator = theSearch.getTopicNavigator(10); + List topicNavigator = theSearch.getTopicNavigator(30); if (topicNavigator == null || topicNavigator.isEmpty()) { topicNavigator = new ArrayList(); prop.put("nav-topics", "0"); @@ -144,7 +144,9 @@ public class yacysearchtrailer { if (/*(theQuery == null) ||*/ (theQuery.queryString == null)) break; if (e != null && e.name != null) { prop.putHTML("nav-topics_element_" + i + "_name", e.name); - prop.put("nav-topics_element_" + i + "_url", "" + e.name + " (" + e.count + ")"); + prop.put("nav-topics_element_" + i + "_url", + "" + e.name + ""); + //+"-")*/; prop.putJSON("nav-topics_element_" + i + "_url-json", QueryParams.navurl("json", 0, display, theQuery, theQuery.queryStringForUrl() + "+" + e.name, theQuery.urlMask.toString(), theQuery.navigators)); prop.put("nav-topics_element_" + i + "_count", e.count); prop.put("nav-topics_element_" + i + "_modifier", e.name); diff --git a/source/de/anomic/crawler/ResultURLs.java b/source/de/anomic/crawler/ResultURLs.java index 72ee5fc3d..7bb0e52d7 100644 --- a/source/de/anomic/crawler/ResultURLs.java +++ b/source/de/anomic/crawler/ResultURLs.java @@ -85,7 +85,7 @@ public final class ResultURLs { try { final DynamicScore domains = getDomains(stackType); if (domains != null) { - domains.incScore(e.metadata().url().getHost()); + domains.inc(e.metadata().url().getHost()); } } catch (final Exception ex) { System.out.println("INTERNAL ERROR in newEntry/3: " + ex.toString()); @@ -117,7 +117,7 @@ public final class ResultURLs { */ public Iterator domains(final EventOrigin stack) { assert getDomains(stack) != null : "getDomains(" + stack + ") = null"; - return getDomains(stack).scores(false); + return getDomains(stack).keys(false); } public int deleteDomain(final EventOrigin stack, String host, String hosthash) { @@ -132,7 +132,7 @@ public final class ResultURLs { if (urlhash == null || urlhash.substring(6).equals(hosthash)) i.remove(); } assert getDomains(stack) != null : "getDomains(" + stack + ") = null"; - return getDomains(stack).deleteScore(host); + return getDomains(stack).delete(host); } /** @@ -144,7 +144,7 @@ public final class ResultURLs { public int domainCount(final EventOrigin stack, String domain) { assert domain != null : "domain = null"; assert getDomains(stack) != null : "getDomains(" + stack + ") = null"; - return getDomains(stack).getScore(domain); + return getDomains(stack).get(domain); } /** diff --git a/source/de/anomic/data/DidYouMean.java b/source/de/anomic/data/DidYouMean.java index 61817a85e..89949f109 100644 --- a/source/de/anomic/data/DidYouMean.java +++ b/source/de/anomic/data/DidYouMean.java @@ -132,13 +132,13 @@ public class DidYouMean { for (final String s: preSorted) { if (System.currentTimeMillis() > timelimit) break; if (scored.size() >= 2 * preSortSelection) break; - scored.addScore(s, index.count(Word.word2hash(s))); + scored.inc(s, index.count(Word.word2hash(s))); } SortedSet countSorted = Collections.synchronizedSortedSet(new TreeSet(new indexSizeComparator())); int wc = index.count(Word.word2hash(this.word)); // all counts must be greater than this while (scored.size() > 0 && countSorted.size() < preSortSelection) { - String s = scored.getMaxObject(); - int score = scored.deleteScore(s); + String s = scored.getMaxKey(); + int score = scored.delete(s); if (s.length() >= MinimumOutputWordLength && score > wc) countSorted.add(s); if (System.currentTimeMillis() > timelimit) break; } diff --git a/source/de/anomic/data/DidYouMeanLibrary.java b/source/de/anomic/data/DidYouMeanLibrary.java index 5c33b2367..cca665499 100644 --- a/source/de/anomic/data/DidYouMeanLibrary.java +++ b/source/de/anomic/data/DidYouMeanLibrary.java @@ -78,7 +78,7 @@ public class DidYouMeanLibrary { if (word == null) return; word = word.trim().toLowerCase(); if (word.length() < commonWordsMinLength) return; - commonWords.incScore(word); + commonWords.inc(word); if (commonWords.size() >= commonWordsMaxSize) { commonWords.shrinkToMaxSize(commonWordsMaxSize / 2); } diff --git a/source/de/anomic/search/MetadataRepository.java b/source/de/anomic/search/MetadataRepository.java index 875104aad..b9cd5a115 100644 --- a/source/de/anomic/search/MetadataRepository.java +++ b/source/de/anomic/search/MetadataRepository.java @@ -610,11 +610,11 @@ public final class MetadataRepository implements Iterable { // order elements by size DynamicScore s = new ScoreCluster(); for (Map.Entry e: map.entrySet()) { - s.addScore(e.getValue().urlhash, e.getValue().count); + s.inc(e.getValue().urlhash, e.getValue().count); } // fetch urls from the database to determine the host in clear text - Iterator j = s.scores(false); // iterate urlhash-examples in reverse order (biggest first) + Iterator j = s.keys(false); // iterate urlhash-examples in reverse order (biggest first) URIMetadataRow urlref; String urlhash; count += 10; // make some more to prevent that we have to do this again after deletions too soon. @@ -630,7 +630,7 @@ public final class MetadataRepository implements Iterable { if (statsDump == null) return new ArrayList().iterator(); // some other operation has destroyed the object comps = urlref.metadata(); url = comps.url(); - statsDump.add(new hostStat(url.getHost(), url.getPort(), urlhash.substring(6), s.getScore(urlhash))); + statsDump.add(new hostStat(url.getHost(), url.getPort(), urlhash.substring(6), s.get(urlhash))); count--; if (count == 0) break; } diff --git a/source/de/anomic/search/RankingProcess.java b/source/de/anomic/search/RankingProcess.java index 3f840b0f7..cc2c71773 100644 --- a/source/de/anomic/search/RankingProcess.java +++ b/source/de/anomic/search/RankingProcess.java @@ -620,7 +620,7 @@ public final class RankingProcess extends Thread { // create a list of words that had been computed by statistics over all // words that appeared in the url or the description of all urls if (!this.query.navigators.equals("all") && this.query.navigators.indexOf("topics") < 0) return new ArrayList(0); - List result = this.ref.entries(10); + List result = this.ref.entries(count); if (result.size() < 2) result.clear(); // navigators with one entry are not useful return result; } diff --git a/source/de/anomic/search/ReferenceOrder.java b/source/de/anomic/search/ReferenceOrder.java index 1ab917459..db62a9ef0 100644 --- a/source/de/anomic/search/ReferenceOrder.java +++ b/source/de/anomic/search/ReferenceOrder.java @@ -166,7 +166,7 @@ public class ReferenceOrder { final Iterator> di = doms0.entrySet().iterator(); while (di.hasNext()) { entry = di.next(); - doms.addScore(entry.getKey(), (entry.getValue()).intValue()); + doms.inc(entry.getKey(), (entry.getValue()).intValue()); } if (!doms.isEmpty()) maxdomcount = doms.getMaxScore(); } catch (InterruptedException e) { @@ -184,7 +184,7 @@ public class ReferenceOrder { } public int authority(final byte[] urlHash) { - return (doms.getScore(new String(urlHash, 6, 6)) << 8) / (1 + this.maxdomcount); + return (doms.get(new String(urlHash, 6, 6)) << 8) / (1 + this.maxdomcount); } /** diff --git a/source/de/anomic/yacy/dht/PeerSelection.java b/source/de/anomic/yacy/dht/PeerSelection.java index 679045a13..e2a3d4381 100755 --- a/source/de/anomic/yacy/dht/PeerSelection.java +++ b/source/de/anomic/yacy/dht/PeerSelection.java @@ -72,7 +72,7 @@ public class PeerSelection { if (seed == null || seed.hash == null) continue; if (!seed.getFlagAcceptRemoteIndex()) continue; // probably a robinson peer if (Log.isFine("PLASMA")) Log.logFine("PLASMA", "selectPeers/DHTorder: " + seed.hash + ":" + seed.getName() + "/ score " + c); - ranking.addScore(seed.hash, 2 * c); + ranking.inc(seed.hash, 2 * c); regularSeeds.put(seed.hash, seed); c--; } @@ -351,13 +351,13 @@ public class PeerSelection { ys = s.next(); if ((ys != null) && (ys.get(yacySeed.LASTSEEN, "").length() > 10)) try { absage = Math.abs(System.currentTimeMillis() + DateFormatter.dayMillis - ys.getLastSeenUTC()); - seedScore.addScore(ys.hash, (int) absage); // the higher absage, the older is the peer + seedScore.inc(ys.hash, (int) absage); // the higher absage, the older is the peer } catch (final Exception e) {} } // result is now in the score object; create a result vector final Map result = new HashMap(); - final Iterator it = seedScore.scores(up); + final Iterator it = seedScore.keys(up); int c = 0; while ((c < count) && (it.hasNext())) { c++; diff --git a/source/de/anomic/yacy/yacySearch.java b/source/de/anomic/yacy/yacySearch.java index e14c5a968..74abaea26 100644 --- a/source/de/anomic/yacy/yacySearch.java +++ b/source/de/anomic/yacy/yacySearch.java @@ -206,7 +206,7 @@ public class yacySearch extends Thread { if (!seed.getFlagAcceptRemoteIndex()) continue; // probably a robinson peer score = (int) Math.round(Math.random() * ((c / 3) + 3)); if (Log.isFine("PLASMA")) Log.logFine("PLASMA", "selectPeers/RWIcount: " + seed.hash + ":" + seed.getName() + ", RWIcount=" + seed.getWordCount() + ", score " + score); - ranking.addScore(seed.hash, score); + ranking.inc(seed.hash, score); regularSeeds.put(seed.hash, seed); c--; } @@ -221,12 +221,12 @@ public class yacySearch extends Thread { String specialized = seed.getPeerTags().toString(); if (!specialized.equals("[*]")) Log.logInfo("PLASMA", "selectPeers/PeerTags: " + seed.hash + ":" + seed.getName() + ", is specialized peer for " + specialized); regularSeeds.remove(seed.hash); - ranking.deleteScore(seed.hash); + ranking.delete(seed.hash); matchingSeeds.put(seed.hash, seed); } else if (seed.getFlagAcceptRemoteIndex() && seed.getAge() < 1) { // the 'workshop feature' Log.logInfo("PLASMA", "selectPeers/Age: " + seed.hash + ":" + seed.getName() + ", is newbie, age = " + seed.getAge()); regularSeeds.remove(seed.hash); - ranking.deleteScore(seed.hash); + ranking.delete(seed.hash); matchingSeeds.put(seed.hash, seed); } } @@ -235,7 +235,7 @@ public class yacySearch extends Thread { seedcount = Math.min(ranking.size(), seedcount); final yacySeed[] result = new yacySeed[seedcount + matchingSeeds.size()]; c = 0; - Iterator iters = ranking.scores(false); // higher are better + Iterator iters = ranking.keys(false); // higher are better while (iters.hasNext() && c < seedcount) { seed = regularSeeds.get(iters.next()); seed.selectscore = c; diff --git a/source/net/yacy/cora/storage/DynamicScore.java b/source/net/yacy/cora/storage/DynamicScore.java index c4718c86e..3698be16f 100644 --- a/source/net/yacy/cora/storage/DynamicScore.java +++ b/source/net/yacy/cora/storage/DynamicScore.java @@ -22,10 +22,10 @@ package net.yacy.cora.storage; public interface DynamicScore extends StaticScore { - public void incScore(final E obj); + public void inc(final E obj); + public void inc(final E obj, final int incrementScore); - public void decScore(final E obj); - - public void addScore(final E obj, final int incrementScore); + public void dec(final E obj); + public void dec(final E obj, final int incrementScore); } diff --git a/source/net/yacy/cora/storage/IntScore.java b/source/net/yacy/cora/storage/IntScore.java index bc9c785f4..c2b9ec9b8 100644 --- a/source/net/yacy/cora/storage/IntScore.java +++ b/source/net/yacy/cora/storage/IntScore.java @@ -81,7 +81,8 @@ public class IntScore implements Comparable, Comparator { } public int hashCode() { - return (int) (this.value ^ (this.value >>> 32)); + return this.value; + // return (int) (this.value ^ (this.value >>> 32)); // hash code for long values } public int compareTo(IntScore o) { diff --git a/source/net/yacy/cora/storage/ScoreCluster.java b/source/net/yacy/cora/storage/ScoreCluster.java index e2e7ba7df..b94689c6f 100644 --- a/source/net/yacy/cora/storage/ScoreCluster.java +++ b/source/net/yacy/cora/storage/ScoreCluster.java @@ -186,15 +186,15 @@ public final class ScoreCluster implements DynamicScore { return map.isEmpty(); } - public synchronized void incScore(final E obj) { - addScore(obj, 1); + public synchronized void inc(final E obj) { + inc(obj, 1); } - public synchronized void decScore(final E obj) { - addScore(obj, -1); + public synchronized void dec(final E obj) { + inc(obj, -1); } - public void setScore(final E obj, final int newScore) { + public void set(final E obj, final int newScore) { if (obj == null) return; synchronized (this) { Long usk = map.remove(obj); // get unique score key, old entry is not needed any more @@ -228,7 +228,7 @@ public final class ScoreCluster implements DynamicScore { gcount += newScore; } - public void addScore(final E obj, final int incrementScore) { + public void inc(final E obj, final int incrementScore) { if (obj == null) return; synchronized (this) { Long usk = map.remove(obj); // get unique score key, old entry is not needed any more @@ -262,8 +262,12 @@ public final class ScoreCluster implements DynamicScore { // increase overall counter gcount += incrementScore; } + + public void dec(final E obj, final int incrementScore) { + inc(obj, -incrementScore); + } - public int deleteScore(final E obj) { + public int delete(final E obj) { // deletes entry and returns previous score if (obj == null) return 0; final Long usk; @@ -284,11 +288,11 @@ public final class ScoreCluster implements DynamicScore { return oldScore; } - public synchronized boolean existsScore(final E obj) { + public synchronized boolean containsKey(final E obj) { return map.containsKey(obj); } - public int getScore(final E obj) { + public int get(final E obj) { if (obj == null) return 0; final Long cs; synchronized (this) { @@ -308,12 +312,12 @@ public final class ScoreCluster implements DynamicScore { return (int) ((pam.firstKey().longValue() & 0xFFFFFFFF00000000L) >> 32); } - public synchronized E getMaxObject() { + public synchronized E getMaxKey() { if (map.isEmpty()) return null; return pam.get(pam.lastKey()); } - public synchronized E getMinObject() { + public synchronized E getMinKey() { if (map.isEmpty()) return null; return pam.get(pam.firstKey()); } @@ -322,7 +326,7 @@ public final class ScoreCluster implements DynamicScore { return map + " / " + pam; } - public synchronized Iterator scores(final boolean up) { + public synchronized Iterator keys(final boolean up) { if (up) return new simpleScoreIterator(); return new reverseScoreIterator(); } @@ -405,7 +409,7 @@ public final class ScoreCluster implements DynamicScore { for (int i = 0; i < count; i++) { r = random.nextInt(); mem[i] = r; - s.addScore("score#" + r, r); + s.inc("score#" + r, r); c += r; } @@ -413,18 +417,18 @@ public final class ScoreCluster implements DynamicScore { int p; for (int i = 0; i < (count / 2); i++) { p = (int) (random.nextFloat() * count); - if (s.existsScore("score#" + mem[p])) { + if (s.containsKey("score#" + mem[p])) { System.out.println("delete score#" + mem[p]); - s.deleteScore("score#" + mem[p]); + s.delete("score#" + mem[p]); c -= mem[p]; } } } System.out.println("result:"); - Iterator i = s.scores(true); + Iterator i = s.keys(true); while (i.hasNext()) System.out.println("up: " + i.next()); - i = s.scores(false); + i = s.keys(false); while (i.hasNext()) System.out.println("down: " + i.next()); System.out.println("finished create. time = " + (System.currentTimeMillis() - time)); diff --git a/source/net/yacy/cora/storage/ScoreMap.java b/source/net/yacy/cora/storage/ScoreMap.java index dad73bfb0..77878073f 100644 --- a/source/net/yacy/cora/storage/ScoreMap.java +++ b/source/net/yacy/cora/storage/ScoreMap.java @@ -95,7 +95,7 @@ public class ScoreMap implements DynamicScore { return map.isEmpty(); } - public void incScore(final E obj) { + public void inc(final E obj) { if (obj == null) return; synchronized (this) { IntScore score = this.map.get(obj); @@ -109,7 +109,7 @@ public class ScoreMap implements DynamicScore { gcount++; } - public void decScore(final E obj) { + public void dec(final E obj) { if (obj == null) return; synchronized (this) { IntScore score = this.map.get(obj); @@ -123,7 +123,7 @@ public class ScoreMap implements DynamicScore { gcount--; } - public void setScore(final E obj, final int newScore) { + public void set(final E obj, final int newScore) { if (obj == null) return; synchronized (this) { IntScore score = this.map.get(obj); @@ -138,7 +138,7 @@ public class ScoreMap implements DynamicScore { gcount += newScore; } - public void addScore(final E obj, final int incrementScore) { + public void inc(final E obj, final int incrementScore) { if (obj == null) return; synchronized (this) { IntScore score = this.map.get(obj); @@ -152,7 +152,11 @@ public class ScoreMap implements DynamicScore { gcount += incrementScore; } - public int deleteScore(final E obj) { + public void dec(final E obj, final int incrementScore) { + inc(obj, -incrementScore); + } + + public int delete(final E obj) { // deletes entry and returns previous score if (obj == null) return 0; final IntScore score; @@ -166,11 +170,11 @@ public class ScoreMap implements DynamicScore { return score.intValue(); } - public synchronized boolean existsScore(final E obj) { + public synchronized boolean containsKey(final E obj) { return map.containsKey(obj); } - public int getScore(final E obj) { + public int get(final E obj) { if (obj == null) return 0; final IntScore score; synchronized (this) { @@ -202,7 +206,7 @@ public class ScoreMap implements DynamicScore { return minScore; } - public E getMaxObject() { + public E getMaxKey() { if (map.isEmpty()) return null; E maxObject = null; int maxScore = Integer.MIN_VALUE; @@ -215,7 +219,7 @@ public class ScoreMap implements DynamicScore { return maxObject; } - public E getMinObject() { + public E getMinKey() { if (map.isEmpty()) return null; E minObject = null; int minScore = Integer.MAX_VALUE; @@ -232,7 +236,7 @@ public class ScoreMap implements DynamicScore { return map.toString(); } - public Iterator scores(boolean up) { + public Iterator keys(boolean up) { synchronized (this) { // re-organize entries TreeMap> m = new TreeMap>(); diff --git a/source/net/yacy/cora/storage/StaticScore.java b/source/net/yacy/cora/storage/StaticScore.java index 211f09bf0..149478468 100644 --- a/source/net/yacy/cora/storage/StaticScore.java +++ b/source/net/yacy/cora/storage/StaticScore.java @@ -44,24 +44,24 @@ public interface StaticScore { public boolean isEmpty(); - public void setScore(final E obj, final int newScore); + public void set(final E obj, final int newScore); - public int deleteScore(final E obj); + public int delete(final E obj); - public boolean existsScore(final E obj); + public boolean containsKey(final E obj); - public int getScore(final E obj); + public int get(final E obj); public int getMaxScore(); public int getMinScore(); - public E getMaxObject(); + public E getMaxKey(); - public E getMinObject(); + public E getMinKey(); public String toString(); - public Iterator scores(final boolean up); + public Iterator keys(final boolean up); } diff --git a/source/net/yacy/kelondro/blob/MapDataMining.java b/source/net/yacy/kelondro/blob/MapDataMining.java index 607274255..2fb2ad4ca 100644 --- a/source/net/yacy/kelondro/blob/MapDataMining.java +++ b/source/net/yacy/kelondro/blob/MapDataMining.java @@ -120,7 +120,7 @@ public class MapDataMining extends MapHeap { if (sortfields != null && cluster != null) for (int i = 0; i < sortfields.length; i++) { cell = map.get(sortfields[i]); - if (cell != null) cluster[i].setScore(new String(mapnameb), ScoreCluster.object2score(cell)); + if (cell != null) cluster[i].set(new String(mapnameb), ScoreCluster.object2score(cell)); } if (longaccfields != null && longaccumulator != null) for (int i = 0; i < longaccfields.length; i++) { @@ -246,7 +246,7 @@ public class MapDataMining extends MapHeap { cell = map.get(sortfields[i]); if (cell != null) { cluster = sortClusterMap.get(sortfields[i]); - cluster.setScore(key, ScoreCluster.object2score(cell)); + cluster.set(key, ScoreCluster.object2score(cell)); sortClusterMap.put(sortfields[i], cluster); } } @@ -282,7 +282,7 @@ public class MapDataMining extends MapHeap { StaticScore cluster; for (int i = 0; i < sortfields.length; i++) { cluster = sortClusterMap.get(sortfields[i]); - cluster.deleteScore(key); + cluster.delete(key); sortClusterMap.put(sortfields[i], cluster); } } @@ -293,7 +293,7 @@ public class MapDataMining extends MapHeap { final StaticScore cluster = sortClusterMap.get(field); if (cluster == null) return null; // sort field does not exist //System.out.println("DEBUG: cluster for field " + field + ": " + cluster.toString()); - return new string2bytearrayIterator(cluster.scores(up)); + return new string2bytearrayIterator(cluster.keys(up)); } public static class string2bytearrayIterator implements Iterator { diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java index 8d8b3add2..b40d4eabb 100644 --- a/source/net/yacy/yacy.java +++ b/source/net/yacy/yacy.java @@ -611,18 +611,18 @@ public final class yacy { while (ef.hasMoreElements()) { f = ef.nextElement(); h = f.getName().substring(0, Word.commonHashLength).getBytes(); - hs.addScore(h, (int) f.length()); + hs.inc(h, (int) f.length()); } // list the hashes in reverse order Log.logInfo("GEN-WORDSTAT", "listing words in reverse size order..."); String w; - final Iterator i = hs.scores(false); + final Iterator i = hs.keys(false); while (i.hasNext()) { h = i.next(); w = words.get(h); if (w == null) System.out.print("# " + h); else System.out.print(w); - System.out.println(" - " + hs.getScore(h)); + System.out.println(" - " + hs.get(h)); } // finished