yacy_search_server/source/de/anomic/yacy/graphics/OSMTile.java
orbiter dcd01698b4 added a 'transition feature' that shall lower the barrier to move from g**gle to yacy (yes!):
Here a new concept called 'search heuristics' is introduced. A heuristic is a kind of 'shortcut' to good results in IT, here for good search results. In this case it will be used to get a very transparent way to compare what YaCy is able to produce as search result and what g**gle produces as search result. Here is what your can do now:
- add the phrase 'heuristic:scroogle' to your search query, like 'oil spill heuristic:scroogle' and then a call to scroogle is made to get anonymous search results from g**gle.
- these results are _not_ taken as meta-search results, but are used to instantly feed a crawling and indexing process. This happens very fast, here 20 results from scroogle are taken and loaded all simultanously, parsed and indexed immediately and from the results of the parsed content the search result is feeded, along to the normal p2p search
- when new results from that heuristic (more to come) get part of the search results, then it is verified if such results are redundant to existing (they had been part of the normal YaCy search result anyway) or if they had been completely new to YaCy.
- in the search results the new search results from heuristics are marked with a 'H ++' and search results from heuristics that had been already found by YaCy are marked with a 'H ='. That means:
- you can now see YaCy and Scroogle search results in one result page but you also see that you would not have 'missed' the g**gle results when you would only have used YaCy.

- to make it short: YaCy now subsumes g**gle results. If you use only YaCy, you miss nothing.

to come: a configuration page that let you configure the usage of heuristics and get this feature by default.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6944 6c8d7289-2bf4-0310-a012-ef5d649a1542
2010-06-25 16:44:57 +00:00

129 lines
5.6 KiB
Java

// ymageOSM.java
// (C) 2008 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 12.02.2008 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
// $LastChangedRevision: 1986 $
// $LastChangedBy: orbiter $
//
// 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
package de.anomic.yacy.graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Random;
import javax.imageio.ImageIO;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.visualization.RasterPlotter;
import de.anomic.crawler.CrawlProfile;
import de.anomic.crawler.retrieval.Response;
import de.anomic.http.client.Cache;
import de.anomic.search.Switchboard;
public class OSMTile {
// helper methods to load map images from openstreetmap.org
public static RasterPlotter getCombinedTiles(final tileCoordinates t11) {
tileCoordinates t00, t10, t20, t01, t21, t02, t12, t22;
t00 = new tileCoordinates(t11.xtile - 1, t11.ytile - 1, t11.zoom);
t10 = new tileCoordinates(t11.xtile , t11.ytile - 1, t11.zoom);
t20 = new tileCoordinates(t11.xtile + 1, t11.ytile - 1, t11.zoom);
t01 = new tileCoordinates(t11.xtile - 1, t11.ytile , t11.zoom);
t21 = new tileCoordinates(t11.xtile + 1, t11.ytile , t11.zoom);
t02 = new tileCoordinates(t11.xtile - 1, t11.ytile + 1, t11.zoom);
t12 = new tileCoordinates(t11.xtile , t11.ytile + 1, t11.zoom);
t22 = new tileCoordinates(t11.xtile + 1, t11.ytile + 1, t11.zoom);
final RasterPlotter m = new RasterPlotter(768, 768, RasterPlotter.MODE_REPLACE, "FFFFFF");
BufferedImage bi;
bi = getSingleTile(t00); if (bi != null) m.insertBitmap(getSingleTile(t00), 0, 0);
bi = getSingleTile(t10); if (bi != null) m.insertBitmap(getSingleTile(t10), 256, 0);
bi = getSingleTile(t20); if (bi != null) m.insertBitmap(getSingleTile(t20), 512, 0);
bi = getSingleTile(t01); if (bi != null) m.insertBitmap(getSingleTile(t01), 0, 256);
bi = getSingleTile(t11); if (bi != null) m.insertBitmap(getSingleTile(t11), 256, 256);
bi = getSingleTile(t21); if (bi != null) m.insertBitmap(getSingleTile(t21), 512, 256);
bi = getSingleTile(t02); if (bi != null) m.insertBitmap(getSingleTile(t02), 0, 512);
bi = getSingleTile(t12); if (bi != null) m.insertBitmap(getSingleTile(t12), 256, 512);
bi = getSingleTile(t22); if (bi != null) m.insertBitmap(getSingleTile(t22), 512, 512);
return m;
}
public static BufferedImage getSingleTile(final tileCoordinates tile) {
DigestURI tileURL;
try {
tileURL = new DigestURI(tile.url(), null);
} catch (final MalformedURLException e) {
return null;
}
//System.out.println("*** DEBUG: fetching OSM tile: " + tileURL.toNormalform(true, true));
byte[] tileb = Cache.getContent(tileURL);
if (tileb == null) {
// download resource using the crawler and keep resource in memory if possible
Response entry = null;
try {
entry = Switchboard.getSwitchboard().loader.load(Switchboard.getSwitchboard().loader.request(tileURL, false, false), CrawlProfile.CacheStrategy.IFEXIST, Long.MAX_VALUE);
} catch (IOException e) {
Log.logWarning("yamyOSM", "cannot load: " + e.getMessage());
return null;
}
tileb = entry.getContent();
}
try {
ImageIO.setUseCache(false); // do not write a cache to disc; keep in RAM
return ImageIO.read(new ByteArrayInputStream(tileb));
} catch (final EOFException e) {
return null;
} catch (final IOException e) {
return null;
}
}
public static final Random r = new Random(System.currentTimeMillis()); // to selet tile server
public static class tileCoordinates {
int xtile, ytile, zoom;
public tileCoordinates(final double lat, final double lon, final int zoom) {
this.zoom = zoom;
this.xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom));
this.ytile = (int) Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom));
}
public tileCoordinates(final int xtile, final int ytile, final int zoom) {
this.zoom = zoom;
this.xtile = xtile;
this.ytile = ytile;
}
public String url() {
char server = (char) ((int)'a' + r.nextInt(3));
return("http://" + server + ".tile.openstreetmap.org/" + zoom + "/" + xtile + "/" + ytile + ".png");
}
}
}