Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- fixed document number limitation for crawls that restrict the number of documents per domain - some restructuring of the document counting and logging structures was necessary - better abstraction of CrawlProfiles - added deletion of logs to the index deletion option (if the index is deleted using the servlets) which is necessary to reset the domain counters for the page limitation - more refactoring to get the LibraryProvider more clean - some refactoring of the Condenser class

orbiter4588b5a2918e
diff --git a/defaults/yacy.init b/defaults/yacy.init
index 2c4d1a9b9..2391a515d 100644
--- a/defaults/yacy.init
+++ b/defaults/yacy.init
@@ -12,6 +12,9 @@
# port number where the server should bind to
port = 8090
+# prefix for new default peer names
+peernameprefix=_anon
+
# use UPnP [true/false]
upnp.enabled = true
# remote host on UPnP device (for more than one connection)
diff --git a/htroot/CrawlProfileEditor_p.java b/htroot/CrawlProfileEditor_p.java
index ad6d83cd9..05e606c99 100644
--- a/htroot/CrawlProfileEditor_p.java
+++ b/htroot/CrawlProfileEditor_p.java
@@ -37,6 +37,7 @@ import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
+import de.anomic.crawler.CrawlStacker;
import de.anomic.crawler.CrawlSwitchboard;
import de.anomic.crawler.CrawlProfile;
import de.anomic.search.Switchboard;
@@ -108,21 +109,21 @@ public class CrawlProfileEditor_p {
if (post != null) {
if (post.containsKey("terminate")) try {
// termination of a crawl: shift the crawl from active to passive
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(handle.getBytes());
- if (mp != null) sb.crawler.profilesPassiveCrawls.put(handle.getBytes(), new CrawlProfile(mp));
+ final CrawlProfile p = sb.crawler.getActive(handle.getBytes());
+ if (p != null) sb.crawler.putPassive(handle.getBytes(), p);
// delete all entries from the crawl queue that are deleted here
- sb.crawler.profilesActiveCrawls.remove(handle.getBytes());
+ sb.crawler.removeActive(handle.getBytes());
sb.crawlQueues.noticeURL.removeByProfileHandle(handle, 10000);
} catch (RowSpaceExceededException e) {
Log.logException(e);
}
if (post.containsKey("delete")) {
// deletion of a terminated crawl profile
- sb.crawler.profilesPassiveCrawls.remove(handle.getBytes());
+ sb.crawler.removePassive(handle.getBytes());
}
if (post.containsKey("deleteTerminatedProfiles")) {
- for (final byte[] h: sb.crawler.profilesPassiveCrawls.keySet()) {
- sb.crawler.profilesPassiveCrawls.remove(h);
+ for (final byte[] h: sb.crawler.getPassive()) {
+ sb.crawler.removePassive(h);
}
}
}
@@ -130,8 +131,8 @@ public class CrawlProfileEditor_p {
// generate handle list: first sort by handle name
CrawlProfile selentry;
Map<String, String> orderdHandles = new TreeMap<String, String>();
- for (final byte[] h : sb.crawler.profilesActiveCrawls.keySet()) {
- selentry = new CrawlProfile(sb.crawler.profilesActiveCrawls.get(h));
+ for (final byte[] h : sb.crawler.getActive()) {
+ selentry = sb.crawler.getActive(h);
if (ignoreNames.contains(selentry.name())) continue;
orderdHandles.put(selentry.name(), selentry.handle());
}
@@ -146,8 +147,7 @@ public class CrawlProfileEditor_p {
count++;
}
prop.put("profiles", count);
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(handle.getBytes());
- selentry = (mp == null) ? null : new CrawlProfile(mp);
+ selentry = sb.crawler.getActive(handle.getBytes());
assert selentry == null || selentry.handle() != null;
// read post for change submit
if ((post != null) && (selentry != null)) {
@@ -161,7 +161,7 @@ public class CrawlProfileEditor_p {
final String val = (tee.type == eentry.BOOLEAN) ? Boolean.toString(post.containsKey(tee.name)) : post.get(tee.name, cval);
if (!cval.equals(val)) {
selentry.put(tee.name, val);
- sb.crawler.profilesActiveCrawls.put(selentry.handle().getBytes(), selentry);
+ sb.crawler.putActive(selentry.handle().getBytes(), selentry);
}
}
} catch (final Exception ex) {
@@ -178,17 +178,17 @@ public class CrawlProfileEditor_p {
final int domlistlength = (post == null) ? 160 : post.getInt("domlistlength", 160);
CrawlProfile profile;
// put active crawls into list
- for (final byte[] h: sb.crawler.profilesActiveCrawls.keySet()) {
- profile = new CrawlProfile(sb.crawler.profilesActiveCrawls.get(h));
- putProfileEntry(prop, profile, true, dark, count, domlistlength);
+ for (final byte[] h: sb.crawler.getActive()) {
+ profile = sb.crawler.getActive(h);
+ putProfileEntry(prop, sb.crawlStacker, profile, true, dark, count, domlistlength);
dark = !dark;
count++;
}
// put passive crawls into list
boolean existPassiveCrawls = false;
- for (final byte[] h: sb.crawler.profilesPassiveCrawls.keySet()) {
- profile = new CrawlProfile(sb.crawler.profilesPassiveCrawls.get(h));
- putProfileEntry(prop, profile, false, dark, count, domlistlength);
+ for (final byte[] h: sb.crawler.getPassive()) {
+ profile = sb.crawler.getPassive(h);
+ putProfileEntry(prop, sb.crawlStacker, profile, false, dark, count, domlistlength);
dark = !dark;
count++;
existPassiveCrawls = true;
@@ -226,7 +226,7 @@ public class CrawlProfileEditor_p {
return prop;
}
- private static void putProfileEntry(final servletProperties prop, final CrawlProfile profile, final boolean active, final boolean dark, final int count, final int domlistlength) {
+ private static void putProfileEntry(final servletProperties prop, final CrawlStacker crawlStacker, final CrawlProfile profile, final boolean active, final boolean dark, final int count, final int domlistlength) {
prop.put(CRAWL_PROFILE_PREFIX + count + "_dark", dark ? "1" : "0");
prop.put(CRAWL_PROFILE_PREFIX + count + "_name", profile.name());
@@ -245,7 +245,7 @@ public class CrawlProfileEditor_p {
// start contrib [MN]
int i = 0;
String item;
- while (i <= domlistlength && !"".equals(item = profile.domName(true, i))){
+ while (i <= domlistlength && !"".equals(item = crawlStacker.domName(true, i))){
if (i == domlistlength) {
item = item + " ...";
}
diff --git a/htroot/CrawlResults.java b/htroot/CrawlResults.java
index cfcbb82b9..d769d74d5 100644
--- a/htroot/CrawlResults.java
+++ b/htroot/CrawlResults.java
@@ -36,8 +36,9 @@ import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.logging.Log;
+import de.anomic.crawler.ResultURLs;
+import de.anomic.crawler.ResultURLs.EventOrigin;
import de.anomic.crawler.ResultURLs.InitExecEntry;
-import de.anomic.crawler.retrieval.EventOrigin;
import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
@@ -77,9 +78,9 @@ public class CrawlResults {
post != null &&
post.containsKey("autoforward") &&
tabletype == EventOrigin.LOCAL_CRAWLING &&
- sb.crawlResults.getStackSize(EventOrigin.LOCAL_CRAWLING) == 0) {
+ ResultURLs.getStackSize(EventOrigin.LOCAL_CRAWLING) == 0) {
// the main menu does a request to the local crawler page, but in case this table is empty, the overview page is shown
- tabletype = (sb.crawlResults.getStackSize(EventOrigin.SURROGATES) == 0) ? EventOrigin.UNKNOWN : EventOrigin.SURROGATES;
+ tabletype = (ResultURLs.getStackSize(EventOrigin.SURROGATES) == 0) ? EventOrigin.UNKNOWN : EventOrigin.SURROGATES;
}
// check if authorization is needed and/or given
@@ -107,7 +108,7 @@ public class CrawlResults {
}
// do the commands
- if (post.containsKey("clearlist")) sb.crawlResults.clearStack(tabletype);
+ if (post.containsKey("clearlist")) ResultURLs.clearStack(tabletype);
if (post.containsKey("deleteentry")) {
final String hash = post.get("hash", null);
@@ -124,7 +125,7 @@ public class CrawlResults {
// delete all urls for this domain from database
try {
sb.indexSegments.urlMetadata(Segments.Process.LOCALCRAWLING).deleteDomain(hashpart);
- sb.crawlResults.deleteDomain(tabletype, domain, hashpart);
+ ResultURLs.deleteDomain(tabletype, domain, hashpart);
} catch (IOException e) {
Log.logException(e);
}
@@ -146,18 +147,18 @@ public class CrawlResults {
// create table
if (tabletype == EventOrigin.UNKNOWN) {
prop.put("table", "2");
- } else if (sb.crawlResults.getStackSize(tabletype) == 0 && sb.crawlResults.getDomainListSize(tabletype) == 0) {
+ } else if (ResultURLs.getStackSize(tabletype) == 0 && ResultURLs.getDomainListSize(tabletype) == 0) {
prop.put("table", "0");
} else {
prop.put("table", "1");
- if (lines > sb.crawlResults.getStackSize(tabletype)) lines = sb.crawlResults.getStackSize(tabletype);
- if (lines == sb.crawlResults.getStackSize(tabletype)) {
+ if (lines > ResultURLs.getStackSize(tabletype)) lines = ResultURLs.getStackSize(tabletype);
+ if (lines == ResultURLs.getStackSize(tabletype)) {
prop.put("table_size", "0");
} else {
prop.put("table_size", "1");
prop.put("table_size_count", lines);
}
- prop.put("table_size_all", sb.crawlResults.getStackSize(tabletype));
+ prop.put("table_size_all", ResultURLs.getStackSize(tabletype));
prop.putHTML("table_feedbackpage", "CrawlResults.html");
prop.put("table_tabletype", tabletype.getCode());
@@ -175,7 +176,7 @@ public class CrawlResults {
URIMetadataRow.Components metadata;
int cnt = 0;
- final Iterator<Map.Entry<String, InitExecEntry>> i = sb.crawlResults.results(tabletype);
+ final Iterator<Map.Entry<String, InitExecEntry>> i = ResultURLs.results(tabletype);
Map.Entry<String, InitExecEntry> entry;
while (i.hasNext()) {
entry = i.next();
@@ -260,7 +261,7 @@ public class CrawlResults {
cnt = 0;
dark = true;
- final Iterator<String> j = sb.crawlResults.domains(tabletype);
+ final Iterator<String> j = ResultURLs.domains(tabletype);
String domain;
while (j.hasNext() && cnt < 100) {
domain = j.next();
@@ -270,7 +271,7 @@ public class CrawlResults {
prop.put("table_domains_" + cnt + "_tabletype", tabletype.getCode());
prop.put("table_domains_" + cnt + "_domain", domain);
prop.put("table_domains_" + cnt + "_hashpart", DigestURI.hosthash6(domain));
- prop.put("table_domains_" + cnt + "_count", sb.crawlResults.domainCount(tabletype, domain));
+ prop.put("table_domains_" + cnt + "_count", ResultURLs.domainCount(tabletype, domain));
dark = !dark;
cnt++;
}
diff --git a/htroot/Crawler_p.java b/htroot/Crawler_p.java
index d1eff945d..a7e7e788f 100644
--- a/htroot/Crawler_p.java
+++ b/htroot/Crawler_p.java
@@ -252,7 +252,7 @@ public class Crawler_p {
xdstopw,
xpstopw,
cachePolicy);
- sb.crawler.profilesActiveCrawls.put(profile.handle().getBytes(), profile);
+ sb.crawler.putActive(profile.handle().getBytes(), profile);
sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
final DigestURI url = crawlingStartURL;
sb.crawlStacker.enqueueEntries(sb.peers.mySeed().hash.getBytes(), profile.handle(), "ftp", url.getHost(), url.getPort(), false);
@@ -290,7 +290,7 @@ public class Crawler_p {
sb.crawlQueues.errorURL.remove(urlhash);
// stack url
- sb.crawler.profilesPassiveCrawls.remove(crawlingStartURL.hash()); // if there is an old entry, delete it
+ sb.crawler.removePassive(crawlingStartURL.hash()); // if there is an old entry, delete it
final CrawlProfile pe = new CrawlProfile(
(crawlingStartURL.getHost() == null) ? crawlingStartURL.toNormalform(true, false) : crawlingStartURL.getHost(),
crawlingStartURL,
@@ -307,7 +307,7 @@ public class Crawler_p {
xdstopw,
xpstopw,
cachePolicy);
- sb.crawler.profilesActiveCrawls.put(pe.handle().getBytes(), pe);
+ sb.crawler.putActive(pe.handle().getBytes(), pe);
final String reasonString = sb.crawlStacker.stackCrawl(new Request(
sb.peers.mySeed().hash.getBytes(),
url,
@@ -421,7 +421,7 @@ public class Crawler_p {
xdstopw,
xpstopw,
cachePolicy);
- sb.crawler.profilesActiveCrawls.put(profile.handle().getBytes(), profile);
+ sb.crawler.putActive(profile.handle().getBytes(), profile);
sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
sb.crawlStacker.enqueueEntries(sb.peers.mySeed().hash.getBytes(), profile.handle(), hyperlinks, true);
} catch (final PatternSyntaxException e) {
@@ -458,7 +458,7 @@ public class Crawler_p {
xdstopw,
xpstopw,
cachePolicy);
- sb.crawler.profilesActiveCrawls.put(pe.handle().getBytes(), pe);
+ sb.crawler.putActive(pe.handle().getBytes(), pe);
final SitemapImporter importer = new SitemapImporter(sb, sitemapURL, pe);
importer.start();
} catch (final Exception e) {
@@ -507,7 +507,7 @@ public class Crawler_p {
xdstopw,
xpstopw,
cachePolicy);
- sb.crawler.profilesActiveCrawls.put(profile.handle().getBytes(), profile);
+ sb.crawler.putActive(profile.handle().getBytes(), profile);
sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
final Iterator<Map.Entry<MultiProtocolURI, String>> linkiterator = hyperlinks.entrySet().iterator();
DigestURI nexturl;
diff --git a/htroot/DictionaryLoader_p.java b/htroot/DictionaryLoader_p.java
index 0036ec087..9928e5e18 100644
--- a/htroot/DictionaryLoader_p.java
+++ b/htroot/DictionaryLoader_p.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.MalformedURLException;
import net.yacy.cora.protocol.RequestHeader;
+import net.yacy.document.LibraryProvider;
import net.yacy.document.geolocalization.GeonamesLocalization;
import net.yacy.document.geolocalization.OpenGeoDBLocalization;
import net.yacy.kelondro.data.meta.DigestURI;
@@ -29,7 +30,6 @@ import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.FileUtils;
import de.anomic.crawler.CrawlProfile;
import de.anomic.crawler.retrieval.Response;
-import de.anomic.data.LibraryProvider;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.java
index 3e934901b..4aa467625 100644
--- a/htroot/IndexControlRWIs_p.java
+++ b/htroot/IndexControlRWIs_p.java
@@ -54,6 +54,7 @@ import net.yacy.kelondro.util.FileUtils;
import net.yacy.repository.Blacklist;
import de.anomic.crawler.CrawlProfile;
+import de.anomic.crawler.ResultURLs;
import de.anomic.data.ListManager;
import de.anomic.data.WorkTables;
import de.anomic.http.client.Cache;
@@ -154,6 +155,7 @@ public class IndexControlRWIs_p {
if (post.get("deleteCrawlQueues", "").equals("on")) {
sb.crawlQueues.clear();
sb.crawlStacker.clear();
+ ResultURLs.clearStacks();
}
if (post.get("deleteCache", "").equals("on")) {
Cache.clear();
diff --git a/htroot/IndexCreateWWWGlobalQueue_p.java b/htroot/IndexCreateWWWGlobalQueue_p.java
index 5d4019346..c3b577ad9 100644
--- a/htroot/IndexCreateWWWGlobalQueue_p.java
+++ b/htroot/IndexCreateWWWGlobalQueue_p.java
@@ -31,7 +31,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
-import java.util.Map;
import net.yacy.cora.protocol.RequestHeader;
@@ -103,8 +102,7 @@ public class IndexCreateWWWGlobalQueue_p {
if (urle != null && urle.url() != null) {
initiator = sb.peers.getConnected((urle.initiator() == null) ? "" : new String(urle.initiator()));
profileHandle = urle.profileHandle();
- final Map<String, String> mp = profileHandle == null ? null : sb.crawler.profilesActiveCrawls.get(profileHandle.getBytes());
- profileEntry = mp == null ? null : new CrawlProfile(mp);
+ profileEntry = profileHandle == null ? null : sb.crawler.getActive(profileHandle.getBytes());
prop.put("crawler-queue_list_"+showNum+"_dark", dark ? "1" : "0");
prop.putHTML("crawler-queue_list_"+showNum+"_initiator", ((initiator == null) ? "proxy" : initiator.getName()) );
prop.put("crawler-queue_list_"+showNum+"_profile", ((profileEntry == null) ? "unknown" : profileEntry.name()));
diff --git a/htroot/IndexCreateWWWLocalQueue_p.java b/htroot/IndexCreateWWWLocalQueue_p.java
index db542a83c..4c8b87d08 100644
--- a/htroot/IndexCreateWWWLocalQueue_p.java
+++ b/htroot/IndexCreateWWWLocalQueue_p.java
@@ -33,7 +33,6 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -97,8 +96,8 @@ public class IndexCreateWWWLocalQueue_p {
// search and delete the crawl profile (_much_ faster, independant of queue size)
// XXX: what to do about the annoying LOST PROFILE messages in the log?
CrawlProfile entry;
- for (byte[] handle: sb.crawler.profilesActiveCrawls.keySet()) {
- entry = new CrawlProfile(sb.crawler.profilesActiveCrawls.get(handle));
+ for (byte[] handle: sb.crawler.getActive()) {
+ entry = sb.crawler.getActive(handle);
final String name = entry.name();
if (name.equals(CrawlSwitchboard.CRAWL_PROFILE_PROXY) ||
name.equals(CrawlSwitchboard.CRAWL_PROFILE_REMOTE) ||
@@ -108,7 +107,7 @@ public class IndexCreateWWWLocalQueue_p {
name.equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA) ||
name.equals(CrawlSwitchboard.CRAWL_PROFILE_SURROGATE))
continue;
- if (compiledPattern.matcher(name).find()) sb.crawler.profilesActiveCrawls.remove(entry.handle().getBytes());
+ if (compiledPattern.matcher(name).find()) sb.crawler.removeActive(entry.handle().getBytes());
}
} else {
// iterating through the list of URLs
@@ -170,8 +169,7 @@ public class IndexCreateWWWLocalQueue_p {
if ((urle != null)&&(urle.url()!=null)) {
initiator = sb.peers.getConnected(urle.initiator() == null ? "" : new String(urle.initiator()));
profileHandle = urle.profileHandle();
- final Map<String, String> mp = profileHandle == null ? null : sb.crawler.profilesActiveCrawls.get(profileHandle.getBytes());
- profileEntry = mp == null ? null : new CrawlProfile(mp);
+ profileEntry = profileHandle == null ? null : sb.crawler.getActive(profileHandle.getBytes());
prop.put("crawler-queue_list_"+showNum+"_dark", dark ? "1" : "0");
prop.putHTML("crawler-queue_list_"+showNum+"_initiator", ((initiator == null) ? "proxy" : initiator.getName()) );
prop.put("crawler-queue_list_"+showNum+"_profile", ((profileEntry == null) ? "unknown" : profileEntry.name()));
diff --git a/htroot/IndexCreateWWWRemoteQueue_p.java b/htroot/IndexCreateWWWRemoteQueue_p.java
index 16eccfab4..957017e32 100644
--- a/htroot/IndexCreateWWWRemoteQueue_p.java
+++ b/htroot/IndexCreateWWWRemoteQueue_p.java
@@ -28,7 +28,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
-import java.util.Map;
import net.yacy.cora.protocol.RequestHeader;
@@ -100,8 +99,7 @@ public class IndexCreateWWWRemoteQueue_p {
if (urle != null && urle.url() != null) {
initiator = sb.peers.getConnected((urle.initiator() == null) ? "" : new String(urle.initiator()));
profileHandle = urle.profileHandle();
- final Map<String, String> mp = profileHandle == null ? null : sb.crawler.profilesActiveCrawls.get(profileHandle.getBytes());
- profileEntry = mp == null ? null : new CrawlProfile(mp);
+ profileEntry = profileHandle == null ? null : sb.crawler.getActive(profileHandle.getBytes());
prop.put("crawler-queue_list_" + showNum + "_dark", dark ? "1" : "0");
prop.putHTML("crawler-queue_list_" + showNum + "_initiator", ((initiator == null) ? "proxy" : initiator.getName()));
prop.put("crawler-queue_list_" + showNum + "_profile", ((profileEntry == null) ? "unknown" : profileEntry.name()));
diff --git a/htroot/ProxyIndexingMonitor_p.java b/htroot/ProxyIndexingMonitor_p.java
index 40fb07ee3..f4bcca6a2 100644
--- a/htroot/ProxyIndexingMonitor_p.java
+++ b/htroot/ProxyIndexingMonitor_p.java
@@ -107,7 +107,7 @@ public class ProxyIndexingMonitor_p {
sb.crawler.defaultProxyProfile.put("remoteIndexing",proxyIndexingRemote ? "true":"false");
sb.crawler.defaultProxyProfile.put("indexText",proxyIndexingLocalText ? "true":"false");
sb.crawler.defaultProxyProfile.put("indexMedia",proxyIndexingLocalMedia ? "true":"false");
- sb.crawler.profilesActiveCrawls.put(sb.crawler.defaultProxyProfile.handle().getBytes(), sb.crawler.defaultProxyProfile);
+ sb.crawler.putActive(sb.crawler.defaultProxyProfile.handle().getBytes(), sb.crawler.defaultProxyProfile);
prop.put("info", "2");//new proxyPrefetchdepth
prop.put("info_message", newProxyPrefetchDepth);
diff --git a/htroot/QuickCrawlLink_p.java b/htroot/QuickCrawlLink_p.java
index 7c4ec4d40..332882b7b 100644
--- a/htroot/QuickCrawlLink_p.java
+++ b/htroot/QuickCrawlLink_p.java
@@ -162,7 +162,7 @@ public class QuickCrawlLink_p {
xdstopw,
xpstopw,
CrawlProfile.CacheStrategy.IFFRESH);
- sb.crawler.profilesActiveCrawls.put(pe.handle().getBytes(), pe);
+ sb.crawler.putActive(pe.handle().getBytes(), pe);
} catch (final Exception e) {
// mist
prop.put("mode_status", "2");//Error with url
diff --git a/htroot/ViewFile.java b/htroot/ViewFile.java
index a274c43bb..f4fee8e88 100644
--- a/htroot/ViewFile.java
+++ b/htroot/ViewFile.java
@@ -28,6 +28,7 @@
//if the shell's current path is HTROOT
import java.io.IOException;
+import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URLDecoder;
@@ -40,7 +41,9 @@ import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
+import net.yacy.document.LibraryProvider;
import net.yacy.document.Parser;
+import net.yacy.document.WordTokenizer;
import net.yacy.document.parser.html.CharacterCoding;
import net.yacy.document.parser.html.ImageEntry;
import net.yacy.kelondro.data.meta.DigestURI;
@@ -48,7 +51,6 @@ import net.yacy.kelondro.data.meta.URIMetadataRow;
import de.anomic.crawler.CrawlProfile;
import de.anomic.crawler.retrieval.Response;
-import de.anomic.data.LibraryProvider;
import de.anomic.http.client.Cache;
import de.anomic.search.Segment;
import de.anomic.search.Segments;
@@ -284,7 +286,12 @@ public class ViewFile {
// Search word highlighting
for (final StringBuilder s: sentences) {
sentence = s.toString();
- final Enumeration<String> tokens = Condenser.wordTokenizer(sentence, "UTF-8", LibraryProvider.dymLib);
+ Enumeration<String> tokens = null;
+ try {
+ tokens = new WordTokenizer(new ByteArrayInputStream(sentence.getBytes("UTF-8")), LibraryProvider.dymLib);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
while (tokens.hasMoreElements()) {
token = tokens.nextElement();
if (token.length() > 0) {
diff --git a/htroot/WatchWebStructure_p.java b/htroot/WatchWebStructure_p.java
index e11251138..6bc988b98 100644
--- a/htroot/WatchWebStructure_p.java
+++ b/htroot/WatchWebStructure_p.java
@@ -49,8 +49,8 @@ public class WatchWebStructure_p {
if (host.equals("auto")) {
// try to find the host from the crawl profiles
CrawlProfile e;
- for (byte[] handle: sb.crawler.profilesActiveCrawls.keySet()) {
- e = new CrawlProfile(sb.crawler.profilesActiveCrawls.get(handle));
+ for (byte[] handle: sb.crawler.getActive()) {
+ e = sb.crawler.getActive(handle);
if (e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_PROXY) ||
e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_REMOTE) ||
e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT) ||
diff --git a/htroot/yacy/crawlReceipt.java b/htroot/yacy/crawlReceipt.java
index 94f042162..5d3de2f41 100644
--- a/htroot/yacy/crawlReceipt.java
+++ b/htroot/yacy/crawlReceipt.java
@@ -33,7 +33,8 @@ import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.logging.Log;
-import de.anomic.crawler.retrieval.EventOrigin;
+import de.anomic.crawler.ResultURLs;
+import de.anomic.crawler.ResultURLs.EventOrigin;
import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
@@ -141,7 +142,7 @@ public final class crawlReceipt {
if ("fill".equals(result)) try {
// put new entry into database
sb.indexSegments.urlMetadata(Segments.Process.RECEIPTS).store(entry);
- sb.crawlResults.stack(entry, youare.getBytes(), iam.getBytes(), EventOrigin.REMOTE_RECEIPTS);
+ ResultURLs.stack(entry, youare.getBytes(), iam.getBytes(), EventOrigin.REMOTE_RECEIPTS);
sb.crawlQueues.delegatedURL.remove(entry.hash()); // the delegated work has been done
if (log.isInfo()) log.logInfo("crawlReceipt: RECEIVED RECEIPT from " + otherPeerName + " for URL " + new String(entry.hash()) + ":" + metadata.url().toNormalform(false, true));
diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java
index ae89d4942..bb1a5f4ec 100644
--- a/htroot/yacy/search.java
+++ b/htroot/yacy/search.java
@@ -294,7 +294,7 @@ public final class search {
yacyChannel.channels(yacyChannel.REMOTESEARCH).addMessage(new RSSMessage("Remote Search Request from " + ((remoteSeed == null) ? "unknown" : remoteSeed.getName()), QueryParams.anonymizedQueryHashes(theQuery.queryHashes), ""));
// make event
- theSearch = SearchEventCache.getEvent(theQuery, sb.peers, sb.tables, sb.crawlResults, null, abstracts.length() > 0, sb.loader);
+ theSearch = SearchEventCache.getEvent(theQuery, sb.peers, sb.tables, null, abstracts.length() > 0, sb.loader);
// set statistic details of search result and find best result index set
joincount = theSearch.getRankingResult().getLocalIndexCount() - theSearch.getRankingResult().getMissCount();
diff --git a/htroot/yacy/transferURL.java b/htroot/yacy/transferURL.java
index 5e5fd4e50..19a470e92 100644
--- a/htroot/yacy/transferURL.java
+++ b/htroot/yacy/transferURL.java
@@ -36,7 +36,8 @@ import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.logging.Log;
import net.yacy.repository.Blacklist;
-import de.anomic.crawler.retrieval.EventOrigin;
+import de.anomic.crawler.ResultURLs;
+import de.anomic.crawler.ResultURLs.EventOrigin;
import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
import de.anomic.server.serverCore;
@@ -143,7 +144,7 @@ public final class transferURL {
if (yacyCore.log.isFine()) yacyCore.log.logFine("Accepting URL " + i + "/" + urlc + " from peer " + otherPeerName + ": " + lEntry.metadata().url().toNormalform(true, false));
try {
sb.indexSegments.urlMetadata(Segments.Process.DHTIN).store(lEntry);
- sb.crawlResults.stack(lEntry, iam.getBytes(), iam.getBytes(), EventOrigin.DHT_TRANSFER);
+ ResultURLs.stack(lEntry, iam.getBytes(), iam.getBytes(), EventOrigin.DHT_TRANSFER);
if (yacyCore.log.isFine()) yacyCore.log.logFine("transferURL: received URL '" + metadata.url().toNormalform(false, true) + "' from peer " + otherPeerName);
received++;
} catch (final IOException e) {
diff --git a/htroot/yacy/urls.java b/htroot/yacy/urls.java
index e512d0bc6..f9620e4d9 100644
--- a/htroot/yacy/urls.java
+++ b/htroot/yacy/urls.java
@@ -69,7 +69,7 @@ public class urls {
(System.currentTimeMillis() < timeout) &&
(sb.crawlQueues.noticeURL.stackSize(stackType) > 0)) {
try {
- entry = sb.crawlQueues.noticeURL.pop(stackType, false, sb.crawler.profilesActiveCrawls);
+ entry = sb.crawlQueues.noticeURL.pop(stackType, false, sb.crawler);
} catch (final IOException e) {
break;
}
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index e4fe64e92..cb870ec22 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -40,6 +40,7 @@ import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.ResponseHeader;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
+import net.yacy.document.LibraryProvider;
import net.yacy.document.Parser;
import net.yacy.document.geolocalization.Location;
import net.yacy.kelondro.data.meta.DigestURI;
@@ -56,7 +57,6 @@ import net.yacy.kelondro.util.ISO639;
import de.anomic.crawler.CrawlProfile;
import de.anomic.data.DidYouMean;
-import de.anomic.data.LibraryProvider;
import de.anomic.search.AccessTracker;
import de.anomic.search.ContentDomain;
import de.anomic.search.QueryParams;
@@ -520,7 +520,7 @@ public class yacysearch {
theQuery.setOffset(0); // in case that this is a new search, always start without a offset
offset = 0;
}
- final SearchEvent theSearch = SearchEventCache.getEvent(theQuery, sb.peers, sb.tables, sb.crawlResults, (sb.isRobinsonMode()) ? sb.clusterhashes : null, false, sb.loader);
+ final SearchEvent theSearch = SearchEventCache.getEvent(theQuery, sb.peers, sb.tables, (sb.isRobinsonMode()) ? sb.clusterhashes : null, false, sb.loader);
try {Thread.sleep(global ? 100 : 10);} catch (InterruptedException e1) {} // wait a little time to get first results in the search
if (offset == 0) {
diff --git a/htroot/yacysearch_location.java b/htroot/yacysearch_location.java
index a4c2d2038..6dfa41083 100644
--- a/htroot/yacysearch_location.java
+++ b/htroot/yacysearch_location.java
@@ -27,8 +27,8 @@ import net.yacy.cora.document.RSSMessage;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.services.SearchSRURSS;
+import net.yacy.document.LibraryProvider;
import net.yacy.document.geolocalization.Location;
-import de.anomic.data.LibraryProvider;
import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
import de.anomic.server.serverCore;
diff --git a/htroot/yacysearchtrailer.java b/htroot/yacysearchtrailer.java
index ad75ffcf1..5000d9dab 100644
--- a/htroot/yacysearchtrailer.java
+++ b/htroot/yacysearchtrailer.java
@@ -28,9 +28,9 @@ import java.util.Iterator;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.storage.StaticScore;
+import net.yacy.document.LibraryProvider;
import net.yacy.kelondro.util.EventTracker;
-import de.anomic.data.LibraryProvider;
import de.anomic.search.QueryParams;
import de.anomic.search.SearchEvent;
import de.anomic.search.SearchEventCache;
diff --git a/source/de/anomic/crawler/Balancer.java b/source/de/anomic/crawler/Balancer.java
index ccd27a0c7..462b7d2df 100644
--- a/source/de/anomic/crawler/Balancer.java
+++ b/source/de/anomic/crawler/Balancer.java
@@ -318,7 +318,7 @@ public class Balancer {
* @throws IOException
* @throws RowSpaceExceededException
*/
- public Request pop(final boolean delay, final Map<byte[], Map<String, String>> profiles) throws IOException {
+ public Request pop(final boolean delay, final CrawlSwitchboard cs) throws IOException {
// returns a crawl entry from the stack and ensures minimum delta times
try {
@@ -382,8 +382,7 @@ public class Balancer {
// at this point we must check if the crawlEntry has relevance because the crawl profile still exists
// if not: return null. A calling method must handle the null value and try again
- final Map<String, String> mp = profiles == null ? null : profiles.get(crawlEntry.profileHandle());
- final CrawlProfile profileEntry = mp == null ? null : new CrawlProfile(mp);
+ final CrawlProfile profileEntry = cs.getActive(crawlEntry.profileHandle().getBytes());
if (profileEntry == null) {
Log.logWarning("Balancer", "no profile entry for handle " + crawlEntry.profileHandle());
return null;
diff --git a/source/de/anomic/crawler/CrawlProfile.java b/source/de/anomic/crawler/CrawlProfile.java
index d54917559..d8f66a4be 100644
--- a/source/de/anomic/crawler/CrawlProfile.java
+++ b/source/de/anomic/crawler/CrawlProfile.java
@@ -22,7 +22,6 @@
package de.anomic.crawler;
-import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
@@ -59,10 +58,8 @@ public class CrawlProfile extends ConcurrentHashMap<String, String> implements M
public static final String XPSTOPW = "xpstopw";
public static final String CACHE_STRAGEGY = "cacheStrategy";
- private Map<String, DomProfile> doms;
private Pattern mustmatch = null, mustnotmatch = null;
-
public CrawlProfile(
final String name,
final DigestURI startURL,
@@ -100,13 +97,11 @@ public class CrawlProfile extends ConcurrentHashMap<String, String> implements M
put(XDSTOPW, xdstopw); // exclude dynamic stop-word
put(XPSTOPW, xpstopw); // exclude parent stop-words
put(CACHE_STRAGEGY, cacheStrategy.toString());
- doms = new ConcurrentHashMap<String, DomProfile>();
}
public CrawlProfile(Map<String, String> ext) {
super(ext == null ? 1 : ext.size());
if (ext != null) this.putAll(ext);
- doms = new ConcurrentHashMap<String, DomProfile>();
}
public void put(String key, boolean value) {
@@ -241,63 +236,6 @@ public class CrawlProfile extends ConcurrentHashMap<String, String> implements M
if (r == null) return false;
return (r.equals(Boolean.TRUE.toString()));
}
- public void domInc(final String domain, final String referrer, final int depth) {
- final DomProfile dp = doms.get(domain);
- if (dp == null) {
- // new domain
- doms.put(domain, new DomProfile(referrer, depth));
- } else {
- // increase counter
- dp.inc();
- }
- }
- public boolean grantedDomCount(final String domain) {
- final int max = domMaxPages();
- if (max == Integer.MAX_VALUE) return true;
- final DomProfile dp = doms.get(domain);
- if (dp == null) {
- return 0 < max;
- }
- return dp.count <= max;
- }
- public int domSize() {
- return doms.size();
- }
-
- public String domName(final boolean attr, final int index){
- final Iterator<Map.Entry<String, DomProfile>> domnamesi = doms.entrySet().iterator();
- String domname="";
- Map.Entry<String, DomProfile> ey;
- DomProfile dp;
- int i = 0;
- while ((domnamesi.hasNext()) && (i < index)) {
- ey = domnamesi.next();
- i++;
- }
- if (domnamesi.hasNext()) {
- ey = domnamesi.next();
- dp = ey.getValue();
- domname = ey.getKey() + ((attr) ? ("/r=" + dp.referrer + ", d=" + dp.depth + ", c=" + dp.count) : " ");
- }
- return domname;
- }
-
- public final static class DomProfile {
-
- public String referrer;
- public int depth, count;
-
- public DomProfile(final String ref, final int d) {
- this.referrer = ref;
- this.depth = d;
- this.count = 1;
- }
-
- public void inc() {
- this.count++;
- }
-
- }
public static enum CacheStrategy {
NOCACHE(0), // never use the cache, all content from fresh internet source
diff --git a/source/de/anomic/crawler/CrawlQueues.java b/source/de/anomic/crawler/CrawlQueues.java
index 2ebd72d28..5dbc4c2bf 100644
--- a/source/de/anomic/crawler/CrawlQueues.java
+++ b/source/de/anomic/crawler/CrawlQueues.java
@@ -203,7 +203,7 @@ public class CrawlQueues {
// move some tasks to the core crawl job so we have something to do
final int toshift = Math.min(10, limitCrawlJobSize()); // this cannot be a big number because the balancer makes a forced waiting if it cannot balance
for (int i = 0; i < toshift; i++) {
- noticeURL.shift(NoticedURL.StackType.LIMIT, NoticedURL.StackType.CORE, sb.crawler.profilesActiveCrawls);
+ noticeURL.shift(NoticedURL.StackType.LIMIT, NoticedURL.StackType.CORE, sb.crawler);
}
log.logInfo("shifted " + toshift + " jobs from global crawl to local crawl (coreCrawlJobSize()=" + coreCrawlJobSize() +
", limitCrawlJobSize()=" + limitCrawlJobSize() + ", cluster.mode=" + sb.getConfig(SwitchboardConstants.CLUSTER_MODE, "") +
@@ -233,20 +233,20 @@ public class CrawlQueues {
try {
if (noticeURL.stackSize(NoticedURL.StackType.NOLOAD) > 0) {
// get one entry that will not be loaded, just indexed
- urlEntry = noticeURL.pop(NoticedURL.StackType.NOLOAD, true, sb.crawler.profilesActiveCrawls);
+ urlEntry = noticeURL.pop(NoticedURL.StackType.NOLOAD, true, sb.crawler);
if (urlEntry == null) continue;
final String profileHandle = urlEntry.profileHandle();
if (profileHandle == null) {
log.logSevere(stats + ": NULL PROFILE HANDLE '" + urlEntry.profileHandle() + "' for URL " + urlEntry.url());
return true;
}
- Map<String, String> map = sb.crawler.profilesActiveCrawls.get(profileHandle);
- if (map == null) {
+ CrawlProfile profile = sb.crawler.getActive(profileHandle.getBytes());
+ if (profile == null) {
log.logSevere(stats + ": NULL PROFILE HANDLE '" + urlEntry.profileHandle() + "' for URL " + urlEntry.url());
return true;
}
try {
- sb.indexingDocumentProcessor.enQueue(new indexingQueueEntry(Segments.Process.LOCALCRAWLING, new Response(urlEntry, new CrawlProfile(map)), null, null));
+ sb.indexingDocumentProcessor.enQueue(new indexingQueueEntry(Segments.Process.LOCALCRAWLING, new Response(urlEntry, profile), null, null));
Log.logInfo("CrawlQueues", "placed NOLOAD URL on indexing queue: " + urlEntry.url().toNormalform(true, false));
} catch (InterruptedException e) {
Log.logException(e);
@@ -254,7 +254,7 @@ public class CrawlQueues {
return true;
}
- urlEntry = noticeURL.pop(NoticedURL.StackType.CORE, true, sb.crawler.profilesActiveCrawls);
+ urlEntry = noticeURL.pop(NoticedURL.StackType.CORE, true, sb.crawler);
if (urlEntry == null) continue;
final String profileHandle = urlEntry.profileHandle();
// System.out.println("DEBUG plasmaSwitchboard.processCrawling:
@@ -282,14 +282,13 @@ public class CrawlQueues {
* @return
*/
private void load(Request urlEntry, final String stats, final String profileHandle) {
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(profileHandle.getBytes());
- if (mp != null) {
+ final CrawlProfile profile = sb.crawler.getActive(profileHandle.getBytes());
+ if (profile != null) {
// check if the protocol is supported
final DigestURI url = urlEntry.url();
final String urlProtocol = url.getProtocol();
if (sb.loader.isSupportedProtocol(urlProtocol)) {
- CrawlProfile profile = new CrawlProfile(mp);
if (this.log.isFine())
log.logFine(stats + ": URL=" + urlEntry.url()
+ ", initiator=" + ((urlEntry.initiator() == null) ? "" : new String(urlEntry.initiator()))
@@ -520,7 +519,7 @@ public class CrawlQueues {
final String stats = "REMOTETRIGGEREDCRAWL[" + noticeURL.stackSize(NoticedURL.StackType.CORE) + ", " + noticeURL.stackSize(NoticedURL.StackType.LIMIT) + ", " + noticeURL.stackSize(NoticedURL.StackType.OVERHANG) + ", "
+ noticeURL.stackSize(NoticedURL.StackType.REMOTE) + "]";
try {
- final Request urlEntry = noticeURL.pop(NoticedURL.StackType.REMOTE, true, sb.crawler.profilesActiveCrawls);
+ final Request urlEntry = noticeURL.pop(NoticedURL.StackType.REMOTE, true, sb.crawler);
final String profileHandle = urlEntry.profileHandle();
// System.out.println("DEBUG plasmaSwitchboard.processCrawling:
// profileHandle = " + profileHandle + ", urlEntry.url = " +
@@ -534,7 +533,6 @@ public class CrawlQueues {
}
}
-
public int workerSize() {
return workers.size();
}
@@ -590,8 +588,7 @@ public class CrawlQueues {
try {
request.setStatus("loading", WorkflowJob.STATUS_RUNNING);
final long maxFileSize = sb.getConfigLong("crawler.http.maxFileSize", HTTPLoader.DEFAULT_MAXFILESIZE);
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
- CrawlProfile e = mp == null ? null : new CrawlProfile(mp);
+ final CrawlProfile e = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = sb.loader.load(request, e == null ? CrawlProfile.CacheStrategy.IFEXIST : e.cacheStrategy(), maxFileSize, true);
if (response == null) {
request.setStatus("error", WorkflowJob.STATUS_FINISHED);
diff --git a/source/de/anomic/crawler/CrawlStacker.java b/source/de/anomic/crawler/CrawlStacker.java
index feec79c2f..9b5154348 100644
--- a/source/de/anomic/crawler/CrawlStacker.java
+++ b/source/de/anomic/crawler/CrawlStacker.java
@@ -33,8 +33,10 @@ import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.util.Date;
+import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.Domains;
@@ -48,6 +50,7 @@ import net.yacy.kelondro.workflow.WorkflowProcessor;
import net.yacy.repository.Blacklist;
import net.yacy.repository.FilterEngine;
+import de.anomic.crawler.ResultURLs.EventOrigin;
import de.anomic.crawler.retrieval.FTPLoader;
import de.anomic.crawler.retrieval.HTTPLoader;
import de.anomic.crawler.retrieval.Request;
@@ -70,6 +73,25 @@ public final class CrawlStacker {
private final boolean acceptLocalURLs, acceptGlobalURLs;
private final FilterEngine domainList;
+ public final static class DomProfile {
+
+ public String referrer;
+ public int depth, count;
+
+ public DomProfile(final String ref, final int d) {
+ this.referrer = ref;
+ this.depth = d;
+ this.count = 1;
+ }
+
+ public void inc() {
+ this.count++;
+ }
+
+ }
+
+ private Map<String, DomProfile> doms;
+
// this is the process that checks url for double-occurrences and for allowance/disallowance by robots.txt
public CrawlStacker(
@@ -92,10 +114,38 @@ public final class CrawlStacker {
this.fastQueue = new WorkflowProcessor<Request>("CrawlStackerFast", "This process checks new urls before they are enqueued into the balancer (proper, double-check, correct domain, filter)", new String[]{"Balancer"}, this, "job", 10000, null, 2);
this.slowQueue = new WorkflowProcessor<Request>("CrawlStackerSlow", "This is like CrawlStackerFast, but does additionaly a DNS lookup. The CrawlStackerFast does not need this because it can use the DNS cache.", new String[]{"Balancer"}, this, "job", 1000, null, 5);
-
+ this.doms = new ConcurrentHashMap<String, DomProfile>();
this.log.logInfo("STACKCRAWL thread initialized.");
}
+ private void domInc(final String domain, final String referrer, final int depth) {
+ final DomProfile dp = doms.get(domain);
+ if (dp == null) {
+ // new domain
+ doms.put(domain, new DomProfile(referrer, depth));
+ } else {
+ // increase counter
+ dp.inc();
+ }
+ }
+ public String domName(final boolean attr, final int index){
+ final Iterator<Map.Entry<String, DomProfile>> domnamesi = doms.entrySet().iterator();
+ String domname="";
+ Map.Entry<String, DomProfile> ey;
+ DomProfile dp;
+ int i = 0;
+ while ((domnamesi.hasNext()) && (i < index)) {
+ ey = domnamesi.next();
+ i++;
+ }
+ if (domnamesi.hasNext()) {
+ ey = domnamesi.next();
+ dp = ey.getValue();
+ domname = ey.getKey() + ((attr) ? ("/r=" + dp.referrer + ", d=" + dp.depth + ", c=" + dp.count) : " ");
+ }
+ return domname;
+ }
+
public int size() {
return this.fastQueue.queueSize() + this.slowQueue.queueSize();
}
@@ -108,6 +158,7 @@ public final class CrawlStacker {
public void clear() {
this.fastQueue.clear();
this.slowQueue.clear();
+ this.doms.clear();
}
public void announceClose() {
@@ -268,8 +319,7 @@ public final class CrawlStacker {
// returns null if successful, a reason string if not successful
//this.log.logFinest("stackCrawl: nexturlString='" + nexturlString + "'");
- final Map<String, String> mp = crawler.profilesActiveCrawls.get(entry.profileHandle().getBytes());
- CrawlProfile profile = mp == null ? null : new CrawlProfile(mp);
+ final CrawlProfile profile = crawler.getActive(entry.profileHandle().getBytes());
String error;
if (profile == null) {
error = "LOST STACKER PROFILE HANDLE '" + entry.profileHandle() + "' for URL " + entry.url();
@@ -280,13 +330,6 @@ public final class CrawlStacker {
error = checkAcceptance(entry.url(), profile, entry.depth());
if (error != null) return error;
- final DigestURI referrerURL = (entry.referrerhash() == null || entry.referrerhash().length == 0) ? null : nextQueue.getURL(entry.referrerhash());
-
- // add domain to profile domain list
- if (profile.domMaxPages() != Integer.MAX_VALUE) {
- profile.domInc(entry.url().getHost(), (referrerURL == null) ? null : referrerURL.getHost().toLowerCase(), entry.depth());
- }
-
// store information
final boolean local = Base64Order.enhancedCoder.equal(entry.initiator(), peers.mySeed().hash.getBytes());
final boolean proxy = (entry.initiator() == null || entry.initiator().length == 0 || new String(entry.initiator()).equals("------------")) && profile.handle().equals(crawler.defaultProxyProfile.handle());
@@ -322,6 +365,13 @@ public final class CrawlStacker {
return null;
}
+ final DigestURI referrerURL = (entry.referrerhash() == null || entry.referrerhash().length == 0) ? null : nextQueue.getURL(entry.referrerhash());
+
+ // add domain to profile domain list
+ if (profile.domMaxPages() != Integer.MAX_VALUE) {
+ domInc(entry.url().getHost(), (referrerURL == null) ? null : referrerURL.getHost().toLowerCase(), entry.depth());
+ }
+
if (global) {
// it may be possible that global == true and local == true, so do not check an error case against it
if (proxy) this.log.logWarning("URL '" + entry.url().toString() + "' has conflicting initiator properties: global = true, proxy = true, initiator = proxy" + ", profile.handle = " + profile.handle());
@@ -399,12 +449,6 @@ public final class CrawlStacker {
return "post url not allowed";
}
- // deny urls that exceed allowed number of occurrences
- if (!(profile.grantedDomCount(url.getHost()))) {
- if (this.log.isFine()) this.log.logFine("URL '" + url.toString() + "' appeared too often, a maximum of " + profile.domMaxPages() + " is allowed.");
- return "domain counter exceeded";
- }
-
// check if the url is double registered
final String dbocc = nextQueue.urlExists(url.hash()); // returns the name of the queue if entry exists
URIMetadataRow oldEntry = indexSegment.urlMetadata().load(url.hash(), null, 0);
@@ -439,6 +483,21 @@ public final class CrawlStacker {
}
}
}
+
+ // deny urls that exceed allowed number of occurrences
+ final int maxAllowedPagesPerDomain = profile.domMaxPages();
+ if (maxAllowedPagesPerDomain < Integer.MAX_VALUE) {
+ final DomProfile dp = doms.get(url.getHost());
+ if (dp != null && dp.count >= maxAllowedPagesPerDomain) {
+ if (this.log.isFine()) this.log.logFine("URL '" + url.toString() + "' appeared too often in crawl stack, a maximum of " + profile.domMaxPages() + " is allowed.");
+ return "crawl stack domain counter exceeded";
+ }
+
+ if (ResultURLs.domainCount(EventOrigin.LOCAL_CRAWLING, url.getHost()) >= profile.domMaxPages()) {
+ if (this.log.isFine()) this.log.logFine("URL '" + url.toString() + "' appeared too often in result stack, a maximum of " + profile.domMaxPages() + " is allowed.");
+ return "result stack domain counter exceeded";
+ }
+ }
return null;
}
diff --git a/source/de/anomic/crawler/CrawlSwitchboard.java b/source/de/anomic/crawler/CrawlSwitchboard.java
index 025369ba4..9090d1416 100644
--- a/source/de/anomic/crawler/CrawlSwitchboard.java
+++ b/source/de/anomic/crawler/CrawlSwitchboard.java
@@ -29,6 +29,7 @@ package de.anomic.crawler;
import java.io.File;
import java.io.IOException;
import java.util.Map;
+import java.util.Set;
import net.yacy.kelondro.blob.MapHeap;
import net.yacy.kelondro.data.word.Word;
@@ -58,7 +59,7 @@ public final class CrawlSwitchboard {
public static final long CRAWL_PROFILE_SURROGATE_RECRAWL_CYCLE = 60L * 24L * 30L;
private final Log log;
- public Map<byte[], Map<String, String>> profilesActiveCrawls, profilesPassiveCrawls;
+ private Map<byte[], Map<String, String>> profilesActiveCrawls, profilesPassiveCrawls;
public CrawlProfile defaultProxyProfile;
public CrawlProfile defaultRemoteProfile;
public CrawlProfile defaultTextSnippetLocalProfile, defaultTextSnippetGlobalProfile;
@@ -125,6 +126,46 @@ public final class CrawlSwitchboard {
", " + this.profilesPassiveCrawls.size() + " entries" +
", " + profilesPassiveFile.length()/1024);
}
+
+ public CrawlProfile getActive(byte[] profileKey) {
+ if (profileKey == null) return null;
+ Map<String, String> m = this.profilesActiveCrawls.get(profileKey);
+ if (m == null) return null;
+ return new CrawlProfile(m);
+ }
+
+ public CrawlProfile getPassive(byte[] profileKey) {
+ if (profileKey == null) return null;
+ Map<String, String> m = this.profilesPassiveCrawls.get(profileKey);
+ if (m == null) return null;
+ return new CrawlProfile(m);
+ }
+
+ public Set<byte[]> getActive() {
+ return this.profilesActiveCrawls.keySet();
+ }
+
+ public Set<byte[]> getPassive() {
+ return this.profilesPassiveCrawls.keySet();
+ }
+
+ public void removeActive(byte[] profileKey) {
+ if (profileKey == null) return;
+ this.profilesActiveCrawls.remove(profileKey);
+ }
+
+ public void removePassive(byte[] profileKey) {
+ if (profileKey == null) return;
+ this.profilesPassiveCrawls.remove(profileKey);
+ }
+
+ public void putActive(byte[] profileKey, CrawlProfile profile) {
+ this.profilesActiveCrawls.put(profileKey, profile);
+ }
+
+ public void putPassive(byte[] profileKey, CrawlProfile profile) {
+ this.profilesPassiveCrawls.put(profileKey, profile);
+ }
public void clear() {
}
diff --git a/source/de/anomic/crawler/NoticedURL.java b/source/de/anomic/crawler/NoticedURL.java
index 69e728654..ab88c9a22 100755
--- a/source/de/anomic/crawler/NoticedURL.java
+++ b/source/de/anomic/crawler/NoticedURL.java
@@ -29,7 +29,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
@@ -228,19 +227,19 @@ public class NoticedURL {
}
}
- public Request pop(final StackType stackType, final boolean delay, Map<byte[], Map<String, String>> profiles) throws IOException {
+ public Request pop(final StackType stackType, final boolean delay, CrawlSwitchboard cs) throws IOException {
switch (stackType) {
- case CORE: return pop(coreStack, delay, profiles);
- case LIMIT: return pop(limitStack, delay, profiles);
- case REMOTE: return pop(remoteStack, delay, profiles);
- case NOLOAD: return pop(noloadStack, false, profiles);
+ case CORE: return pop(coreStack, delay, cs);
+ case LIMIT: return pop(limitStack, delay, cs);
+ case REMOTE: return pop(remoteStack, delay, cs);
+ case NOLOAD: return pop(noloadStack, false, cs);
default: return null;
}
}
- public void shift(final StackType fromStack, final StackType toStack, Map<byte[], Map<String, String>> profiles) {
+ public void shift(final StackType fromStack, final StackType toStack, CrawlSwitchboard cs) {
try {
- final Request entry = pop(fromStack, false, profiles);
+ final Request entry = pop(fromStack, false, cs);
if (entry != null) push(toStack, entry);
} catch (final IOException e) {
return;
@@ -258,14 +257,14 @@ public class NoticedURL {
}
}
- private Request pop(final Balancer balancer, final boolean delay, Map<byte[], Map<String, String>> profiles) throws IOException {
+ private Request pop(final Balancer balancer, final boolean delay, CrawlSwitchboard cs) throws IOException {
// this is a filo - pop
int s;
Request entry;
int errors = 0;
synchronized (balancer) {
while ((s = balancer.size()) > 0) {
- entry = balancer.pop(delay, profiles);
+ entry = balancer.pop(delay, cs);
if (entry == null) {
if (s > balancer.size()) continue;
errors++;
diff --git a/source/de/anomic/crawler/ResultURLs.java b/source/de/anomic/crawler/ResultURLs.java
index 7bb0e52d7..9250dd809 100644
--- a/source/de/anomic/crawler/ResultURLs.java
+++ b/source/de/anomic/crawler/ResultURLs.java
@@ -40,32 +40,61 @@ import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.util.ReverseMapIterator;
-import de.anomic.crawler.retrieval.EventOrigin;
-
public final class ResultURLs {
- private final Map<EventOrigin, Map<String, InitExecEntry>> resultStacks; // a mapping from urlHash to Entries
- private final Map<EventOrigin, DynamicScore<String>> resultDomains;
+ public enum EventOrigin {
- public class InitExecEntry {
- public byte[] initiatorHash, executorHash;
- public InitExecEntry(final byte[] initiatorHash, final byte[] executorHash) {
- this.initiatorHash = initiatorHash;
- this.executorHash = executorHash;
+ // we must distinguish the following cases: resource-load was initiated by
+ // 1) global crawling: the index is extern, not here (not possible here)
+ // 2) result of search queries, some indexes are here (not possible here)
+ // 3) result of index transfer, some of them are here (not possible here)
+ // 4) proxy-load (initiator is "------------")
+ // 5) local prefetch/crawling (initiator is own seedHash)
+ // 6) local fetching for global crawling (other known or unknown initiator)
+
+ UNKNOWN(0),
+ REMOTE_RECEIPTS(1),
+ QUERIES(2),
+ DHT_TRANSFER(3),
+ PROXY_LOAD(4),
+ LOCAL_CRAWLING(5),
+ GLOBAL_CRAWLING(6),
+ SURROGATES(7);
+
+ protected int code;
+ private static final EventOrigin[] list = {
+ UNKNOWN, REMOTE_RECEIPTS, QUERIES, DHT_TRANSFER, PROXY_LOAD, LOCAL_CRAWLING, GLOBAL_CRAWLING, SURROGATES};
+ private EventOrigin(int code) {
+ this.code = code;
+ }
+ public int getCode() {
+ return this.code;
+ }
+ public static final EventOrigin getEvent(int key) {
+ return list[key];
}
}
- public ResultURLs(int initialStackCapacity) {
- // init result stacks
- resultStacks = new ConcurrentHashMap<EventOrigin, Map<String, InitExecEntry>>(initialStackCapacity);
- resultDomains = new ConcurrentHashMap<EventOrigin, DynamicScore<String>>(initialStackCapacity);
+ private final static int initialStackCapacity = 500;
+ private final static Map<EventOrigin, Map<String, InitExecEntry>> resultStacks = new ConcurrentHashMap<EventOrigin, Map<String, InitExecEntry>>(initialStackCapacity); // a mapping from urlHash to Entries
+ private final static Map<EventOrigin, DynamicScore<String>> resultDomains = new ConcurrentHashMap<EventOrigin, DynamicScore<String>>(initialStackCapacity);
+
+ static {
for (EventOrigin origin: EventOrigin.values()) {
resultStacks.put(origin, new LinkedHashMap<String, InitExecEntry>());
resultDomains.put(origin, new ScoreCluster<String>());
}
}
+
+ public static class InitExecEntry {
+ public byte[] initiatorHash, executorHash;
+ public InitExecEntry(final byte[] initiatorHash, final byte[] executorHash) {
+ this.initiatorHash = initiatorHash;
+ this.executorHash = executorHash;
+ }
+ }
- public synchronized void stack(
+ public static void stack(
final URIMetadataRow e,
final byte[] initiatorHash,
final byte[] executorHash,
@@ -93,19 +122,19 @@ public final class ResultURLs {
}
}
- public int getStackSize(final EventOrigin stack) {
+ public static int getStackSize(final EventOrigin stack) {
final Map<String, InitExecEntry> resultStack = getStack(stack);
if (resultStack == null) return 0;
return resultStack.size();
}
- public int getDomainListSize(final EventOrigin stack) {
+ public static int getDomainListSize(final EventOrigin stack) {
final DynamicScore<String> domains = getDomains(stack);
if (domains == null) return 0;
return domains.size();
}
- public Iterator<Map.Entry<String, InitExecEntry>> results(final EventOrigin stack) {
+ public static Iterator<Map.Entry<String, InitExecEntry>> results(final EventOrigin stack) {
final Map<String, InitExecEntry> resultStack = getStack(stack);
if (resultStack == null) return new LinkedHashMap<String, InitExecEntry>().entrySet().iterator();
return new ReverseMapIterator<String, InitExecEntry>(resultStack);
@@ -115,12 +144,12 @@ public final class ResultURLs {
* iterate all domains in the result domain statistic
* @return iterator of domains in reverse order (downwards)
*/
- public Iterator<String> domains(final EventOrigin stack) {
+ public static Iterator<String> domains(final EventOrigin stack) {
assert getDomains(stack) != null : "getDomains(" + stack + ") = null";
return getDomains(stack).keys(false);
}
- public int deleteDomain(final EventOrigin stack, String host, String hosthash) {
+ public static int deleteDomain(final EventOrigin stack, String host, String hosthash) {
assert host != null : "host = null";
assert hosthash.length() == 6;
final Iterator<Map.Entry<String, InitExecEntry>> i = results(stack);
@@ -141,7 +170,7 @@ public final class ResultURLs {
* @param domain name
* @return the number of occurrences of the domain in the stack statistics
*/
- public int domainCount(final EventOrigin stack, String domain) {
+ public static int domainCount(final EventOrigin stack, String domain) {
assert domain != null : "domain = null";
assert getDomains(stack) != null : "getDomains(" + stack + ") = null";
return getDomains(stack).get(domain);
@@ -153,18 +182,18 @@ public final class ResultURLs {
* @param stack id of resultStack
* @return null if stack does not exist (id is unknown or stack is null (which should not occur and an error is logged))
*/
- private Map<String, InitExecEntry> getStack(final EventOrigin stack) {
+ private static Map<String, InitExecEntry> getStack(final EventOrigin stack) {
return resultStacks.get(stack);
}
- private DynamicScore<String> getDomains(final EventOrigin stack) {
+ private static DynamicScore<String> getDomains(final EventOrigin stack) {
return resultDomains.get(stack);
}
- public void clearStacks() {
+ public static void clearStacks() {
for (EventOrigin origin: EventOrigin.values()) clearStack(origin);
}
- public synchronized void clearStack(final EventOrigin stack) {
+ public static void clearStack(final EventOrigin stack) {
final Map<String, InitExecEntry> resultStack = getStack(stack);
if (resultStack != null) resultStack.clear();
final DynamicScore<String> resultDomains = getDomains(stack);
@@ -175,7 +204,7 @@ public final class ResultURLs {
}
}
- public synchronized boolean remove(final String urlHash) {
+ public static boolean remove(final String urlHash) {
if (urlHash == null) return false;
Map<String, InitExecEntry> resultStack;
for (EventOrigin origin: EventOrigin.values()) {
@@ -190,16 +219,15 @@ public final class ResultURLs {
* @param args
*/
public static void main(final String[] args) {
- final ResultURLs results = new ResultURLs(10);
try {
final DigestURI url = new DigestURI("http", "www.yacy.net", 80, "/");
final URIMetadataRow urlRef = new URIMetadataRow(url, "YaCy Homepage", "", "", "", new Date(), new Date(), new Date(), "", new byte[] {}, 123, 42, '?', new Bitfield(), "de", 0, 0, 0, 0, 0, 0);
EventOrigin stackNo = EventOrigin.LOCAL_CRAWLING;
System.out.println("valid test:\n=======");
// add
- results.stack(urlRef, urlRef.hash(), url.hash(), stackNo);
+ stack(urlRef, urlRef.hash(), url.hash(), stackNo);
// size
- System.out.println("size of stack:\t"+ results.getStackSize(stackNo));
+ System.out.println("size of stack:\t"+ getStackSize(stackNo));
} catch (final MalformedURLException e) {
Log.logException(e);
}
diff --git a/source/de/anomic/crawler/retrieval/EventOrigin.java b/source/de/anomic/crawler/retrieval/EventOrigin.java
deleted file mode 100644
index 265eaee0a..000000000
--- a/source/de/anomic/crawler/retrieval/EventOrigin.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package de.anomic.crawler.retrieval;
-
-
-public enum EventOrigin {
-
- // we must distinguish the following cases: resource-load was initiated by
- // 1) global crawling: the index is extern, not here (not possible here)
- // 2) result of search queries, some indexes are here (not possible here)
- // 3) result of index transfer, some of them are here (not possible here)
- // 4) proxy-load (initiator is "------------")
- // 5) local prefetch/crawling (initiator is own seedHash)
- // 6) local fetching for global crawling (other known or unknown initiator)
-
- UNKNOWN(0),
- REMOTE_RECEIPTS(1),
- QUERIES(2),
- DHT_TRANSFER(3),
- PROXY_LOAD(4),
- LOCAL_CRAWLING(5),
- GLOBAL_CRAWLING(6),
- SURROGATES(7);
-
- protected int code;
- private static final EventOrigin[] list = {
- UNKNOWN, REMOTE_RECEIPTS, QUERIES, DHT_TRANSFER, PROXY_LOAD, LOCAL_CRAWLING, GLOBAL_CRAWLING, SURROGATES};
- private EventOrigin(int code) {
- this.code = code;
- }
- public int getCode() {
- return this.code;
- }
- public static final EventOrigin getEvent(int key) {
- return list[key];
- }
-}
diff --git a/source/de/anomic/crawler/retrieval/FTPLoader.java b/source/de/anomic/crawler/retrieval/FTPLoader.java
index 740172f30..807b48ff0 100644
--- a/source/de/anomic/crawler/retrieval/FTPLoader.java
+++ b/source/de/anomic/crawler/retrieval/FTPLoader.java
@@ -31,7 +31,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;
-import java.util.Map;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.HeaderFramework;
@@ -127,13 +126,13 @@ public class FTPLoader {
ResponseHeader responseHeader = new ResponseHeader();
responseHeader.put(HeaderFramework.LAST_MODIFIED, HeaderFramework.formatRFC1123(new Date()));
responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/html");
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
dirList.toString().getBytes());
}
} else {
@@ -246,13 +245,13 @@ public class FTPLoader {
// create response with metadata only
responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/plain");
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
null);
return response;
}
@@ -261,13 +260,13 @@ public class FTPLoader {
byte[] b = ftpClient.get(path);
// create a response
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
b);
return response;
}
diff --git a/source/de/anomic/crawler/retrieval/FileLoader.java b/source/de/anomic/crawler/retrieval/FileLoader.java
index e7eb2caba..2bf835774 100644
--- a/source/de/anomic/crawler/retrieval/FileLoader.java
+++ b/source/de/anomic/crawler/retrieval/FileLoader.java
@@ -25,7 +25,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
@@ -86,13 +85,13 @@ public class FileLoader {
ResponseHeader responseHeader = new ResponseHeader();
responseHeader.put(HeaderFramework.LAST_MODIFIED, HeaderFramework.formatRFC1123(new Date()));
responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/html");
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
content.toString().getBytes());
return response;
@@ -126,13 +125,13 @@ public class FileLoader {
// create response with metadata only
responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/plain");
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
url.toTokens().getBytes());
return response;
}
@@ -143,13 +142,13 @@ public class FileLoader {
is.close();
// create response with loaded content
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
b);
return response;
}
diff --git a/source/de/anomic/crawler/retrieval/HTTPLoader.java b/source/de/anomic/crawler/retrieval/HTTPLoader.java
index 36c784b4b..550b4c443 100644
--- a/source/de/anomic/crawler/retrieval/HTTPLoader.java
+++ b/source/de/anomic/crawler/retrieval/HTTPLoader.java
@@ -26,7 +26,6 @@ package de.anomic.crawler.retrieval;
import java.io.IOException;
import java.util.Date;
-import java.util.Map;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.HeaderFramework;
@@ -188,13 +187,13 @@ public final class HTTPLoader {
}
// create a new cache entry
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
response = new Response(
request,
requestHeader,
header,
Integer.toString(code),
- mp == null ? null : new CrawlProfile(mp),
+ profile,
responseBody
);
diff --git a/source/de/anomic/crawler/retrieval/Response.java b/source/de/anomic/crawler/retrieval/Response.java
index f634727e2..7d3502bec 100755
--- a/source/de/anomic/crawler/retrieval/Response.java
+++ b/source/de/anomic/crawler/retrieval/Response.java
@@ -39,6 +39,7 @@ import net.yacy.document.Parser;
import net.yacy.document.TextParser;
import net.yacy.kelondro.data.meta.DigestURI;
import de.anomic.crawler.CrawlProfile;
+import de.anomic.crawler.ResultURLs.EventOrigin;
public class Response {
diff --git a/source/de/anomic/crawler/retrieval/SMBLoader.java b/source/de/anomic/crawler/retrieval/SMBLoader.java
index 9789636db..2f46d5a3c 100644
--- a/source/de/anomic/crawler/retrieval/SMBLoader.java
+++ b/source/de/anomic/crawler/retrieval/SMBLoader.java
@@ -34,7 +34,6 @@ import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
@@ -110,13 +109,13 @@ public class SMBLoader {
ResponseHeader responseHeader = new ResponseHeader();
responseHeader.put(HeaderFramework.LAST_MODIFIED, HeaderFramework.formatRFC1123(new Date()));
responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/html");
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
content.toString().getBytes());
return response;
@@ -150,13 +149,13 @@ public class SMBLoader {
// create response with metadata only
responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/plain");
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
url.toTokens().getBytes());
return response;
}
@@ -167,13 +166,13 @@ public class SMBLoader {
is.close();
// create response with loaded content
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
Response response = new Response(
request,
requestHeader,
responseHeader,
"200",
- mp == null ? null : new CrawlProfile(mp),
+ profile,
b);
return response;
}
diff --git a/source/de/anomic/data/DidYouMean.java b/source/de/anomic/data/DidYouMean.java
index 5c9ea8918..c51b8b0d9 100644
--- a/source/de/anomic/data/DidYouMean.java
+++ b/source/de/anomic/data/DidYouMean.java
@@ -9,6 +9,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import net.yacy.cora.storage.DynamicScore;
import net.yacy.cora.storage.ScoreCluster;
+import net.yacy.document.LibraryProvider;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.logging.Log;
diff --git a/source/de/anomic/data/YMarkTables.java b/source/de/anomic/data/YMarkTables.java
index 5aa7345a5..c9a889668 100644
--- a/source/de/anomic/data/YMarkTables.java
+++ b/source/de/anomic/data/YMarkTables.java
@@ -1,6 +1,7 @@
package de.anomic.data;
import java.io.IOException;
+import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.text.ParseException;
@@ -19,6 +20,8 @@ import java.util.TreeMap;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
+import net.yacy.document.LibraryProvider;
+import net.yacy.document.WordTokenizer;
import net.yacy.kelondro.blob.Tables;
import net.yacy.kelondro.blob.Tables.Data;
import net.yacy.kelondro.data.meta.DigestURI;
@@ -464,7 +467,7 @@ public class YMarkTables {
buffer.append(document.dc_title());
buffer.append(document.dc_description());
buffer.append(document.dc_subject(' '));
- final Enumeration<String> tokens = Condenser.wordTokenizer(buffer.toString(), "UTF-8", LibraryProvider.dymLib);
+ final Enumeration<String> tokens = new WordTokenizer(new ByteArrayInputStream(buffer.toString().getBytes("UTF-8")), LibraryProvider.dymLib);
while(tokens.hasMoreElements()) {
int max = 1;
String token = tokens.nextElement();
diff --git a/source/de/anomic/search/AccessTracker.java b/source/de/anomic/search/AccessTracker.java
index 3d27b6728..f239dab06 100644
--- a/source/de/anomic/search/AccessTracker.java
+++ b/source/de/anomic/search/AccessTracker.java
@@ -31,8 +31,8 @@ import java.util.Iterator;
import java.util.LinkedList;
import net.yacy.cora.date.GenericFormatter;
+import net.yacy.document.LibraryProvider;
import net.yacy.kelondro.logging.Log;
-import de.anomic.data.LibraryProvider;
public class AccessTracker {
diff --git a/source/de/anomic/search/DocumentIndex.java b/source/de/anomic/search/DocumentIndex.java
index a1c16f1f9..0ece72015 100644
--- a/source/de/anomic/search/DocumentIndex.java
+++ b/source/de/anomic/search/DocumentIndex.java
@@ -35,10 +35,10 @@ import java.util.Date;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
-import de.anomic.data.LibraryProvider;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
+import net.yacy.document.LibraryProvider;
import net.yacy.document.TextParser;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
diff --git a/source/de/anomic/search/MediaSnippet.java b/source/de/anomic/search/MediaSnippet.java
index 0af028c7b..cefc731f1 100644
--- a/source/de/anomic/search/MediaSnippet.java
+++ b/source/de/anomic/search/MediaSnippet.java
@@ -38,9 +38,9 @@ import de.anomic.crawler.CrawlProfile;
import de.anomic.data.MimeTable;
import net.yacy.cora.document.MultiProtocolURI;
-import net.yacy.document.Condenser;
import net.yacy.document.Document;
import net.yacy.document.Parser;
+import net.yacy.document.WordTokenizer;
import net.yacy.document.parser.html.ImageEntry;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.index.HandleSet;
@@ -210,7 +210,7 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaS
private static HandleSet removeAppearanceHashes(final String sentence, final HandleSet queryhashes) {
// remove all hashes that appear in the sentence
if (sentence == null) return queryhashes;
- final SortedMap<byte[], Integer> hs = Condenser.hashSentence(sentence, null);
+ final SortedMap<byte[], Integer> hs = WordTokenizer.hashSentence(sentence, null);
final Iterator<byte[]> j = queryhashes.iterator();
byte[] hash;
Integer pos;
diff --git a/source/de/anomic/search/SearchEvent.java b/source/de/anomic/search/SearchEvent.java
index ea975d5ea..804972835 100644
--- a/source/de/anomic/search/SearchEvent.java
+++ b/source/de/anomic/search/SearchEvent.java
@@ -46,7 +46,6 @@ import net.yacy.kelondro.util.MemoryControl;
import net.yacy.kelondro.util.SetTools;
import net.yacy.repository.LoaderDispatcher;
-import de.anomic.crawler.ResultURLs;
import de.anomic.data.WorkTables;
import de.anomic.yacy.yacySearch;
import de.anomic.yacy.yacySeedDB;
@@ -75,7 +74,6 @@ public final class SearchEvent {
// class variables for remote searches
private yacySearch[] primarySearchThreads, secondarySearchThreads;
private final SortedMap<byte[], String> preselectedPeerHashes;
- private final ResultURLs crawlResults;
private final Thread localSearchThread;
private final SortedMap<byte[], Integer> IACount;
private final SortedMap<byte[], String> IAResults;
@@ -86,14 +84,12 @@ public final class SearchEvent {
public SearchEvent(final QueryParams query,
final yacySeedDB peers,
final WorkTables workTables,
- final ResultURLs crawlResults,
final SortedMap<byte[], String> preselectedPeerHashes,
final boolean generateAbstracts,
final LoaderDispatcher loader) {
this.eventTime = System.currentTimeMillis(); // for lifetime check
this.peers = peers;
this.workTables = workTables;
- this.crawlResults = crawlResults;
this.query = query;
this.secondarySearchSuperviser = (query.queryHashes.size() > 1) ? new SecondarySearchSuperviser() : null; // generate abstracts only for combined searches
if (this.secondarySearchSuperviser != null) this.secondarySearchSuperviser.start();
@@ -135,7 +131,6 @@ public final class SearchEvent {
query.maxDistance,
query.getSegment(),
peers,
- crawlResults,
rankingProcess,
secondarySearchSuperviser,
fetchpeers,
@@ -520,7 +515,7 @@ public final class SearchEvent {
rankingProcess.moreFeeders(1);
checkedPeers.add(peer);
secondarySearchThreads[c++] = yacySearch.secondaryRemoteSearch(
- words, urls, query.getSegment(), peers, crawlResults, rankingProcess, peer, Switchboard.urlBlacklist,
+ words, urls, query.getSegment(), peers, rankingProcess, peer, Switchboard.urlBlacklist,
query.ranking, query.constraint, preselectedPeerHashes);
}
diff --git a/source/de/anomic/search/SearchEventCache.java b/source/de/anomic/search/SearchEventCache.java
index f3edcd331..b821cea74 100644
--- a/source/de/anomic/search/SearchEventCache.java
+++ b/source/de/anomic/search/SearchEventCache.java
@@ -37,7 +37,6 @@ import java.util.concurrent.ConcurrentHashMap;
import net.yacy.kelondro.util.MemoryControl;
import net.yacy.repository.LoaderDispatcher;
-import de.anomic.crawler.ResultURLs;
import de.anomic.data.WorkTables;
import de.anomic.yacy.yacySeedDB;
@@ -103,7 +102,6 @@ public class SearchEventCache {
final QueryParams query,
final yacySeedDB peers,
final WorkTables workTables,
- final ResultURLs crawlResults,
final SortedMap<byte[], String> preselectedPeerHashes,
final boolean generateAbstracts,
final LoaderDispatcher loader) {
@@ -128,7 +126,7 @@ public class SearchEventCache {
}
if (event == null) {
// start a new event
- event = new SearchEvent(query, peers, workTables, crawlResults, preselectedPeerHashes, generateAbstracts, loader);
+ event = new SearchEvent(query, peers, workTables, preselectedPeerHashes, generateAbstracts, loader);
}
return event;
diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java
index f0743eede..ce74e58ab 100644
--- a/source/de/anomic/search/Switchboard.java
+++ b/source/de/anomic/search/Switchboard.java
@@ -89,6 +89,7 @@ import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.cora.protocol.http.ProxySettings;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
+import net.yacy.document.LibraryProvider;
import net.yacy.document.Parser;
import net.yacy.document.TextParser;
import net.yacy.document.content.DCEntry;
@@ -129,10 +130,9 @@ import de.anomic.crawler.ResultImages;
import de.anomic.crawler.ResultURLs;
import de.anomic.crawler.RobotsTxt;
import de.anomic.crawler.CrawlProfile.CacheStrategy;
-import de.anomic.crawler.retrieval.EventOrigin;
+import de.anomic.crawler.ResultURLs.EventOrigin;
import de.anomic.crawler.retrieval.Request;
import de.anomic.crawler.retrieval.Response;
-import de.anomic.data.LibraryProvider;
import de.anomic.data.WorkTables;
import de.anomic.data.URLLicense;
import de.anomic.data.BlogBoard;
@@ -200,7 +200,6 @@ public final class Switchboard extends serverSwitch {
public LoaderDispatcher loader;
public CrawlSwitchboard crawler;
public CrawlQueues crawlQueues;
- public ResultURLs crawlResults;
public CrawlStacker crawlStacker;
public MessageBoard messageDB;
public WikiBoard wikiDB;
@@ -255,6 +254,9 @@ public final class Switchboard extends serverSwitch {
// set loglevel and log
setLog(new Log("PLASMA"));
+ // set default peer name
+ yacySeed.ANON_PREFIX = getConfig("peernameprefix", "_anon");
+
// UPnP port mapping
if (getConfigBool(SwitchboardConstants.UPNP_ENABLED, false))
InstantBusyThread.oneTimeJob(UPnP.class, "addPortMapping", UPnP.log, 0);
@@ -356,10 +358,6 @@ public final class Switchboard extends serverSwitch {
log,
this.queuesRoot);
-
- // init crawl results monitor cache
- crawlResults = new ResultURLs(100);
-
// start yacy core
log.logConfig("Starting YaCy Protocol Core");
this.yc = new yacyCore(this);
@@ -839,7 +837,7 @@ public final class Switchboard extends serverSwitch {
this.queuesRoot.mkdirs();
// clear statistic data
- this.crawlResults.clearStacks();
+ ResultURLs.clearStacks();
// remove heuristics
setConfig("heuristic.site", false);
@@ -1053,7 +1051,7 @@ public final class Switchboard extends serverSwitch {
public void urlRemove(final Segment segment, final byte[] hash) {
segment.urlMetadata().remove(hash);
- crawlResults.remove(new String(hash));
+ ResultURLs.remove(new String(hash));
crawlQueues.urlRemove(hash);
}
@@ -1425,7 +1423,7 @@ public final class Switchboard extends serverSwitch {
if ((crawlQueues.delegatedURL.stackSize() > 1000)) c++;
if ((crawlQueues.errorURL.stackSize() > 1000)) c++;
for (EventOrigin origin: EventOrigin.values()) {
- if (crawlResults.getStackSize(origin) > 1000) c++;
+ if (ResultURLs.getStackSize(origin) > 1000) c++;
}
return c;
}
@@ -1448,11 +1446,11 @@ public final class Switchboard extends serverSwitch {
// refresh recrawl dates
try{
CrawlProfile selentry;
- for (byte[] handle: crawler.profilesActiveCrawls.keySet()) {
- selentry = new CrawlProfile(crawler.profilesActiveCrawls.get(handle));
+ for (byte[] handle: crawler.getActive()) {
+ selentry = crawler.getActive(handle);
assert selentry.handle() != null : "profile.name = " + selentry.name();
if (selentry.handle() == null) {
- crawler.profilesActiveCrawls.remove(handle);
+ crawler.removeActive(handle);
continue;
}
boolean insert = false;
@@ -1487,7 +1485,7 @@ public final class Switchboard extends serverSwitch {
Long.toString(CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_SURROGATE_RECRAWL_CYCLE)));
insert = true;
}
- if (insert) crawler.profilesActiveCrawls.put(selentry.handle().getBytes(), selentry);
+ if (insert) crawler.putActive(selentry.handle().getBytes(), selentry);
}
} catch (final Exception e) {
Log.logException(e);
@@ -1547,9 +1545,9 @@ public final class Switchboard extends serverSwitch {
// clean up loadedURL stack
for (EventOrigin origin: EventOrigin.values()) {
checkInterruption();
- if (crawlResults.getStackSize(origin) > 1000) {
- if (this.log.isFine()) log.logFine("Cleaning Loaded-URLs report stack, " + crawlResults.getStackSize(origin) + " entries on stack " + origin.getCode());
- crawlResults.clearStack(origin);
+ if (ResultURLs.getStackSize(origin) > 1000) {
+ if (this.log.isFine()) log.logFine("Cleaning Loaded-URLs report stack, " + ResultURLs.getStackSize(origin) + " entries on stack " + origin.getCode());
+ ResultURLs.clearStack(origin);
}
}
@@ -1935,7 +1933,7 @@ public final class Switchboard extends serverSwitch {
}
// update url result list statistics
- crawlResults.stack(
+ ResultURLs.stack(
newEntry, // loaded url db entry
queueEntry.initiator(), // initiator peer hash
this.peers.mySeed().hash.getBytes(), // executor peer hash
@@ -2003,8 +2001,8 @@ public final class Switchboard extends serverSwitch {
if (searchEvent != null) searchEvent.addHeuristic(url.hash(), heuristicName, true);
if (indexSegments.segment(process).urlMetadata.exists(url.hash())) return; // don't do double-work
final Request request = loader.request(url, true, true);
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
- String acceptedError = this.crawlStacker.checkAcceptance(url, mp == null ? null : new CrawlProfile(mp), 0);
+ final CrawlProfile profile = sb.crawler.getActive(request.profileHandle().getBytes());
+ String acceptedError = this.crawlStacker.checkAcceptance(url, profile, 0);
if (acceptedError != null) {
log.logWarning("addToIndex: cannot load " + url.toNormalform(false, false) + ": " + acceptedError);
return;
diff --git a/source/de/anomic/search/TextSnippet.java b/source/de/anomic/search/TextSnippet.java
index 51b5360c7..f95d916e5 100644
--- a/source/de/anomic/search/TextSnippet.java
+++ b/source/de/anomic/search/TextSnippet.java
@@ -34,10 +34,10 @@ import java.util.regex.Pattern;
import net.yacy.cora.storage.ARC;
import net.yacy.cora.storage.ConcurrentARC;
-import net.yacy.document.Condenser;
import net.yacy.document.Document;
import net.yacy.document.Parser;
import net.yacy.document.SnippetExtractor;
+import net.yacy.document.WordTokenizer;
import net.yacy.document.parser.html.CharacterCoding;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
@@ -426,7 +426,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
}
private static boolean containsAllHashes(final String sentence, final HandleSet queryhashes) {
- final SortedMap<byte[], Integer> m = Condenser.hashSentence(sentence, null);
+ final SortedMap<byte[], Integer> m = WordTokenizer.hashSentence(sentence, null);
for (final byte[] b: queryhashes) {
if (!(m.containsKey(b))) return false;
}
diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.java
index 514fe533e..0c2e09395 100644
--- a/source/de/anomic/yacy/yacyClient.java
+++ b/source/de/anomic/yacy/yacyClient.java
@@ -81,7 +81,7 @@ import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.StringBody;
import de.anomic.crawler.ResultURLs;
-import de.anomic.crawler.retrieval.EventOrigin;
+import de.anomic.crawler.ResultURLs.EventOrigin;
import de.anomic.search.ContentDomain;
import de.anomic.search.QueryParams;
import de.anomic.search.RankingProfile;
@@ -392,7 +392,6 @@ public final class yacyClient {
final int partitions,
final yacySeed target,
final Segment indexSegment,
- final ResultURLs crawlResults,
final RankingProcess containerCache,
final SearchEvent.SecondarySearchSuperviser secondarySearchSuperviser,
final Blacklist blacklist,
@@ -478,7 +477,7 @@ public final class yacyClient {
// passed all checks, store url
try {
indexSegment.urlMetadata().store(urlEntry);
- crawlResults.stack(urlEntry, mySeed.hash.getBytes(), target.hash.getBytes(), EventOrigin.QUERIES);
+ ResultURLs.stack(urlEntry, mySeed.hash.getBytes(), target.hash.getBytes(), EventOrigin.QUERIES);
} catch (final IOException e) {
yacyCore.log.logSevere("could not store search result", e);
continue; // db-error
diff --git a/source/de/anomic/yacy/yacySearch.java b/source/de/anomic/yacy/yacySearch.java
index 557882f2b..9704677af 100644
--- a/source/de/anomic/yacy/yacySearch.java
+++ b/source/de/anomic/yacy/yacySearch.java
@@ -39,7 +39,6 @@ import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.repository.Blacklist;
-import de.anomic.crawler.ResultURLs;
import de.anomic.search.QueryParams;
import de.anomic.search.RankingProfile;
import de.anomic.search.RankingProcess;
@@ -67,8 +66,6 @@ public class yacySearch extends Thread {
final private Bitfield constraint;
final private yacySeedDB peers;
- ResultURLs crawlResults;
-
public yacySearch(
final String wordhashes, final String excludehashes,
final String urlhashes,
@@ -80,7 +77,6 @@ public class yacySearch extends Thread {
final yacySeed targetPeer,
final Segment indexSegment,
final yacySeedDB peers,
- final ResultURLs crawlResults,
final RankingProcess containerCache,
final SearchEvent.SecondarySearchSuperviser secondarySearchSuperviser,
final Blacklist blacklist,
@@ -101,7 +97,6 @@ public class yacySearch extends Thread {
this.partitions = partitions;
this.indexSegment = indexSegment;
this.peers = peers;
- this.crawlResults = crawlResults;
this.containerCache = containerCache;
this.secondarySearchSuperviser = secondarySearchSuperviser;
this.blacklist = blacklist;
@@ -121,7 +116,7 @@ public class yacySearch extends Thread {
wordhashes, excludehashes, urlhashes, prefer, filter, language,
sitehash, authorhash,
count, maxDistance, global, partitions,
- targetPeer, indexSegment, crawlResults, containerCache, secondarySearchSuperviser,
+ targetPeer, indexSegment, containerCache, secondarySearchSuperviser,
blacklist, rankingProfile, constraint);
if (urls >= 0) {
// urls is an array of url hashes. this is only used for log output
@@ -262,7 +257,6 @@ public class yacySearch extends Thread {
final int count, final int maxDist,
final Segment indexSegment,
final yacySeedDB peers,
- final ResultURLs crawlResults,
final RankingProcess containerCache,
final SearchEvent.SecondarySearchSuperviser secondarySearchSuperviser,
int targets,
@@ -295,7 +289,7 @@ public class yacySearch extends Thread {
wordhashes, excludehashes, "", prefer, filter, language,
sitehash, authorhash,
count, maxDist, true, targets, targetPeers[i],
- indexSegment, peers, crawlResults, containerCache, secondarySearchSuperviser, blacklist, rankingProfile, constraint);
+ indexSegment, peers, containerCache, secondarySearchSuperviser, blacklist, rankingProfile, constraint);
searchThreads[i].start();
} catch (OutOfMemoryError e) {
break;
@@ -308,7 +302,6 @@ public class yacySearch extends Thread {
final String wordhashes, final String urlhashes,
final Segment indexSegment,
final yacySeedDB peers,
- final ResultURLs crawlResults,
final RankingProcess containerCache,
final String targethash, final Blacklist blacklist,
final RankingProfile rankingProfile,
@@ -326,7 +319,7 @@ public class yacySearch extends Thread {
if (clusterselection != null) targetPeer.setAlternativeAddress(clusterselection.get(targetPeer.hash.getBytes()));
final yacySearch searchThread = new yacySearch(
wordhashes, "", urlhashes, Pattern.compile(""), Pattern.compile(".*"), "", "", "", 0, 9999, true, 0, targetPeer,
- indexSegment, peers, crawlResults, containerCache, null, blacklist, rankingProfile, constraint);
+ indexSegment, peers, containerCache, null, blacklist, rankingProfile, constraint);
searchThread.start();
return searchThread;
}
diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java
index 33c6d5a49..772469525 100644
--- a/source/de/anomic/yacy/yacySeed.java
+++ b/source/de/anomic/yacy/yacySeed.java
@@ -73,6 +73,8 @@ import de.anomic.yacy.dht.FlatWordPartitionScheme;
public class yacySeed implements Cloneable {
+ public static String ANON_PREFIX = "_anon";
+
public static final int maxsize = 16000;
/**
* <b>substance</b> "sI" (send index/words)
@@ -245,7 +247,7 @@ public class yacySeed implements Cloneable {
* @return
*/
private static String defaultPeerName() {
- return "_anon" + OS.infoKey() + "-" + (System.currentTimeMillis() % 77777777L) + "-" + yacyCore.speedKey;
+ return ANON_PREFIX + OS.infoKey() + "-" + (System.currentTimeMillis() % 77777777L) + "-" + yacyCore.speedKey;
}
/**
diff --git a/source/net/yacy/document/Condenser.java b/source/net/yacy/document/Condenser.java
index f6003bbad..38eaf1254 100644
--- a/source/net/yacy/document/Condenser.java
+++ b/source/net/yacy/document/Condenser.java
@@ -20,41 +20,31 @@
package net.yacy.document;
-import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
-import java.util.SortedMap;
import java.util.TreeMap;
-import de.anomic.data.DidYouMeanLibrary;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.document.language.Identificator;
-import net.yacy.document.parser.html.ContentScraper;
import net.yacy.document.parser.html.ImageEntry;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.data.word.WordReferenceRow;
import net.yacy.kelondro.logging.Log;
-import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.util.SetTools;
@@ -114,7 +104,7 @@ public final class Condenser {
final Document document,
final boolean indexText,
final boolean indexMedia,
- final DidYouMeanLibrary meaningLib
+ final WordCache meaningLib
) throws UnsupportedEncodingException {
// if addMedia == true, then all the media links are also parsed and added to the words
// added media words are flagged with the appropriate media flag
@@ -238,13 +228,13 @@ public final class Condenser {
final int flagpos,
final Bitfield flagstemplate,
final boolean useForLanguageIdentification,
- final DidYouMeanLibrary meaningLib) {
+ final WordCache meaningLib) {
if (text == null) return;
String word;
Word wprop;
- sievedWordsEnum wordenum;
+ WordTokenizer wordenum;
try {
- wordenum = new sievedWordsEnum(new ByteArrayInputStream(text.getBytes("UTF-8")), meaningLib);
+ wordenum = new WordTokenizer(new ByteArrayInputStream(text.getBytes("UTF-8")), meaningLib);
} catch (final UnsupportedEncodingException e) {
return;
}
@@ -264,7 +254,7 @@ public final class Condenser {
}
}
- public Condenser(final InputStream text, final DidYouMeanLibrary meaningLib) throws UnsupportedEncodingException {
+ public Condenser(final InputStream text, final WordCache meaningLib) throws UnsupportedEncodingException {
this.languageIdentificator = null; // we don't need that here
// analysis = new Properties();
words = new TreeMap<String, Word>();
@@ -288,7 +278,7 @@ public final class Condenser {
return this.languageIdentificator.getLanguage();
}
- private void createCondensement(final InputStream is, final DidYouMeanLibrary meaningLib) throws UnsupportedEncodingException {
+ private void createCondensement(final InputStream is, final WordCache meaningLib) throws UnsupportedEncodingException {
assert is != null;
final Set<String> currsentwords = new HashSet<String>();
StringBuilder sentence = new StringBuilder(100);
@@ -308,7 +298,7 @@ public final class Condenser {
final Map<StringBuilder, Phrase> sentences = new HashMap<StringBuilder, Phrase>(100);
// read source
- final sievedWordsEnum wordenum = new sievedWordsEnum(is, meaningLib);
+ final WordTokenizer wordenum = new WordTokenizer(is, meaningLib);
while (wordenum.hasMoreElements()) {
word = (wordenum.nextElement().toString()).toLowerCase(Locale.ENGLISH); // TODO: does toLowerCase work for non ISO-8859-1 chars?
if (languageIdentificator != null) languageIdentificator.add(word);
@@ -317,7 +307,7 @@ public final class Condenser {
// distinguish punctuation and words
wordlen = word.length();
Iterator<String> it;
- if ((wordlen == 1) && (ContentScraper.punctuation(word.charAt(0)))) {
+ if ((wordlen == 1) && (SentenceReader.punctuation(word.charAt(0)))) {
// store sentence
if (sentence.length() > 0) {
// we store the punctuation symbol as first element of the sentence vector
@@ -461,285 +451,8 @@ public final class Condenser {
this.RESULT_NUMB_SENTENCES = allsentencecounter;
this.RESULT_DIFF_SENTENCES = sentenceHandleCount;
}
-
- public final static boolean invisible(final char c) {
- final int type = Character.getType(c);
- return !(type == Character.LOWERCASE_LETTER
- || type == Character.DECIMAL_DIGIT_NUMBER
- || type == Character.UPPERCASE_LETTER
- || type == Character.MODIFIER_LETTER
- || type == Character.OTHER_LETTER
- || type == Character.TITLECASE_LETTER
- || ContentScraper.punctuation(c));
- }
-
- /**
- * tokenize the given sentence and generate a word-wordPos mapping
- * @param sentence the sentence to be tokenized
- * @return a ordered map containing word hashes as key and positions as value. The map is orderd by the hash ordering
- */
- public static SortedMap<byte[], Integer> hashSentence(final String sentence, final DidYouMeanLibrary meaningLib) {
- final SortedMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Base64Order.enhancedCoder);
- final Enumeration<String> words = wordTokenizer(sentence, "UTF-8", meaningLib);
- int pos = 0;
- String word;
- byte[] hash;
- Integer oldpos;
- while (words.hasMoreElements()) {
- word = words.nextElement();
- hash = Word.word2hash(word.toString());
-
- // don't overwrite old values, that leads to too far word distances
- oldpos = map.put(hash, LargeNumberCache.valueOf(pos));
- if (oldpos != null) {
- map.put(hash, oldpos);
- }
-
- pos += word.length() + 1;
- }
- return map;
- }
-
- public static Enumeration<String> wordTokenizer(final String s, final String charset, final DidYouMeanLibrary meaningLib) {
- try {
- return new sievedWordsEnum(new ByteArrayInputStream(s.getBytes(charset)), meaningLib);
- } catch (final Exception e) {
- return null;
- }
- }
-
- public static class sievedWordsEnum implements Enumeration<String> {
- // this enumeration removes all words that contain either wrong characters or are too short
-
- private StringBuilder buffer = null;
- private unsievedWordsEnum e;
- private DidYouMeanLibrary meaningLib;
-
- public sievedWordsEnum(final InputStream is, final DidYouMeanLibrary meaningLib) throws UnsupportedEncodingException {
- assert is != null;
- this.e = new unsievedWordsEnum(is);
- this.buffer = nextElement0();
- this.meaningLib = meaningLib;
- }
-
- public void pre(final boolean x) {
- e.pre(x);
- }
-
- private StringBuilder nextElement0() {
- StringBuilder s;
- loop: while (e.hasMoreElements()) {
- s = e.nextElement();
- if ((s.length() == 1) && (ContentScraper.punctuation(s.charAt(0)))) return s;
- for (int i = 0; i < s.length(); i++) {
- if (invisible(s.charAt(i))) continue loop;
- }
- return s;
- }
- return null;
- }
-
- public boolean hasMoreElements() {
- return buffer != null;
- }
-
- public String nextElement() {
- final String r = (buffer == null) ? null : buffer.toString();
- buffer = nextElement0();
- // put word to words statistics cache
- if (meaningLib != null) meaningLib.learn(r);
- return r;
- }
-
- }
-
- private static class unsievedWordsEnum implements Enumeration<StringBuilder> {
- // returns an enumeration of StringBuilder Objects
- private StringBuilder buffer = null;
- private sentencesFromInputStreamEnum e;
- private List<StringBuilder> s;
- private int sIndex;
-
- public unsievedWordsEnum(final InputStream is) throws UnsupportedEncodingException {
- assert is != null;
- e = new sentencesFromInputStreamEnum(is);
- s = new ArrayList<StringBuilder>();
- sIndex = 0;
- buffer = nextElement0();
- }
-
- public void pre(final boolean x) {
- e.pre(x);
- }
-
- private StringBuilder nextElement0() {
- StringBuilder r;
- StringBuilder sb;
- char c;
- if (sIndex >= s.size()) {
- sIndex = 0;
- s.clear();
- }
- while (s.isEmpty()) {
- if (!e.hasNext()) return null;
- r = e.next();
- if (r == null) return null;
- r = trim(r);
- sb = new StringBuilder(20);
- for (int i = 0; i < r.length(); i++) {
- c = r.charAt(i);
- if (invisible(c)) {
- if (sb.length() > 0) {s.add(sb); sb = new StringBuilder(20);}
- } else if (ContentScraper.punctuation(c)) {
- if (sb.length() > 0) {s.add(sb); sb = new StringBuilder(1);}
- sb.append(c);
- s.add(sb);
- sb = new StringBuilder(20);
- } else {
- sb = sb.append(c);
- }
- }
- if (sb.length() > 0) {
- s.add(sb);
- sb = null;
- }
- }
- r = s.get(sIndex++);
- return r;
- }
-
- public boolean hasMoreElements() {
- return buffer != null;
- }
-
- public StringBuilder nextElement() {
- final StringBuilder r = buffer;
- buffer = nextElement0();
- return r;
- }
-
- }
-
- static StringBuilder trim(StringBuilder sb) {
- int i = 0;
- while (i < sb.length() && sb.charAt(i) <= ' ') {
- i++;
- }
- if (i > 0) {
- sb.delete(0, i);
- }
- i = sb.length() - 1;
- while (i >= 0 && i < sb.length() && sb.charAt(i) <= ' ') {
- i--;
- }
- if (i > 0) {
- sb.delete(i + 1, sb.length());
- }
- return sb;
- }
- public static sentencesFromInputStreamEnum sentencesFromInputStream(final InputStream is) {
- assert is != null;
- try {
- return new sentencesFromInputStreamEnum(is);
- } catch (final UnsupportedEncodingException e) {
- return null;
- }
- }
-
- public static class sentencesFromInputStreamEnum implements Iterator<StringBuilder> {
- // read sentences from a given input stream
- // this enumerates StringBuilder objects
-
- private StringBuilder buffer;
- private BufferedReader raf;
- private int counter = 0;
- private boolean pre = false;
-
- public sentencesFromInputStreamEnum(final InputStream is) throws UnsupportedEncodingException {
- assert is != null;
- raf = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- buffer = nextElement0();
- counter = 0;
- pre = false;
- }
-
- public void pre(final boolean x) {
- this.pre = x;
- }
-
- private StringBuilder nextElement0() {
- try {
- final StringBuilder s = readSentence(raf, pre);
- //System.out.println(" SENTENCE='" + s + "'"); // DEBUG
- if (s == null) {
- raf.close();
- return null;
- }
- return s;
- } catch (final IOException e) {
- try {
- raf.close();
- } catch (final Exception ee) {
- }
- return null;
- }
- }
-
- public boolean hasNext() {
- return buffer != null;
- }
-
- public StringBuilder next() {
- if (buffer == null) {
- return null;
- }
- counter = counter + buffer.length() + 1;
- final StringBuilder r = buffer;
- buffer = nextElement0();
- return r;
- }
-
- public int count() {
- return counter;
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- static StringBuilder readSentence(final Reader reader, final boolean pre) throws IOException {
- final StringBuilder s = new StringBuilder(80);
- int nextChar;
- char c, lc = ' '; // starting with ' ' as last character prevents that the result string starts with a ' '
-
- // find sentence end
- while (true) {
- nextChar = reader.read();
- //System.out.print((char) nextChar); // DEBUG
- if (nextChar < 0) {
- if (s.length() == 0) return null;
- break;
- }
- c = (char) nextChar;
- if (pre && ((c == (char) 10) || (c == (char) 13))) break;
- if (c < ' ') c = ' ';
- if ((lc == ' ') && (c == ' ')) continue; // ignore double spaces
- s.append(c);
- if (ContentScraper.punctuation(lc) && invisible(c)) break;
- lc = c;
- }
-
- if (s.length() == 0) return s;
- if (s.charAt(s.length() - 1) == ' ') {
- s.trimToSize();
- s.deleteCharAt(s.length() - 1);
- }
- return s;
- }
-
- public static Map<String, Word> getWords(final String text, final DidYouMeanLibrary meaningLib) {
+ public static Map<String, Word> getWords(final String text, final WordCache meaningLib) {
// returns a word/indexWord relation map
if (text == null) return null;
ByteArrayInputStream buffer;
diff --git a/source/net/yacy/document/Document.java b/source/net/yacy/document/Document.java
index ecacf5bf5..2075c9ef0 100644
--- a/source/net/yacy/document/Document.java
+++ b/source/net/yacy/document/Document.java
@@ -296,7 +296,7 @@ dc_rights
public List<StringBuilder> getSentences(final boolean pre) {
if (this.text == null) return null;
- final Condenser.sentencesFromInputStreamEnum e = Condenser.sentencesFromInputStream(getText());
+ final SentenceReader e = new SentenceReader(getText());
e.pre(pre);
List<StringBuilder> sentences = new ArrayList<StringBuilder>();
while (e.hasNext()) {
diff --git a/source/de/anomic/data/LibraryProvider.java b/source/net/yacy/document/LibraryProvider.java
similarity index 95%
rename from source/de/anomic/data/LibraryProvider.java
rename to source/net/yacy/document/LibraryProvider.java
index 2a65a45cc..221ba0ba3 100644
--- a/source/de/anomic/data/LibraryProvider.java
+++ b/source/net/yacy/document/LibraryProvider.java
@@ -20,7 +20,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
-package de.anomic.data;
+package net.yacy.document;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -47,7 +47,7 @@ public class LibraryProvider {
public static final String disabledExtension = ".disabled";
- public static DidYouMeanLibrary dymLib = new DidYouMeanLibrary(null);
+ public static WordCache dymLib = new WordCache(null);
public static OverarchingLocalization geoLoc = new OverarchingLocalization();
private static File dictSource = null;
private static File dictRoot = null;
@@ -124,7 +124,7 @@ public class LibraryProvider {
public static void initDidYouMean() {
final File dymDict = new File(dictRoot, path_to_did_you_mean_dictionaries);
if (!dymDict.exists()) dymDict.mkdirs();
- dymLib = new DidYouMeanLibrary(dymDict);
+ dymLib = new WordCache(dymDict);
}
public static void integrateDeReWo() {
diff --git a/source/net/yacy/document/SentenceReader.java b/source/net/yacy/document/SentenceReader.java
new file mode 100644
index 000000000..f43adc407
--- /dev/null
+++ b/source/net/yacy/document/SentenceReader.java
@@ -0,0 +1,140 @@
+/**
+ * SentenceReader
+ * Copyright 2011 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
+ * first published 09.02.2011 on http://yacy.net
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program in the file lgpl21.txt
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.yacy.document;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+
+public class SentenceReader implements Iterator<StringBuilder> {
+ // read sentences from a given input stream
+ // this enumerates StringBuilder objects
+
+ private StringBuilder buffer;
+ private BufferedReader raf;
+ private int counter = 0;
+ private boolean pre = false;
+
+ public SentenceReader(final InputStream is) {
+ assert is != null;
+ try {
+ raf = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ buffer = nextElement0();
+ counter = 0;
+ pre = false;
+ }
+
+ public void pre(final boolean x) {
+ this.pre = x;
+ }
+
+ private StringBuilder nextElement0() {
+ try {
+ final StringBuilder s = readSentence(raf, pre);
+ //System.out.println(" SENTENCE='" + s + "'"); // DEBUG
+ if (s == null) {
+ raf.close();
+ return null;
+ }
+ return s;
+ } catch (final IOException e) {
+ try {
+ raf.close();
+ } catch (final Exception ee) {
+ }
+ return null;
+ }
+ }
+
+ private static StringBuilder readSentence(final Reader reader, final boolean pre) throws IOException {
+ final StringBuilder s = new StringBuilder(80);
+ int nextChar;
+ char c, lc = ' '; // starting with ' ' as last character prevents that the result string starts with a ' '
+
+ // find sentence end
+ while (true) {
+ nextChar = reader.read();
+ //System.out.print((char) nextChar); // DEBUG
+ if (nextChar < 0) {
+ if (s.length() == 0) return null;
+ break;
+ }
+ c = (char) nextChar;
+ if (pre && ((c == (char) 10) || (c == (char) 13))) break;
+ if (c < ' ') c = ' ';
+ if ((lc == ' ') && (c == ' ')) continue; // ignore double spaces
+ s.append(c);
+ if (punctuation(lc) && invisible(c)) break;
+ lc = c;
+ }
+
+ if (s.length() == 0) return s;
+ if (s.charAt(s.length() - 1) == ' ') {
+ s.trimToSize();
+ s.deleteCharAt(s.length() - 1);
+ }
+ return s;
+ }
+
+ public final static boolean invisible(final char c) {
+ final int type = Character.getType(c);
+ return !(type == Character.LOWERCASE_LETTER
+ || type == Character.DECIMAL_DIGIT_NUMBER
+ || type == Character.UPPERCASE_LETTER
+ || type == Character.MODIFIER_LETTER
+ || type == Character.OTHER_LETTER
+ || type == Character.TITLECASE_LETTER
+ || punctuation(c));
+ }
+
+ public final static boolean punctuation(final char c) {
+ return c == '.' || c == '!' || c == '?';
+ }
+
+ public boolean hasNext() {
+ return buffer != null;
+ }
+
+ public StringBuilder next() {
+ if (buffer == null) {
+ return null;
+ }
+ counter = counter + buffer.length() + 1;
+ final StringBuilder r = buffer;
+ buffer = nextElement0();
+ return r;
+ }
+
+ public int count() {
+ return counter;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/source/net/yacy/document/SnippetExtractor.java b/source/net/yacy/document/SnippetExtractor.java
index 2a45e0c57..03ab4cd99 100644
--- a/source/net/yacy/document/SnippetExtractor.java
+++ b/source/net/yacy/document/SnippetExtractor.java
@@ -47,7 +47,7 @@ public class SnippetExtractor {
int linenumber = 0;
int fullmatchcounter = 0;
lookup: for (StringBuilder sentence: sentences) {
- hs = Condenser.hashSentence(sentence.toString(), null);
+ hs = WordTokenizer.hashSentence(sentence.toString(), null);
positions = new TreeSet<Integer>();
for (byte[] word: queryhashes) {
pos = hs.get(word);
@@ -126,7 +126,7 @@ public class SnippetExtractor {
byte[] hash;
// find all hashes that appear in the sentence
- final Map<byte[], Integer> hs = Condenser.hashSentence(sentence, null);
+ final Map<byte[], Integer> hs = WordTokenizer.hashSentence(sentence, null);
final Iterator<byte[]> j = queryhashes.iterator();
Integer pos;
int p, minpos = sentence.length(), maxpos = -1;
diff --git a/source/de/anomic/data/DidYouMeanLibrary.java b/source/net/yacy/document/WordCache.java
similarity index 85%
rename from source/de/anomic/data/DidYouMeanLibrary.java
rename to source/net/yacy/document/WordCache.java
index e5befeeee..726eaf6f0 100644
--- a/source/de/anomic/data/DidYouMeanLibrary.java
+++ b/source/net/yacy/document/WordCache.java
@@ -1,30 +1,24 @@
-// DidYouMeanLibrary.java
-// (C) 2009 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
-// first published 01.10.2009 on http://yacy.net
-//
-// This is a part of YaCy
-//
-// $LastChangedDate$
-// $LastChangedRevision$
-// $LastChangedBy$
-//
-// LICENSE
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+/**
+ * WordCache
+ * Copyright 2009 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
+ * first published 01.10.2009 on http://yacy.net
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program in the file lgpl21.txt
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
-package de.anomic.data;
+package net.yacy.document;
import java.io.BufferedReader;
import java.io.File;
@@ -49,7 +43,7 @@ import net.yacy.kelondro.logging.Log;
* provide a completion library for the did-you-mean class
*
*/
-public class DidYouMeanLibrary {
+public class WordCache {
// common word cache
private static final int commonWordsMaxSize = 100000; // maximum size of common word cache
@@ -68,7 +62,7 @@ public class DidYouMeanLibrary {
* Comment lines may be given and are encoded as line starting with '#'
* @param dictionaryPath path to a directory with library files
*/
- public DidYouMeanLibrary(final File dictionaryPath) {
+ public WordCache(final File dictionaryPath) {
this.dictionaryPath = dictionaryPath;
reload();
}
diff --git a/source/net/yacy/document/WordTokenizer.java b/source/net/yacy/document/WordTokenizer.java
new file mode 100644
index 000000000..fcf75ba5d
--- /dev/null
+++ b/source/net/yacy/document/WordTokenizer.java
@@ -0,0 +1,195 @@
+/**
+ * WordTokenizer
+ * Copyright 2011 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
+ * first published 09.02.2011 on http://yacy.net
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program in the file lgpl21.txt
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.yacy.document;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import net.yacy.kelondro.data.word.Word;
+import net.yacy.kelondro.order.Base64Order;
+
+
+public class WordTokenizer implements Enumeration<String> {
+ // this enumeration removes all words that contain either wrong characters or are too short
+
+ private StringBuilder buffer = null;
+ private unsievedWordsEnum e;
+ private WordCache meaningLib;
+
+ public WordTokenizer(final InputStream is, final WordCache meaningLib) throws UnsupportedEncodingException {
+ assert is != null;
+ this.e = new unsievedWordsEnum(is);
+ this.buffer = nextElement0();
+ this.meaningLib = meaningLib;
+ }
+
+ public void pre(final boolean x) {
+ e.pre(x);
+ }
+
+ private StringBuilder nextElement0() {
+ StringBuilder s;
+ loop: while (e.hasMoreElements()) {
+ s = e.nextElement();
+ if ((s.length() == 1) && (SentenceReader.punctuation(s.charAt(0)))) return s;
+ for (int i = 0; i < s.length(); i++) {
+ if (SentenceReader.invisible(s.charAt(i))) continue loop;
+ }
+ return s;
+ }
+ return null;
+ }
+
+ public boolean hasMoreElements() {
+ return buffer != null;
+ }
+
+ public String nextElement() {
+ final String r = (buffer == null) ? null : buffer.toString();
+ buffer = nextElement0();
+ // put word to words statistics cache
+ if (meaningLib != null) meaningLib.learn(r);
+ return r;
+ }
+
+ private static class unsievedWordsEnum implements Enumeration<StringBuilder> {
+ // returns an enumeration of StringBuilder Objects
+ private StringBuilder buffer = null;
+ private SentenceReader e;
+ private List<StringBuilder> s;
+ private int sIndex;
+
+ public unsievedWordsEnum(final InputStream is) throws UnsupportedEncodingException {
+ assert is != null;
+ e = new SentenceReader(is);
+ s = new ArrayList<StringBuilder>();
+ sIndex = 0;
+ buffer = nextElement0();
+ }
+
+ public void pre(final boolean x) {
+ e.pre(x);
+ }
+
+ private StringBuilder nextElement0() {
+ StringBuilder r;
+ StringBuilder sb;
+ char c;
+ if (sIndex >= s.size()) {
+ sIndex = 0;
+ s.clear();
+ }
+ while (s.isEmpty()) {
+ if (!e.hasNext()) return null;
+ r = e.next();
+ if (r == null) return null;
+ r = trim(r);
+ sb = new StringBuilder(20);
+ for (int i = 0; i < r.length(); i++) {
+ c = r.charAt(i);
+ if (SentenceReader.invisible(c)) {
+ if (sb.length() > 0) {s.add(sb); sb = new StringBuilder(20);}
+ } else if (SentenceReader.punctuation(c)) {
+ if (sb.length() > 0) {s.add(sb); sb = new StringBuilder(1);}
+ sb.append(c);
+ s.add(sb);
+ sb = new StringBuilder(20);
+ } else {
+ sb = sb.append(c);
+ }
+ }
+ if (sb.length() > 0) {
+ s.add(sb);
+ sb = null;
+ }
+ }
+ r = s.get(sIndex++);
+ return r;
+ }
+
+ public boolean hasMoreElements() {
+ return buffer != null;
+ }
+
+ public StringBuilder nextElement() {
+ final StringBuilder r = buffer;
+ buffer = nextElement0();
+ return r;
+ }
+
+ }
+
+ public static StringBuilder trim(StringBuilder sb) {
+ int i = 0;
+ while (i < sb.length() && sb.charAt(i) <= ' ') {
+ i++;
+ }
+ if (i > 0) {
+ sb.delete(0, i);
+ }
+ i = sb.length() - 1;
+ while (i >= 0 && i < sb.length() && sb.charAt(i) <= ' ') {
+ i--;
+ }
+ if (i > 0) {
+ sb.delete(i + 1, sb.length());
+ }
+ return sb;
+ }
+
+ /**
+ * tokenize the given sentence and generate a word-wordPos mapping
+ * @param sentence the sentence to be tokenized
+ * @return a ordered map containing word hashes as key and positions as value. The map is orderd by the hash ordering
+ */
+ public static SortedMap<byte[], Integer> hashSentence(final String sentence, final WordCache meaningLib) {
+ final SortedMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Base64Order.enhancedCoder);
+ Enumeration<String> words = null;
+ try {
+ words = new WordTokenizer(new ByteArrayInputStream(sentence.getBytes("UTF-8")), meaningLib);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ int pos = 0;
+ String word;
+ byte[] hash;
+ Integer oldpos;
+ while (words.hasMoreElements()) {
+ word = words.nextElement();
+ hash = Word.word2hash(word.toString());
+
+ // don't overwrite old values, that leads to too far word distances
+ oldpos = map.put(hash, LargeNumberCache.valueOf(pos));
+ if (oldpos != null) {
+ map.put(hash, oldpos);
+ }
+
+ pos += word.length() + 1;
+ }
+ return map;
+ }
+}
diff --git a/source/net/yacy/document/parser/html/ContentScraper.java b/source/net/yacy/document/parser/html/ContentScraper.java
index 715d16552..cd895fed0 100644
--- a/source/net/yacy/document/parser/html/ContentScraper.java
+++ b/source/net/yacy/document/parser/html/ContentScraper.java
@@ -44,6 +44,7 @@ import java.util.Set;
import javax.swing.event.EventListenerList;
import net.yacy.cora.document.MultiProtocolURI;
+import net.yacy.document.SentenceReader;
import net.yacy.document.parser.htmlParser;
import net.yacy.kelondro.io.CharBuffer;
import net.yacy.kelondro.logging.Log;
@@ -115,10 +116,6 @@ public class ContentScraper extends AbstractScraper implements Scraper {
this.htmlFilterEventListeners = new EventListenerList();
}
- public final static boolean punctuation(final char c) {
- return c == '.' || c == '!' || c == '?';
- }
-
public void scrapeText(final char[] newtext, final String insideTag) {
// System.out.println("SCRAPE: " + new String(newtext));
String b = cleanLine(super.stripAll(newtext));
@@ -128,7 +125,7 @@ public class ContentScraper extends AbstractScraper implements Scraper {
// condenser to distinguish headlines from text beginnings.
// to make it easier for the condenser, a dot ('.') is appended in case that
// no punctuation is part of the newtext line
- if ((b.length() != 0) && (!(punctuation(b.charAt(b.length() - 1))))) b = b + '.';
+ if ((b.length() != 0) && (!(SentenceReader.punctuation(b.charAt(b.length() - 1))))) b = b + '.';
//System.out.println("*** Appended dot: " + b.toString());
}
// find http links inside text
diff --git a/source/net/yacy/document/parser/torrentParser.java b/source/net/yacy/document/parser/torrentParser.java
index ee3019567..a1f369d9b 100644
--- a/source/net/yacy/document/parser/torrentParser.java
+++ b/source/net/yacy/document/parser/torrentParser.java
@@ -32,12 +32,12 @@ import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
-import de.anomic.data.LibraryProvider;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.document.AbstractParser;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
+import net.yacy.document.LibraryProvider;
import net.yacy.document.Parser;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.util.BDecoder;
diff --git a/source/net/yacy/repository/LoaderDispatcher.java b/source/net/yacy/repository/LoaderDispatcher.java
index 6f6cdcaf4..d1e8f8493 100644
--- a/source/net/yacy/repository/LoaderDispatcher.java
+++ b/source/net/yacy/repository/LoaderDispatcher.java
@@ -185,8 +185,7 @@ public final class LoaderDispatcher {
final String host = url.getHost();
// check if we have the page in the cache
- final Map<String, String> mp = sb.crawler.profilesActiveCrawls.get(request.profileHandle().getBytes());
- CrawlProfile crawlProfile = mp == null ? null : new CrawlProfile(mp);
+ final CrawlProfile crawlProfile = sb.crawler.getActive(request.profileHandle().getBytes());
if (crawlProfile != null && cacheStrategy != CrawlProfile.CacheStrategy.NOCACHE) {
// we have passed a first test if caching is allowed
// now see if there is a cache entry