Revision: 1302
http://obo.svn.sourceforge.net/obo/?rev=1302&view=rev
Author: cmungall
Date: 2007-12-10 17:56:57 -0800 (Mon, 10 Dec 2007)
Log Message:
-----------
Modified Paths:
--------------
obdapi/trunk/OBDAPI/src/org/obd/model/Graph.java
obdapi/trunk/OBDAPI/src/org/obd/model/LinkStatement.java
obdapi/trunk/OBDAPI/src/org/obd/model/LiteralStatement.java
obdapi/trunk/OBDAPI/src/org/obd/model/Node.java
obdapi/trunk/OBDAPI/src/org/obd/model/Statement.java
obdapi/trunk/OBDAPI/src/org/obd/model/bridge/OBOBridge.java
obdapi/trunk/OBDAPI/src/org/obd/query/GraphQuery.java
obdapi/trunk/OBDAPI/src/org/obd/ws/OBDQueryService.java
Added Paths:
-----------
obdapi/trunk/OBDAPI/src/org/obd/model/InstanceQuantifier.java
obdapi/trunk/OBDAPI/src/org/obd/model/NestedCompositionalDescription.java
obdapi/trunk/OBDAPI/src/org/obd/query/AtomicQueryTerm.java
obdapi/trunk/OBDAPI/src/org/obd/query/ComparisonQueryTerm.java
obdapi/trunk/OBDAPI/src/org/obd/query/LinkQueryTerm.java
obdapi/trunk/OBDAPI/src/org/obd/query/LiteralQueryTerm.java
obdapi/trunk/OBDAPI/src/org/obd/query/QueryTerm.java
obdapi/trunk/OBDAPI/src/org/obd/query/Shard.java
obdapi/trunk/OBDAPI/src/org/obd/query/impl/
obdapi/trunk/OBDAPI/src/org/obd/query/impl/AbstractShard.java
obdapi/trunk/OBDAPI/src/org/obd/query/impl/MultiShard.java
obdapi/trunk/OBDAPI/src/org/obd/query/impl/MutableOBOSessionShard.java
obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBDSQLShard.java
obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBOSessionShard.java
obdapi/trunk/OBDAPI/src/org/obd/test/AnnotationGraphTest.java
obdapi/trunk/OBDAPI/src/org/obd/test/MiniTest.java
obdapi/trunk/OBDAPI/src/org/obd/test/MultiNodeFetchTest.java
obdapi/trunk/OBDAPI/src/org/obd/test/QueryTest.java
obdapi/trunk/OBDAPI/src/org/obd/test/SearchTest.java
Removed Paths:
-------------
obdapi/trunk/OBDAPI/src/org/obd/model/Shard.java
obdapi/trunk/OBDAPI/src/org/obd/model/impl/MultiShard.java
obdapi/trunk/OBDAPI/src/org/obd/model/impl/MutableOBOSessionShard.java
obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBDSQLShard.java
obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBOSessionShard.java
obdapi/trunk/OBDAPI/src/org/obd/test/OBDQueryServiceTest.java
Modified: obdapi/trunk/OBDAPI/src/org/obd/model/Graph.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/Graph.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/Graph.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -48,6 +48,8 @@
nids.add(s.getNodeId());
nids.add(s.getTargetId());
nids.add(s.getRelationId());
+ if (s.getPositedByNodeId() != null)
+ nids.add(s.getPositedByNodeId());
}
return (String[]) nids.toArray(new String[0]);
}
@@ -62,7 +64,7 @@
nodeMap.put(n.getId(), n);
}
public void addNodes(Node[] nodeArr) {
- LinkedList<Node> nodes = new LinkedList<Node>();
+ HashSet<Node> nodes = new HashSet<Node>();
nodes.addAll(Arrays.asList(nodeArr));
addNodes(nodes);
}
@@ -87,7 +89,7 @@
* or not
*/
private Statement[] getAllStatements() {
- LinkedList<Statement> statements = new LinkedList<Statement>();
+ HashSet<Statement> statements = new HashSet<Statement>();
statements.addAll(Arrays.asList(getStatements()));
for (Node n : getNodes()) {
statements.addAll(Arrays.asList(n.getStatements()));
@@ -108,7 +110,7 @@
public void addStatements(Collection<Statement> newStatements) {
if (statements == null)
- statements = new LinkedList<Statement>();
+ statements = new HashSet<Statement>();
statements.addAll(newStatements);
}
@@ -119,7 +121,7 @@
public void clearStatements() {
- statements = new LinkedList<Statement>();
+ statements = new HashSet<Statement>();
}
// shift to frame-style
Added: obdapi/trunk/OBDAPI/src/org/obd/model/InstanceQuantifier.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/InstanceQuantifier.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/InstanceQuantifier.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,36 @@
+package org.obd.model;
+
+public class InstanceQuantifier {
+
+ protected boolean isExistential;
+ protected boolean isUniversal;
+ protected int minCardinality;
+ protected int maxCardinality;
+
+ public boolean isExistential() {
+ return isExistential;
+ }
+ public void setExistential(boolean isExistential) {
+ this.isExistential = isExistential;
+ }
+ public boolean isUniversal() {
+ return isUniversal;
+ }
+ public void setUniversal(boolean isUniversal) {
+ this.isUniversal = isUniversal;
+ }
+ public int getMaxCardinality() {
+ return maxCardinality;
+ }
+ public void setMaxCardinality(int maxCardinality) {
+ this.maxCardinality = maxCardinality;
+ }
+ public int getMinCardinality() {
+ return minCardinality;
+ }
+ public void setMinCardinality(int minCardinality) {
+ this.minCardinality = minCardinality;
+ }
+
+
+}
Modified: obdapi/trunk/OBDAPI/src/org/obd/model/LinkStatement.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/LinkStatement.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/LinkStatement.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -3,11 +3,11 @@
public class LinkStatement extends Statement {
protected boolean appliesToAllInstancesOf;
- protected boolean isExistential;
- protected boolean isUniversal;
protected boolean hasIntersectionSemantics;
protected boolean hasUnionSemantics;
+ protected InstanceQuantifier instanceQuantifier;
+
public boolean isAppliesToAllInstancesOf() {
return appliesToAllInstancesOf;
}
@@ -15,16 +15,26 @@
this.appliesToAllInstancesOf = appliesToAllInstancesOf;
}
public boolean isExistential() {
- return isExistential;
+ if (instanceQuantifier == null)
+ return false;
+ else
+ return instanceQuantifier.isExistential();
}
public void setExistential(boolean isExistential) {
- this.isExistential = isExistential;
+ if (instanceQuantifier == null)
+ instanceQuantifier = new InstanceQuantifier();
+ instanceQuantifier.setExistential(isExistential);
}
public boolean isUniversal() {
- return isUniversal;
+ if (instanceQuantifier == null)
+ return false;
+ else
+ return instanceQuantifier.isUniversal();
}
public void setUniversal(boolean isUniversal) {
- this.isUniversal = isUniversal;
+ if (instanceQuantifier == null)
+ instanceQuantifier = new InstanceQuantifier();
+ instanceQuantifier.setUniversal(isUniversal);
}
public boolean isHasIntersectionSemantics() {
return hasIntersectionSemantics;
@@ -45,4 +55,10 @@
s = s + " [^]";
return s;
}
+ public InstanceQuantifier getInstanceQuantifier() {
+ return instanceQuantifier;
+ }
+ public void setInstanceQuantifier(InstanceQuantifier instanceQuantifier) {
+ this.instanceQuantifier = instanceQuantifier;
+ }
}
Modified: obdapi/trunk/OBDAPI/src/org/obd/model/LiteralStatement.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/LiteralStatement.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/LiteralStatement.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -24,4 +24,10 @@
this.value = value;
}
+ public String toString() {
+ String s = super.toString();
+ s = s + " "+getValue();
+ return s;
+ }
+
}
Added: obdapi/trunk/OBDAPI/src/org/obd/model/NestedCompositionalDescription.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/NestedCompositionalDescription.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/NestedCompositionalDescription.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,18 @@
+package org.obd.model;
+
+import java.util.Collection;
+
+public class NestedCompositionalDescription {
+ public enum DescriptionType { INTERSECTION, UNION, COMPLEMENT, RESTRICTION, ATOM }
+
+ protected DescriptionType type;
+ protected Collection<NestedCompositionalDescription> children;
+
+ public DescriptionType xxxgetType() {
+ if (children.size() == 0)
+ return DescriptionType.ATOM;
+ return null;
+ }
+
+
+}
Modified: obdapi/trunk/OBDAPI/src/org/obd/model/Node.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/Node.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/Node.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -19,7 +19,7 @@
public Node() {
- statements = new LinkedList<Statement>();
+ statements = new HashSet<Statement>();
}
public String getId() {
@@ -65,6 +65,13 @@
statements = new HashSet<Statement>();
statements.add(statement);
}
+
+ public void addStatements(Collection<Statement> newStatements) {
+ if (statements == null)
+ statements = new HashSet<Statement>();
+ statements.addAll(newStatements);
+ }
+
public void clearStatements() {
statements = new LinkedList<Statement>();
}
@@ -94,6 +101,9 @@
return s;
}
+ public int hashCode() {
+ return id.hashCode();
+ }
Deleted: obdapi/trunk/OBDAPI/src/org/obd/model/Shard.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/Shard.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/Shard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -1,51 +0,0 @@
-package org.obd.model;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.obd.model.bridge.OBOBridge;
-import org.obd.model.stats.AggregateStatisticCollection;
-import org.obo.datamodel.IdentifiedObject;
-
-public interface Shard {
-
- public enum EntailmentUse {
- USE_ASSERTED,
- USE_IMPLIED,
- FULL_TRANSITIVE_CLOSURE
- }
- public enum GraphExpansionAlgorithm {
- MINIMAL,
- INCLUDE_SUBGRAPH
- }
-
- public Node getNode(String id);
- public Collection<Node> getNodes();
- public Collection<Node> getNodes(String sourceId);
- public Collection<Node> getSourceNodes();
-
- //public Statement getStatement(String id);
- public Collection<Statement> getStatements(String sourceId);
-
- public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id,
- EntailmentUse entailment, GraphExpansionAlgorithm strategy);
- public Graph getAnnotationGraphAroundNode(String id,
- EntailmentUse entailment, GraphExpansionAlgorithm gea);
-
- public Collection<Statement> getStatementsForNode(String id);
- public Collection<Statement> getStatementsForNodeWithSource(String id, String sourceId);
- public Collection<Statement> getStatementsForTarget(String id);
- public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId);
-
- public Collection<Statement> getStatements(String nodeId,
- String relationId, String targetId, String sourceId,
- Boolean useImplied, Boolean isReified);
-
- public Collection<Statement> getSubjectStatements(String subjectId,
- String subjectRelationId, String targetRelationId,
- String nodeId, String targetId,
- String subjectSourceId, String nodeSourceId,
- Boolean useImplied, Boolean isReified);
-
- public AggregateStatisticCollection getSummaryStatistics();
-}
Modified: obdapi/trunk/OBDAPI/src/org/obd/model/Statement.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/Statement.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/Statement.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -56,7 +56,12 @@
if (isImplied)
s = s + " [Implied]";
if (positedByNodeId != null)
- s = s + "positedBy:"+positedByNodeId;
+ s = s + " positedBy:"+positedByNodeId;
return s;
}
+
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
}
Modified: obdapi/trunk/OBDAPI/src/org/obd/model/bridge/OBOBridge.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/bridge/OBOBridge.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/bridge/OBOBridge.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -3,8 +3,10 @@
import org.obd.model.LinkStatement;
import org.obd.model.LiteralStatement;
import org.obd.model.Node;
+import org.obd.model.NodeAlias;
import org.obd.model.Statement;
import org.obo.annotation.datamodel.Annotation;
+import org.obo.datamodel.DefinedObject;
import org.obo.datamodel.IdentifiedObject;
import org.obo.datamodel.Link;
import org.obo.datamodel.LinkedObject;
@@ -44,12 +46,22 @@
}
if (io instanceof SynonymedObject) {
for (Synonym s : ((SynonymedObject)io).getSynonyms()) {
- LiteralStatement ls = new LiteralStatement();
+ LiteralStatement ls = new NodeAlias();
ls.setNodeId(node.getId());
ls.setValue(s.getText());
node.addStatement(ls);
}
}
+ if (io instanceof DefinedObject) {
+ String def = ((DefinedObject)io).getDefinition();
+ if (def != null) {
+ LiteralStatement ls = new LiteralStatement();
+ ls.setNodeId(node.getId());
+ ls.setValue(def);
+ ls.setRelationId("definition");
+ node.addStatement(ls);
+ }
+ }
return node;
}
Deleted: obdapi/trunk/OBDAPI/src/org/obd/model/impl/MultiShard.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/impl/MultiShard.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/impl/MultiShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -1,149 +0,0 @@
-package org.obd.model.impl;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.obd.model.Graph;
-import org.obd.model.Node;
-import org.obd.model.Shard;
-import org.obd.model.Statement;
-import org.obd.model.Shard.EntailmentUse;
-import org.obd.model.Shard.GraphExpansionAlgorithm;
-import org.obd.model.stats.AggregateStatistic;
-import org.obd.model.stats.AggregateStatisticCollection;
-
-public class MultiShard implements Shard {
-
- Collection<Shard> shards = new HashSet<Shard>();
-
- public Node getNode(String id) {
- System.out.println("ms getNode: "+id);
- for (Shard s : shards) {
- Node n = s.getNode(id);
- System.out.println(s+" "+n);
- if (n != null)
- return n;
- }
- return null;
- }
-
- public Collection<Node> getNodes() {
- HashSet<Node> nodes = new HashSet<Node>();
- for (Shard s : shards)
- nodes.addAll(s.getNodes());
- return nodes;
- }
-
- public Collection<Node> getNodes(String sourceId) {
- HashSet<Node> nodes = new HashSet<Node>();
- for (Shard s : shards)
- nodes.addAll(s.getNodes(sourceId));
- return nodes;
- }
-
-
-
- public Collection<Statement> getStatements(String sourceId) {
- HashSet<Statement> statements = new HashSet<Statement>();
- for (Shard s : shards)
- statements.addAll(s.getStatements(sourceId));
- return statements;
- }
-
- public Collection<Statement> getStatementsForTarget(String id) {
- HashSet<Statement> statements = new HashSet<Statement>();
- for (Shard s : shards)
- statements.addAll(s.getStatementsForTarget(id));
- return statements;
- }
- public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId) {
- HashSet<Statement> statements = new HashSet<Statement>();
- for (Shard s : shards)
- statements.addAll(s.getStatementsForTargetWithSource(id, sourceId));
- return statements;
- }
-
- public Collection<Shard> getShards() {
- return shards;
- }
-
- public void setShards(Collection<Shard> shards) {
- this.shards = shards;
- }
-
- public void addShard(Shard shard) {
- if (shards == null)
- shards = new HashSet<Shard>();
- shards.add(shard);
- }
-
- public Collection<Statement> getStatementsForNode(String id) {
- HashSet<Statement> statements = new HashSet<Statement>();
- System.out.println("getting parents for="+id);
- for (Shard s : shards)
- statements.addAll(s.getStatementsForNode(id));
- return statements;
- }
-
- public Collection<Statement> getStatementsForNodeWithSource(String id, String sourceId) {
- HashSet<Statement> statements = new HashSet<Statement>();
- for (Shard s : shards)
- statements.addAll(s.getStatementsForNodeWithSource(id, sourceId));
- return statements;
- }
-
-
- public Collection<Statement> getStatements(String nodeId, String relationId, String targetId, String sourceId, Boolean useImplied, Boolean isReified) {
- HashSet<Statement> statements = new HashSet<Statement>();
- for (Shard s : shards)
- statements.addAll(s.getStatements(nodeId,
- relationId, targetId, sourceId, useImplied, isReified));
- return statements;
- }
-
- public Collection<Statement> getSubjectStatements(String subjectId, String subjectRelationId, String targetRelationId, String nodeId, String targetId, String subjectSourceId, String nodeSourceId, Boolean useImplied, Boolean isReified) {
- HashSet<Statement> statements = new HashSet<Statement>();
- for (Shard s : shards)
- statements.addAll(s.getSubjectStatements( subjectId,
- subjectRelationId, targetRelationId, nodeId, targetId,
- subjectSourceId, nodeSourceId, useImplied, isReified));
-
- return statements;
- }
-
- public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id, EntailmentUse entailment, GraphExpansionAlgorithm strategy) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Graph getAnnotationGraphAroundNode(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
- Graph g = new Graph();
- for (Shard s : shards)
- g.merge(s.getAnnotationGraphAroundNode(id, entailment, gea));
- return g;
-
- }
-
-
- public Collection<Node> getSourceNodes() {
- HashSet<Node> nodes = new HashSet<Node>();
- for (Shard s : shards)
- nodes.addAll(s.getSourceNodes());
- return nodes;
- }
-
- public AggregateStatisticCollection getSummaryStatistics() {
- AggregateStatisticCollection combinedStats = new AggregateStatisticCollection();
- for (Shard s : shards) {
- AggregateStatisticCollection sc = s.getSummaryStatistics();
- Collection<AggregateStatistic> stats;
- if (sc != null) {
- stats = sc.getStats();
- combinedStats.getStats().addAll(stats);
- }
- }
- return combinedStats;
- }
-
-
-}
Deleted: obdapi/trunk/OBDAPI/src/org/obd/model/impl/MutableOBOSessionShard.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/impl/MutableOBOSessionShard.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/impl/MutableOBOSessionShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -1,29 +0,0 @@
-package org.obd.model.impl;
-
-import org.bbop.dataadapter.DataAdapterException;
-import org.obo.dataadapter.OBOAdapter;
-import org.obo.dataadapter.OBOFileAdapter;
-
-public class MutableOBOSessionShard extends OBOSessionShard {
-
- public int loadLocal(String ontName) throws DataAdapterException {
- String path = "/users/cjm/obo-all/"+ontName+"/"+ontName+".obo";
- return loadFile(path);
- }
- public int load(String ontName) throws DataAdapterException {
- String path = "http://purl.org/obo/obo-all/"+ontName+"/"+ontName+".obo";
- return loadFile(path);
- }
- public int loadFile(String path) throws DataAdapterException {
- OBOFileAdapter.OBOAdapterConfiguration config = new OBOFileAdapter.OBOAdapterConfiguration();
- config.getReadPaths().add(path);
-
- config.setAllowDangling(true);
- config.setBasicSave(false);
- config.setFailFast(false);
- session = adapter.doOperation(OBOAdapter.READ_ONTOLOGY, config,
- null);
- return session.getObjects().size();
- }
-
-}
Deleted: obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBDSQLShard.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBDSQLShard.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBDSQLShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -1,417 +0,0 @@
-package org.obd.model.impl;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-
-import org.bbop.rdbms.RelationalQuery;
-import org.bbop.rdbms.WhereClause;
-import org.bbop.rdbms.impl.SqlQueryImpl;
-import org.bbop.rdbms.impl.SqlWhereClauseImpl;
-import org.obd.model.Graph;
-import org.obd.model.Node;
-import org.obd.model.Shard;
-import org.obd.model.Statement;
-import org.obd.model.bridge.OBOBridge;
-import org.obd.model.stats.AggregateStatisticCollection;
-import org.obd.query.GraphQuery;
-import org.obo.annotation.datamodel.Annotation;
-import org.obo.dataadapter.OBDSQLDatabaseAdapter;
-import org.obo.dataadapter.OBOFileAdapter;
-import org.obo.dataadapter.OBDSQLDatabaseAdapter.OBDSQLDatabaseAdapterConfiguration;
-import org.obo.datamodel.IdentifiedObject;
-import org.obo.datamodel.Link;
-import org.obo.datamodel.LinkedObject;
-import org.obo.datamodel.OBOSession;
-import org.obo.datamodel.impl.DanglingLinkImpl;
-import org.obo.datamodel.impl.OBOSessionImpl;
-
-/**
- * @author cjm
- *
- */
-public class OBDSQLShard implements Shard {
-
- OBDSQLDatabaseAdapter obd = new OBDSQLDatabaseAdapter();
- OBDSQLDatabaseAdapterConfiguration obdconfig =
- new OBDSQLDatabaseAdapter.OBDSQLDatabaseAdapterConfiguration();
-
- protected OBOSession session =
- new OBOSessionImpl(); // TODO: remove? need it for tracking namespaces etc
-
- public OBDSQLShard() throws SQLException, ClassNotFoundException {
- }
-
- public void connect(String jdbcPath) throws SQLException, ClassNotFoundException {
- obdconfig.getReadPaths().add(jdbcPath);
- obd = new OBDSQLDatabaseAdapter();
- obd.setConfiguration(obdconfig);
- obd.connect();
- }
-
- public String getID() {
- return "OBD-Query-Service"; // TODO: introspect metadata
- }
-
-
-
- public Node getNode(String id) {
- RelationalQuery q = new SqlQueryImpl();
- q.addTable("node_with_source");
- WhereClause whereClause = q.getWhereClause();
- whereClause.addEqualityConstraint("uid", id);
- Node n = null;
- try {
- ResultSet rs = execute(q);
- if (rs.next()) {
- IdentifiedObject lo = obd.fetchObject(session, rs);
- n = OBOBridge.obj2node(lo);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return n;
- }
-
- public Collection<Node> getNodes(String sourceId) {
- Collection<Node> nodes = new LinkedList<Node>();
- RelationalQuery q = new SqlQueryImpl();
- q.addTable("node_with_source");
- WhereClause whereClause = q.getWhereClause();
- if (sourceId != null)
- whereClause.addEqualityConstraint("source_uid", sourceId);
- Node n = null;
- try {
- ResultSet rs = execute(q);
- while (rs.next()) {
- IdentifiedObject io = obd.fetchObject(session, rs);
- nodes.add(OBOBridge.obj2node(io));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return nodes;
- }
-
- public Collection<Node> getNodes() {
- return getNodes(null);
- }
-
- public Collection<Node> getSourceNodes() {
- Collection<Node> nodes = new LinkedList<Node>();
- RelationalQuery q = new SqlQueryImpl();
- q.addTable("source_node");
- WhereClause whereClause = q.getWhereClause();
- Node n = null;
- try {
- ResultSet rs = execute(q);
- while (rs.next()) {
- IdentifiedObject io = obd.fetchObject(session, rs);
- nodes.add(OBOBridge.obj2node(io));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return nodes;
- }
-
- public Collection<Statement> getStatements() {
- // TODO Auto-generated method stub
- return new HashSet<Statement>();
- }
-
-
-
- public Collection<Statement> getStatements(String ns) {
- WhereClause whereClause = new SqlWhereClauseImpl();
- if (ns != null) {
- whereClause.addEqualityConstraint("source_uid",ns);
- }
- return getStatements(whereClause);
- }
-
- public Collection<Statement> getStatements(WhereClause whereClause) {
- HashSet<Statement> statements = new HashSet<Statement>();
- try {
- for (Link link : obd.fetchLinks(whereClause)) {
- statements.add(OBOBridge.link2statement(link));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return statements;
-
- }
-
-
-
- public Collection<Statement> getStatementsForTarget(String id) {
-
- HashSet<Statement> statements = new HashSet<Statement>();
- try {
- for (Link link : obd.fetchLinksByObject(id)) {
- statements.add(OBOBridge.link2statement(link));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return statements;
- }
-
- public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId) {
- HashSet<Statement> statements = new HashSet<Statement>();
- System.out.println("id="+id+" src="+sourceId);
- try {
- for (Link link : obd.fetchLinksByObject(id, sourceId)) {
- statements.add(OBOBridge.link2statement(link));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return statements;
- }
-
- /**
- * @param id
- * @return All statements whose target is subsumed by id
- * @throws Exception
- */
- public Collection<Statement> getStatementsAround(String id) throws Exception {
-
- WhereClause whereClause = new SqlWhereClauseImpl();
- whereClause.addConstraint("object_uid in "+
- "(SELECT node_id FROM link_to_node WHERE object_uid ='"+id+"')");
- return getStatements(whereClause);
- }
-
-
-
-
- public Collection<Statement> getStatementsForNode(String id) {
- WhereClause whereClause = new SqlWhereClauseImpl();
- whereClause.addEqualityConstraint("node_uid",id);
- return getStatements(whereClause);
- }
-
- public Collection<Statement> getStatementsForNode(String id, boolean useImplied) {
- WhereClause whereClause = new SqlWhereClauseImpl();
- whereClause.addEqualityConstraint("node_uid",id);
- if (!useImplied)
- whereClause.addEqualityConstraint("is_inferred",false);
- return getStatements(whereClause);
- }
-
-
- public Collection<Statement> getStatementsForNodeWithSource(String id, String ns) {
- WhereClause whereClause = new SqlWhereClauseImpl();
- whereClause.addEqualityConstraint("node_uid",id);
- if (ns != null) {
- whereClause.addEqualityConstraint("source_uid",ns);
- }
- return getStatements(whereClause);
- }
-
- public Collection<Statement> getStatements(String nodeId,
- String relationId, String targetId, String sourceId,
- Boolean useImplied, Boolean isReified) {
- WhereClause whereClause = new SqlWhereClauseImpl();
- if (nodeId != null)
- whereClause.addEqualityConstraint("node_uid",nodeId);
- if (relationId != null)
- whereClause.addEqualityConstraint("pred_uid",relationId);
- if (targetId != null)
- whereClause.addEqualityConstraint("object_uid",targetId);
- if (sourceId != null)
- whereClause.addEqualityConstraint("source_uid",sourceId);
- if (useImplied != null)
- whereClause.addEqualityConstraint("is_inferred",useImplied);
- if (isReified)
- whereClause.addConstraint("reiflink_node_id IS NOT NULL");
- return getStatements(whereClause);
- }
-
- public Collection<Statement> getSubjectStatements(String subjectId,
- String subjectRelationId, String targetRelationId,
- String nodeId, String targetId,
- String subjectSourceId, String nodeSourceId,
- Boolean useImplied, Boolean isReified) {
-
- System.out.println("getSubjectStatements "+subjectId+","+
- subjectRelationId +","+ targetRelationId +"," + nodeId +","+ targetId + "," +
- subjectSourceId + ","+ nodeSourceId +","+ useImplied +","+ isReified);
-
- WhereClause whereClause = new SqlWhereClauseImpl();
- if (subjectId != null && !subjectId.equals(""))
- whereClause.addEqualityConstraint("node_uid",subjectId);
- if (subjectRelationId != null && !subjectRelationId.equals(""))
- whereClause.addEqualityConstraint("pred_uid",subjectRelationId);
- if (nodeId != null && !nodeId.equals(""))
- whereClause.addEqualityConstraint("node_uid",nodeId);
- if (subjectSourceId != null && !subjectSourceId.equals(""))
- whereClause.addEqualityConstraint("source_uid",subjectSourceId);
- if (isReified != null && isReified)
- whereClause.addConstraint("reiflink_node_id IS NOT NULL");
-
- RelationalQuery subQuery = new SqlQueryImpl();
- subQuery.getSelectClause().addColumn("node_uid");
- subQuery.addTable("node_link_node_with_pred_and_source");
- WhereClause subWhereClause = new SqlWhereClauseImpl();
- subQuery.setWhereClause(subWhereClause);
-
- if (targetId != null && !targetId.equals(""))
- subWhereClause.addEqualityConstraint("object_uid",targetId);
- if (nodeSourceId != null && !nodeSourceId.equals(""))
- subWhereClause.addEqualityConstraint("source_uid",nodeSourceId);
- if (targetRelationId != null && !targetRelationId.equals(""))
- subWhereClause.addEqualityConstraint("pred_uid",targetRelationId);
- if (useImplied != null && !useImplied.equals(""))
- subWhereClause.addEqualityConstraint("is_inferred",useImplied);
-
- whereClause.addInConstraint("object_uid", subQuery);
- return getStatements(whereClause);
-
- }
-
-
-
-
-
-
-
-
-
- public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id, EntailmentUse entailment, GraphExpansionAlgorithm strategy) {
-
- // node_uid is the annotated entity - find everything about it -
- // both additional metadata and annotation
- WhereClause whereClause = new SqlWhereClauseImpl();
- whereClause.addEqualityConstraint("node_uid",id);
- Collection<Statement> annots = getStatements(whereClause);
- return annots;
- }
-
- public Graph getAnnotationGraphAroundNode(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
-
- // find graph around node, outwards
- Collection<Statement> stmts;
- if (gea == null || gea.equals(GraphExpansionAlgorithm.INCLUDE_SUBGRAPH)) {
- Graph sg = getSubgraph(id, entailment, gea);
- stmts = Arrays.asList(sg.getStatements());
- }
- else
- stmts = new LinkedList<Statement>(); // TODO: minimal info?
-
-
- // find all annotations to id
- WhereClause whereClause = new SqlWhereClauseImpl();
- if (true || entailment == null) {
- // currently this is under-constrained
- // will fetch the full graph;
- // G has_role* X and X R* Y, where Y is ground
- /*
- * we actually want
- * G has_role X, X Rmd MD, X R* Y
- */
- RelationalQuery subQuery = new SqlQueryImpl();
- subQuery.getSelectClause().addColumn("node_uid");
- subQuery.addTable("node_link_node_with_pred_and_source");
- WhereClause subWhereClause = new SqlWhereClauseImpl();
- subWhereClause.addEqualityConstraint("object_uid",id);
- subQuery.setWhereClause(subWhereClause);
-
- whereClause.addInConstraint("object_uid",subQuery);
- whereClause.addEqualityConstraint("is_inferred", false);
- }
- else {
- // TODO: only works in annot links are inlcuded in deductive closure
- whereClause.addEqualityConstraint("object_uid",id);
- }
- //whereClause.addConstraint("reiflink_node_id IS NOT NULL");
- Collection<Statement> annots = getStatements(whereClause);
- Graph g = new Graph(annots);
- for (String nid : g.getReferencedNodeIds()) {
- Node n = getNode(nid);
- g.addNode(n);
- Collection<Statement> mdLinks = getStatementsForNode(nid,false);
- g.addStatements(mdLinks);
- }
- g.addStatements(stmts);
- g.nestStatementsUnderNodes();
- return g;
-
- }
-
- public Graph getSubGraphUsingQuery(GraphQuery gq) {
-
- WhereClause whereClause = new SqlWhereClauseImpl();
-
- // node_uid is the ontology - find full DAG
- whereClause.addEqualityConstraint("node_uid",gq.getNodeId());
- Collection<Statement> stmts = getStatements(whereClause);
- Graph g = new Graph(stmts);
- return g;
- }
-
- public Graph getSubgraph(String nodeId, EntailmentUse entailment,
- GraphExpansionAlgorithm gea) {
-
- WhereClause whereClause = new SqlWhereClauseImpl();
- whereClause.addEqualityConstraint("node_uid",nodeId);
-
- RelationalQuery subQuery = new SqlQueryImpl();
- subQuery.getSelectClause().addColumn("node_uid");
- subQuery.addTable("node_link_node_with_pred_and_source");
- WhereClause subWhereClause = new SqlWhereClauseImpl();
- subQuery.setWhereClause(subWhereClause);
- Collection<Statement> stmts = getStatements(whereClause);
- Graph g = new Graph(stmts);
- return g;
- }
-
- public AggregateStatisticCollection getSummaryStatistics() {
- AggregateStatisticCollection sc = new AggregateStatisticCollection();
-
- RelationalQuery q = new SqlQueryImpl();
- q.addTable("source_summary");
- ResultSet rs;
- try {
- rs = execute(q);
- while (rs.next()) {
- String src = rs.getString("uid");
- Integer nc = rs.getInt("node_count");
- sc.setCount("node", src, nc);
- Integer lc = rs.getInt("link_count");
- sc.setCount("link", src, lc);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return sc;
- }
-
- // UTIL
-
- public ResultSet execute(RelationalQuery q) throws SQLException {
- ResultSet rs = q.execute(obd.getConnection());
- return rs;
- }
-
-
-
-
-
-
-
-
-}
Deleted: obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBOSessionShard.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBOSessionShard.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBOSessionShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -1,183 +0,0 @@
-package org.obd.model.impl;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.logging.Logger;
-
-import org.obd.model.Graph;
-import org.obd.model.Node;
-import org.obd.model.Shard;
-import org.obd.model.Statement;
-import org.obd.model.Shard.EntailmentUse;
-import org.obd.model.Shard.GraphExpansionAlgorithm;
-import org.obd.model.bridge.OBOBridge;
-import org.obd.model.stats.AggregateStatisticCollection;
-import org.obd.model.stats.MeasuredEntity;
-import org.obo.dataadapter.OBOFileAdapter;
-import org.obo.datamodel.DefinedObject;
-import org.obo.datamodel.IdentifiedObject;
-import org.obo.datamodel.Link;
-import org.obo.datamodel.LinkedObject;
-import org.obo.datamodel.Namespace;
-import org.obo.datamodel.OBOSession;
-
-
-public class OBOSessionShard implements Shard {
- OBOFileAdapter adapter = new OBOFileAdapter();
-
- protected OBOSession session;
-
- // node fetching
- public Node getNode(String id) {
- Node node = OBOBridge.obj2node(session.getObject(id));
- //node.serial
- return node;
- }
-
- public Collection<Node> getNodes() {
- HashSet<Node> nodes = new HashSet<Node>();
- for (IdentifiedObject io : session.getObjects()) {
- if (io.isBuiltIn())
- continue;
- nodes.add(OBOBridge.obj2node(io));
- }
- return nodes;
- }
-
- public Collection<Node> getNodes(String sourceId) {
- HashSet<Node> nodes = new HashSet<Node>();
- for (IdentifiedObject io : session.getObjects()) {
- if (io.isBuiltIn())
- continue;
- if (io.getNamespace() != null && io.getNamespace().getID().equals(sourceId))
- nodes.add(OBOBridge.obj2node(io));
- }
- return nodes;
- }
-
-
- // simple types
- public Collection<String> getNodeIDs() {
- HashSet<String> ids = new HashSet<String>();
- for (IdentifiedObject io : session.getObjects()) {
- ids.add(io.getID());
- }
- return ids;
- }
-
- public Collection<Statement> getStatements() {
- // TODO Auto-generated method stub
- return new HashSet<Statement>();
- }
-
- public Collection<Statement> getStatements(String sourceId) {
- // TODO Auto-generated method stub
- return new HashSet<Statement>();
- }
-
- public Collection<Statement> getStatementsForNode(String id) {
- HashSet<Statement> statements = new HashSet<Statement>();
- LinkedObject obj = (LinkedObject)session.getObject(id);
- System.out.println("obj="+obj);
- if (obj != null ) {
- for (Link link : obj.getParents()) {
- System.out.println("p="+link);
- Logger.getLogger("org.obd").info("p2s"+link);
- statements.add(OBOBridge.link2statement(link));
- }
- }
- return statements;
- }
-
-
- public Collection<Statement> getStatementsForNodeWithSource(String id, String sourceId) {
- HashSet<Statement> statements = new HashSet<Statement>();
- LinkedObject obj = (LinkedObject)session.getObject(id);
- for (Link link : obj.getParents()) {
- Statement s = OBOBridge.link2statement(link);
- if (s.getSourceId().equals(sourceId))
- statements.add(s);
- }
- return statements;
- }
-
-
- public Collection<Statement> getStatementsForTarget(String id) {
- HashSet<Statement> statements = new HashSet<Statement>();
- LinkedObject obj = (LinkedObject)session.getObject(id);
- if (obj != null) {
- for (Link link : obj.getChildren()) {
- statements.add(OBOBridge.link2statement(link));
- }
- }
- return statements;
- }
-
- public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId) {
- HashSet<Statement> statements = new HashSet<Statement>();
- LinkedObject obj = (LinkedObject)session.getObject(id);
- if (obj != null) {
- for (Link link : obj.getChildren()) {
- Statement s = OBOBridge.link2statement(link);
- if (s.getSourceId().equals(sourceId))
- statements.add(s);
- }
- }
- return statements;
- }
-
- // simple types
- public String getNodeName(String id) {
- return session.getObject(id).getName();
- }
-
- public String getNodeDef(String id) {
- return ((DefinedObject)session.getObject(id)).getDefinition();
- }
-
- public Collection<Node> getSourceNodes() {
- Collection<Namespace> nsl = session.getNamespaces();
- HashSet<Node> nodes = new HashSet<Node>();
- for (Namespace ns : nsl)
- nodes.add(OBOBridge.namespace2srcNode(ns));
- return nodes;
- }
-
- public AggregateStatisticCollection getSummaryStatistics() {
- AggregateStatisticCollection stats = new AggregateStatisticCollection();
- for (IdentifiedObject io : session.getObjects()) {
- if (io.isBuiltIn())
- continue;
- String src = OBOBridge.namespace2src(io.getNamespace());
- MeasuredEntity entity = stats.getMeasuredEntity("node",src);
- stats.incrementCount(entity);
- if (io instanceof LinkedObject) {
- for (Link link : ((LinkedObject)io).getParents()) {
- stats.incrementCount("link", src);
- }
- }
- }
- return stats;
- }
-
- public Collection<Statement> getStatements(String nodeId, String relationId, String targetId, String sourceId, Boolean useImplied, Boolean isReified) {
- return new LinkedList<Statement>();
- }
-
- public Collection<Statement> getSubjectStatements(String subjectId, String subjectRelationId, String targetRelationId, String nodeId, String targetId, String subjectSourceId, String nodeSourceId, Boolean useImplied, Boolean isReified) {
- return new LinkedList<Statement>();
- }
-
- public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id, EntailmentUse entailment, GraphExpansionAlgorithm strategy) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Graph getAnnotationGraphAroundNode(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
- return new Graph();
- }
-
-
-}
Added: obdapi/trunk/OBDAPI/src/org/obd/query/AtomicQueryTerm.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/AtomicQueryTerm.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/AtomicQueryTerm.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,24 @@
+package org.obd.query;
+
+public class AtomicQueryTerm extends QueryTerm {
+
+ protected String value;
+
+ public AtomicQueryTerm(String value) {
+ super();
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String toString() {
+ return getValue().toString();
+ }
+
+}
Added: obdapi/trunk/OBDAPI/src/org/obd/query/ComparisonQueryTerm.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/ComparisonQueryTerm.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/ComparisonQueryTerm.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,43 @@
+package org.obd.query;
+
+public class ComparisonQueryTerm extends QueryTerm {
+ public enum Operator {EQUALS, STARTS_WITH, CONTAINS}
+
+ protected Operator operator;
+ protected QueryTerm value;
+
+ public ComparisonQueryTerm(Operator operator, String valueAtom) {
+ super();
+ this.operator = operator;
+ this.value = new AtomicQueryTerm(valueAtom);
+ }
+ public ComparisonQueryTerm(Operator operator, QueryTerm value) {
+ super();
+ this.operator = operator;
+ this.value = value;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ public QueryTerm getValue() {
+ return value;
+ }
+
+ public void setValue(QueryTerm value) {
+ this.value = value;
+ }
+
+ public String toString() {
+ String s = operator.toString();
+ if (getValue() != null)
+ s = s + " "+getValue().toString();
+ return s;
+ }
+
+}
Modified: obdapi/trunk/OBDAPI/src/org/obd/query/GraphQuery.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/GraphQuery.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/GraphQuery.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -12,5 +12,4 @@
}
-
}
Added: obdapi/trunk/OBDAPI/src/org/obd/query/LinkQueryTerm.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/LinkQueryTerm.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/LinkQueryTerm.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,50 @@
+package org.obd.query;
+
+public class LinkQueryTerm extends QueryTerm {
+ protected QueryTerm target;
+
+
+ /**
+ * Example: anything that is part of something that develops from the imaginal disc
+ * LinkStatementQueryTerm(partOf,
+ * new LinkStatementQueryTerm(developsFrom,
+ * new LiteralStatementQueryTerm(NAME, "imaginal disc")))
+ *
+ * @param relation
+ * @param target
+ */
+ public LinkQueryTerm(String relation, QueryTerm target) {
+ super();
+ this.relation = new AtomicQueryTerm(relation);
+ this.target = target;
+ }
+ public LinkQueryTerm(QueryTerm relation, QueryTerm target) {
+ super();
+ this.relation = relation;
+ this.target = target;
+ }
+
+ public LinkQueryTerm(String relationAtom, String targetAtom) {
+ super();
+ this.relation = new AtomicQueryTerm(relationAtom);
+ this.target = new AtomicQueryTerm(targetAtom);
+ }
+
+
+ public QueryTerm getTarget() {
+ return target;
+ }
+
+ public void setTarget(QueryTerm target) {
+ this.target = target;
+ }
+
+ public String toString() {
+ String s = getRelation().toString();
+ if (getTarget() != null)
+ s = s + " "+getTarget().toString();
+ return s;
+ }
+
+
+}
Added: obdapi/trunk/OBDAPI/src/org/obd/query/LiteralQueryTerm.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/LiteralQueryTerm.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/LiteralQueryTerm.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,49 @@
+package org.obd.query;
+
+public class LiteralQueryTerm extends QueryTerm {
+ public enum AliasType {ID, PRIMARY_NAME, ALTERNATE_LABEL, ANY_LABEL }
+
+ protected AliasType aliasType = AliasType.ID;
+ protected QueryTerm value;
+
+ public LiteralQueryTerm(AliasType aliasType, String valueAtom) {
+ super();
+ this.value = new AtomicQueryTerm(valueAtom);;
+ this.aliasType = aliasType;
+ }
+ public LiteralQueryTerm(AliasType aliasType, QueryTerm value) {
+ super();
+ this.value = value;
+ this.aliasType = aliasType;
+ }
+ public LiteralQueryTerm(QueryTerm value) {
+ super();
+ this.value = value;
+ }
+ public LiteralQueryTerm(String valueAtom) {
+ super();
+ this.value = new AtomicQueryTerm(valueAtom);
+ }
+
+ public QueryTerm getValue() {
+ return value;
+ }
+
+ public void setValue(QueryTerm value) {
+ this.value = value;
+ }
+
+ public AliasType getAliasType() {
+ return aliasType;
+ }
+ public void setAliasType(AliasType aliasType) {
+ this.aliasType = aliasType;
+ }
+
+ public String toString() {
+ String s = " has "+getAliasType().toString();
+ if (getValue() != null)
+ s = s + " "+getValue().toString();
+ return s;
+ }
+}
Added: obdapi/trunk/OBDAPI/src/org/obd/query/QueryTerm.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/QueryTerm.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/QueryTerm.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,46 @@
+package org.obd.query;
+
+public abstract class QueryTerm {
+
+ protected QueryTerm relation;
+ protected QueryTerm source;
+ protected QueryTerm positedBy;
+
+ public QueryTerm() {
+ super();
+ }
+
+ public QueryTerm(QueryTerm relation, QueryTerm source, QueryTerm positedBy) {
+ super();
+ this.relation = relation;
+ this.source = source;
+ this.positedBy = positedBy;
+ }
+ public QueryTerm getPositedBy() {
+ return positedBy;
+ }
+ public void setPositedBy(QueryTerm positedBy) {
+ this.positedBy = positedBy;
+ }
+ public QueryTerm getSource() {
+ return source;
+ }
+ public void setSource(QueryTerm source) {
+ this.source = source;
+ }
+ public QueryTerm getRelation() {
+ return relation;
+ }
+ public void setRelation(QueryTerm relation) {
+ this.relation = relation;
+ }
+
+ public String toString() {
+ String s = "";
+ if (positedBy != null)
+ s = s + positedBy.toString();
+ return s;
+ }
+
+
+}
Copied: obdapi/trunk/OBDAPI/src/org/obd/query/Shard.java (from rev 1299, obdapi/trunk/OBDAPI/src/org/obd/model/Shard.java)
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/Shard.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/Shard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,173 @@
+package org.obd.query;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.model.bridge.OBOBridge;
+import org.obd.model.stats.AggregateStatisticCollection;
+import org.obo.datamodel.IdentifiedObject;
+
+
+/**
+ * @author cjm
+ *
+ */
+public interface Shard {
+
+ public enum EntailmentUse {
+ USE_ASSERTED,
+ USE_IMPLIED,
+ FULL_TRANSITIVE_CLOSURE
+ }
+ public enum GraphExpansionAlgorithm {
+ MINIMAL,
+ INCLUDE_SUBGRAPH
+ }
+
+ /**
+ * @return Node with matching ID
+ */
+ public Node getNode(String id);
+ public Collection<Node> getNodes();
+
+ /**
+ * @return all nodes with matching source
+ */
+ public Collection<Node> getNodesBySource(String sourceId);
+
+ /**
+ * @param searchTerm
+ * @return all matching Nodes
+ */
+ public Collection<Node> getNodesBySearch(String searchTerm);
+
+ /**
+ * @return all Nodes used as a source
+ */
+ public Collection<Node> getSourceNodes();
+
+ /**
+ * @param ids
+ * @param entailment
+ * @param gea
+ * @return all Nodes that are beneath each of the nodes with given ids
+ */
+ public Collection<Node> getNodesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea);
+
+ public Collection<Node> getNodesByQuery(QueryTerm queryTerm);
+
+
+ /**
+ * @param ids
+ * @param entailment
+ * @param gea
+ * @return all annotated entities that have at least one annotation to each node
+ * in the given set
+ */
+ public Collection<Node> getAnnotatedEntitiesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea);
+
+
+ //public Statement getStatement(String id);
+
+ /**
+ * @param sourceId
+ * @return all statements matching this source
+ */
+ public Collection<Statement> getStatements(String sourceId);
+
+ public Collection<Statement> getStatementsByQuery(QueryTerm queryTerm);
+
+
+ /**
+ * @param id
+ * @param entailment
+ * @param strategy
+ * @return given an annotated entity (eg a genotype node), return all annotation
+ * statements
+ */
+ public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id,
+ EntailmentUse entailment, GraphExpansionAlgorithm strategy);
+
+ /**
+ * @param id
+ * @param entailment
+ * @param gea
+ * @return given a node (eg a class in an ontology), return a graph centered
+ * around this node, including annotation to nodes subsumed by this node
+ */
+ public Graph getAnnotationGraphAroundNode(String id,
+ EntailmentUse entailment, GraphExpansionAlgorithm gea);
+
+ public Graph getGraphByQuery(QueryTerm queryTerm,
+ EntailmentUse entailment, GraphExpansionAlgorithm gea);
+
+
+ /**
+ * @param id
+ * @return
+ */
+ public Collection<Statement> getStatementsForNode(String id);
+
+ /**
+ * @param id
+ * @param sourceId
+ * @return
+ */
+ public Collection<Statement> getStatementsForNodeWithSource(String id, String sourceId);
+
+ /**
+ * @param id
+ * @return
+ */
+ public Collection<Statement> getStatementsForTarget(String id);
+
+ /**
+ * @param id
+ * @param sourceId
+ * @return
+ */
+ public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId);
+
+ /**
+ * @param nodeId
+ * @param relationId
+ * @param targetId
+ * @param sourceId
+ * @param useImplied
+ * @param isReified
+ * @return
+ */
+ public Collection<Statement> getStatements(String nodeId,
+ String relationId, String targetId, String sourceId,
+ Boolean useImplied, Boolean isReified);
+
+ /**
+ * @param subjectId
+ * @param subjectRelationId
+ * @param targetRelationId
+ * @param nodeId
+ * @param targetId
+ * @param subjectSourceId
+ * @param nodeSourceId
+ * @param useImplied
+ * @param isReified
+ * @return
+ */
+ public Collection<Statement> getSubjectStatements(String subjectId,
+ String subjectRelationId, String targetRelationId,
+ String nodeId, String targetId,
+ String subjectSourceId, String nodeSourceId,
+ Boolean useImplied, Boolean isReified);
+
+ /**
+ * @return
+ */
+ public AggregateStatisticCollection getSummaryStatistics();
+}
Added: obdapi/trunk/OBDAPI/src/org/obd/query/impl/AbstractShard.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/impl/AbstractShard.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/impl/AbstractShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,9 @@
+package org.obd.query.impl;
+
+import org.obd.query.Shard;
+
+
+public abstract class AbstractShard implements Shard {
+
+
+}
Copied: obdapi/trunk/OBDAPI/src/org/obd/query/impl/MultiShard.java (from rev 1299, obdapi/trunk/OBDAPI/src/org/obd/model/impl/MultiShard.java)
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/impl/MultiShard.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/impl/MultiShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,192 @@
+package org.obd.query.impl;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.model.stats.AggregateStatistic;
+import org.obd.model.stats.AggregateStatisticCollection;
+import org.obd.query.QueryTerm;
+import org.obd.query.Shard;
+import org.obd.query.Shard.EntailmentUse;
+import org.obd.query.Shard.GraphExpansionAlgorithm;
+
+public class MultiShard implements Shard {
+
+ Collection<Shard> shards = new HashSet<Shard>();
+
+ public Node getNode(String id) {
+ System.out.println("ms getNode: "+id);
+ for (Shard s : shards) {
+ Node n = s.getNode(id);
+ System.out.println(s+" "+n);
+ if (n != null)
+ return n;
+ }
+ return null;
+ }
+
+ public Collection<Node> getNodes() {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (Shard s : shards)
+ nodes.addAll(s.getNodes());
+ return nodes;
+ }
+
+ public Collection<Node> getNodesBySource(String sourceId) {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (Shard s : shards)
+ nodes.addAll(s.getNodesBySource(sourceId));
+ return nodes;
+ }
+
+ public Collection<Node> getNodesBySearch(String searchTerm) {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (Shard s : shards)
+ nodes.addAll(s.getNodesBySearch(searchTerm));
+ return nodes;
+ }
+
+ public Collection<Node> getNodesBelowNodeSet(Collection<String> ids, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (Shard s : shards)
+ nodes.addAll(s.getNodesBelowNodeSet(ids, entailment, gea));
+ return nodes;
+ }
+
+
+
+
+ public Collection<Statement> getStatements(String sourceId) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ for (Shard s : shards)
+ statements.addAll(s.getStatements(sourceId));
+ return statements;
+ }
+
+ public Collection<Statement> getStatementsForTarget(String id) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ for (Shard s : shards)
+ statements.addAll(s.getStatementsForTarget(id));
+ return statements;
+ }
+ public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ for (Shard s : shards)
+ statements.addAll(s.getStatementsForTargetWithSource(id, sourceId));
+ return statements;
+ }
+
+ public Collection<Shard> getShards() {
+ return shards;
+ }
+
+ public void setShards(Collection<Shard> shards) {
+ this.shards = shards;
+ }
+
+ public void addShard(Shard shard) {
+ if (shards == null)
+ shards = new HashSet<Shard>();
+ shards.add(shard);
+ }
+
+ public Collection<Statement> getStatementsForNode(String id) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ System.out.println("getting parents for="+id);
+ for (Shard s : shards)
+ statements.addAll(s.getStatementsForNode(id));
+ return statements;
+ }
+
+ public Collection<Statement> getStatementsForNodeWithSource(String id, String sourceId) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ for (Shard s : shards)
+ statements.addAll(s.getStatementsForNodeWithSource(id, sourceId));
+ return statements;
+ }
+
+
+ public Collection<Statement> getStatements(String nodeId, String relationId, String targetId, String sourceId, Boolean useImplied, Boolean isReified) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ for (Shard s : shards)
+ statements.addAll(s.getStatements(nodeId,
+ relationId, targetId, sourceId, useImplied, isReified));
+ return statements;
+ }
+
+ public Collection<Statement> getSubjectStatements(String subjectId, String subjectRelationId, String targetRelationId, String nodeId, String targetId, String subjectSourceId, String nodeSourceId, Boolean useImplied, Boolean isReified) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ for (Shard s : shards)
+ statements.addAll(s.getSubjectStatements( subjectId,
+ subjectRelationId, targetRelationId, nodeId, targetId,
+ subjectSourceId, nodeSourceId, useImplied, isReified));
+
+ return statements;
+ }
+
+ public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ for (Shard s : shards)
+ statements.addAll(s.getAnnotationStatementsForAnnotatedEntity( id,
+ entailment, gea));
+
+ return statements;
+ }
+
+ public Graph getAnnotationGraphAroundNode(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ Graph g = new Graph();
+ for (Shard s : shards)
+ g.merge(s.getAnnotationGraphAroundNode(id, entailment, gea));
+ return g;
+
+ }
+
+ public Collection<Node> getAnnotatedEntitiesBelowNodeSet(Collection<String> ids, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (Shard s : shards)
+ nodes.addAll(s.getAnnotatedEntitiesBelowNodeSet(ids, entailment, gea));
+ return nodes;
+ }
+
+
+ public Collection<Node> getSourceNodes() {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (Shard s : shards)
+ nodes.addAll(s.getSourceNodes());
+ return nodes;
+ }
+
+ public AggregateStatisticCollection getSummaryStatistics() {
+ AggregateStatisticCollection combinedStats = new AggregateStatisticCollection();
+ for (Shard s : shards) {
+ AggregateStatisticCollection sc = s.getSummaryStatistics();
+ Collection<AggregateStatistic> stats;
+ if (sc != null) {
+ stats = sc.getStats();
+ combinedStats.getStats().addAll(stats);
+ }
+ }
+ return combinedStats;
+ }
+
+ public Collection<Node> getNodesByQuery(QueryTerm queryTerm) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Graph getGraphByQuery(QueryTerm queryTerm, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Collection<Statement> getStatementsByQuery(QueryTerm queryTerm) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+}
Copied: obdapi/trunk/OBDAPI/src/org/obd/query/impl/MutableOBOSessionShard.java (from rev 1290, obdapi/trunk/OBDAPI/src/org/obd/model/impl/MutableOBOSessionShard.java)
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/impl/MutableOBOSessionShard.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/impl/MutableOBOSessionShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,29 @@
+package org.obd.query.impl;
+
+import org.bbop.dataadapter.DataAdapterException;
+import org.obo.dataadapter.OBOAdapter;
+import org.obo.dataadapter.OBOFileAdapter;
+
+public class MutableOBOSessionShard extends OBOSessionShard {
+
+ public int loadLocal(String ontName) throws DataAdapterException {
+ String path = "/users/cjm/obo-all/"+ontName+"/"+ontName+".obo";
+ return loadFile(path);
+ }
+ public int load(String ontName) throws DataAdapterException {
+ String path = "http://purl.org/obo/obo-all/"+ontName+"/"+ontName+".obo";
+ return loadFile(path);
+ }
+ public int loadFile(String path) throws DataAdapterException {
+ OBOFileAdapter.OBOAdapterConfiguration config = new OBOFileAdapter.OBOAdapterConfiguration();
+ config.getReadPaths().add(path);
+
+ config.setAllowDangling(true);
+ config.setBasicSave(false);
+ config.setFailFast(false);
+ session = adapter.doOperation(OBOAdapter.READ_ONTOLOGY, config,
+ null);
+ return session.getObjects().size();
+ }
+
+}
Copied: obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBDSQLShard.java (from rev 1299, obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBDSQLShard.java)
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBDSQLShard.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBDSQLShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,530 @@
+package org.obd.query.impl;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+
+import org.bbop.rdbms.RelationalQuery;
+import org.bbop.rdbms.WhereClause;
+import org.bbop.rdbms.impl.SqlQueryImpl;
+import org.bbop.rdbms.impl.SqlWhereClauseImpl;
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.model.bridge.OBOBridge;
+import org.obd.model.stats.AggregateStatisticCollection;
+import org.obd.query.GraphQuery;
+import org.obd.query.QueryTerm;
+import org.obd.query.Shard;
+import org.obo.annotation.datamodel.Annotation;
+import org.obo.dataadapter.OBDSQLDatabaseAdapter;
+import org.obo.dataadapter.OBOFileAdapter;
+import org.obo.dataadapter.OBDSQLDatabaseAdapter.OBDSQLDatabaseAdapterConfiguration;
+import org.obo.datamodel.IdentifiedObject;
+import org.obo.datamodel.Link;
+import org.obo.datamodel.LinkedObject;
+import org.obo.datamodel.OBOSession;
+import org.obo.datamodel.impl.DanglingLinkImpl;
+import org.obo.datamodel.impl.OBOSessionImpl;
+
+/**
+ * @author cjm
+ *
+ */
+public class OBDSQLShard implements Shard {
+
+ OBDSQLDatabaseAdapter obd = new OBDSQLDatabaseAdapter();
+ OBDSQLDatabaseAdapterConfiguration obdconfig =
+ new OBDSQLDatabaseAdapter.OBDSQLDatabaseAdapterConfiguration();
+
+ protected OBOSession session =
+ new OBOSessionImpl(); // TODO: remove? need it for tracking namespaces etc
+
+ public OBDSQLShard() throws SQLException, ClassNotFoundException {
+ }
+
+ public void connect(String jdbcPath) throws SQLException, ClassNotFoundException {
+ obdconfig.getReadPaths().add(jdbcPath);
+ obd = new OBDSQLDatabaseAdapter();
+ obd.setConfiguration(obdconfig);
+ obd.connect();
+ }
+
+ public String getID() {
+ return "OBD-Query-Service"; // TODO: introspect metadata
+ }
+
+
+
+ public Node getNode(String id) {
+ RelationalQuery q = new SqlQueryImpl();
+ q.addTable("node_with_source");
+ WhereClause whereClause = q.getWhereClause();
+ whereClause.addEqualityConstraint("uid", id);
+ Node n = null;
+ OBOSession tempSession = new OBOSessionImpl();
+ try {
+ ResultSet rs = execute(q);
+ if (rs.next()) {
+ IdentifiedObject lo = obd.fetchObject(tempSession, rs);
+ obd.fetchObjectInfo(tempSession, lo);
+ n = OBOBridge.obj2node(lo);
+ Collection<Statement> statements = getStatementsForNode(n.getId(),false);
+ n.addStatements(statements);
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return n;
+ }
+
+ public Collection<Node> getNodesBySource(String sourceId) {
+ Collection<Node> nodes = new LinkedList<Node>();
+ RelationalQuery q = new SqlQueryImpl();
+ q.addTable("node_with_source");
+ WhereClause whereClause = q.getWhereClause();
+ if (sourceId != null)
+ whereClause.addEqualityConstraint("source_uid", sourceId);
+ Node n = null;
+ try {
+ ResultSet rs = execute(q);
+ while (rs.next()) {
+ IdentifiedObject io = obd.fetchObject(session, rs);
+ nodes.add(OBOBridge.obj2node(io));
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return nodes;
+ }
+
+ public Collection<Node> getNodesBySearch(String searchTerm) {
+ RelationalQuery q = new SqlQueryImpl();
+ q.addTable("node_with_source");
+ WhereClause whereClause = q.getWhereClause();
+ whereClause.addOperatorConstraint("LIKE", "label", searchTerm);
+ return getNodes(q);
+ }
+
+ public Collection<Node> getNodesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea){
+ return getNodesBelowNodeSet(ids, entailment, gea, "link_to_node");
+ }
+
+ public Collection<Node> getNodesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea,
+ String linkTable){
+ RelationalQuery q = new SqlQueryImpl();
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ q.addTable("node_with_source", "node");
+ int num = 0;
+ for (String id : ids) {
+ String alias = "link"+num;
+ q.addTable(linkTable, alias);
+ num++;
+ whereClause.addEqualityConstraint(alias+".object_uid",id);
+ whereClause.addConstraint(alias+".node_id"+" = node.node_id");
+ q.setWhereClause(whereClause);
+ }
+ q.getSelectClause().addColumn("node.*");
+ q.getSelectClause().setDistinct(true);
+ return getNodes(q);
+ }
+
+ public Collection<Node> getNodes(RelationalQuery q) {
+ OBOSession tempSession = new OBOSessionImpl();
+ Collection<Node> nodes = new LinkedList<Node>();
+ try {
+ ResultSet rs = execute(q);
+ while (rs.next()) {
+ IdentifiedObject lo = obd.fetchObject(tempSession, rs);
+ obd.fetchObjectInfo(tempSession, lo);
+ Node n = OBOBridge.obj2node(lo);
+ nodes.add(n);
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return nodes;
+ }
+
+
+
+
+ public Collection<Node> getNodes() {
+ return getNodesBySource(null);
+ }
+
+ public Collection<Node> getSourceNodes() {
+ Collection<Node> nodes = new LinkedList<Node>();
+ RelationalQuery q = new SqlQueryImpl();
+ q.addTable("source_node");
+ WhereClause whereClause = q.getWhereClause();
+ Node n = null;
+ try {
+ ResultSet rs = execute(q);
+ while (rs.next()) {
+ IdentifiedObject io = obd.fetchObject(session, rs);
+ nodes.add(OBOBridge.obj2node(io));
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return nodes;
+ }
+
+ public Collection<Statement> getStatements() {
+ // TODO Auto-generated method stub
+ return new HashSet<Statement>();
+ }
+
+
+
+ public Collection<Statement> getStatements(String ns) {
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ if (ns != null) {
+ whereClause.addEqualityConstraint("source_uid",ns);
+ }
+ return getStatements(whereClause);
+ }
+
+ public Collection<Statement> getStatements(WhereClause whereClause) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ try {
+ RelationalQuery q = new SqlQueryImpl();
+ q.addTable("node_link_node_with_pred_and_source");
+ q.setWhereClause(whereClause);
+ ResultSet rs = execute(q);
+
+ OBOSession tempSession = new OBOSessionImpl();
+ HashMap<String, Link> positsMap = new HashMap<String,Link>();
+ while (rs.next()) {
+ obd.includeLinkResultSetInSession(tempSession, rs, positsMap);
+ }
+ HashSet<Link> links = new HashSet<Link>();
+ for (IdentifiedObject io : tempSession.getObjects()) {
+ if (io instanceof LinkedObject && !io.isBuiltIn())
+ links.addAll(((LinkedObject)io).getParents());
+ }
+ HashMap<String,Statement> statementMap = new HashMap<String,Statement>();
+ for (Link link : links) {
+ Statement s = OBOBridge.link2statement(link);
+ statements.add(s);
+ statementMap.put(s.toString(), s);
+ }
+ // slighly convoluted way of making reverse links, from
+ // posited link to positing (annotation) node
+ for (IdentifiedObject io : tempSession.getObjects()) {
+ String nodeId = io.getID();
+ if (positsMap.containsKey(nodeId)) {
+ Statement sKey = OBOBridge.link2statement(positsMap.get(io.getID()));
+ Statement s = statementMap.get(sKey.toString());
+ s.setPositedByNodeId(nodeId);
+ }
+ }
+
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return statements;
+
+ }
+
+ public Collection<Statement> getStatementsForTarget(String id) {
+
+ HashSet<Statement> statements = new HashSet<Statement>();
+ try {
+ for (Link link : obd.fetchLinksByObject(id)) {
+ statements.add(OBOBridge.link2statement(link));
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return statements;
+ }
+
+ public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ System.out.println("id="+id+" src="+sourceId);
+ try {
+ for (Link link : obd.fetchLinksByObject(id, sourceId)) {
+ statements.add(OBOBridge.link2statement(link));
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return statements;
+ }
+
+ /**
+ * @param id
+ * @return All statements whose target is subsumed by id
+ * @throws Exception
+ */
+ public Collection<Statement> getStatementsAround(String id) throws Exception {
+
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ whereClause.addConstraint("object_uid in "+
+ "(SELECT node_id FROM link_to_node WHERE object_uid ='"+id+"')");
+ return getStatements(whereClause);
+ }
+
+
+
+
+ public Collection<Statement> getStatementsForNode(String id) {
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ whereClause.addEqualityConstraint("node_uid",id);
+ return getStatements(whereClause);
+ }
+
+ public Collection<Statement> getStatementsForNode(String id, boolean useImplied) {
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ whereClause.addEqualityConstraint("node_uid",id);
+ if (!useImplied)
+ whereClause.addEqualityConstraint("is_inferred",false);
+ return getStatements(whereClause);
+ }
+
+
+ public Collection<Statement> getStatementsForNodeWithSource(String id, String ns) {
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ whereClause.addEqualityConstraint("node_uid",id);
+ if (ns != null) {
+ whereClause.addEqualityConstraint("source_uid",ns);
+ }
+ return getStatements(whereClause);
+ }
+
+
+
+ public Collection<Statement> getStatements(String nodeId,
+ String relationId, String targetId, String sourceId,
+ Boolean useImplied, Boolean isReified) {
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ if (nodeId != null)
+ whereClause.addEqualityConstraint("node_uid",nodeId);
+ if (relationId != null)
+ whereClause.addEqualityConstraint("pred_uid",relationId);
+ if (targetId != null)
+ whereClause.addEqualityConstraint("object_uid",targetId);
+ if (sourceId != null)
+ whereClause.addEqualityConstraint("source_uid",sourceId);
+ if (useImplied != null)
+ whereClause.addEqualityConstraint("is_inferred",useImplied);
+ if (isReified)
+ whereClause.addConstraint("reiflink_node_id IS NOT NULL");
+ return getStatements(whereClause);
+ }
+
+ public Collection<Statement> getSubjectStatements(String subjectId,
+ String subjectRelationId, String targetRelationId,
+ String nodeId, String targetId,
+ String subjectSourceId, String nodeSourceId,
+ Boolean useImplied, Boolean isReified) {
+
+ System.out.println("getSubjectStatements "+subjectId+","+
+ subjectRelationId +","+ targetRelationId +"," + nodeId +","+ targetId + "," +
+ subjectSourceId + ","+ nodeSourceId +","+ useImplied +","+ isReified);
+
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ if (subjectId != null && !subjectId.equals(""))
+ whereClause.addEqualityConstraint("node_uid",subjectId);
+ if (subjectRelationId != null && !subjectRelationId.equals(""))
+ whereClause.addEqualityConstraint("pred_uid",subjectRelationId);
+ if (nodeId != null && !nodeId.equals(""))
+ whereClause.addEqualityConstraint("node_uid",nodeId);
+ if (subjectSourceId != null && !subjectSourceId.equals(""))
+ whereClause.addEqualityConstraint("source_uid",subjectSourceId);
+ if (isReified != null && isReified)
+ whereClause.addConstraint("reiflink_node_id IS NOT NULL");
+
+ RelationalQuery subQuery = new SqlQueryImpl();
+ subQuery.getSelectClause().addColumn("node_uid");
+ subQuery.addTable("node_link_node_with_pred_and_source");
+ WhereClause subWhereClause = new SqlWhereClauseImpl();
+ subQuery.setWhereClause(subWhereClause);
+
+ if (targetId != null && !targetId.equals(""))
+ subWhereClause.addEqualityConstraint("object_uid",targetId);
+ if (nodeSourceId != null && !nodeSourceId.equals(""))
+ subWhereClause.addEqualityConstraint("source_uid",nodeSourceId);
+ if (targetRelationId != null && !targetRelationId.equals(""))
+ subWhereClause.addEqualityConstraint("pred_uid",targetRelationId);
+ if (useImplied != null && !useImplied.equals(""))
+ subWhereClause.addEqualityConstraint("is_inferred",useImplied);
+
+ whereClause.addInConstraint("object_uid", subQuery);
+ return getStatements(whereClause);
+
+ }
+
+
+
+
+
+
+
+
+
+ public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id, EntailmentUse entailment, GraphExpansionAlgorithm strategy) {
+
+ // node_uid is the annotated entity - find everything about it -
+ // both additional metadata and annotation
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ whereClause.addEqualityConstraint("node_uid",id);
+ Collection<Statement> annots = getStatements(whereClause);
+ return annots;
+ }
+
+ public Graph getAnnotationGraphAroundNode(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+
+ // find graph around node, outwards
+ Collection<Statement> stmts;
+ if (gea == null || gea.equals(GraphExpansionAlgorithm.INCLUDE_SUBGRAPH)) {
+ Graph sg = getSubgraph(id, entailment, gea);
+ stmts = Arrays.asList(sg.getStatements());
+ }
+ else
+ stmts = new LinkedList<Statement>(); // TODO: minimal info?
+
+
+ // find all annotations to id
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ if (true || entailment == null) {
+ // currently this is under-constrained
+ // will fetch the full graph;
+ // G has_role* X and X R* Y, where Y is ground
+ /*
+ * we actually want
+ * G has_role X, X Rmd MD, X R* Y
+ */
+ RelationalQuery subsumedNodeQuery = new SqlQueryImpl();
+ subsumedNodeQuery.getSelectClause().addColumn("node_uid");
+ subsumedNodeQuery.addTable("node_link_node_with_pred_and_source");
+ WhereClause subWhereClause = new SqlWhereClauseImpl();
+ subWhereClause.addEqualityConstraint("object_uid",id);
+ subsumedNodeQuery.setWhereClause(subWhereClause);
+
+ whereClause.addInConstraint("object_uid",subsumedNodeQuery);
+ whereClause.addEqualityConstraint("is_inferred", false);
+ }
+ else {
+ // TODO: only works in annot links are inlcuded in deductive closure
+ whereClause.addEqualityConstraint("object_uid",id);
+ }
+ //whereClause.addConstraint("reiflink_node_id IS NOT NULL");
+ Collection<Statement> annots = getStatements(whereClause);
+ Graph g = new Graph(annots);
+ for (String nid : g.getReferencedNodeIds()) {
+ Node n = getNode(nid);
+ g.addNode(n);
+ Collection<Statement> mdLinks = getStatementsForNode(nid,false);
+ g.addStatements(mdLinks);
+ }
+ g.addStatements(stmts);
+ g.nestStatementsUnderNodes();
+ return g;
+
+ }
+
+ public Collection<Node> getAnnotatedEntitiesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea){
+ return getNodesBelowNodeSet(ids, entailment, gea,
+ "implied_annotation_link_to_node");
+ }
+
+ public Graph getSubGraphUsingQuery(GraphQuery gq) {
+
+ WhereClause whereClause = new SqlWhereClauseImpl();
+
+ // node_uid is the ontology - find full DAG
+ whereClause.addEqualityConstraint("node_uid",gq.getNodeId());
+ Collection<Statement> stmts = getStatements(whereClause);
+ Graph g = new Graph(stmts);
+ return g;
+ }
+
+ public Graph getSubgraph(String nodeId, EntailmentUse entailment,
+ GraphExpansionAlgorithm gea) {
+
+ WhereClause whereClause = new SqlWhereClauseImpl();
+ whereClause.addEqualityConstraint("node_uid",nodeId);
+
+ RelationalQuery subQuery = new SqlQueryImpl();
+ subQuery.getSelectClause().addColumn("node_uid");
+ subQuery.addTable("node_link_node_with_pred_and_source");
+ WhereClause subWhereClause = new SqlWhereClauseImpl();
+ subQuery.setWhereClause(subWhereClause);
+ Collection<Statement> stmts = getStatements(whereClause);
+ Graph g = new Graph(stmts);
+ return g;
+ }
+
+ public AggregateStatisticCollection getSummaryStatistics() {
+ AggregateStatisticCollection sc = new AggregateStatisticCollection();
+
+ RelationalQuery q = new SqlQueryImpl();
+ q.addTable("source_summary");
+ ResultSet rs;
+ try {
+ rs = execute(q);
+ while (rs.next()) {
+ String src = rs.getString("uid");
+ Integer nc = rs.getInt("node_count");
+ sc.setCount("node", src, nc);
+ Integer lc = rs.getInt("link_count");
+ sc.setCount("link", src, lc);
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return sc;
+ }
+
+ // UTIL
+
+ public ResultSet execute(RelationalQuery q) throws SQLException {
+ ResultSet rs = q.execute(obd.getConnection());
+ return rs;
+ }
+
+ public Collection<Node> getNodesByQuery(QueryTerm queryTerm) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Graph getGraphByQuery(QueryTerm queryTerm, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Collection<Statement> getStatementsByQuery(QueryTerm queryTerm) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+
+
+
+
+
+}
Copied: obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBOSessionShard.java (from rev 1299, obdapi/trunk/OBDAPI/src/org/obd/model/impl/OBOSessionShard.java)
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBOSessionShard.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/query/impl/OBOSessionShard.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,218 @@
+package org.obd.query.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.logging.Logger;
+
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.model.bridge.OBOBridge;
+import org.obd.model.stats.AggregateStatisticCollection;
+import org.obd.model.stats.MeasuredEntity;
+import org.obd.query.QueryTerm;
+import org.obd.query.Shard;
+import org.obd.query.Shard.EntailmentUse;
+import org.obd.query.Shard.GraphExpansionAlgorithm;
+import org.obo.dataadapter.OBOFileAdapter;
+import org.obo.datamodel.DefinedObject;
+import org.obo.datamodel.IdentifiedObject;
+import org.obo.datamodel.Link;
+import org.obo.datamodel.LinkedObject;
+import org.obo.datamodel.Namespace;
+import org.obo.datamodel.OBOSession;
+
+
+public class OBOSessionShard implements Shard {
+ OBOFileAdapter adapter = new OBOFileAdapter();
+
+ protected OBOSession session;
+
+ // node fetching
+ public Node getNode(String id) {
+ Node node = OBOBridge.obj2node(session.getObject(id));
+ //node.serial
+ return node;
+ }
+
+ public Collection<Node> getNodes() {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (IdentifiedObject io : session.getObjects()) {
+ if (io.isBuiltIn())
+ continue;
+ nodes.add(OBOBridge.obj2node(io));
+ }
+ return nodes;
+ }
+
+ public Collection<Node> getNodesBySource(String sourceId) {
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (IdentifiedObject io : session.getObjects()) {
+ if (io.isBuiltIn())
+ continue;
+ if (io.getNamespace() != null && io.getNamespace().getID().equals(sourceId))
+ nodes.add(OBOBridge.obj2node(io));
+ }
+ return nodes;
+ }
+
+ public Collection<Node> getNodesBySearch(String searchTerm) {
+ // TODO Auto-generated method stub
+ return new HashSet<Node>();
+ }
+
+ public Collection<Node> getNodesBelowNodeSet(Collection<String> ids, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ // TODO Auto-generated method stub
+ return new HashSet<Node>();
+ }
+
+
+ // simple types
+ public Collection<String> getNodeIDs() {
+ HashSet<String> ids = new HashSet<String>();
+ for (IdentifiedObject io : session.getObjects()) {
+ ids.add(io.getID());
+ }
+ return ids;
+ }
+
+ public Collection<Statement> getStatements() {
+ // TODO Auto-generated method stub
+ return new HashSet<Statement>();
+ }
+
+ public Collection<Statement> getStatements(String sourceId) {
+ // TODO Auto-generated method stub
+ return new HashSet<Statement>();
+ }
+
+ public Collection<Statement> getStatementsForNode(String id) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ LinkedObject obj = (LinkedObject)session.getObject(id);
+ System.out.println("obj="+obj);
+ if (obj != null ) {
+ for (Link link : obj.getParents()) {
+ System.out.println("p="+link);
+ Logger.getLogger("org.obd").info("p2s"+link);
+ statements.add(OBOBridge.link2statement(link));
+ }
+ }
+ return statements;
+ }
+
+
+ public Collection<Statement> getStatementsForNodeWithSource(String id, String sourceId) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ LinkedObject obj = (LinkedObject)session.getObject(id);
+ for (Link link : obj.getParents()) {
+ Statement s = OBOBridge.link2statement(link);
+ if (s.getSourceId().equals(sourceId))
+ statements.add(s);
+ }
+ return statements;
+ }
+
+
+ public Collection<Statement> getStatementsForTarget(String id) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ LinkedObject obj = (LinkedObject)session.getObject(id);
+ if (obj != null) {
+ for (Link link : obj.getChildren()) {
+ statements.add(OBOBridge.link2statement(link));
+ }
+ }
+ return statements;
+ }
+
+ public Collection<Statement> getStatementsForTargetWithSource(String id, String sourceId) {
+ HashSet<Statement> statements = new HashSet<Statement>();
+ LinkedObject obj = (LinkedObject)session.getObject(id);
+ if (obj != null) {
+ for (Link link : obj.getChildren()) {
+ Statement s = OBOBridge.link2statement(link);
+ if (s.getSourceId().equals(sourceId))
+ statements.add(s);
+ }
+ }
+ return statements;
+ }
+
+ // simple types
+ public String getNodeName(String id) {
+ return session.getObject(id).getName();
+ }
+
+ public String getNodeDef(String id) {
+ return ((DefinedObject)session.getObject(id)).getDefinition();
+ }
+
+ public Collection<Node> getSourceNodes() {
+ Collection<Namespace> nsl = session.getNamespaces();
+ HashSet<Node> nodes = new HashSet<Node>();
+ for (Namespace ns : nsl)
+ nodes.add(OBOBridge.namespace2srcNode(ns));
+ return nodes;
+ }
+
+ public AggregateStatisticCollection getSummaryStatistics() {
+ AggregateStatisticCollection stats = new AggregateStatisticCollection();
+ for (IdentifiedObject io : session.getObjects()) {
+ if (io.isBuiltIn())
+ continue;
+ String src = OBOBridge.namespace2src(io.getNamespace());
+ MeasuredEntity entity = stats.getMeasuredEntity("node",src);
+ stats.incrementCount(entity);
+ if (io instanceof LinkedObject) {
+ for (Link link : ((LinkedObject)io).getParents()) {
+ stats.incrementCount("link", src);
+ }
+ }
+ }
+ return stats;
+ }
+
+ public Collection<Statement> getStatements(String nodeId, String relationId, String targetId, String sourceId, Boolean useImplied, Boolean isReified) {
+ return new LinkedList<Statement>();
+ }
+
+ public Collection<Statement> getSubjectStatements(String subjectId, String subjectRelationId, String targetRelationId, String nodeId, String targetId, String subjectSourceId, String nodeSourceId, Boolean useImplied, Boolean isReified) {
+ return new HashSet<Statement>();
+ }
+
+ public Collection<Statement> getAnnotationStatementsForAnnotatedEntity(String id, EntailmentUse entailment, GraphExpansionAlgorithm strategy) {
+ return new HashSet<Statement>();
+ }
+
+ public Graph getAnnotationGraphAroundNode(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ return new Graph();
+ }
+
+ public Collection<Node> getAnnotatedEntitiesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea){
+ return new LinkedList<Node>(); // TODO
+ }
+
+ public Collection<Node> getNodesByQuery(QueryTerm queryTerm) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Graph getGraphByQuery(QueryTerm queryTerm, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Collection<Statement> getStatementsByQuery(QueryTerm queryTerm) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+
+
+
+}
Added: obdapi/trunk/OBDAPI/src/org/obd/test/AnnotationGraphTest.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/test/AnnotationGraphTest.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/test/AnnotationGraphTest.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,55 @@
+package org.obd.test;
+
+import java.io.PrintStream;
+import java.util.logging.Logger;
+
+import org.bbop.io.AuditedPrintStream;
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.ws.OBDQueryService;
+import org.obo.datamodel.impl.DefaultLinkDatabase;
+import org.obo.reasoner.impl.ForwardChainingReasoner;
+import org.obo.test.OBDAnnotationSaveTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AnnotationGraphTest extends TestCase {
+
+ OBDQueryService service;
+
+
+ public AnnotationGraphTest(String n) {
+ super(n);
+ }
+
+
+ public void setUp() throws Exception {
+ System.out.println("Setting up: " + this);
+ service = new OBDQueryService();
+
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ addTests(suite);
+ return suite;
+ }
+
+ public static void addTests(TestSuite suite) {
+ suite.addTest(new AnnotationGraphTest("testQuery"));
+ }
+
+ public void testQuery() {
+
+
+
+ for (Statement s : service.getAnnotationStatementsForAnnotatedEntity("ZFIN:ZDB-GENO-960809-7", null, null)) {
+ System.out.println(s);
+ }
+
+ }
+
+}
Copied: obdapi/trunk/OBDAPI/src/org/obd/test/MiniTest.java (from rev 1299, obdapi/trunk/OBDAPI/src/org/obd/test/OBDQueryServiceTest.java)
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/test/MiniTest.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/test/MiniTest.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,61 @@
+package org.obd.test;
+
+import java.io.PrintStream;
+import java.util.logging.Logger;
+
+import org.bbop.io.AuditedPrintStream;
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.ws.OBDQueryService;
+import org.obo.datamodel.impl.DefaultLinkDatabase;
+import org.obo.reasoner.impl.ForwardChainingReasoner;
+import org.obo.test.OBDAnnotationSaveTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class MiniTest extends TestCase {
+
+ OBDQueryService service;
+
+
+ public MiniTest(String n) {
+ super(n);
+ }
+
+
+ public void setUp() throws Exception {
+ System.out.println("Setting up: " + this);
+ service = new OBDQueryService();
+
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ addTests(suite);
+ return suite;
+ }
+
+ public static void addTests(TestSuite suite) {
+ suite.addTest(new MiniTest("testQuery"));
+ }
+
+ public void testQuery() {
+ Graph g= new Graph();
+ g.addStatement(testStatement());
+ g.addStatement(testStatement());
+ System.out.println("Len="+g.getStatements().length);
+
+ }
+
+ public Statement testStatement() {
+ Statement s = new Statement();
+ s.setNodeId("x");
+ s.setRelationId("y");
+ s.setTargetId("z");
+ return s;
+ }
+
+}
Added: obdapi/trunk/OBDAPI/src/org/obd/test/MultiNodeFetchTest.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/test/MultiNodeFetchTest.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/test/MultiNodeFetchTest.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,67 @@
+package org.obd.test;
+
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.logging.Logger;
+
+import org.bbop.io.AuditedPrintStream;
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.ws.OBDQueryService;
+import org.obo.datamodel.impl.DefaultLinkDatabase;
+import org.obo.reasoner.impl.ForwardChainingReasoner;
+import org.obo.test.OBDAnnotationSaveTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class MultiNodeFetchTest extends TestCase {
+
+ OBDQueryService service;
+
+
+ public MultiNodeFetchTest(String n) {
+ super(n);
+ }
+
+
+ public void setUp() throws Exception {
+ System.out.println("Setting up: " + this);
+ service = new OBDQueryService();
+
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ addTests(suite);
+ return suite;
+ }
+
+ public static void addTests(TestSuite suite) {
+ suite.addTest(new MultiNodeFetchTest("testQuery"));
+ }
+
+ public void testQuery() {
+
+ // heart development & blood cell
+ String[] ids =
+ {"GO:0003007", "PATO:0000001"};
+
+ for (Node n : service.getNodesBelowNodeSet(Arrays.asList(ids) , null, null)) {
+ System.out.println(n);
+ }
+
+ String[] ids2 =
+ {"GO:0003007", "CL:0000081"};
+
+ for (Node n : service.getAnnotatedEntitiesBelowNodeSet(Arrays.asList(ids2) , null, null)) {
+ System.out.println(n);
+ }
+
+
+ }
+
+}
Deleted: obdapi/trunk/OBDAPI/src/org/obd/test/OBDQueryServiceTest.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/test/OBDQueryServiceTest.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/test/OBDQueryServiceTest.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -1,76 +0,0 @@
-package org.obd.test;
-
-import java.io.PrintStream;
-import java.util.logging.Logger;
-
-import org.bbop.io.AuditedPrintStream;
-import org.obd.model.Graph;
-import org.obd.model.Node;
-import org.obd.model.Statement;
-import org.obd.ws.OBDQueryService;
-import org.obo.datamodel.impl.DefaultLinkDatabase;
-import org.obo.reasoner.impl.ForwardChainingReasoner;
-import org.obo.test.OBDAnnotationSaveTest;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class OBDQueryServiceTest extends TestCase {
-
- OBDQueryService service;
-
-
- public OBDQueryServiceTest(String n) {
- super(n);
- }
-
-
- public void setUp() throws Exception {
- System.out.println("Setting up: " + this);
- service = new OBDQueryService();
-
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- addTests(suite);
- return suite;
- }
-
- public static void addTests(TestSuite suite) {
- suite.addTest(new OBDQueryServiceTest("testQuery"));
- }
-
- public void testQuery() {
- String id = "GO:0006811";
- Node node =
- service.getNode(id);
- Logger.getLogger("org.obd.test").info("node="+node.getName());
- assertTrue(node != null);
-
- for (Statement s : service.getStatementsForNode(id)) {
- Logger.getLogger("org.obd.test").info("parentLink="+s);
- }
-
- for (Statement s : service.getStatementsForTarget(id)) {
- Logger.getLogger("org.obd.test").info("childLink="+s);
- }
-
- for (Statement s : service.getSubjectStatements(null,
- null, null, null, id, null, null, true, true)) {
- Logger.getLogger("org.obd.test").info("annot="+s);
- }
-
- Graph g = service.getAnnotationGraphAroundNode(id, null, null);
- g.nestStatementsUnderNodes();
- for (Node n : g.getNodes()) {
- System.out.println(n);
- for (Statement s : n.getStatements()) {
- System.out.println(" "+s);
- }
- }
-
- }
-
-}
Added: obdapi/trunk/OBDAPI/src/org/obd/test/QueryTest.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/test/QueryTest.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/test/QueryTest.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,69 @@
+package org.obd.test;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.obd.model.Statement;
+import org.obd.query.ComparisonQueryTerm;
+import org.obd.query.LinkQueryTerm;
+import org.obd.query.LiteralQueryTerm;
+import org.obd.query.QueryTerm;
+import org.obd.query.ComparisonQueryTerm.Operator;
+import org.obd.query.LiteralQueryTerm.AliasType;
+import org.obd.ws.OBDQueryService;
+
+public class QueryTest extends TestCase {
+
+ OBDQueryService service;
+
+
+ public QueryTest(String n) {
+ super(n);
+ }
+
+
+ public void setUp() throws Exception {
+ System.out.println("Setting up: " + this);
+ service = new OBDQueryService();
+
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ addTests(suite);
+ return suite;
+ }
+
+ public static void addTests(TestSuite suite) {
+ suite.addTest(new QueryTest("testQuery"));
+ }
+
+ public void testQuery() {
+
+ QueryTerm qt;
+
+ runQuery(new LiteralQueryTerm(AliasType.PRIMARY_NAME,
+ "apoptosis"));
+ runQuery(new LiteralQueryTerm(AliasType.ALTERNATE_LABEL,
+ new ComparisonQueryTerm(Operator.STARTS_WITH,
+ "apoptosis")));
+
+ String partOf = "OBO_REL:part_of";
+ String developsFrom = "OBO_REL:developsFrom";
+ runQuery(new LinkQueryTerm(partOf, "GO:0005634"));
+ runQuery(new LinkQueryTerm(partOf,
+ new LiteralQueryTerm(AliasType.ANY_LABEL, "nucleus")));
+ runQuery(new LinkQueryTerm(partOf,
+ new LinkQueryTerm(developsFrom, "CL:1234567")));
+
+
+
+ }
+
+ public void runQuery(QueryTerm qt) {
+ System.out.println("running Q: "+qt.toString());
+
+ }
+
+}
Added: obdapi/trunk/OBDAPI/src/org/obd/test/SearchTest.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/test/SearchTest.java (rev 0)
+++ obdapi/trunk/OBDAPI/src/org/obd/test/SearchTest.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -0,0 +1,66 @@
+package org.obd.test;
+
+import java.io.PrintStream;
+import java.util.logging.Logger;
+
+import org.bbop.io.AuditedPrintStream;
+import org.obd.model.Graph;
+import org.obd.model.Node;
+import org.obd.model.Statement;
+import org.obd.ws.OBDQueryService;
+import org.obo.datamodel.impl.DefaultLinkDatabase;
+import org.obo.reasoner.impl.ForwardChainingReasoner;
+import org.obo.test.OBDAnnotationSaveTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class SearchTest extends TestCase {
+
+ OBDQueryService service;
+
+
+ public SearchTest(String n) {
+ super(n);
+ }
+
+
+ public void setUp() throws Exception {
+ System.out.println("Setting up: " + this);
+ service = new OBDQueryService();
+
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ addTests(suite);
+ return suite;
+ }
+
+ public static void addTests(TestSuite suite) {
+ suite.addTest(new SearchTest("testQuery"));
+ }
+
+ public void testQuery() {
+
+ for (Node n : service.getNodesBySearch("AB%")) {
+ System.out.println(n);
+ for (Statement s : n.getStatements()) {
+ System.out.println(" "+s);
+ }
+
+ }
+
+ for (Node n : service.getNodesBySearch("apoptosis%")) {
+ System.out.println(n);
+ for (Statement s : n.getStatements()) {
+ System.out.println(" "+s);
+ }
+
+ }
+
+
+ }
+
+}
Modified: obdapi/trunk/OBDAPI/src/org/obd/ws/OBDQueryService.java
===================================================================
--- obdapi/trunk/OBDAPI/src/org/obd/ws/OBDQueryService.java 2007-12-10 20:13:17 UTC (rev 1301)
+++ obdapi/trunk/OBDAPI/src/org/obd/ws/OBDQueryService.java 2007-12-11 01:56:57 UTC (rev 1302)
@@ -8,14 +8,15 @@
import org.bbop.dataadapter.DataAdapterException;
import org.obd.model.Graph;
import org.obd.model.Node;
-import org.obd.model.Shard;
import org.obd.model.Statement;
-import org.obd.model.Shard.EntailmentUse;
-import org.obd.model.Shard.GraphExpansionAlgorithm;
-import org.obd.model.impl.MultiShard;
-import org.obd.model.impl.MutableOBOSessionShard;
-import org.obd.model.impl.OBDSQLShard;
import org.obd.model.stats.AggregateStatisticCollection;
+import org.obd.query.QueryTerm;
+import org.obd.query.Shard;
+import org.obd.query.Shard.EntailmentUse;
+import org.obd.query.Shard.GraphExpansionAlgorithm;
+import org.obd.query.impl.MultiShard;
+import org.obd.query.impl.MutableOBOSessionShard;
+import org.obd.query.impl.OBDSQLShard;
@@ -62,9 +63,20 @@
public Node[] getSourceNodes() {
return (Node[] )shard.getSourceNodes().toArray(new Node[0]);
}
- public Node[] getNodesWithSource(String sourceId) {
- return (Node[])shard.getNodes(sourceId).toArray(new Node[0]);
+
+
+ public Node[] getNodesBySource(String sourceId) {
+ return (Node[])shard.getNodesBySource(sourceId).toArray(new Node[0]);
}
+ public Node[] getNodesBySearch(String searchTerm) {
+ return (Node[])shard.getNodesBySearch(searchTerm).toArray(new Node[0]);
+ }
+
+ public Node[] getNodesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea) {
+ return (Node[])shard.getNodesBelowNodeSet(ids, entailment, gea).toArray(new Node[0]);
+ }
public Graph getGraph() {
return null;
@@ -75,7 +87,35 @@
public Graph getAnnotationGraphAroundNode(String id, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
return shard.getAnnotationGraphAroundNode(id, entailment, gea);
}
+
+
+ public Statement[] getAnnotationStatementsForAnnotatedEntity(String id, EntailmentUse entailment, GraphExpansionAlgorithm strategy) {
+ return (Statement[] ) shard.
+ getAnnotationStatementsForAnnotatedEntity(id, entailment, strategy).
+ toArray(new Statement[0]);
+ }
+
+ public Node[] getAnnotatedEntitiesBelowNodeSet(Collection<String> ids,
+ EntailmentUse entailment,
+ GraphExpansionAlgorithm gea) {
+ return (Node[])shard.getAnnotatedEntitiesBelowNodeSet(ids, entailment, gea).toArray(new Node[0]);
+ }
+
+
+
+ public Graph getGraphByQuery(QueryTerm queryTerm, EntailmentUse entailment, GraphExpansionAlgorithm gea) {
+ return shard.getGraphByQuery(queryTerm, entailment, gea);
+ }
+
+ public Node[] getNodesByQuery(QueryTerm queryTerm) {
+ return (Node[])shard.getNodesByQuery(queryTerm).toArray(new Node[0]);
+ }
+
+ public Statement[] getStatementsByQuery(QueryTerm queryTerm) {
+ return (Statement[])shard.getStatementsByQuery(queryTerm).toArray(new Statement[0]);
+ }
+
public Statement getStatement(String id) {
//return shard.getStatements().iterator().next();
return null;
@@ -118,6 +158,7 @@
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|