nutch-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (NUTCH-1993) Nutch does not use backup parsers
Date Thu, 19 Jul 2018 13:07:00 GMT

    [ https://issues.apache.org/jira/browse/NUTCH-1993?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16549247#comment-16549247
] 

ASF GitHub Bot commented on NUTCH-1993:
---------------------------------------

sebastian-nagel closed pull request #364: NUTCH-1993 Nutch does not use backup parsers
URL: https://github.com/apache/nutch/pull/364
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/java/org/apache/nutch/parse/ParseResult.java b/src/java/org/apache/nutch/parse/ParseResult.java
index 15b46ac42..9987e80a0 100644
--- a/src/java/org/apache/nutch/parse/ParseResult.java
+++ b/src/java/org/apache/nutch/parse/ParseResult.java
@@ -59,7 +59,7 @@ public ParseResult(String originalUrl) {
 
   /**
    * Convenience method for obtaining {@link ParseResult} from a single
-   * <code>Parse</code> output.
+   * {@link Parse} output.
    * 
    * @param url
    *          canonical url.
@@ -150,7 +150,7 @@ public void put(String key, ParseText text, ParseData data) {
 
   /**
    * Remove all results where status is not successful (as determined by
-   * <code>ParseStatus#isSuccess()</code>). Note that effects of this operation
+   * {@link ParseStatus#isSuccess()}). Note that effects of this operation
    * cannot be reversed.
    */
   public void filter() {
@@ -166,7 +166,7 @@ public void filter() {
 
   /**
    * A convenience method which returns true only if all parses are successful.
-   * Parse success is determined by <code>ParseStatus#isSuccess()</code>.
+   * Parse success is determined by {@link ParseStatus#isSuccess()}.
    */
   public boolean isSuccess() {
     for (Iterator<Entry<Text, Parse>> i = iterator(); i.hasNext();) {
@@ -177,4 +177,18 @@ public boolean isSuccess() {
     }
     return true;
   }
+
+  /**
+   * A convenience method which returns true if at least one of the parses is
+   * successful. Parse success is determined by {@link ParseStatus#isSuccess()}.
+   */
+  public boolean isAnySuccess() {
+    for (Iterator<Entry<Text, Parse>> i = iterator(); i.hasNext();) {
+      Entry<Text, Parse> entry = i.next();
+      if (entry.getValue().getData().getStatus().isSuccess()) {
+        return true;
+      }
+    }
+    return false;
+  }
 }
diff --git a/src/java/org/apache/nutch/parse/ParseUtil.java b/src/java/org/apache/nutch/parse/ParseUtil.java
index e77c97f23..169be0fcf 100644
--- a/src/java/org/apache/nutch/parse/ParseUtil.java
+++ b/src/java/org/apache/nutch/parse/ParseUtil.java
@@ -34,9 +34,6 @@
  * as iterating through a preferred list of {@link Parser}s to obtain
  * {@link Parse} objects.
  * 
- * @author mattmann
- * @author J&eacute;r&ocirc;me Charron
- * @author S&eacute;bastien Le Callonnec
  */
 public class ParseUtil {
 
@@ -102,8 +99,16 @@ public ParseResult parse(Content content) throws ParseException {
         }
       }
 
-      if (parseResult != null && !parseResult.isEmpty())
+      if (parseResult != null && parseResult.isAnySuccess()) {
         return parseResult;
+      }
+
+      // continue and try further parsers if parse failed
+    }
+
+    // if there is a failed parse result return it (contains reason for failure)
+    if (parseResult != null && !parseResult.isEmpty()) {
+      return parseResult;
     }
 
     if (LOG.isWarnEnabled()) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Nutch does not use backup parsers
> ---------------------------------
>
>                 Key: NUTCH-1993
>                 URL: https://issues.apache.org/jira/browse/NUTCH-1993
>             Project: Nutch
>          Issue Type: Bug
>          Components: parser
>    Affects Versions: 1.13
>            Reporter: Arkadi Kosmynin
>            Assignee: Sebastian Nagel
>            Priority: Major
>             Fix For: 1.15
>
>         Attachments: NUTCH-1193.patch
>
>
> From reading the code it is clear that it is designed to allow using several parsers
to parse a document in a sequence, until it is successfully parsed. In practice, this does
not work because these lines 
> if (parseResult != null && !parseResult.isEmpty())
>         return parseResult;
> break the loop even if the parsing has failed because parseResult is not empty anyway,
it contains a ParseData with ParseStatus.FAILED.
> A fix:
> if ( parseResult.isAnySuccess() ) 
>         return parseResult;
> Where parseResult.isAnySuccess() returns true if any of the parsing attempts were successful.
> This fix is important because it allows use of backup parsers as originally designed
and thus increase index completeness.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message