⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 summary.java

📁 nutch搜索的改进型工具和优化爬虫的相关工具
💻 JAVA
字号:
/* Copyright (c) 2003 The Nutch Organization.  All rights reserved.   */
/* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */

package net.nutch.searcher;

import java.util.ArrayList;
import net.nutch.html.Entities;

/** A document summary dynamically generated to match a query. */
public class Summary {

  /** A fragment of text within a summary. */
  public static class Fragment {
    private String text;

    /** Constructs a fragment for the given text. */
    public Fragment(String text) { this.text = text; }

    /** Returns the text of this fragment. */
    public String getText() { return text; }

    /** Returns true iff this fragment is to be highlighted. */
    public boolean isHighlight() { return false; }

    /** Returns true iff this fragment is an ellipsis. */
    public boolean isEllipsis() { return false; }

    /** Returns an HTML representation of this fragment. */
    public String toString() { 
    	//return Entities.encode(text);
    	return text;}
  }

  /** A highlighted fragment of text within a summary. */
  public static class Highlight extends Fragment {
    /** Constructs a highlighted fragment for the given text. */
    public Highlight(String text) { super(text); }

    /** Returns true. */
    public boolean isHighlight() { return true; }

    /** Returns an HTML representation of this fragment. */
    //public String toString() { return "<b>" + super.toString() + "</b>"; }
    public String toString() { return "<font color=\"red\">" + super.toString() + "</font>"; }
  }

  /** An ellipsis fragment within a summary. */
  public static class Ellipsis extends Fragment {
    /** Constructs an ellipsis fragment for the given text. */
    public Ellipsis() { super(" ... "); }

    /** Returns true. */
    public boolean isEllipsis() { return true; }

    /** Returns an HTML representation of this fragment. */
    public String toString() { return " ... "; }
  }

  private ArrayList fragments = new ArrayList();

  private static final Fragment[] FRAGMENT_PROTO = new Fragment[0];

  /** Constructs an empty Summary.*/
  public Summary() {}

  /** Adds a fragment to a summary.*/
  public void add(Fragment fragment) { fragments.add(fragment); }

  /** Returns an array of all of this summary's fragments.*/
  public Fragment[] getFragments() {
    return (Fragment[])fragments.toArray(FRAGMENT_PROTO);
  }

  /** Returns an HTML representation of this fragment. */
  public String toString() {
	  StringBuffer buffer = new StringBuffer();
	  boolean isHighlight = false;
	  for (int i = 0; i < fragments.size(); i++) {
		  String text = fragments.get(i).toString();
		  if (text.length() == 0) continue;
		  if (isHighlight){
			  if (text.substring(0,1).matches("[a-zA-Z0-9]"))
				  buffer.append(" ");
			  isHighlight = false;
		  }
		  if (text.matches("<font color=\"red\">[a-zA-Z0-9]+</font>")){
			  isHighlight = true;
			  String bufTemp = buffer.toString();
			  if (bufTemp.length() > 0 && bufTemp.substring(bufTemp.length()-1).matches("[a-zA-Z0-9]"))
				  buffer.append(" ");
		  }
		  buffer.append(text);
	  }
	  return buffer.toString().replaceAll("</font><font color=\"red\">","");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -