[MOBY-guts] biomoby commit
Gary Schiltz
gss at pub.open-bio.org
Thu Oct 6 18:15:05 UTC 2005
gss
Thu Oct 6 14:15:05 EDT 2005
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/parser
In directory pub.open-bio.org:/tmp/cvs-serv9759/src/org/semanticmoby/parser
Modified Files:
Parser.java
Log Message:
Fixe a few more bugs
moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/parser Parser.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/parser/Parser.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/core/src/org/semanticmoby/parser/Parser.java 2005/09/14 22:06:10 1.3
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/parser/Parser.java 2005/10/06 18:15:05 1.4
@@ -190,9 +190,9 @@
Resource headResource = typeStmt.getSubject();
Model model = headResource.getModel();
-
- // First parse the scalar properties
+ // First parse the literal properties
+ //
Statement nameStmt =
model.getProperty(headResource, MOBY.name);
@@ -204,9 +204,12 @@
// A service can have multiple operatesOn properties, each of
// which leads to a subgraph. Parse each of these subgraphs.
+ //
Map operatesOn = new HashMap();
- StmtIterator it =
- model.listStatements(headResource, MOBY.operatesOn, (RDFNode) null);
+
+ StmtIterator it = model.listStatements(
+ headResource, MOBY.operatesOn, (RDFNode) null);
+
while (it.hasNext())
{
Statement operatesOnStmt = it.nextStatement();
@@ -237,6 +240,7 @@
if (isGraph(res))
{
// Throw an exception if it is also a data structure
+ //
if (isDataStructure(res))
{
throw new NonCanonicalException(
@@ -245,22 +249,24 @@
}
// The defining statement for the MOBYGraph instance
+ //
Statement typeStmt = model.listStatements(
res, RDF.type, MOBY.Graph).nextStatement();
-
- // The statement that asserts the hasMapping property
+
+ // Since the resource is a MOBY Graph, it should have exactly one
+ // hasMapping property that leads to its mapping subgraph.
+ //
Statement hasMappingStmt = model.listStatements(
res, MOBY.hasMapping, (RDFNode) null).nextStatement();
- // Since the resource is a MOBY Graph, it should have exactly one
- // hasMapping property that leads to its mapping subgraph.
- Resource hasMapping = getResourcePropertyValue(res, MOBY.hasMapping);
+ Resource hasMappingObject = (Resource) hasMappingStmt.getObject();
return new MOBYGraph(model, typeStmt, hasMappingStmt,
- parseHasMapping(hasMapping));
+ parseHasMapping(hasMappingObject));
}
else
{
// Throw an exception if it is also a graph
+ //
if (isGraph(res))
{
throw new NonCanonicalException(
@@ -272,6 +278,7 @@
// data structure. Iterate through the data structure elements,
// parsing a mapping subgraph from each by recursively calling
// this method.
+ //
Iterator it = iteratorFor(res);
List subgraphs = new ArrayList();
while (it.hasNext())
@@ -282,6 +289,7 @@
// Create and return a collection of the subgraphs; the type
// of the collection depends on the type of the passed resource
+ //
return collectionFor(res, subgraphs);
}
}
@@ -301,6 +309,7 @@
// It is *not* legal for the object of a hasMapping to be *neither*
// a Subject nor a data structure, so throw an exception if this is
// the case.
+ //
if ((! isSubject(res)) && (! isDataStructure(res)))
{
throw new NonCanonicalException(
@@ -310,18 +319,22 @@
// Collect the properties of this subject that are
// meant to be filled in by the client
+ //
List propValStmts = mobyPropertyStatementsOf(res);
// List of direct mappings, i.e. those related through hasMapping
// properties.
+ //
Map directMappings = new HashMap();
// List of nested hasMapping subgraphs
+ //
List nestedMappings = new ArrayList();
// The statement that asserts this to be of rdf:type moby:Subject.
// Since it is legal for this to not be a Subject, then the statement
// can be null
+ //
Statement typeStmt = null;
if (isSubject(res))
@@ -331,14 +344,17 @@
// The resource is a MOBY Subject, so should have one or more
// mapsTo properties that lead to its mapped subgraphs.
+ //
List mapsTo = new ArrayList();
+
StmtIterator it =
model.listStatements(res, MOBY.mapsTo, (RDFNode) null);
+
while (it.hasNext())
{
Statement mapsToStmt = it.nextStatement();
- Resource mapsToSubject = mapsToStmt.getResource();
- MOBYGraphNode object = parseMapsTo(mapsToSubject);
+ Resource mapsToObject = (Resource) mapsToStmt.getObject();
+ MOBYGraphNode object = parseMapsTo(mapsToObject);
directMappings.put(object, mapsToStmt);
}
}
@@ -349,6 +365,7 @@
// nested in each element. For each element in the data structure,
// recursively call this method to create a mapping subgraph, an
// save the parsed object in the nestedMappings list.
+ //
Iterator it = iteratorFor(res);
while (it.hasNext())
{
@@ -360,13 +377,12 @@
return new MOBYSubject(model, typeStmt, propValStmts, directMappings,
collectionFor(res, nestedMappings));
}
-
+
/**
- * Parse the object of an mapsTo statement, which should be a
- * Subject, a data structure, or both. If the object is a Subject,
- * then it should be connected to one or more mapped subgraphs through
- * mapsTo properties. If the object is a data structure, then
- * each element of the data structure should be a mapped subgraph.
+ * Parse the object of a mapsTo statement, which should be an
+ * Object, a data structure, or both. If the object is a data
+ * structure, then each element of the data structure should
+ * in turn be an Object, a data structure, or both.
*/
private MOBYObject parseMapsTo(Resource res)
throws NonCanonicalException
@@ -376,6 +392,7 @@
// It is *not* legal for the object of a mapsTo to be *neither*
// an Object nor a data structure, so throw an exception if this is
// the case.
+ //
if ((! isObject(res)) && (! isDataStructure(res)))
{
throw new NonCanonicalException(
@@ -385,14 +402,17 @@
// Collect the properties of this subject that are
// meant to be filled in by the client
+ //
List propValStmts = mobyPropertyStatementsOf(res);
// List of nested Object subgraphs
+ //
List nestedObjects = new ArrayList();
// The statement that asserts this to be of rdf:type moby:Object.
// Since it is legal for this to not be an Object, then the statement
// can be null
+ //
Statement typeStmt = null;
if (isObject(res))
@@ -407,6 +427,7 @@
// nested in each element. For each element in the data structure,
// recursively call this method to create a mapping subgraph, an
// save the parsed object in the nestedMappings list.
+ //
Iterator it = iteratorFor(res);
while (it.hasNext())
{
@@ -418,66 +439,28 @@
return new MOBYObject(model, typeStmt, propValStmts,
collectionFor(res, nestedObjects));
}
-
-
- /**
- * Parse the object of a mapsTo statement, which should be an
- * Object, a data structure, or both. If the object is a data
- * structure, then each element of the data structure should
- * in turn be an Object, a data structure, or both.
- */
- /*
- private MOBYObject parseMapsTo(Resource res)
- {
- Model model = res.getModel();
-
- // Collect the properties of this object that are
- // meant to be filled in by the service
- List statements = mobyPropertyStatementsOf(res);
-
- // List of nested mapsTo statements
- //
- List nested = new ArrayList();
-
- if (isDataStructure(res))
- {
- // The resource is a data structure, so has a mapping subgraph
- // nested in each element. For each element in the data structure,
- // recursively call this method to create a mapping subgraph, and
- // save the parsed object in the nested list.
- //
- Iterator it = iteratorFor(res);
- while (it.hasNext())
- {
- Resource r = (Resource) it.next();
- nested.add(parseMapsTo(r));
- }
- }
- return new MOBYObject(res,
- new MOBYFixedCollection(statements, res, model),
- collectionFor(res, nested), model);
- }
- */
/**
* Return a list of statements for whom the subject is a given resource,
- * whose predicate is a subproperty of moby:Property, and whose object
- * is a blank node.
+ * whose predicate is a subproperty of moby:Property.
*/
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())
{
Statement stmt = it.nextStatement();
- if (stmt.getObject().isAnon() &&
- !propDetector.isMOBYProperty(stmt.getPredicate()))
- {
- stmts.add(stmt);
+ Property property = stmt.getPredicate();
+
+ if (propDetector.isMOBYProperty(property)) {
+ stmts.add(new MOBYPropValStmt(res.getModel(), stmt));
+ System.out.println("MOBY Property: " + property);
}
}
return stmts;
More information about the MOBY-guts
mailing list