Apache Nutch is an extensible and scalable web crawler
remove reprecated objects Inlinks(s) + ParseData
Julien Nioche196727ba0517
diff --git a/src/java/org/apache/nutch/crawl/Inlink.java b/src/java/org/apache/nutch/crawl/Inlink.javadeleted file mode 100644index a5f78878e..000000000--- a/src/java/org/apache/nutch/crawl/Inlink.java+++ /dev/null@@ -1,78 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.crawl;--import java.io.*;-import org.apache.hadoop.io.*;--/* An incoming link to a page. */-public class Inlink implements Writable {-- private String fromUrl;- private String anchor;-- public Inlink() {}-- public Inlink(String fromUrl, String anchor) {- this.fromUrl = fromUrl;- this.anchor = anchor;- }-- public void readFields(DataInput in) throws IOException {- fromUrl = Text.readString(in);- anchor = Text.readString(in);- }-- /** Skips over one Inlink in the input. */- public static void skip(DataInput in) throws IOException {- Text.skip(in); // skip fromUrl- Text.skip(in); // skip anchor- }-- public void write(DataOutput out) throws IOException {- Text.writeString(out, fromUrl);- Text.writeString(out, anchor);- }-- public static Inlink read(DataInput in) throws IOException {- Inlink inlink = new Inlink();- inlink.readFields(in);- return inlink;- }-- public String getFromUrl() { return fromUrl; }- public String getAnchor() { return anchor; }-- public boolean equals(Object o) {- if (!(o instanceof Inlink))- return false;- Inlink other = (Inlink)o;- return- this.fromUrl.equals(other.fromUrl) &&- this.anchor.equals(other.anchor);- }-- public int hashCode() {- return fromUrl.hashCode() ^ anchor.hashCode();- }-- public String toString() {- return "fromUrl: " + fromUrl + " anchor: " + anchor;- }--}diff --git a/src/java/org/apache/nutch/crawl/Inlinks.java b/src/java/org/apache/nutch/crawl/Inlinks.javadeleted file mode 100644index 78b0f9f84..000000000--- a/src/java/org/apache/nutch/crawl/Inlinks.java+++ /dev/null@@ -1,100 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.crawl;--import java.io.*;-import java.net.*;-import java.util.*;--import org.apache.hadoop.io.*;--/** A list of {@link Inlink}s. */-public class Inlinks implements Writable {- private HashSet<Inlink> inlinks = new HashSet<Inlink>(1);-- public void add(Inlink inlink) { inlinks.add(inlink); }-- public void add(Inlinks inlinks) { this.inlinks.addAll(inlinks.inlinks); }-- public Iterator<Inlink> iterator() {- return this.inlinks.iterator();- }-- public int size() { return inlinks.size(); }-- public void clear() { inlinks.clear(); }-- public void readFields(DataInput in) throws IOException {- int length = in.readInt();- inlinks.clear();- for (int i = 0; i < length; i++) {- add(Inlink.read(in));- }- }-- public void write(DataOutput out) throws IOException {- out.writeInt(inlinks.size());- Iterator<Inlink> it = inlinks.iterator();- while (it.hasNext()) {- it.next().write(out);- }- }-- public String toString() {- StringBuffer buffer = new StringBuffer();- buffer.append("Inlinks:\n");- Iterator<Inlink> it = inlinks.iterator();- while (it.hasNext()) {- buffer.append(" ");- buffer.append(it.next());- buffer.append("\n");- }- return buffer.toString();- }-- /** Return the set of anchor texts. Only a single anchor with a given text- * is permitted from a given domain. */- public String[] getAnchors() {- HashMap<String, Set<String>> domainToAnchors =- new HashMap<String, Set<String>>();- ArrayList<String> results = new ArrayList<String>();- Iterator<Inlink> it = inlinks.iterator();- while (it.hasNext()) {- Inlink inlink = it.next();- String anchor = inlink.getAnchor();-- if (anchor.length() == 0) // skip empty anchors- continue;- String domain = null; // extract domain name- try {- domain = new URL(inlink.getFromUrl()).getHost();- } catch (MalformedURLException e) {}- Set<String> domainAnchors = domainToAnchors.get(domain);- if (domainAnchors == null) {- domainAnchors = new HashSet<String>();- domainToAnchors.put(domain, domainAnchors);- }- if (domainAnchors.add(anchor)) { // new anchor from domain- results.add(anchor); // collect it- }- }-- return results.toArray(new String[results.size()]);- }--}diff --git a/src/java/org/apache/nutch/parse/ParseData.java b/src/java/org/apache/nutch/parse/ParseData.javadeleted file mode 100644index cc0bf9ccc..000000000--- a/src/java/org/apache/nutch/parse/ParseData.java+++ /dev/null@@ -1,236 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.parse;--import java.io.*;-import java.util.*;--import org.apache.hadoop.io.*;-import org.apache.hadoop.util.GenericOptionsParser;-import org.apache.hadoop.conf.Configuration;-import org.apache.hadoop.fs.*;--import org.apache.nutch.metadata.Metadata;-import org.apache.nutch.util.NutchConfiguration;---/** Data extracted from a page's content.- * @see Parse#getData()- */-public final class ParseData extends VersionedWritable {- public static final String DIR_NAME = "parse_data";-- private final static byte VERSION = 5;-- private String title;- private Outlink[] outlinks;- private Metadata contentMeta;- private Metadata parseMeta;- private ParseStatus status;- private byte version = VERSION;-- public ParseData() {- contentMeta = new Metadata();- parseMeta = new Metadata();- }-- public ParseData(ParseStatus status, String title, Outlink[] outlinks,- Metadata contentMeta) {- this(status, title, outlinks, contentMeta, new Metadata());- }-- public ParseData(ParseStatus status, String title, Outlink[] outlinks,- Metadata contentMeta, Metadata parseMeta) {- this.status = status;- this.title = title;- this.outlinks = outlinks;- this.contentMeta = contentMeta;- this.parseMeta = parseMeta;- }-- //- // Accessor methods- //-- /** The status of parsing the page. */- public ParseStatus getStatus() { return status; }-- /** The title of the page. */- public String getTitle() { return title; }-- /** The outlinks of the page. */- public Outlink[] getOutlinks() { return outlinks; }-- /** The original Metadata retrieved from content */- public Metadata getContentMeta() { return contentMeta; }-- /**- * Other content properties.- * This is the place to find format-specific properties.- * Different parser implementations for different content types will populate- * this differently.- */- public Metadata getParseMeta() { return parseMeta; }-- public void setParseMeta(Metadata parseMeta) {- this.parseMeta = parseMeta;- }-- /**- * Get a metadata single value.- * This method first looks for the metadata value in the parse metadata. If no- * value is found it the looks for the metadata in the content metadata.- * @see #getContentMeta()- * @see #getParseMeta()- */- public String getMeta(String name) {- String value = parseMeta.get(name);- if (value == null) {- value = contentMeta.get(name);- }- return value;- }-- //- // Writable methods- //-- public byte getVersion() { return version; }-- public final void readFields(DataInput in) throws IOException {-- version = in.readByte();- // incompatible change from UTF8 (version < 5) to Text- if (version != VERSION)- throw new VersionMismatchException(VERSION, version);- status = ParseStatus.read(in);- title = Text.readString(in); // read title-- int numOutlinks = in.readInt();- outlinks = new Outlink[numOutlinks];- for (int i = 0; i < numOutlinks; i++) {- outlinks[i] = Outlink.read(in);- }-- if (version < 3) {- int propertyCount = in.readInt(); // read metadata- contentMeta.clear();- for (int i = 0; i < propertyCount; i++) {- contentMeta.add(Text.readString(in), Text.readString(in));- }- } else {- contentMeta.clear();- contentMeta.readFields(in);- }- if (version > 3) {- parseMeta.clear();- parseMeta.readFields(in);- }- }-- public final void write(DataOutput out) throws IOException {- out.writeByte(VERSION); // write version- status.write(out); // write status- Text.writeString(out, title); // write title-- out.writeInt(outlinks.length); // write outlinks- for (int i = 0; i < outlinks.length; i++) {- outlinks[i].write(out);- }- contentMeta.write(out); // write content metadata- parseMeta.write(out);- }-- public static ParseData read(DataInput in) throws IOException {- ParseData parseText = new ParseData();- parseText.readFields(in);- return parseText;- }-- //- // other methods- //-- public boolean equals(Object o) {- if (!(o instanceof ParseData))- return false;- ParseData other = (ParseData)o;- return- this.status.equals(other.status) &&- this.title.equals(other.title) &&- Arrays.equals(this.outlinks, other.outlinks) &&- this.contentMeta.equals(other.contentMeta) &&- this.parseMeta.equals(other.parseMeta);- }-- public String toString() {- StringBuffer buffer = new StringBuffer();-- buffer.append("Version: " + version + "\n" );- buffer.append("Status: " + status + "\n" );- buffer.append("Title: " + title + "\n" );-- if (outlinks != null) {- buffer.append("Outlinks: " + outlinks.length + "\n" );- for (int i = 0; i < outlinks.length; i++) {- buffer.append(" outlink: " + outlinks[i] + "\n");- }- }-- buffer.append("Content Metadata: " + contentMeta + "\n" );- buffer.append("Parse Metadata: " + parseMeta + "\n" );-- return buffer.toString();- }-- public static void main(String args[]) throws Exception {- String usage = "ParseData (-fs <local|namenode:port>) recno segment";-- if (args.length < 3) {- System.out.println("usage:" + usage);- return;- }-- GenericOptionsParser optParser =- new GenericOptionsParser(NutchConfiguration.create(), args);- String[] argv = optParser.getRemainingArgs();- Configuration conf = optParser.getConfiguration();-- FileSystem fs = FileSystem.get(conf);- try {- int recno = Integer.parseInt(argv[0]);- String segment = argv[1];-- Path file = new Path(segment, DIR_NAME);- System.out.println("Reading from file: " + file);-- ArrayFile.Reader parses = new ArrayFile.Reader(fs, file.toString(), conf);-- ParseData parseDatum = new ParseData();- parses.get(recno, parseDatum);-- System.out.println("Retrieved " + recno + " from file " + file);- System.out.println(parseDatum);-- parses.close();- } finally {- fs.close();- }- }--}diff --git a/src/test/org/apache/nutch/parse/TestParseData.java b/src/test/org/apache/nutch/parse/TestParseData.javadeleted file mode 100644index 4cd20f0ef..000000000--- a/src/test/org/apache/nutch/parse/TestParseData.java+++ /dev/null@@ -1,66 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.parse;--import org.apache.hadoop.conf.Configuration;-import org.apache.nutch.util.NutchConfiguration;--import org.apache.nutch.util.WritableTestUtils;-import org.apache.nutch.metadata.Metadata;--import junit.framework.TestCase;--/** Unit tests for ParseData. */--public class TestParseData extends TestCase {-- private Configuration conf = NutchConfiguration.create();-- public TestParseData(String name) { super(name); }-- public void testParseData() throws Exception {-- String title = "The Foo Page";-- Outlink[] outlinks = new Outlink[] {- new Outlink("http://foo.com/", "Foo"),- new Outlink("http://bar.com/", "Bar")- };-- Metadata metaData = new Metadata();- metaData.add("Language", "en/us");- metaData.add("Charset", "UTF-8");-- ParseData r = new ParseData(ParseStatus.STATUS_SUCCESS, title, outlinks, metaData);-- WritableTestUtils.testWritable(r, null);- }-- public void testMaxOutlinks() throws Exception {- Outlink[] outlinks = new Outlink[128];- for (int i=0; i<outlinks.length; i++) {- outlinks[i] = new Outlink("http://outlink.com/" + i, "Outlink" + i);- }- ParseData original = new ParseData(ParseStatus.STATUS_SUCCESS,- "Max Outlinks Title",- outlinks,- new Metadata());- ParseData data = (ParseData) WritableTestUtils.writeRead(original, null);- assertEquals(outlinks.length, data.getOutlinks().length);- }-}