[MOBY-guts] biomoby commit
Gary Schlitz
gss at pub.open-bio.org
Thu Nov 4 22:33:50 UTC 2004
gss
Thu Nov 4 17:33:50 EST 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/semanticmoby.org/src/org/smoby/ref/servlets
In directory pub.open-bio.org:/tmp/cvs-serv32064/src/org/smoby/ref/servlets
Modified Files:
KeywordSearchServlet.java
Log Message:
Added doc
moby-live/S-MOBY/ref-impl/semanticmoby.org/src/org/smoby/ref/servlets KeywordSearchServlet.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/semanticmoby.org/src/org/smoby/ref/servlets/KeywordSearchServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/semanticmoby.org/src/org/smoby/ref/servlets/KeywordSearchServlet.java 2004/07/21 22:35:25 1.3
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/semanticmoby.org/src/org/smoby/ref/servlets/KeywordSearchServlet.java 2004/11/04 22:33:50 1.4
@@ -6,9 +6,29 @@
import javax.servlet.http.*;
import org.smoby.graph.*;
import org.smoby.ref.tools.*;
+import org.smoby.vocabulary.MOBY;
+/**
+ * This servlet class is used to search the Semantic MOBY metadata
+ * repository for providers that match keywords. It produces a page
+ * of search results, including a result count and information about
+ * each matching provider.
+ * <br><br>
+ * In the process of registration of a Semantic MOBY provider, nodes
+ * in the provider description graph, which represent the provider,
+ * subjects, and objects (i.e. they are subjects of statements whose
+ * predicate is rdf:type, and whose object is moby:Provider,
+ * moby:Subject, and moby:Object, respectively) are examined for
+ * other statements with rdf:type as their predicate, but with other
+ * non-MOBY classes as their objects. For each of non-MOBY classes,
+ * an attempt is made to retrieve the class definition. If the
+ * definition is a valid MOBY graph
+ */
public class KeywordSearchServlet extends BaseServlet
{
+ /**
+ * Perform a search based on keywords.
+ */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
@@ -18,7 +38,7 @@
List accepts = getKeywords("accepts", request);
List returns = getKeywords("returns", request);
- startHTML(response, out);
+ startHTML(response, "Semantic MOBY keyword search results", out);
if ((provider.isEmpty()) && (accepts.isEmpty()) && (returns.isEmpty()))
{
showResultCount(-1, out);
@@ -37,29 +57,41 @@
showProvider(p, out);
}
}
- finishHTML(response, out);
+ finishHTML(out);
}
+ /**
+ * Return a list of keywords for the given parameter name (i.e.
+ * "provider", "accepts", or "returns")
+ */
private List getKeywords(String paramName, HttpServletRequest request)
{
List keywords = new ArrayList();
+ // If the parameter is not defined or is blank,
+ // then return an empty list
+ //
String value = request.getParameter(paramName);
if (value == null) return keywords;
-
value = value.trim();
-
if (value.length() == 0) return keywords;
+ // Use a stream tokenizer to parse the keywords. Make sure the
+ // tokenizer doesn't strip out the wildcard character ('*')
+ //
StreamTokenizer st = new StreamTokenizer(new StringReader(value));
st.wordChars('*', '*');
- st.wordChars('%', '%');
+
try
{
while (st.nextToken() != StreamTokenizer.TT_EOF)
{
if (st.sval != null)
{
+ // The keywords will be used as part of an SQL "LIKE"
+ // query, which uses '%' as a wildcard instead of the
+ // more conventional '*', so replace '%' with '*'
+ //
String val = st.sval.toLowerCase().trim().replace('*', '%');
keywords.add(val);
}
@@ -69,18 +101,34 @@
return keywords;
}
+ /**
+ * Show the count of providers that match the keyword search
+ * criteria.
+ */
private void showResultCount(int count, PrintStream out)
{
out.println("<table border=\"0\" width=\"100%\">");
out.println("<tr>");
out.println("<td style=\"background-color:#e5ecf9\">");
- if (count < 0) {
+ if (count < 0)
+ {
+ // A negative count indicates that no keywords were given.
+ //
out.println("No keywords were entered, so no search was performed.");
- } else if (count < 1) {
+ }
+ else if (count == 0)
+ {
+ // Indicate that no matching providers were found, and
+ // give the user feedback as to why this might be expected.
+ //
out.println("No matching providers were found. <i>Note that");
out.println("very few providers have yet been defined.</i>");
- } else {
+ }
+ else
+ {
+ // Show how many providers were found
+ //
out.println(count + " matching provider" +
(count > 1 ? "s" : "") + " found");
}
@@ -90,6 +138,9 @@
out.println("<br>");
}
+ /**
+ * Show a provider that matches the keyword search criteria.
+ */
private void showProvider(MOBYProvider provider, PrintStream out)
{
String uri = provider.getResource().getURI();
@@ -97,11 +148,18 @@
String description = provider.getOneLineDescription();
String moreInfo = provider.getMoreInfoURI();
+ // Display a link to the Semantic MOBY engage-provider service
+ //
out.println("<b>");
out.print("<a href=\"");
out.print("http://www.semanticmoby.org/engage-provider?provider-url=");
out.print(uri);
out.print("\">");
+
+ // If the provider has a name (MOBY.name property), then
+ // display that for the text of the above link; otherwise,
+ // use the URI of the provider.
+ //
if ((name != null) && (name.trim().length() > 0)) {
out.println(name);
} else {
@@ -109,13 +167,21 @@
}
out.print("</a>");
out.println("</b>");
+
+ // Provide a link to the provider description graph itself, and
+ // use the RDF logo as a picture for the link
+ //
out.print("<a href=\"");
out.print(uri);
out.print("\">");
- out.print("<img border=\"0\" src=\"images/rdf-logo.png\" alt=\"Definition\">");
+ out.print("<img border=\"0\" src=\"images/rdf-logo.png\" alt=\"View RDF Definition\">");
out.print("</a>");
out.println("<br>");
+ // If the provider has a description (MOBY.oneLineDescription
+ // property), then display it here; otherwise, indicate that
+ // the provider has no description.
+ //
if ((description != null) && (description.trim().length() > 0)) {
out.println(description);
} else {
@@ -123,6 +189,10 @@
}
out.println("<br>");
+ // If a URI was provided for finding more information
+ // (MOBY.aboutURI property), then display a link to
+ // that URI.
+ //
if ((moreInfo != null) && (moreInfo.trim().length() > 0)) {
out.println("For more information see <a href=\"" + moreInfo +
"\">" + moreInfo + "</a>");
@@ -130,6 +200,9 @@
out.println("<br>");
}
+ /**
+ * Handle POST requests the same way as GET requests
+ */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
More information about the MOBY-guts
mailing list