[MOBY-guts] biomoby commit

Gary Schlitz gss at pub.open-bio.org
Wed May 19 18:26:40 UTC 2004


gss
Wed May 19 14:26:40 EDT 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools
In directory pub.open-bio.org:/tmp/cvs-serv634/src/org/smoby/ref/tools

Modified Files:
	URIInvestigator.java DiscoveryQuery.java 
Log Message:
Incorporation of new parser

moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools URIInvestigator.java,1.2,1.3 DiscoveryQuery.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/URIInvestigator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/URIInvestigator.java	2004/03/27 01:27:51	1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/URIInvestigator.java	2004/05/19 18:26:40	1.3
@@ -3,11 +3,13 @@
 import java.util.*;
 import java.io.*;
 import javax.servlet.http.*;
-import org.smoby.tools.common.*;
+
+import org.smoby.tools.*;
+import org.smoby.http.*;
+import org.smoby.parser.*;
 import org.smoby.ref.tools.db.*;
-import org.smoby.tools.common.graph.*;
-import org.smoby.tools.common.http.*;
-import org.smoby.tools.common.vocabulary.*;
+import org.smoby.graph.*;
+import org.smoby.vocabulary.*;
 import org.apache.commons.httpclient.util.*;
 import org.apache.commons.logging.*;
 
@@ -50,7 +52,7 @@
         synchronized (instances)
         {
         	if (instances.get(providerURL) != null) {
-                syncLog.warn("Already investigating " + providerURL);
+        		syncLog.warn("Already investigating " + providerURL);
                 return;
             }
             
@@ -97,7 +99,7 @@
         }
         catch (MissingPropertyException e)
         {
-            syncLog.error("Missing DB_REPOSITORY_NAME property");
+        	syncLog.error("Missing DB_REPOSITORY_NAME property");
         }
         finally
         {
@@ -140,7 +142,7 @@
         }
         catch (StorageException e)
         {
-            syncLog.error("Couldn't check if provider URL " + providerURI + " exists", e);
+        	syncLog.error("Couldn't check if provider URL " + providerURI + " exists", e);
             return;
         }
         
@@ -151,7 +153,7 @@
             }
             catch (StorageException e)
             {
-                syncLog.error("Couldn't check for last modified date of provider URL " + providerURI, e);
+            	syncLog.error("Couldn't check for last modified date of provider URL " + providerURI, e);
                 return;
             }
         }
@@ -164,7 +166,9 @@
         // be sent if it has been modified since that date
         //
         if (lastModifiedDate != null) {
-            request.addHeader(MOBY.IF_MODIFIED_HEADER,  Util.formatDateForHTTP(lastModifiedDate));
+            request.addHeader(
+                MOBY.IF_MODIFIED_HEADER,
+                Util.formatDateForHTTP(lastModifiedDate));
         }
         
         // Send the request and check the response code
@@ -178,7 +182,7 @@
         }
         catch (HTTPException e)
         {
-            syncLog.warn("Couldn't reach suggested provider " + providerURI);
+        	syncLog.warn("Couldn't reach suggested provider " + providerURI);
             return;
         }
         
@@ -203,7 +207,7 @@
                     // Log a message about the last modified date not being
                     // retrievable, but register the graph anyway
                     //
-                    syncLog.warn("Unable to get Last-Modified date for "
+                	syncLog.warn("Unable to get Last-Modified date for "
                                  + providerURI + "; ignoring");
                 }
                 catch (Throwable t)
@@ -211,7 +215,7 @@
                     // Log a message about the last modified date not being
                     // parsable, but register the graph anyway
                     //
-                    syncLog.warn("Unparsable Last-Modified date " + "(\"" + dateString +
+                	syncLog.warn("Unparsable Last-Modified date " + "(\"" + dateString +
                                 "\") for " + providerURI + "; ignoring");
                 }
 
@@ -219,25 +223,24 @@
                 // provider was already registered, then first de-register
                 // its currently stored description graph.
                 //
-                String graphString = "";
-                
+                InputStream in = null;
                 try {
-                	graphString = response.getBody();
+                	in = response.getBodyAsStream();
                 }
                 catch (HTTPException e)
                 {
-                    syncLog.error("Couldn't retrieve graph from " + providerURI);
+                	syncLog.error("Couldn't retrieve graph from " + providerURI);
                     return;
                 }
                 
-                Model graph = null;
-                
+                MOBYProvider provider = null;
                 try {
-                    graph = MOBYGraph.parseModel(graphString);
+                    Parser parser = Parser.forInputStream(in, Parser.LANGUAGE_RDF_XML);
+                    provider = parser.parseProvider();
                 }
-                catch (UnparsableModelException e)
+                catch (UnparsableGraphException e)
                 {
-                    syncLog.warn("Unparsable graph found at " + providerURI +
+                	syncLog.warn("Unparsable graph found at " + providerURI +
                         (alreadyRegistered ? "; deregistering" : "; ignoring"));
                     if (alreadyRegistered) {
                         deregisterProvider(manager);
@@ -251,14 +254,14 @@
                 
                 try
                 {
-                    manager.registerGraph(graph, providerURI, lastModifiedDate);
+                    manager.registerProvider(provider, lastModifiedDate);
                     
                     // Log a message about successfully registering the graph:
                     //
                     syncLog.info((alreadyRegistered ? "UPDATED : " : "ADDED   : ") + providerURI);
                 }
                 catch (StorageException e) {
-                    syncLog.error("Error storing graph for " + providerURI, e);
+                	syncLog.error("Error storing graph for " + providerURI, e);
                 }
                 
                 break;
@@ -268,7 +271,7 @@
                 // The resource has not been modified since it was
                 // registered, so there is nothing to do but log a message.
                 //
-                syncLog.info("IN-SYNC : " + providerURI);
+            	syncLog.info("IN-SYNC : " + providerURI);
                 break;
             
             case HttpServletResponse.SC_NOT_FOUND:
@@ -281,7 +284,7 @@
                     try
                     {
                     	manager.deregisterProvider(providerURI);
-                        syncLog.info("REMOVED : " + providerURI);
+                    	syncLog.info("REMOVED : " + providerURI);
                     }
                     catch (StorageException e) {
                     	syncLog.error("Unable to de-register provider " + providerURI, e);
@@ -296,7 +299,7 @@
                 
                 // Log a message about the failed attempt to contact the URL
                 //
-                syncLog.error("Status " + status + " received while trying " +
+            	syncLog.error("Status " + status + " received while trying " +
                              "to contact provider " + providerURI);
                 break;
         }

===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/DiscoveryQuery.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/server/src/org/smoby/ref/tools/DiscoveryQuery.java	2004/03/30 23:54:34	1.3
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/DiscoveryQuery.java	2004/05/19 18:26:40	1.4
@@ -4,9 +4,12 @@
 import java.text.*;
 import java.util.*;
 
+import org.smoby.parser.Parser;
 import org.smoby.ref.tools.db.*;
-import org.smoby.tools.common.graph.*;
-import org.smoby.tools.common.vocabulary.MOBY;
+import org.smoby.graph.*;
+import org.smoby.graph.impl.MOBYObjectFactory;
+import org.smoby.graph.impl.MOBYProviderImpl;
+import org.smoby.vocabulary.*;
 
 import com.hp.hpl.jena.db.*;
 import com.hp.hpl.jena.graph.*;
@@ -41,7 +44,7 @@
     /**
      * The graph that serves as a template for providers that match.
      */
-    private MOBYGraph queryGraph;
+    private MOBYProvider queryProvider;
     
     /**
      * Flag indicating which statements should be returned: URI_ONLY,
@@ -67,9 +70,9 @@
      * @param statementsToReturn which statements should be returned: URI_ONLY,
      * QUERY_STMTS_ONLY, or ALL_STMTS (use the static constants on this class).
      */
-    public DiscoveryQuery(MOBYGraph queryGraph, int statementsToReturn)
+    public DiscoveryQuery(MOBYProvider queryProvider, int statementsToReturn)
     {
-    	this.queryGraph = queryGraph;
+    	this.queryProvider = queryProvider;
         this.statementsToReturn = statementsToReturn;
     }
     
@@ -83,22 +86,21 @@
         lastBnodeNumber = 0;
     }
     
-	public ProviderDescriptionGraph[] findMatchingGraphs()
+    public MOBYCollection findMatchingGraphs()
 	{
         init();
         
 		try
 		{
-            String queryString = buildQueryString(queryGraph);
+		    Model queryModel = ((MOBYProviderImpl) queryProvider).getUnderlying();
+            String queryString = buildQueryString(queryModel);
             StorageManager manager = new StorageManager();
-
             Model model = manager.openDBModel();
             ((ModelRDB) model).setDoFastpath(false);
             
 			// Execute the query
 			//
 			QueryResults results = Query.exec(queryString, model);
-
 			ArrayList matching = new ArrayList();
             
 			while (results.hasNext())
@@ -108,17 +110,19 @@
 			}
 			results.close();
 			
-			ProviderDescriptionGraph[] graphs =
-                new ProviderDescriptionGraph[matching.size()];
-			int i = 0;
-			for (Iterator it = matching.iterator(); it.hasNext(); i++)
+			List returnList = new ArrayList();
+			
+			for (Iterator it = matching.iterator(); it.hasNext();)
 			{
-				MOBYGraph mg = buildGraphModel(queryGraph, (ResultBinding) it.next());
-				graphs[i] = new ProviderDescriptionGraph(
-					new MOBYGraph(manager.openModel(mg.getProvider().getURI())));
+				MOBYProvider mp = buildGraphModel(queryModel, (ResultBinding) it.next());
+				String uri = mp.getURI();
+				// YUCK!
+				Model providerModel = manager.openModel(uri);
+				Parser parser = new Parser(providerModel);
+				returnList.add(parser.parseProvider());
 			}
 			
-			return graphs;
+			return MOBYObjectFactory.newUnorderedCollection(null, returnList, null);
 			
 		} catch (Throwable t) {
 			return null;
@@ -128,10 +132,8 @@
 	/**
 	 * Build and return an RDQL query string for the reified Model
 	 */
-	private String buildQueryString(MOBYGraph queryGraph)
+	private String buildQueryString(Model queryModel)
 	{
-        Model queryModel = queryGraph.getModel();
-        
         String SPACES = "      ";
         
         Map nsMap = queryModel.getNsPrefixMap();
@@ -220,12 +222,8 @@
 	 * @param binding bindings for variables
 	 * @return
 	 */
-	private MOBYGraph buildGraphModel(MOBYGraph queryGraph,
-                                      ResultBinding binding)
-		throws NonCanonicalException
+	private MOBYProvider buildGraphModel(Model queryModel, ResultBinding binding)
 	{
-        Model queryModel = queryGraph.getModel();
-        
 		// Create a default model to return
 		//
 		Model model = ModelFactory.createDefaultModel();
@@ -247,7 +245,8 @@
 			Statement copy = model.createStatement(subject, property, object);
 			model.add(copy);
 		}
-		return new MOBYGraph(model);
+		Parser parser = new Parser(model);
+		return parser.parseProvider();
 	}
 	
 	private RDFNode getBinding(RDFNode node, ResultBinding binding)




More information about the MOBY-guts mailing list