Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

update to nutch 1.*

Thilo Haasbb92ab7107e6
diff --git a/build.xml b/build.xml
index 2d33f96ac..56175be72 100644
--- a/build.xml
+++ b/build.xml
@@ -1021,6 +1021,9 @@
<source path="${basedir}/src/java/" />
<source path="${basedir}/src/test/" output="build/test/classes" />
+ <source path="${plugins.dir}/any23/src/java/" />
+ <source path="${plugins.dir}/any23/src/test/" />
+
<source path="${plugins.dir}/creativecommons/src/java/" />
<source path="${plugins.dir}/creativecommons/src/test/" />
<source path="${plugins.dir}/feed/src/java/" />
diff --git a/ivy/ivy.xml b/ivy/ivy.xml
index e6695f407..40b73e16d 100644
--- a/ivy/ivy.xml
+++ b/ivy/ivy.xml
@@ -66,6 +66,7 @@
<!-- End of Hadoop Dependencies -->
<dependency org="org.apache.tika" name="tika-core" rev="1.12" />
+ <dependency org="org.apache.any23" name="apache-any23-core" rev="2.0"/>
<dependency org="com.ibm.icu" name="icu4j" rev="55.1" />
<dependency org="xerces" name="xercesImpl" rev="2.11.0" />
diff --git a/ivy/ivysettings.xml b/ivy/ivysettings.xml
index 2c4af02f2..d9b504400 100644
--- a/ivy/ivysettings.xml
+++ b/ivy/ivysettings.xml
@@ -25,8 +25,6 @@
http://ibiblio.lsu.edu/main/pub/packages/maven2
http://www.ibiblio.net/pub/packages/maven2
-->
-
- <!-- BEGIN: Repositories -->
<property name="oss.sonatype.org"
value="http://oss.sonatype.org/content/repositories/releases/"
override="false"/>
diff --git a/src/plugin/any23/ivy.xml b/src/plugin/any23/ivy.xml
index 98a2a489f..cb1095da8 100644
--- a/src/plugin/any23/ivy.xml
+++ b/src/plugin/any23/ivy.xml
@@ -36,7 +36,7 @@
</publications>
<dependencies>
- <dependency org="org.apache.any23" name="apache-any23-core" rev="0.9.0" conf="*->default"/>
+ <dependency org="org.apache.any23" name="apache-any23-core" rev="2.0" conf="*->default"/>
</dependencies>
-
+
</ivy-module>
diff --git a/src/plugin/any23/plugin.xml b/src/plugin/any23/plugin.xml
index 007bcaed8..37fe3b852 100644
--- a/src/plugin/any23/plugin.xml
+++ b/src/plugin/any23/plugin.xml
@@ -16,70 +16,38 @@
limitations under the License.
-->
<plugin
- id="any23"
- name="Apache Any23 Parser/Indexer"
- version="1.0.0"
- provider-name="nutch.org">
-
- <runtime>
- <library name="any23.jar">
- <export name="*"/>
- </library>
- <library name="apache-any23-core-0.9.0.jar"/>
- <library name="apache-any23-api-0.9.0.jar"/>
- <library name="slf4j-api-1.7.5.jar"/>
- <!--library name="aspectjrt-1.6.11.jar"/>
- <library name="bcmail-jdk15-1.45.jar"/>
- <library name="bcprov-jdk15-1.45.jar"/>
- <library name="boilerpipe-1.1.0.jar"/>
- <library name="commons-codec-1.5.jar"/>
- <library name="commons-compress-1.5.jar"/>
- <library name="commons-logging-1.1.1.jar"/>
- <library name="dom4j-1.6.1.jar"/>
- <library name="fontbox-1.8.4.jar"/>
- <library name="geronimo-stax-api_1.0_spec-1.0.1.jar"/>
- <library name="isoparser-1.0-RC-1.jar"/>
- <library name="jdom-1.0.jar"/>
- <library name="jempbox-1.8.4.jar"/>
- <library name="jhighlight-1.0.jar"/>
- <library name="juniversalchardet-1.0.3.jar"/>
- <library name="metadata-extractor-2.6.2.jar"/>
- <library name="netcdf-4.2-min.jar"/>
- <library name="pdfbox-1.8.4.jar"/>
- <library name="poi-3.10-beta2.jar"/>
- <library name="poi-ooxml-3.10-beta2.jar"/>
- <library name="poi-ooxml-schemas-3.10-beta2.jar"/>
- <library name="poi-scratchpad-3.10-beta2.jar"/>
- <library name="rome-0.9.jar"/>
- <library name="slf4j-api-1.5.6.jar"/>
- <library name="tagsoup-1.2.1.jar"/>
- <library name="tika-parsers-1.5.jar"/>
- <library name="vorbis-java-core-0.1.jar"/>
- <library name="vorbis-java-tika-0.1.jar"/>
- <library name="xercesImpl-2.8.1.jar"/>
- <library name="xml-apis-1.3.03.jar"/>
- <library name="xmlbeans-2.3.0.jar"/>
- <library name="xmpcore-5.1.2.jar"/>
- <library name="xz-1.2.jar"/-->
- </runtime>
-
- <requires>
- <import plugin="nutch-extensionpoints"/>
- </requires>
-
- <extension id="org.apache.nutch.any23.Any23ParseFilter"
- name="Any23 parser"
- point="org.apache.nutch.parse.ParseFilter">
- <implementation id="Any23Parser"
- class="org.apache.nutch.any23.Any23ParseFilter"/>
- </extension>
-
- <extension id="org.apache.nutch.any23.Any23IndexingFilter"
- name="Any23 indexing filter"
- point="org.apache.nutch.indexer.IndexingFilter">
- <implementation id="Any23IndexingFilter"
- class="org.apache.nutch.any23.Any23IndexingFilter"/>
- </extension>
+ id="any23"
+ name="Apache Any23 Parser/Indexer"
+ version="1.0.0"
+ provider-name="nutch.org">
+
+ <runtime>
+ <library name="any23.jar">
+ <export name="*"/>
+ </library>
+ <library name="apache-any23-core-2.0.jar"/>
+ <library name="apache-any23-api-2.0.jar"/>
+ <library name="slf4j-api-1.7.5.jar"/>
+ </runtime>
+
+ <requires>
+ <import plugin="nutch-extensionpoints"/>
+ </requires>
+
+ <extension id="org.apache.nutch.any23.Any23ParseFilter"
+ name="Any23 parser"
+ point="org.apache.nutch.parse.HtmlParseFilter">
+
+ <implementation id="Any23Parser"
+ class="org.apache.nutch.any23.Any23ParseFilter"/>
+ </extension>
+
+ <extension id="org.apache.nutch.any23.Any23IndexingFilter"
+ name="Any23 indexing filter"
+ point="org.apache.nutch.indexer.IndexingFilter">
+
+ <implementation id="Any23IndexingFilter"
+ class="org.apache.nutch.any23.Any23IndexingFilter"/>
+ </extension>
</plugin>
-
diff --git a/src/plugin/any23/src/java/org/apache/nutch/any23/Any23IndexingFilter.java b/src/plugin/any23/src/java/org/apache/nutch/any23/Any23IndexingFilter.java
index 5a0540d23..4b63f2082 100644
--- a/src/plugin/any23/src/java/org/apache/nutch/any23/Any23IndexingFilter.java
+++ b/src/plugin/any23/src/java/org/apache/nutch/any23/Any23IndexingFilter.java
@@ -16,18 +16,14 @@
*/
package org.apache.nutch.any23;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.apache.avro.util.Utf8;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+import org.apache.nutch.crawl.CrawlDatum;
+import org.apache.nutch.crawl.Inlinks;
import org.apache.nutch.indexer.IndexingException;
import org.apache.nutch.indexer.IndexingFilter;
import org.apache.nutch.indexer.NutchDocument;
-import org.apache.nutch.storage.WebPage;
-import org.apache.nutch.storage.WebPage.Field;
-import org.apache.nutch.util.Bytes;
+import org.apache.nutch.parse.Parse;
/**
* <p>This implementation of {@link org.apache.nutch.indexer.IndexingFilter}
@@ -36,30 +32,10 @@ import org.apache.nutch.util.Bytes;
* @see {@link org.apache.nutch.any23.Any23ParseFilter}.
*/
public class Any23IndexingFilter implements IndexingFilter {
-
- private Configuration conf;
-
- private static final Collection<WebPage.Field> FIELDS = new HashSet<WebPage.Field>();
-
- static {
- FIELDS.add(WebPage.Field.BASE_URL);
- FIELDS.add(WebPage.Field.METADATA);
- }
- /**
- * Gets all the fields for a given {@link WebPage}
- * Many datastores need to setup the mapreduce job by specifying the fields
- * needed. All extensions that work on {@link org.apache.nutch.storage.WebPage}
- * are able to specify what fields they need.
- *
- * @see org.apache.nutch.plugin.FieldPluggable#getFields()
- */
- @Override
- public Collection<Field> getFields() {
- return FIELDS;
- }
+ private Configuration conf;
- /**
+ /**
* Get the {@link Configuration} object
* @see org.apache.hadoop.conf.Configurable#getConf()
*/
@@ -78,24 +54,34 @@ public class Any23IndexingFilter implements IndexingFilter {
}
/**
- * @param doc The {@link NutchDocument} object
- * @param url URL to be filtered for triples.
- * @param page {@link WebPage} object relative to the URL
+ *
+ * @param doc
+ * document instance for collecting fields
+ * @param parse
+ * parse data instance
+ * @param url
+ * page url
+ * @param datum
+ * crawl datum for the page (fetch datum from segment containing
+ * fetch status and fetch time)
+ * @param inlinks
+ * page inlinks
* @return filtered NutchDocument
- * @see org.apache.nutch.indexer.IndexingFilter#filter(org.apache.nutch.indexer.NutchDocument, java.lang.String, org.apache.nutch.storage.WebPage)
+ * @see org.apache.nutch.indexer.IndexingFilter#filter(NutchDocument, Parse, Text, CrawlDatum, Inlinks)
+ *
+ * @throws IndexingException
*/
@Override
- public NutchDocument filter(NutchDocument doc, String url, WebPage page) throws IndexingException {
+ public NutchDocument filter(NutchDocument doc, Parse parse, Text url, CrawlDatum datum, Inlinks inlinks) throws IndexingException {
// Check if some Triples are found, possibly put there by Any23ParseFilter
- ByteBuffer bb = page.getFromMetadata(new Utf8(Any23ParseFilter.ANY23_TRIPLES));
+ String[] metadata = parse.getData().getParseMeta().getValues(Any23ParseFilter.ANY23_TRIPLES);
- if (bb != null) {
- String[] triples = Bytes.toString(bb).split("\t");
- for (int i = 0; i < triples.length; i++) {
- doc.add("triple", triples[i]);
+ if (metadata != null && metadata.length >= 1) {
+ String[] triples = metadata[0].split("\t");
+ for (String triple : triples) {
+ doc.add("triple", triple);
}
}
return doc;
}
-
}
diff --git a/src/plugin/any23/src/java/org/apache/nutch/any23/Any23ParseFilter.java b/src/plugin/any23/src/java/org/apache/nutch/any23/Any23ParseFilter.java
index a0233e3bc..885b43e33 100644
--- a/src/plugin/any23/src/java/org/apache/nutch/any23/Any23ParseFilter.java
+++ b/src/plugin/any23/src/java/org/apache/nutch/any23/Any23ParseFilter.java
@@ -19,41 +19,31 @@ package org.apache.nutch.any23;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.TreeSet;
+import java.nio.charset.Charset;
+import java.util.*;
import org.apache.any23.Any23;
-import org.apache.any23.extractor.ExtractionParameters;
-import org.apache.any23.source.DocumentSource;
import org.apache.any23.writer.BenchmarkTripleHandler;
import org.apache.any23.writer.NTriplesWriter;
import org.apache.any23.writer.TripleHandler;
import org.apache.any23.writer.TripleHandlerException;
-import org.apache.avro.util.Utf8;
import org.apache.hadoop.conf.Configuration;
-import org.apache.nutch.parse.HTMLMetaTags;
-import org.apache.nutch.parse.Parse;
-import org.apache.nutch.parse.ParseFilter;
-import org.apache.nutch.storage.WebPage;
-import org.apache.nutch.storage.WebPage.Field;
+import org.apache.nutch.metadata.Metadata;
+import org.apache.nutch.parse.*;
+import org.apache.nutch.protocol.Content;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Node;
/**
- * <p>This implementation of {@link org.apache.nutch.parse.ParseFilter}
+ * <p>This implementation of {@link org.apache.nutch.parse.HtmlParseFilter}
* uses the <a href="http://any23.apache.org">Apache Any23</a> library
- * for parsing and extracting structured data in RDF format from a
- * variety of Web documents. Currently it supports the following
+ * for parsing and extracting structured data in RDF format from a
+ * variety of Web documents. Currently it supports the following
* input formats:</p>
* <ol><li>RDF/XML, Turtle, Notation 3</li>
* <li>RDFa with RDFa1.1 prefix mechanism</li>
- * <li>Microformats: Adr, Geo, hCalendar, hCard, hListing, hResume, hReview,
+ * <li>Microformats: Adr, Geo, hCalendar, hCard, hListing, hResume, hReview,
* License, XFN and Species</li>
* <li>HTML5 Microdata: (such as Schema.org)</li>
* <li>CSV: Comma Separated Values with separator autodetection.</li></ol>.
@@ -61,14 +51,14 @@ import org.w3c.dom.Node;
* <code><http://www.bbc.co.uk/news/scotland/> <http://iptc.org/std/rNews/2011-10-07#datePublished> "2014/03/31 13:53:03"@en-gb .</code>
* and triples are identified within output triple streams by the presence of '\n'.
* The presence of the '\n' is a characteristic specific to N3 serialization in Any23.
- * In order to use another/other writers implementing the
- * <a href="http://any23.apache.org/apidocs/index.html?org/apache/any23/writer/TripleHandler.html">TripleHandler</a>
+ * In order to use another/other writers implementing the
+ * <a href="http://any23.apache.org/apidocs/index.html?org/apache/any23/writer/TripleHandler.html">TripleHandler</a>
* interface, we will most likely need to identify an alternative data characteristic
* which we can use to split triples streams.</p>
* <p>
*
*/
-public class Any23ParseFilter implements ParseFilter {
+public class Any23ParseFilter implements HtmlParseFilter {
/** Logging instance */
public static final Logger LOG = LoggerFactory.getLogger(Any23ParseFilter.class);
@@ -76,8 +66,7 @@ public class Any23ParseFilter implements ParseFilter {
private Configuration conf = null;
/** Constant identifier used as a Key for writing and reading
- * triples to and from the {@link org.apache.nutch.storage.WebPage}
- * metadata Map field.
+ * triples to and from the metadata Map field.
*/
public final static String ANY23_TRIPLES = "Any23-Triples";
@@ -85,10 +74,10 @@ public class Any23ParseFilter implements ParseFilter {
Set<String> triples = null;
- Any23Parser(String url, Node node) throws TripleHandlerException {
+ Any23Parser(String url, String htmlContent) throws TripleHandlerException {
triples = new TreeSet<String>();
try {
- parse(url, node);
+ parse(url, htmlContent);
} catch (URISyntaxException e) {
throw new RuntimeException(e.getReason());
} catch (IOException e) {
@@ -97,23 +86,20 @@ public class Any23ParseFilter implements ParseFilter {
}
/**
- * Maintains a {@link java.util.Set} containing the triples
- * extracted from a {@link org.apache.nutch.storage.WebPage}.</p>
+ * Maintains a {@link java.util.Set} containing the triples
* @return a {@link java.util.Set} of triples.
*/
public Set<String> getTriples() {
return triples;
}
- private void parse(String url, Node node) throws URISyntaxException, IOException, TripleHandlerException {
+ private void parse(String url, String htmlContent) throws URISyntaxException, IOException, TripleHandlerException {
Any23 any23 = new Any23();
- DocumentSource source = any23.createDocumentSource(url);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TripleHandler tHandler = new NTriplesWriter(baos);
BenchmarkTripleHandler bHandler = new BenchmarkTripleHandler(tHandler);
- ExtractionParameters eParams = ExtractionParameters.newDefault(); //pass configuration?
try {
- any23.extract(eParams, source, bHandler);
+ any23.extract(htmlContent, url, "text/HTML", "UTF-8", bHandler);
} catch (Exception e) {
e.printStackTrace();
} finally {
@@ -121,32 +107,16 @@ public class Any23ParseFilter implements ParseFilter {
bHandler.close();
}
//This merely prints out a report of the Any23 extraction.
- LOG.debug("Any23 report: " + bHandler.report());
+ LOG.info("Any23 report: " + bHandler.report());
String n3 = baos.toString("UTF-8");
- // we split the triples stream by the occurrence of
+ // we split the triples stream by the occurrence of
// '\n' as this is a distinguishing feature of NTriples
// output serialization in Any23.
String[] triplesStrings = n3.split("\n");
- for (String triple: triplesStrings) {
- triples.add(triple);
- }
+ Collections.addAll(triples, triplesStrings);
}
}
- private static final Collection<WebPage.Field> FIELDS = new HashSet<WebPage.Field>();
-
- static {
- FIELDS.add(WebPage.Field.BASE_URL);
- FIELDS.add(WebPage.Field.METADATA);
- }
- /**
- * @see org.apache.nutch.plugin.FieldPluggable#getFields()
- */
- @Override
- public Collection<Field> getFields() {
- return FIELDS;
- }
-
/**
* @see org.apache.hadoop.conf.Configurable#getConf()
*/
@@ -163,30 +133,33 @@ public class Any23ParseFilter implements ParseFilter {
this.conf = conf;
}
- /**
- * @see org.apache.nutch.parse.ParseFilter#filter(java.lang.String, org.apache.nutch.storage.WebPage, org.apache.nutch.parse.Parse, org.apache.nutch.parse.HTMLMetaTags, org.w3c.dom.DocumentFragment)
+ /**
+ * @see org.apache.nutch.parse.HtmlParseFilter#filter(Content, ParseResult, HTMLMetaTags, DocumentFragment)
*/
@Override
- public Parse filter(String url, WebPage page, Parse parse,
- HTMLMetaTags metaTags, DocumentFragment doc) {
+ public ParseResult filter(Content content, ParseResult parseResult, HTMLMetaTags metaTags, DocumentFragment doc) {
Any23Parser parser = null;
try {
- parser = new Any23Parser(url, doc);
+ String htmlContent = new String(content.getContent(), Charset.forName("UTF-8"));
+ parser = new Any23Parser(content.getUrl(), htmlContent);
} catch (TripleHandlerException e) {
throw new RuntimeException("Error running Any23 parser: " + e.getMessage());
}
Set<String> triples = parser.getTriples();
// can't store multiple values in page metadata -> separate by tabs
- StringBuffer sb = new StringBuffer();
- Iterator<String> iter = triples.iterator();
- while (iter.hasNext()) {
- sb.append(iter.next());
+ StringBuilder sb = new StringBuilder();
+
+ Parse parse = parseResult.get(content.getUrl());
+ Metadata metadata = parse.getData().getParseMeta();
+
+ for (String triple : triples) {
+ sb.append(triple);
sb.append("\t");
}
- ByteBuffer bb = ByteBuffer.wrap(sb.toString().getBytes());
- page.putToMetadata(new Utf8(ANY23_TRIPLES), bb);
- return parse;
+ metadata.add(ANY23_TRIPLES, sb.toString());
+
+ return parseResult;
}
}
diff --git a/src/plugin/any23/src/java/org/apache/nutch/any23/package-info.java b/src/plugin/any23/src/java/org/apache/nutch/any23/package-info.java
index b90396eeb..05de79b87 100644
--- a/src/plugin/any23/src/java/org/apache/nutch/any23/package-info.java
+++ b/src/plugin/any23/src/java/org/apache/nutch/any23/package-info.java
@@ -18,4 +18,4 @@
* @author lewismc
*
*/
-package org.apache.nutch.any23;
\ No newline at end of file
+package org.apache.nutch.any23;
diff --git a/src/plugin/any23/src/test/org/apache/nutch/any23/TestAny23ParseFilter.java b/src/plugin/any23/src/test/org/apache/nutch/any23/TestAny23ParseFilter.java
index 1ce282935..99a09d374 100644
--- a/src/plugin/any23/src/test/org/apache/nutch/any23/TestAny23ParseFilter.java
+++ b/src/plugin/any23/src/test/org/apache/nutch/any23/TestAny23ParseFilter.java
@@ -107,7 +107,7 @@ public class TestAny23ParseFilter {
bbuf.get(byteArray);
String s = new String(byteArray);
String[] triplesArray = s.split("\t");
+
return triplesArray;
-
}
}
diff --git a/src/plugin/build.xml b/src/plugin/build.xml
index 22b57897b..5a8702c20 100755
--- a/src/plugin/build.xml
+++ b/src/plugin/build.xml
@@ -101,6 +101,7 @@
<!-- ====================================================== -->
<target name="test">
<parallel threadCount="2">
+ <ant dir="any23" target="test"/>
<ant dir="creativecommons" target="test"/>
<ant dir="index-basic" target="test"/>
<ant dir="index-anchor" target="test"/>
diff --git a/src/plugin/microformats-reltag/src/java/org/apache/nutch/microformats/reltag/RelTagIndexingFilter.java b/src/plugin/microformats-reltag/src/java/org/apache/nutch/microformats/reltag/RelTagIndexingFilter.java
index c80e61c5d..e50a15046 100644
--- a/src/plugin/microformats-reltag/src/java/org/apache/nutch/microformats/reltag/RelTagIndexingFilter.java
+++ b/src/plugin/microformats-reltag/src/java/org/apache/nutch/microformats/reltag/RelTagIndexingFilter.java
@@ -37,7 +37,7 @@ import org.apache.hadoop.conf.Configuration;
* @author J&eacute;r&ocirc;me Charron
*/
public class RelTagIndexingFilter implements IndexingFilter {
-
+
private Configuration conf;
// Inherited JavaDoc
diff --git a/src/plugin/parse-tika/howto_upgrade_tika.txt b/src/plugin/parse-tika/howto_upgrade_tika.txt
index 47bf127d6..63a05a4bf 100644
--- a/src/plugin/parse-tika/howto_upgrade_tika.txt
+++ b/src/plugin/parse-tika/howto_upgrade_tika.txt
@@ -1,4 +1,4 @@
-1. Upgrade Tika dependency in trunk/ivy/ivy.xml
+1. Upgrade Tika depencency in trunk/ivy/ivy.xml
2. Upgrade Tika dependency in src/plugin/parse-tika/ivy.xml