Apache Nutch is an extensible and scalable web crawler
initial import of ontology web extension
Sami Siren28e1b429997d
diff --git a/contrib/web2/plugins/build.xml b/contrib/web2/plugins/build.xmlindex 5ec5c3bb9..d2183a8a4 100755--- a/contrib/web2/plugins/build.xml+++ b/contrib/web2/plugins/build.xml@@ -15,6 +15,7 @@<ant dir="web-more" target="deploy"/><ant dir="web-resources" target="deploy"/><ant dir="web-clustering" target="deploy"/>+ <ant dir="web-query-propose-ontology" target="deploy"/></target><!-- ====================================================== -->@@ -34,6 +35,7 @@<ant dir="web-resources" target="clean"/><ant dir="web-more" target="clean"/><ant dir="web-clustering" target="clean"/>+ <ant dir="web-query-propose-ontology" target="clean"/></target></project>diff --git a/contrib/web2/plugins/web-query-propose-ontology/build.xml b/contrib/web2/plugins/web-query-propose-ontology/build.xmlnew file mode 100644index 000000000..ae8bcac3b--- /dev/null+++ b/contrib/web2/plugins/web-query-propose-ontology/build.xml@@ -0,0 +1,19 @@+<?xml version="1.0"?>+<project name="web-query-propose-ontology" default="jar-core">+ <import file="../build-plugin.xml" />+ <property name="nutch.root" location="${root}/../../../../" />+ <target name="init-plugin">+ <echo>Copying resources templates</echo>+ <copy todir="${build.classes}/resources">+ <fileset dir="${resources.dir}" includes="**/*" />+ </copy>+ <echo>Copying UI configuration</echo>+ <copy todir="${build.classes}">+ <fileset dir="src/conf" includes="**/*"/>+ </copy>+ <echo>Copying UI templates</echo>+ <copy todir="${deploy.dir}/web">+ <fileset dir="src/web" includes="**/*"/>+ </copy>+ </target>+</project>diff --git a/contrib/web2/plugins/web-query-propose-ontology/plugin.xml b/contrib/web2/plugins/web-query-propose-ontology/plugin.xmlnew file mode 100644index 000000000..32ce21edd--- /dev/null+++ b/contrib/web2/plugins/web-query-propose-ontology/plugin.xml@@ -0,0 +1,26 @@+<?xml version="1.0" encoding="UTF-8"?>+<plugin+ id="web-query-propose-ontology"+ name="Ontology query proposer"+ version="1.0.0"+ provider-name="apache.org">++ <runtime>+ <library name="web-query-propose-ontology.jar">+ <export name="*"/>+ </library>+ </runtime>++ <requires>+ <import plugin="nutch-extensionpoints"/>+ <import plugin="ontology"/>+ </requires>++ <extension id="org.apache.nutch.webapp.extension.UIExtensionPoint"+ name="Nutch ui extension point"+ point="org.apache.nutch.webapp.extension.UIExtensionPoint">+ <implementation id="web-query-propose-ontology"+ class="org.apache.nutch.webapp.extension.UIExtension.VoidImplementation"/>+ </extension>++</plugin>diff --git a/contrib/web2/plugins/web-query-propose-ontology/src/conf/tiles-defs.xml b/contrib/web2/plugins/web-query-propose-ontology/src/conf/tiles-defs.xmlnew file mode 100644index 000000000..7a2dbf540--- /dev/null+++ b/contrib/web2/plugins/web-query-propose-ontology/src/conf/tiles-defs.xml@@ -0,0 +1,6 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"+ "http://struts.apache.org/dtds/tiles-config_1_1.dtd">+<tiles-definitions>+ <definition name="propose" controllerClass="org.apache.nutch.webapp.controller.OntologyProposerController" path="/plugin/web-query-propose-ontology/propose.jsp"/>+</tiles-definitions>\ No newline at end of filediff --git a/contrib/web2/plugins/web-query-propose-ontology/src/java/org/apache/nutch/webapp/controller/OntologyProposerController.java b/contrib/web2/plugins/web-query-propose-ontology/src/java/org/apache/nutch/webapp/controller/OntologyProposerController.javanew file mode 100644index 000000000..412d2f7cf--- /dev/null+++ b/contrib/web2/plugins/web-query-propose-ontology/src/java/org/apache/nutch/webapp/controller/OntologyProposerController.java@@ -0,0 +1,71 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed 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.webapp.controller;++import java.io.IOException;++import javax.servlet.ServletContext;+import javax.servlet.ServletException;+import javax.servlet.http.HttpServletRequest;+import javax.servlet.http.HttpServletResponse;++import org.apache.nutch.ontology.Ontology;+import org.apache.nutch.webapp.common.ServiceLocator;+import org.apache.nutch.webapp.common.Startable;+import org.apache.struts.tiles.ComponentContext;++public class OntologyProposerController extends NutchController implements Startable {++ public static final String ATTR_NAME="queryPropose";++ static Ontology ontology;++ public void nutchPerform(ComponentContext tileContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) throws ServletException, IOException {++ ServiceLocator locator=getServiceLocator(request);++ if (ontology != null) {+ LOG.info("Calling ontology with parameter:" + locator.getSearch().getQueryString());+ request.setAttribute(ATTR_NAME, ontology.subclasses(locator.getSearch().getQueryString()));+ }+ }++ /*+ * (non-Javadoc)+ * @see org.apache.nutch.webapp.common.Startable#start(javax.servlet.ServletContext)+ */+ public void start(ServletContext servletContext) {++ ServiceLocator locator=getServiceLocator(servletContext);++ try {+ String urls = locator.getConfiguration().get("extension.ontology.urls");+ ontology = new org.apache.nutch.ontology.OntologyFactory(locator.getConfiguration()).getOntology();++ LOG.info("Initializing Ontology with urls:" + urls);++ //FIXME initialization code should be in Ontology instead+ if (urls==null || urls.trim().equals("")) {+ // ignored siliently+ } else {+ ontology.load(urls.split("\\s+"));+ }+ } catch (Exception e) {+ LOG.info("Exception occured while initializing Ontology" + e);+ }+ }+}diff --git a/contrib/web2/plugins/web-query-propose-ontology/src/web/web-query-propose-ontology/propose.jsp b/contrib/web2/plugins/web-query-propose-ontology/src/web/web-query-propose-ontology/propose.jspnew file mode 100644index 000000000..6503ed6b5--- /dev/null+++ b/contrib/web2/plugins/web-query-propose-ontology/src/web/web-query-propose-ontology/propose.jsp@@ -0,0 +1,16 @@+<%@ page session="false"%>+<%@ taglib prefix="tiles" uri="http://jakarta.apache.org/struts/tags-tiles"%>+<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>+<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>+<%+// 20041129, Mike Pan and John Xing+// Displays query-refinement hypertext based on ontology.+// Try to be simple here. No mixing with other features such as clustering.+// Please check refine-query-init.jsp, which does necessary initialization.+%>+<div id="refine">Refine your search:+<c:forEach var="propose" items="${queryPropose}">+ <a href="search.do?query=<c:out value="${propose}"/>">+ <c:out value="${propose}"/>+ </a> |+</c:forEach>