Update of /cvsroot/nutch/nutch/src/java/net/nutch/ontology
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23027/src/java/net/nutch/ontology

Added Files:
        Ontology.java OntologyFactory.java 
Log Message:
Add ontology plugin and its application of query refinement.


--- NEW FILE: Ontology.java ---
/* Copyright (c) 2004 michael j pan.  All rights reserved.   */
/* Use subject to the same conditions as Nutch. */
/* see http://www.nutch.org/LICENSE.txt. */

package net.nutch.ontology;

import java.util.Iterator;

public interface Ontology {
  /** The name of the extension point. */
  public final static String X_POINT_ID = Ontology.class.getName();

  public void load(String[] urls);

  // not yet implemented
  //public void merge(Ontology o);

  public Iterator subclasses(String entitySearchTerm);

  public Iterator synonyms(String queryKeyPhrase);
}

--- NEW FILE: OntologyFactory.java ---
/* Copyright (c) 2004 michael j pan.  All rights reserved.   */
/* Use subject to the same conditions as Nutch. */
/* see http://www.nutch.org/LICENSE.txt. */

package net.nutch.ontology;

import net.nutch.plugin.*;
import net.nutch.util.NutchConf;
import java.util.logging.Logger;
import net.nutch.util.LogFormatter;

/**
 * A factory for retrieving [EMAIL PROTECTED] Ontology} extensions.
 *
 * @author Michael Pan
 * @version $Id: OntologyFactory.java,v 1.1 2004/11/30 06:36:00 johnnx Exp $
 */
public class OntologyFactory {
  public final static Logger LOG =
    LogFormatter.getLogger(OntologyFactory.class.getName());

  private final static ExtensionPoint X_POINT =
    PluginRepository.getInstance().getExtensionPoint(Ontology.X_POINT_ID);

  private OntologyFactory() {}

  /**
  * @return Returns the online ontology extension specified
  * in nutch configuration's key
  * <code>extension.ontology.extension-name</code>.
  * If the name is  empty (no preference),
  * the first available ontology extension is returned.
  */
  public static Ontology getOntology() throws PluginRuntimeException {

    if (X_POINT == null) {
      // not even an extension point defined.
      return null;
    }

    String extensionName = NutchConf.get("extension.ontology.extension-name");
    if (extensionName != null) {
      Extension extension = findExtension(extensionName);
      if (extension != null) {
        LOG.info("Using ontology extension: " + extensionName);
        return (Ontology) extension.getExtensionInstance();
      }
      LOG.warning("Ontology extension not found: '" + extensionName 
        + "', trying the default");
      // not found, fallback to the default, if available.
    }

    Extension[] extensions = X_POINT.getExtentens();
    if (extensions.length > 0) {
      LOG.info("Using the first ontology extension found: "
        + extensions[0].getId());
      return (Ontology) extensions[0].getExtensionInstance();
    } else {
      return null;
    }

  }

  private static Extension findExtension(String name)
    throws PluginRuntimeException {

    Extension[] extensions = X_POINT.getExtentens();

    for (int i = 0; i < extensions.length; i++) {
      Extension extension = extensions[i];

      if (name.equals(extension.getId()))
        return extension;
    }

    return null;
  }

} 



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
Nutch-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nutch-cvs

Reply via email to