[MOBY-guts] biomoby commit

Gary Schiltz gss at pub.open-bio.org
Thu Oct 27 22:20:41 UTC 2005


gss
Thu Oct 27 18:20:41 EDT 2005
Update of /home/repository/moby/s-moby/ref-impl/core/src/org/semanticmoby/graph
In directory pub.open-bio.org:/tmp/cvs-serv10193/src/org/semanticmoby/graph

Added Files:
	MOBYResourceSet.java MOBYResource.java 
Removed Files:
	MOBYService.java MOBYServiceSet.java 
Log Message:
Changed Service to Resource

s-moby/ref-impl/core/src/org/semanticmoby/graph MOBYResourceSet.java,NONE,1.1 MOBYResource.java,1.2,1.3 MOBYService.java,1.2,NONE MOBYServiceSet.java,1.2,NONE
===================================================================
RCS file: /home/repository/moby/s-moby/ref-impl/core/src/org/semanticmoby/graph/MOBYResource.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/s-moby/ref-impl/core/src/org/semanticmoby/graph/MOBYResource.java	2005/09/14 22:06:10	1.2
+++ /home/repository/moby/s-moby/ref-impl/core/src/org/semanticmoby/graph/MOBYResource.java	2005/10/27 22:20:41	1.3
@@ -1,30 +1,263 @@
 package org.semanticmoby.graph;
 
-import org.semanticmoby.graph.*;
-
 import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+import org.semanticmoby.tools.Util;
+
+import org.semanticmoby.vocabulary.MOBY;
+
+import java.io.*;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * This class represents a resource that provides a
+ * resource in MOBY.
+ */
+public class MOBYResource extends MOBYGraphNode {
+
+    /**
+     * The name of the provider; stored in MOBY.name property
+     */
+    private Statement nameStmt;
+
+    /**
+     * A one line description of the provider; stored in the
+     * MOBY.oneLineDescription property
+     */
+    private Statement oneLineDescriptionStmt;
+
+    /**
+     * A URI at which more information can be retrieved about the
+     * provider; stored in the MOBY.moreInfoURI property
+     */
+    private Statement aboutURIStmt;
+
+    /**
+     * The MOBYGraphNode objects that this Resource operates on (instances of
+     * either MOBYCollection or MOBYGraph), each keyed by the statement that
+     * links this resource's URI to it via a hasMapping property
+     */
+    private Map operatesOnGraphStmts = new HashMap();
+
+    /**
+     * Constructor for creating a MOBYResource API object from scratch, given
+     * a model, URI, name, one line description, and about URI for the resource.
+     * Since the RDF statements that the resource represents don't yet exist, it
+     * creates and adds them to the model.
+     * @param model the underlying Jena model to add the statements to
+     * @param uri the URI of the resource
+     * @param name a name for the resource; stored in the moby:name property
+     * @param oneLineDescription a one line description for the resource;
+     * stored in the moby:oneLineDescription property
+     */
+    public MOBYResource(Model jenaModel, String uri, String name,
+                       String oneLineDescription, String aboutURI) {
+        super(jenaModel,
+              jenaModel.createStatement(jenaModel.createResource(uri),
+                                        RDF.type, MOBY.Resource));
+
+        // Save the literal properties by creating the corresponding
+        // statements and adding them to the model
+        //
+        jenaModel.add(nameStmt =
+                      jenaModel.createStatement(getResource(), MOBY.name, name));
+
+        jenaModel.add(oneLineDescriptionStmt =
+                      jenaModel.createStatement(getResource(),
+                                                MOBY.oneLineDescription,
+                                                oneLineDescription));
+
+        jenaModel.add(aboutURIStmt =
+                      jenaModel.createStatement(getResource(), MOBY.aboutURI,
+                                                aboutURI));
+    }
+
+
+    /**
+     * Constructor for creating a MOBYResource API object from scratch, given
+     * a URI, name, and one line description for the resource. The method
+     * first creates a default model using Util.newJenaModel(), and since
+     * the RDF statements that the resource represents don't yet exist, it
+     * then creates and adds them to the model.
+     * @param uri the URI of the resource
+     * @param name a name for the resource; stored in the moby:name property
+     * @param oneLineDescription a one line description for the resource;
+     * stored in the moby:oneLineDescription property
+     */
+    public MOBYResource(String uri, String name, String oneLineDescription,
+                       String aboutURI) {
+        this(Util.newJenaModel(), uri, name, oneLineDescription, aboutURI);
+    }
+
+
+    /**
+     * Constructor for creating an instance from existing RDF statements, as
+     * is the case when parsing an existing model.
+     */
+    public MOBYResource(Model jenaModel, Statement definingStmt,
+                       Statement nameStmt, Statement oneLineDescriptionStmt,
+                       Statement aboutURIStmt, Map operatesOnGraphs) {
+        super(jenaModel, definingStmt);
+        this.nameStmt                   = nameStmt;
+        this.oneLineDescriptionStmt     = oneLineDescriptionStmt;
+        this.aboutURIStmt               = aboutURIStmt;
+
+        for (Iterator it = operatesOnGraphs.keySet().iterator(); it.hasNext();) {
+
+            Statement     operatesOnStmt = (Statement) it.next();
+            MOBYGraphNode node =
+                (MOBYGraphNode) operatesOnGraphs.get(operatesOnStmt);
+            addOperatesOnGraph(operatesOnStmt, node);
+        }
+    }
+
+    /**
+     * Adds a new operatesOn subgraph and an operatesOn statement
+     */
+    public void addOperatesOnGraph(MOBYGraphNode newGraph) {
+
+        // Create and add a statement <url> moby:operatesOn <graph>
+        Statement operatesOnStmt =
+            jenaModel.createStatement(getResource(), MOBY.operatesOn,
+                                      newGraph.getResource());
+        addOperatesOnGraph(operatesOnStmt, newGraph);
+    }
+
+
+    /**
+     * Adds a new operatesOn Graph, linking it to the defining statement's
+     * resource with an operatesOn property
+     */
+    public void addOperatesOnGraph(Statement operatesOnStmt,
+                                   MOBYGraphNode newGraph) {
+
+        jenaModel.add(operatesOnStmt);
+        operatesOnGraphStmts.put(newGraph, operatesOnStmt);
+    }
+
+
+    /**
+     * Removes the graph node and its RDF statements from the underlying
+     * Jena model
+     */
+    public void removeOperatesOnGraph(MOBYGraphNode node) {
+
+        Statement stmt = (Statement) operatesOnGraphStmts.get(node);
+
+        if (stmt != null) {
+
+            jenaModel.remove(stmt);
+        }
+
+        node.removeStatements();
+    }
+
+
+    public Iterator getOperatesOn() {
+
+        return operatesOnGraphStmts.keySet().iterator();
+    }
+
+
+    /**
+     * Removes the statements representing this resource, and calls
+     * removeStatements on all Graph objects related to it through
+     * operatesOn properties
+     */
+    public void removeStatements() {
+
+        // Remove the defining statement
+        removeDefiningStatement();
+
+        // Remove the statements asserting the name and
+        // oneLineDescription properties
+        if (nameStmt != null) {
+
+            jenaModel.remove(nameStmt);
+            nameStmt = null;
+        }
+
+        if (oneLineDescriptionStmt != null) {
+
+            jenaModel.remove(oneLineDescriptionStmt);
+            oneLineDescriptionStmt = null;
+        }
+
+        if (aboutURIStmt != null) {
+
+            jenaModel.remove(aboutURIStmt);
+            aboutURIStmt = null;
+        }
+
+        // Remove each of the operatesOn statements, and have each
+        // MOBYGraphNode object remove its statements
+        if (operatesOnGraphStmts != null) {
+
+            for (Iterator it = operatesOnGraphStmts.keySet().iterator();
+                     it.hasNext();) {
+
+                MOBYGraphNode gnode = (MOBYGraphNode) it.next();
+                Statement     s = (Statement) operatesOnGraphStmts.get(gnode);
+                operatesOnGraphStmts.remove(s);
+                jenaModel.remove(s);
+                gnode.removeStatements();
+            }
+
+            operatesOnGraphStmts = null;
+        }
+    }
+
+
+    /**
+     * Return a descriptive name for the provider.
+     */
+    public String getName() {
+
+        return (nameStmt == null) ? "" : nameStmt.getObject().toString();
+    }
+
+
+    /**
+     * Return a short (one line) description for the provider.
+     */
+    public String getOneLineDescription() {
+
+        return (oneLineDescriptionStmt == null) ? ""
+                                                : oneLineDescriptionStmt.getObject()
+                                                                        .toString();
+    }
+
+
+    /**
+     * Return a URI that can be accessed to obtain more information
+     * about the provider.
+     */
+    public String getAboutURI() {
+
+        return (aboutURIStmt == null) ? "" : aboutURIStmt.getObject().toString();
+    }
+
+
+    /**
+     * Serialize the underlying model as RDF/XML to the given output stream
+     */
+    public void serialize(OutputStream out) {
+
+        jenaModel.write(out);
+    }
+
+
+    /**
+     * Serialize the underlying model as N3 to the given output stream
+     */
+    public void serializeAsN3(OutputStream out) {
 
-public class MOBYResource extends MOBYPropertyValue
-{
-    private Resource resourceValue;
-    
-    public MOBYResource(Resource resourceValue) {
-        this.resourceValue = resourceValue;
-    }
-    
-    public String getResourceURI() {
-        return resourceValue.getURI();
-    }
-    
-    public boolean isLiteral() {
-        return false;
-    }
-
-    public boolean isResource() {
-        return true;
-    }
-    
-    public boolean isBlank() {
-        return resourceValue.isAnon();
+        jenaModel.write(out, "N3");
     }
-}
\ No newline at end of file
+}

rcsdiff: /home/repository/moby/s-moby/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYService.java,v: No such file or directory

rcsdiff: /home/repository/moby/s-moby/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYServiceSet.java,v: No such file or directory




More information about the MOBY-guts mailing list