this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial commit

+414
+30
.gitignore
··· 1 + 2 + # Created by https://www.gitignore.io/api/sbt,scala,ensime 3 + # Edit at https://www.gitignore.io/?templates=sbt,scala,ensime 4 + 5 + ### Ensime ### 6 + # Ensime specific 7 + .ensime 8 + .ensime_cache/ 9 + .ensime_lucene/ 10 + 11 + ### SBT ### 12 + # Simple Build Tool 13 + # http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control 14 + 15 + dist/* 16 + target/ 17 + lib_managed/ 18 + src_managed/ 19 + project/boot/ 20 + project/plugins/project/ 21 + .history 22 + .cache 23 + .lib/ 24 + 25 + ### Scala ### 26 + *.class 27 + *.log 28 + 29 + # End of https://www.gitignore.io/api/sbt,scala,ensime 30 +
+39
build.sbt
··· 1 + import Dependencies._ 2 + 3 + name := "grakn-kbc-poc-ui" 4 + 5 + version := "1.0" 6 + 7 + scalaVersion := "2.12.3" 8 + 9 + resolvers ++= Seq( 10 + "grakn-development-snapshots" at "https://maven.grakn.ai/content/repositories/snapshots/", 11 + Resolver.sonatypeRepo("releases")) 12 + 13 + 14 + 15 + libraryDependencies ++= allDeps 16 + 17 + scalacOptions := Seq( 18 + "-Ypartial-unification", 19 + "-Ywarn-extra-implicit", 20 + "-Ywarn-infer-any", 21 + "-Xlint:adapted-args", 22 + "-Xlint:by-name-right-associative", 23 + "-Xlint:constant", 24 + "-Xlint:delayedinit-select", 25 + "-Xlint:doc-detached", 26 + "-Xlint:inaccessible", 27 + "-Xlint:infer-any", 28 + "-Xlint:missing-interpolator", 29 + "-Xlint:nullary-override", 30 + "-Xlint:nullary-unit", 31 + "-Xlint:option-implicit", 32 + "-Xlint:package-object-classes", 33 + "-Xlint:poly-implicit-overload", 34 + "-Xlint:private-shadow", 35 + "-Xlint:stars-align", 36 + "-Xlint:type-parameter-shadow", 37 + "-Xlint:unsound-match", 38 + "-unchecked" 39 + )
+24
project/Dependencies.scala
··· 1 + import sbt._ 2 + object Dependencies { 3 + // for all category goodness 4 + val cats = "org.typelevel" %% "cats" % "0.9.0" 5 + 6 + // light-weight actor based http server library (not a framework) 7 + val akkaHttp = "com.typesafe.akka" %% "akka-http" % "10.0.9" 8 + 9 + // declarative configuration that's auto parsed 10 + val pureconfig = "com.github.pureconfig" %% "pureconfig" % "0.7.1" 11 + 12 + // graphql library 13 + val sangria = "org.sangria-graphql" %% "sangria" % "1.2.2" 14 + 15 + // grakn types are used in graphql schema 16 + lazy val grakn = "ai.grakn" % "grakn-graph" % "0.13.0" 17 + 18 + // graphql queries are resolved using graql 19 + lazy val grakn_titan = 20 + "ai.grakn" % "titan-factory" % "0.13.0" 21 + 22 + val allDeps = Seq(cats, akkaHttp, pureconfig, sangria) 23 + 24 + }
+1
project/build.properties
··· 1 + sbt.version = 0.13.15
+5
src/main/scala/app/Main.scala
··· 1 + package app 2 + 3 + object Main extends App{ 4 + // println(SchemaRenderer.renderSchema(schema)) 5 + }
+9
src/main/scala/lib/AppContext.scala
··· 1 + package lib 2 + 3 + //trait AppContext { 4 + // val queryAPI: Query 5 + //} 6 + // 7 + //trait LocalContext extends AppContext { 8 + // override val queryAPI: QueryAPI = ModelQueryAPI 9 + //}
+135
src/main/scala/lib/AppSchema.scala
··· 1 + package lib 2 + 3 + import sangria.marshalling.{ 4 + CoercedScalaResultMarshaller, 5 + FromInput, 6 + ResultMarshaller 7 + } 8 + import sangria.schema.{ 9 + Action, 10 + Argument, 11 + EnumType, 12 + EnumValue, 13 + Field, 14 + InputField, 15 + InputObjectType, 16 + InputType, 17 + ListType, 18 + ObjectType, 19 + OptionInputType, 20 + OptionType, 21 + Schema, 22 + StringType, 23 + fields 24 + } 25 + 26 + trait AppSchema[C] { 27 + 28 + lazy val gId: ObjectType[C, ID[_]] = ObjectType( 29 + "id", 30 + fields = fields[C, ID[_]]( 31 + Field( 32 + "value", 33 + fieldType = StringType, 34 + resolve = _.value.value 35 + ) 36 + ) 37 + ) 38 + 39 + lazy val gInputId: InputObjectType[ID[_]] = InputObjectType[ID[_]]( 40 + "inputId", 41 + fields = List( 42 + InputField("value", StringType) 43 + ) 44 + ) 45 + 46 + implicit def idFromInput: FromInput[ID[_]] = 47 + new FromInput[ID[_]] { 48 + override def fromResult(node: marshaller.Node): ID[_] = 49 + ID(node.toString) 50 + 51 + override val marshaller: ResultMarshaller = 52 + CoercedScalaResultMarshaller.default 53 + } 54 + 55 + def idArg(n: String) = 56 + Argument(n, gInputId) 57 + 58 + def idOptArg(n: String): Argument[Option[ID[_]]] = 59 + Argument(n, OptionInputType(gInputId)) 60 + 61 + lazy val gState = EnumType( 62 + "SkillState", 63 + values = List( 64 + EnumValue("PROBABLE", value = SkillState.PROBABLE), 65 + EnumValue("POSSIBLE", value = SkillState.POSSIBLE), 66 + EnumValue("DEMONSTRATED", value = SkillState.DEMONSTRATED), 67 + EnumValue("REFUTED", value = SkillState.REFUTED) 68 + ) 69 + ) 70 + 71 + def idField[T <: Base[T]]: Field[C, T] = 72 + Field("id", fieldType = gId, resolve = _.value.id) 73 + 74 + def stringField[T](l: String, f: T => Action[C, String]): Field[C, T] = 75 + Field(l, fieldType = StringType, resolve = ctx => f(ctx.value)) 76 + 77 + def stringOptField[T](l: String, 78 + f: T => Action[C, Option[String]]): Field[C, T] = 79 + Field(l, fieldType = OptionType(StringType), resolve = ctx => f(ctx.value)) 80 + 81 + lazy val gLevel: ObjectType[C, Level] = ObjectType( 82 + "level", 83 + fields = fields[C, Level]( 84 + idField[Level], 85 + Field( 86 + "name", 87 + fieldType = StringType, 88 + resolve = _.value.name 89 + ) 90 + ) 91 + ) 92 + 93 + lazy val gSkill: ObjectType[C, Skill] = ObjectType( 94 + "skill", 95 + fields = fields[C, Skill]( 96 + idField[Skill], 97 + stringField("name", _.name), 98 + ) 99 + ) 100 + 101 + lazy val stateOptArg = Argument("havingState", OptionInputType(gState)) 102 + 103 + lazy val gStudent: ObjectType[C, Student] = ObjectType( 104 + "student", 105 + fields = fields[C, Student]( 106 + idField[Student], 107 + stringField("firstname", _.firstname), 108 + stringOptField("lastname", _.lastname), 109 + // Field( 110 + // "skills", 111 + // fieldType = ListType(gSkill), 112 + // arguments = idOptArg("atLevel") :: stateOptArg :: Nil, 113 + // resolve = ctx => ctx.value.skills(ctx.arg("id"), ctx.arg("havingState")) 114 + // ) 115 + ) 116 + ) 117 + 118 + lazy val gQuery = ObjectType( 119 + "query", 120 + fields[C, Unit]( 121 + // Field( 122 + // "levels", 123 + // ListType(gLevel), 124 + // resolve = ctx => ctx.ctx.queryAPI.getLevels 125 + // ), 126 + // Field( 127 + // "students", 128 + // ListType(gStudent), 129 + // resolve = ctx => ctx.ctx.queryAPI.getStudents 130 + // ) 131 + ) 132 + ) 133 + 134 + val schema = Schema(gQuery) 135 + }
+65
src/main/scala/lib/Model.scala
··· 1 + package lib 2 + 3 + import scala.language.higherKinds 4 + 5 + case class ID[T] private (value: String) 6 + 7 + object SkillState extends Enumeration { 8 + val PROBABLE, POSSIBLE, DEMONSTRATED, REFUTED = Value 9 + } 10 + 11 + sealed trait Base[T] { 12 + val id: ID[T] 13 + } 14 + 15 + final case class Level private (id: ID[Level], name: String) extends Base[Level] 16 + 17 + final case class Student private (id: ID[Student], 18 + firstname: String, 19 + lastname: Option[String]) 20 + extends Base[Student] 21 + 22 + final case class Skill private (id: ID[Skill], name: String) extends Base[Skill] 23 + 24 + final case class Activity private (id: ID[Activity], name: String) 25 + extends Base[Activity] 26 + 27 + final case class Knowledge_Field private (id: ID[Knowledge_Field], name: String) 28 + extends Base[Knowledge_Field] 29 + 30 + final case class Activity_Occurrence private (id: ID[Activity_Occurrence], 31 + activity_source: Activity, 32 + occurrence_date: Option[String]) 33 + extends Base[Activity_Occurrence] 34 + 35 + // these concrete types are required to pattern match on ID, thanks to JVM type erasure 36 + trait LevelID extends ID[Level] 37 + trait SkillID extends ID[Skill] 38 + trait StudentID extends ID[Student] 39 + trait ActivityID extends ID[Activity] 40 + 41 + trait Repository[F[_]]{ 42 + def get[I,T <: Base[_]](id: I): F[T] 43 + def put[T <: Base[_]](t: Base[T]): F[T] 44 + def all[T <: Base[_]]: F[List[T]] 45 + } 46 + 47 + /* 48 + Smart constructors algebra 49 + */ 50 + trait ModelConsAlg[F[_]]{ 51 + 52 + def level(id: ID[Level], name: String): F[Level] 53 + 54 + def student(id: ID[Student], fn: String, ln: Option[String]): F[Student] 55 + 56 + def skill(id: ID[Skill], name: String): F[Skill] 57 + 58 + def activity(id: ID[Activity], name: String): F[Activity] 59 + 60 + def knowledge_field(id: ID[Knowledge_Field], name: String): F[Knowledge_Field] 61 + 62 + def activity_occurrence(id: ID[Activity_Occurrence], 63 + as: Activity, 64 + od: Option[String]): F[Activity_Occurrence] 65 + }
+57
src/main/scala/lib/Query.scala
··· 1 + package lib 2 + 3 + import cats.Monad 4 + 5 + import scala.language.higherKinds 6 + 7 + trait Query[+A] { 8 + def run[F[+ _]: Monad: ModelConsAlg](F: QueryAlg[F])(R: Repository[F]): F[A] 9 + } 10 + 11 + object Query { 12 + def skills(id: Either[ID[Student], ID[Knowledge_Field]])( 13 + atLevel: Option[ID[Level]], 14 + havingState: Option[List[SkillState.Value]]): Query[List[Skill]] = 15 + new Query[List[Skill]] { 16 + override def run[F[+ _]: Monad: ModelConsAlg](F: QueryAlg[F])( 17 + R: Repository[F]): F[List[Skill]] = 18 + id match { 19 + case Left(iSt) => F.skills(atLevel, havingState)(iSt) 20 + case Right(iKf) => F.skills(iKf) 21 + } 22 + } 23 + 24 + def state(id: ID[Skill])( 25 + forAgent: Student, 26 + atLevel: ID[Level]): Query[Option[SkillState.Value]] = 27 + new Query[Option[SkillState.Value]] { 28 + override def run[F[+ _]: Monad: ModelConsAlg](F: QueryAlg[F])( 29 + R: Repository[F]): F[Option[SkillState.Value]] = 30 + F.state(forAgent, atLevel)(id) 31 + } 32 + 33 + def owners(id: ID[Skill])(atLevel: Option[ID[Level]]): Query[List[Student]] = 34 + ??? 35 + 36 + def enables(id: ID[Skill])( 37 + atLevel: Option[ID[Level]]): Query[List[(Activity, Level)]] = ??? 38 + 39 + def enabledBy(id: ID[Activity]): Query[(Skill, Level)] = ??? 40 + 41 + def related[T <: Base[_]](id: ID[T]): Query[List[T]] = new Query[List[T]] { 42 + override def run[F[+ _]: Monad: ModelConsAlg](F: QueryAlg[F])( 43 + R: Repository[F]): F[List[T]] = 44 + id match { 45 + case id: SkillID => F.relatedSkills(id) 46 + case _ => implicitly[Monad[F]].pure(List()) 47 + } 48 + } 49 + 50 + def levels: Query[List[Level]] = new Query[List[Level]] { 51 + override def run[F[+ _]: Monad: ModelConsAlg](F: QueryAlg[F])( 52 + R: Repository[F]): F[List[Level]] = { 53 + R.all[Level] 54 + } 55 + } 56 + 57 + }
+27
src/main/scala/lib/QueryAlg.scala
··· 1 + package lib 2 + 3 + import scala.language.higherKinds 4 + 5 + trait QueryAlg[F[_]] { 6 + 7 + def skills(atLevel: Option[ID[Level]], 8 + havingState: Option[List[SkillState.Value]])(id: ID[Student])( 9 + implicit mc: ModelConsAlg[F]): F[List[Skill]] 10 + 11 + def state(forAgent: Student, atLevel: ID[Level])(id: ID[Skill])( 12 + implicit mc: ModelConsAlg[F]): F[Option[SkillState.Value]] 13 + def owners(atLevel: Option[ID[Level]])(id: ID[Skill])( 14 + implicit mc: ModelConsAlg[F]): F[List[Student]] 15 + def enables(atLevel: Option[ID[Level]])(id: ID[Skill])( 16 + implicit mc: ModelConsAlg[F]): F[List[(Activity, Level)]] 17 + def relatedSkills(id: ID[Skill])(implicit mc: ModelConsAlg[F]): F[List[Skill]] 18 + def inField(id: ID[Skill])(implicit mc: ModelConsAlg[F]): F[Knowledge_Field] 19 + 20 + def enabledBy(id: ID[Activity])( 21 + implicit mc: ModelConsAlg[F]): F[(Skill, Level)] 22 + def occurredIn(id: ID[Activity])( 23 + implicit mc: ModelConsAlg[F]): F[List[Activity_Occurrence]] 24 + 25 + def skills(id: ID[Knowledge_Field])( 26 + implicit mc: ModelConsAlg[F]): F[List[Skill]] 27 + }
+22
src/main/scala/test.sc
··· 1 + 2 + import sangria.renderer.SchemaRenderer 3 + import sangria.schema._ 4 + 5 + case class Schema1(f: String) { 6 + def someFn(xs: List[String]): List[String] = ??? 7 + } 8 + 9 + val arg = Argument("inp",ListInputType(StringType)) 10 + 11 + val gSchema1 = ObjectType( 12 + "schema1", 13 + fields[Unit, Schema1]( 14 + Field("someFn",ListType(StringType), 15 + arguments = List(arg), 16 + resolve = ctx => ctx.value.someFn(ctx.arg(arg).toList) 17 + ) 18 + )) 19 + val schema = Schema(gSchema1) 20 + SchemaRenderer.renderSchema(schema) 21 + 22 +