[MOBY-guts] biomoby commit

Gary Schlitz gss at pub.open-bio.org
Thu Jul 15 20:28:53 UTC 2004


gss
Thu Jul 15 16:28:53 EDT 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/parser
In directory pub.open-bio.org:/tmp/cvs-serv13718/S-MOBY/ref-impl/core/src/org/smoby/parser

Modified Files:
	Parser.java 
Log Message:
Minor fixes

moby-live/S-MOBY/ref-impl/core/src/org/smoby/parser Parser.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/parser/Parser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/parser/Parser.java	2004/06/18 21:38:27	1.4
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/parser/Parser.java	2004/07/15 20:28:53	1.5
@@ -6,6 +6,7 @@
 import org.smoby.graph.*;
 import org.smoby.graph.impl.*;
 import org.smoby.parser.*;
+import org.smoby.tools.ModelRetriever;
 import org.smoby.tools.Util;
 import org.smoby.vocabulary.*;
 import com.hp.hpl.jena.rdf.model.*;
@@ -28,17 +29,12 @@
     public final static String LANGUAGE_N3 = "N3";
     
     /**
-     * Inference models containing inferred statements derived using
-     * rdfs:subClassOf relationships.
+     * Since models are stored in a single Jena model, we
+     * segregate the single model into multiple sub-models,
+     * each containing an rdf:type moby:Provider statement,
+     * plus all statements that are reachable from it.
      */
-    private Map inferenceModels = new HashMap();
-    
-    /**
-     * Return the inference model associated with a given plain model
-     */
-    private InfModel getInferenceModel(Model model) {
-    	return (InfModel) inferenceModels.get(model);
-    }
+    private List subModels = new ArrayList();
 
     /**
      * Create and return a parser for parsing an N3 file
@@ -136,8 +132,7 @@
         	subModel.setNsPrefixes(model.getNsPrefixMap());
         	Resource subject = stmt.getSubject();
         	Util.addReachableStmts(model, subModel, subject, subject.getURI());
-        	inferenceModels.put(subModel,
-        		ModelFactory.createRDFSModel(subModel));
+        	subModels.add(subModel);
         }
     }
 
@@ -168,7 +163,7 @@
         
         // Parse each provider
         //
-        Iterator it = inferenceModels.keySet().iterator();
+        Iterator it = subModels.iterator();
         while (it.hasNext())
         {
         	Model model = (Model) it.next();
@@ -374,13 +369,17 @@
     
     /**
      * Return a list of statements for whom the subject is a given resource,
-     * whose predicates is a subproperty of moby:Property, and whose object
+     * whose predicate is a subproperty of moby:Property, and whose object
      * is a blank node.
      */
     private List mobyPropertyStatementsOf(Resource res)
     {
+    	// The statements to return
+    	//
         List stmts = new ArrayList();
         
+        // Iterate over the statements whose subjects are the resource
+        //
         StmtIterator it = res.listProperties();
         while (it.hasNext())
         {
@@ -388,17 +387,16 @@
             Property p = stmt.getPredicate();
             RDFNode pval = stmt.getObject();
             
-            Model model = res.getModel();
-            Model inferenceModel = getInferenceModel(model);
+            // Try to retrieve a description of the property at
+            // its URI.
+            //
+            InfModel model = getPropertyModel(p);
             
-            if (model.contains(res, p, pval) &&
-                inferenceModel.contains(p, RDFS.subPropertyOf, MOBY.Property))
+            if (isMobyProperty(p, model))
             {
                 MOBYPropertyValueStatement pvalStmt =
                     MOBYObjectFactory.newPropertyValueStatement(stmt, model);
                 
-                // See if the property 
-                //
                 Statement s = p.getProperty(RDFS.range);
                 
                 if ((s != null) && (s.getObject().canAs(Resource.class)))
@@ -423,6 +421,33 @@
         return stmts;
     }
     
+    /**
+     * Get the model describing a given property by doing a GET
+     * on its URI, and creating an inference model from it.
+     */
+    private InfModel getPropertyModel(Property p)
+    {
+    	Model model = ModelRetriever.retrieveModel(p.getURI());
+    	
+    	if (model == null) {
+    		return null;
+    	} else {
+    		return ModelFactory.createRDFSModel(model);
+    	}
+    }
+    
+    /**
+     * Return whether or not the given property is a MOBY property.
+     * This will be true if there is a statement in the model saying
+     * that the property is an rdfs:subPropertyOf moby:Property.
+     */
+    private boolean isMobyProperty(Property p, InfModel model)
+    {
+    	return
+		    model != null &&
+			model.contains(p, RDFS.subPropertyOf, MOBY.Property);
+    }
+    
     private String getDataPropertyValue(Resource subject, Property property)
     {
         Statement s = subject.getModel().getProperty(subject, property);




More information about the MOBY-guts mailing list