Giter Site home page Giter Site logo

benderama's Issues

Extend benderama to work with sets of tables linked by constraints

stories

As a developer I would like to use benderama on sets of tables, so that the constraints between tables are satisfied.
For instance, if table A has a foreign key b on the table B, benderama should generate a row for table A having column b that exists in table B.

requirements

Extend benderama to work with sets of tables linked by constraints.

Project discontinued

This R&D project has been discontinued as, for the foreseeable future, it will be useful only for one project...

To kill it completely we should:

  • copy this code in the other project's repo
  • remove this repo

Interface proposal

requirements

Interface proposal

object Main extends App {
  import G._

 // data taken from a table
  val data = Map(("col1", "int") -> List(1,2,3,2,2,3,1,5,0), ("col2", "string") -> List("hi", "man", "hi", "hi"))

  // create a model for the given dataset
  val dataModel: M = model(data)

  //samplers are used to specify how to convert parts of the model to values
  //defaults sampler will be defined - and output value will be randomized :D
  implicit def intSampler: IntModel => Int = (i: IntModel) => i.mu.toInt
  implicit def strSampler: StringModel => String = (i: StringModel) =>
    i.wordsFrequency.filter(_._2 == i.wordsFrequency.valuesIterator.max).head._1

  //sample is used to sample one row from the model
  val res: List[_] = dataModel.sample

  println(res)
}

object G {
  //we can add an optional list of pairs (columnName, model) that are matched by columnName
  //this would add some flexibility
  def model(m: Map[(String, String), List[_]]): M = new M(
    m.map { c =>
      val (column, values) = c
      column._2 match {
        case "int" => buildIntModel(values)
        case "string" => buildStringModel(values)
        case _ => throw new Exception("aaa")
      }
    } toList
  )

  private[this] def buildIntModel(values: List[_]): Mi = {
    val intValues = values.asInstanceOf[List[Int]]
    val avg: Double = intValues.sum / intValues.length.toDouble
    val std: Double = math.sqrt(intValues.foldLeft(0.0){ case (k, v) => k + math.pow(v - avg, 2.0) })
    new IntModel(avg, std)
  }

  private[this] def buildStringModel(values: List[_]): Mi = {
    val stringValues = values.asInstanceOf[List[String]]
    new StringModel(stringValues.groupBy(w => w).mapValues(_.length))
  }
}

trait Mi
class IntModel(val mu: Double, std: Double) extends Mi
class StringModel(val wordsFrequency: Map[String, Int]) extends Mi

class M(models: List[Mi]) {
  def sample(implicit
    intSampler: IntModel => Int,
    stringSampler: StringModel => String
  ): List[_] = models.map { a => a match {
    case m: IntModel => m: Int
    case m: StringModel => m: String
  }} 
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.