Skip to content

Commit 7820a6b

Browse files
committed
pretty big refactoring, more types
1 parent 4153009 commit 7820a6b

File tree

14 files changed

+288
-146
lines changed

14 files changed

+288
-146
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ skip in update := true
1515
libraryDependencies ++= Seq(
1616
"ohnosequences" %% "scarph" % "0.2.0-SNAPSHOT",
1717
"ohnosequences" %% "tabula" % "0.1.0-SNAPSHOT",
18+
"ohnosequences" %% "type-sets" % "0.5.0-SNAPSHOT",
1819
//"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "3.0.0", currentlu unavailable for 2.11
1920
"com.amazonaws" % "aws-java-sdk" % "1.8.0",
2021
"org.scala-lang.modules" %% "scala-xml" % "1.0.2",
@@ -23,7 +24,7 @@ libraryDependencies ++= Seq(
2324
)
2425

2526
dependencyOverrides ++= Set(
26-
"ohnosequences" %% "type-sets" % "0.5.0-SNAPSHOT",
27+
// "ohnosequences" %% "type-sets" % "0.5.0-SNAPSHOT",
2728
"org.apache.httpcomponents" % "httpclient" % "4.2",
2829
"commons-codec" % "commons-codec" % "1.7",
2930
"com.amazonaws" % "aws-java-sdk" % "1.8.0",

src/main/scala/com/bio4j/dynamograph/AnyDynamoVertex.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import ohnosequences.typesets._
1111

1212
trait AnyDynamoVertex extends AnySealedVertex { dynamoVertex =>
1313

14+
// TODO move this to have a VertexTable and use that
15+
1416
val dao: AnyDynamoDbDao = ServiceProvider.dao
1517

1618
type Other = String

src/main/scala/com/bio4j/dynamograph/mapper/GoMapper.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ import scala.Some
2020

2121

2222

23-
class GoMapper extends AnyMapper{
23+
class GoMapper extends AnyMapper {
2424

2525
override def map(element: SingleElement): List[AnyPutItemAction] = {
26+
2627
val vertexAttrs = element.vertexAttributes
28+
29+
// TODO you don't need all this tagging, I'll fix it later
2730
case object valueMapper extends Poly1{
2831
implicit def caseN[A <: Singleton with AnyProperty.ofValue[Integer]] =
2932
at[A]{ a : A => (a ->> vertexAttrs(a.label).toInt.asInstanceOf[a.Raw]): A#Rep }
@@ -45,7 +48,8 @@ class GoMapper extends AnyMapper{
4548
).mapValues(mapValue)
4649
createEdge(attrValue(attributes, ParsingContants.relationType), rawEdge)
4750
}
48-
GoWriters.goTermVertexWriter.write(value.recordEntry) ::: element.edges.map(toWriteOperation).flatten
51+
52+
GoWriters.goTermVertexWriter.write(value) ::: element.edges.map(toWriteOperation).flatten
4953
}
5054

5155
private def mapValue(x : String) : AttributeValue = new AttributeValue().withS(x)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.bio4j.dynamograph.model
2+
3+
import ohnosequences.scarph._
4+
import ohnosequences.typesets._
5+
import ohnosequences.tabula._, impl.ImplicitConversions._, toSDKRep._, fromSDKRep._
6+
import shapeless._
7+
import com.bio4j.dynamograph.{AnyDynamoVertex, AnyDynamoEdge}
8+
import com.bio4j.dynamograph.model.GeneralSchema._
9+
10+
trait AnyEdgeTables { edgeTables =>
11+
12+
// TODO missing sealed edge type in scarph
13+
type EdgeType <: Singleton with AnyEdgeType {
14+
type SourceType <: Singleton with AnySealedVertexType
15+
type TargetType <: Singleton with AnySealedVertexType
16+
}
17+
val edgeType: EdgeType
18+
19+
type EdgeId <: Singleton with AnyProperty.ofValue[String]
20+
val edgeId: EdgeId
21+
22+
type Region <: AnyRegion
23+
val region: Region
24+
25+
type SourceVertexTable <: AnyVertexTable with AnyVertexTable.withVertexType[edgeTables.EdgeType#SourceType]
26+
val sourceVertexTable: SourceVertexTable
27+
28+
29+
30+
type OutTable <: AnyTable.inRegion[edgeTables.Region] with
31+
AnyCompositeKeyTable.withHashKey[edgeTables.SourceVertexTable#VertexId] with
32+
AnyCompositeKeyTable.withRangeKey[edgeTables.EdgeId]
33+
34+
val outTable: OutTable
35+
36+
type EdgeTable <: AnyHashKeyTable with AnyTable.inRegion[edgeTables.Region] with
37+
AnyHashKeyTable.withKey[edgeTables.EdgeId]
38+
39+
val edgeTable: EdgeTable
40+
41+
type InTable <: AnyTable.inRegion[edgeTables.Region] with
42+
AnyCompositeKeyTable.withHashKey[edgeTables.TargetVertexTable#VertexId] with
43+
AnyCompositeKeyTable.withRangeKey[edgeTables.EdgeId]
44+
45+
val inTable: InTable
46+
47+
type TargetVertexTable <: AnyVertexTable with AnyVertexTable.withVertexType[edgeTables.EdgeType#TargetType]
48+
val targetVertexTable: TargetVertexTable
49+
50+
val tables = inTable :: outTable :: edgeTable :: HNil
51+
}
52+
53+
class EdgeTables[
54+
ST <: AnyVertexTable with AnyVertexTable.withVertexType[ET#SourceType],
55+
ET <: Singleton with AnyEdgeType {
56+
type SourceType <: Singleton with AnySealedVertexType
57+
type TargetType <: Singleton with AnySealedVertexType
58+
},
59+
TT <: AnyVertexTable with AnyVertexTable.withVertexType[ET#TargetType],
60+
R <: AnyRegion
61+
](
62+
val sourceVertexTable: ST,
63+
val edgeType: ET,
64+
val targetVertexTable: TT,
65+
val tableName: String,
66+
val region: R
67+
)
68+
extends AnyEdgeTables {
69+
70+
type EdgeType = ET
71+
type Region = R
72+
type SourceVertexTable = ST
73+
type TargetVertexTable = TT
74+
75+
// TODO constructor params
76+
type EdgeId = id.type
77+
val edgeId = id
78+
79+
type OutTable = OutTable.type; val outTable = OutTable
80+
case object OutTable extends CompositeKeyTable(s"${tableName}_OUT", sourceVertexTable.vertexId, edgeId, region)
81+
82+
type EdgeTable = EdgeTable.type; val edgeTable = EdgeTable
83+
case object EdgeTable extends HashKeyTable(tableName, relationId, region)
84+
85+
type InTable = InTable.type; val inTable = InTable
86+
case object InTable extends CompositeKeyTable(s"{tableName}_IN", targetVertexTable.vertexId, edgeId, region)
87+
88+
case object outRecord extends Record(sourceVertexTable.vertexId :~: edgeId :~: )
89+
case object edgeRecord extends Record(edgeId :~: sourceVertexTable.vertexId :~: targetVertexTable.vertexId :~: )
90+
case object inRecord extends Record(targetVertexTable.vertexId :~: edgeId :~: )
91+
92+
case object outItem extends Item(outTable, outRecord)
93+
case object edgeItem extends Item(edgeTable, edgeRecord)
94+
case object inItem extends Item(inTable, inRecord)
95+
}

src/main/scala/com/bio4j/dynamograph/model/go/GoSchema.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object GoSchema {
1010
val goTermAttributes = id :~: name :~: comment :~: definition :~:
1111
case object GoTermRecord extends Record(goTermAttributes)
1212
// Vertex Type
13-
object GoTermType extends SealedVertexType("GoTerm",GoTermRecord)
13+
object GoTermType extends SealedVertexType("GoTerm", GoTermRecord)
1414
implicit val GoTermType_properties = GoTermType has goTermAttributes
1515

1616
val goNamespacesAttributes = id :~:
@@ -19,6 +19,7 @@ object GoSchema {
1919
implicit val GoNamespacesType_properties = GoNamespacesType has goNamespacesAttributes
2020

2121
// Edge Types
22+
// TODO sealed edge types
2223
case object HasPartType extends ManyToMany (GoTermType, "hasPart", GoTermType)
2324
case object IsAType extends ManyToMany (GoTermType, "isA", GoTermType)
2425
case object PartOfType extends ManyToMany (GoTermType, "partOf", GoTermType)

src/main/scala/com/bio4j/dynamograph/model/go/TableGoImplementation.scala

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.bio4j.dynamograph.model.go
22

3-
import com.bio4j.dynamograph.model.go.TableGoSchema.{EdgeTables, VertexTable}
4-
import shapeless.HNil
3+
import com.bio4j.dynamograph.model._
4+
import shapeless._
55
import ohnosequences.typesets._
66
import ohnosequences.tabula._
77
import com.bio4j.dynamograph.model.go.GoSchema._
@@ -10,16 +10,47 @@ import com.bio4j.dynamograph.model.go.GoImplementation._
1010

1111
object TableGoImplementation {
1212

13-
case object GoTermTable extends VertexTable(GoTermType, "GoTerm", EU)
14-
case object GoNamespacesTable extends VertexTable(GoNamespacesType, "GoNamespaces", EU)
13+
// vertices
14+
case object GoTermTable extends VertexTable(GoTermType, "GoTerm", EU)
15+
case object GoNamespacesTable
16+
extends VertexTable(GoNamespacesType, "GoNamespaces", EU)
1517

16-
case object IsATables extends EdgeTables(IsA, "GoIsA", EU)
17-
case object HasPartTables extends EdgeTables(HasPart, "GoHasPart",EU)
18-
case object PartOfTables extends EdgeTables(PartOf, "GoPartOf", EU)
19-
case object NegativelyRegulatesTables extends EdgeTables(NegativelyRegulates, "GoNegativelyRegulates", EU)
20-
case object PositivelyRegulatesTables extends EdgeTables(PositivelyRegulates, "GoPositivelyRegulates", EU)
21-
case object RegulatesTables extends EdgeTables(Regulates, "GoRegulates", EU)
22-
case object NamespaceTables extends EdgeTables(Namespace, "GoNamespaceEdges", EU)
18+
// edges
19+
// TODO why explicit types needed?? I don't understand this
20+
case object IsATables
21+
extends EdgeTables[GoTermTable.type, IsA.type, GoTermTable.type, EU.type](
22+
GoTermTable, IsA, GoTermTable, "GoIsA", EU
23+
)
24+
25+
case object HasPartTables
26+
extends EdgeTables[GoTermTable.type, HasPart.type, GoTermTable.type, EU.type](
27+
GoTermTable, HasPart, GoTermTable, "GoHasPart", EU
28+
)
29+
30+
case object PartOfTables
31+
extends EdgeTables[GoTermTable.type, PartOf.type, GoTermTable.type, EU.type](
32+
GoTermTable, PartOf, GoTermTable, "GoPartOf", EU
33+
)
34+
35+
case object NegativelyRegulatesTables
36+
extends EdgeTables[GoTermTable.type, NegativelyRegulates.type, GoTermTable.type, EU.type](
37+
GoTermTable, NegativelyRegulates, GoTermTable,"GoNegativelyRegulates", EU
38+
)
39+
40+
case object PositivelyRegulatesTables
41+
extends EdgeTables[GoTermTable.type, PositivelyRegulates.type, GoTermTable.type, EU.type](
42+
GoTermTable, PositivelyRegulates, GoTermTable, "GoPositivelyRegulates", EU
43+
)
44+
45+
case object RegulatesTables
46+
extends EdgeTables[GoTermTable.type, Regulates.type, GoTermTable.type, EU.type](
47+
GoTermTable, Regulates, GoTermTable, "GoRegulates", EU
48+
)
49+
50+
case object NamespaceTables
51+
extends EdgeTables[GoTermTable.type, Namespace.type, GoNamespacesTable.type, EU.type](
52+
GoTermTable, Namespace, GoNamespacesTable, "GoNamespaceEdges", EU
53+
)
2354

2455
val vertexTables = GoTermTable.table ::
2556
GoNamespacesTable.table ::

src/main/scala/com/bio4j/dynamograph/model/go/TableGoSchema.scala

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/main/scala/com/bio4j/dynamograph/model/go/TableModelInitializer.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import com.bio4j.dynamograph.model.go.TableGoSchema.EdgeTables
99

1010
object TableModelInitializer {
1111

12+
// TODO class with method for this etc
1213
val service = ServiceProvider.service
1314

14-
object createTable extends Poly1{
15+
object createTable extends Poly1 {
1516
implicit def caseAnyTable[T <: Singleton with AnyTable, E <: Executor.For[CreateTable[T]]]
1617
(implicit exec: CreateTable[T] => E) =
1718
at[T](t => service please CreateTable(t, InitialState(t, service.account, InitialThroughput(1,1))))
1819
}
1920

20-
object deleteTable extends Poly1{
21+
object deleteTable extends Poly1 {
2122
implicit def caseAnyTable[T <: Singleton with AnyTable, E <: Executor.For[DeleteTable[T]]]
2223
(implicit exec: DeleteTable[T] => E) =
2324
at[T](t => service please DeleteTable(t, Active(t, service.account, InitialThroughput(1,1))))

0 commit comments

Comments
 (0)