Skip to content

Commit

Permalink
Merge pull request #224 from KacperFKorban/renames
Browse files Browse the repository at this point in the history
Some cleanups and renames + runner helpers
  • Loading branch information
KacperFKorban authored Jan 5, 2022
2 parents 1452c37 + 12de3d8 commit 8e8fcea
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 157 deletions.
4 changes: 2 additions & 2 deletions docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Most of the code concerning this is located in `engineHttp` module.
REST API:
- "/forSignature" <- takes a parameter `signature` which is a string being the queried Scala signature. e.g. "/forSignature?signature="Int=>Int"".
- "/query" <- html with some example queries and a basic GUI to query the engine.
(see [HttpServer.scala](/engineHttp/src/main/scala/org/virtuslab/inkuire/engine/http/http/HttpServer.scala))
(see [HttpServer.scala](/http/src/main/scala/org/virtuslab/inkuire/engine/http/http/HttpServer.scala))

#### JavaScript worker integration

Expand All @@ -30,7 +30,7 @@ Js worker can be used in a similar way as in [Scaladoc Searchbar](https://github

As any Scala codebase, it can be included as a library dependency.

Then Inkuire can be used in a similar way to [Main](/engineHttp/src/main/scala/org/virtuslab/inkuire/engine/http/Main.scala).
Then Inkuire can be used in a similar way to [Main](/http/src/main/scala/org/virtuslab/inkuire/engine/http/Main.scala).

### Data format

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.inkuire.engine.common.service
package org.virtuslab.inkuire.engine.common.api

import org.virtuslab.inkuire.engine.common.model._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.inkuire.engine.common.service
package org.virtuslab.inkuire.engine.common.api

import org.virtuslab.inkuire.engine.common.model.ExternalSignature
import org.virtuslab.inkuire.engine.common.model.InkuireDb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.inkuire.engine.common.parser
package org.virtuslab.inkuire.engine.common.api

import org.virtuslab.inkuire.engine.common.model.ParsedSignature

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.inkuire.engine.common.service
package org.virtuslab.inkuire.engine.common.api

import org.virtuslab.inkuire.engine.common.model.ParsedSignature
import org.virtuslab.inkuire.engine.common.model.ResolveResult
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.virtuslab.inkuire.engine.common.api

import cats.effect.IO
import org.virtuslab.inkuire.engine.common.model._
import org.virtuslab.inkuire.engine.common.parser.ScalaSignatureParserService
import org.virtuslab.inkuire.engine.common.service.DefaultSignatureResolver
import org.virtuslab.inkuire.engine.common.service.ScalaExternalSignaturePrettifier
import org.virtuslab.inkuire.engine.common.service.SubstitutionMatchService
import org.virtuslab.inkuire.engine.common.service.TopLevelMatchQualityService

class InkuireRunner(
configReader: ConfigReader,
inputHandler: InputHandler,
outputHandler: OutputHandler,
parser: BaseSignatureParserService,
resolver: InkuireDb => BaseSignatureResolver,
matchService: InkuireDb => BaseMatchService,
matchQualityService: InkuireDb => BaseMatchQualityService,
prettifier: BaseSignaturePrettifier
) {

def run(args: Seq[String]): IO[Unit] =
configReader
.readConfig(args)
.flatMap { config: AppConfig =>
inputHandler
.readInput(config)
.semiflatMap { db: InkuireDb =>
outputHandler
.serveOutput()
.runA(
Engine.Env(db, matchService(db), matchQualityService(db), prettifier, parser, resolver(db), config)
)
}
}
.fold(str => println(s"Oooooh man, bad luck. Inkuire encountered an unexpected error. Caused by $str"), identity)

}

object InkuireRunner {
def scalaRunner(
configReader: ConfigReader,
inputHandler: InputHandler,
outputHandler: OutputHandler,
parser: BaseSignatureParserService = new ScalaSignatureParserService,
resolver: InkuireDb => BaseSignatureResolver = (db: InkuireDb) => new DefaultSignatureResolver(db),
matchService: InkuireDb => BaseMatchService = (db: InkuireDb) => new SubstitutionMatchService(db),
matchQualityService: InkuireDb => BaseMatchQualityService = (db: InkuireDb) => new TopLevelMatchQualityService(db),
prettifier: BaseSignaturePrettifier = new ScalaExternalSignaturePrettifier
): InkuireRunner =
new InkuireRunner(
configReader,
inputHandler,
outputHandler,
parser,
resolver,
matchService,
matchQualityService,
prettifier
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.virtuslab.inkuire.engine.common.service
package org.virtuslab.inkuire.engine.common.api

import org.virtuslab.inkuire.engine.common.model.ExternalSignature

trait SignaturePrettifier {
trait BaseSignaturePrettifier {
def prettify(sgns: Seq[ExternalSignature]): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package org.virtuslab.inkuire.engine.common.model

import cats.data.StateT
import cats.effect.IO
import org.virtuslab.inkuire.engine.common.parser.BaseSignatureParserService
import org.virtuslab.inkuire.engine.common.service._
import org.virtuslab.inkuire.engine.common.api._

object Engine {
case class Env(
db: InkuireDb,
matcher: BaseMatchService,
matchQualityService: BaseMatchQualityService,
prettifier: SignaturePrettifier,
prettifier: BaseSignaturePrettifier,
parser: BaseSignatureParserService,
resolver: BaseSignatureResolver,
appConfig: AppConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.virtuslab.inkuire.engine.common.parser
import cats.instances.all._
import cats.syntax.all._
import com.softwaremill.quicklens._
import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

import scala.util.matching.Regex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.virtuslab.inkuire.engine.common.service

import org.virtuslab.inkuire.engine.common.model.ExternalSignature
import org.virtuslab.inkuire.engine.common.model.InkuireDb
import org.virtuslab.inkuire.engine.common.model.ResolveResult
import org.virtuslab.inkuire.engine.common.model.Signature
import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

class ExactMatchService(val inkuireDb: InkuireDb) extends BaseMatchService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package org.virtuslab.inkuire.engine.common.service
import cats.data.State
import cats.implicits._
import com.softwaremill.quicklens._
import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

class FluffMatchService(val inkuireDb: InkuireDb) extends BaseMatchService with MatchingOps {
class SubstitutionMatchService(val inkuireDb: InkuireDb) extends BaseMatchService with MatchingOps {

val ancestryGraph: AncestryGraph =
AncestryGraph(inkuireDb.types, inkuireDb.implicitConversions, inkuireDb.typeAliases)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.virtuslab.inkuire.engine.common.service

import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

class IsomorphismMatchQualityService(val db: InkuireDb) extends BaseMatchQualityService with MatchingOps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.virtuslab.inkuire.engine.common.service

import cats.data.NonEmptyList
import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

class KotlinExternalSignaturePrettifier extends SignaturePrettifier {
class KotlinExternalSignaturePrettifier extends BaseSignaturePrettifier {

override def prettify(sgns: Seq[ExternalSignature]): String =
sgns.map(doPrettify).map(identity).mkString("\n")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.virtuslab.inkuire.engine.http.http

import org.virtuslab.inkuire.engine.common.api.BaseSignaturePrettifier
import org.virtuslab.inkuire.engine.common.model.ExternalSignature
import org.virtuslab.inkuire.engine.common.model.Match
import org.virtuslab.inkuire.engine.common.model.ResultFormat
import org.virtuslab.inkuire.engine.common.service.SignaturePrettifier

class OutputFormatter(prettifier: SignaturePrettifier) {
class OutputFormatter(prettifier: BaseSignaturePrettifier) {
def createOutput(query: String, signatures: Seq[(ExternalSignature, Int)]): ResultFormat =
ResultFormat(
query,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.virtuslab.inkuire.engine.common.service

import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

class ScalaExternalSignaturePrettifier extends SignaturePrettifier {
class ScalaExternalSignaturePrettifier extends BaseSignaturePrettifier {

override def prettify(sgns: Seq[ExternalSignature]): String =
sgns.map(prettify).map(identity).mkString("\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.virtuslab.inkuire.engine.common.service

import cats.implicits._
import com.softwaremill.quicklens._
import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

class DefaultSignatureResolver(inkuireDb: InkuireDb) extends BaseSignatureResolver with MatchingOps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.virtuslab.inkuire.engine.common.service

import org.virtuslab.inkuire.engine.common.api._
import org.virtuslab.inkuire.engine.common.model._

class TopLevelMatchQualityService(val db: InkuireDb) extends BaseMatchQualityService with MatchingOps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class EndToEndEngineTest extends munit.FunSuite {
}
override def munitFixtures: List[Fixture[InkuireTestService]] = List(testService)

/**
* Test whether a search using a `signature` includes `funName`
/** Test whether a search using a `signature` includes `funName`
*/
def testFunctionFound(signature: String, funName: String)(implicit loc: munit.Location): Unit = {
test(s"$funName : $signature") {
Expand Down Expand Up @@ -43,5 +42,8 @@ class EndToEndEngineTest extends munit.FunSuite {

testFunctionFound("Boolean => B => A => Either[A, B]", "Either.cond")

testFunctionFound("IArray[Float] => (Float => Boolean) => Boolean", "IArray.forall") // TODO(kπ) IMHO should be just `forall` (generation bug)
testFunctionFound(
"IArray[Float] => (Float => Boolean) => Boolean",
"IArray.forall"
) // TODO(kπ) IMHO should be just `forall` (generation bug)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import org.virtuslab.inkuire.engine.common.model.InkuireDb
import org.virtuslab.inkuire.engine.common.parser.ScalaSignatureParserService
import org.virtuslab.inkuire.engine.common.serialization.EngineModelSerializers
import org.virtuslab.inkuire.engine.common.service.DefaultSignatureResolver
import org.virtuslab.inkuire.engine.common.service.FluffMatchService
import org.virtuslab.inkuire.engine.common.service.SubstitutionMatchService

import java.io.File
import java.net.URL
import scala.io.Source
import scala.util.chaining._

class InkuireTestService(path: String) {

private def getURLs(url: URL, filesExtension: String): List[URL] = {
if (url.toURI.getScheme.toLowerCase == "file" && new File(url.toURI).isDirectory)
new File(url.toURI).listFiles(_.getName.endsWith(filesExtension)).map(_.toURI.toURL).toList
Expand All @@ -36,17 +36,18 @@ class InkuireTestService(path: String) {
}
.pipe(Monoid.combineAll[InkuireDb])

val matchService = new FluffMatchService(db)
val resolver = new DefaultSignatureResolver(db)
val parser = new ScalaSignatureParserService
val matchService = new SubstitutionMatchService(db)
val resolver = new DefaultSignatureResolver(db)
val parser = new ScalaSignatureParserService

def query(q: String): Seq[ExternalSignature] = {
parser
.parse(q)
.flatMap(resolver.resolve)
.map(matchService.findMatches)
.toOption.toSeq
.toOption
.toSeq
.flatMap(_.map(_._1))
}

}
}
36 changes: 8 additions & 28 deletions http/src/main/scala/org/virtuslab/inkuire/engine/http/Main.scala
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
package org.virtuslab.inkuire.engine.http

import org.virtuslab.inkuire.engine.common.model.AppConfig
import org.virtuslab.inkuire.engine.common.model.Engine.Env
import org.virtuslab.inkuire.engine.common.model.InkuireDb
import org.virtuslab.inkuire.engine.common.parser.ScalaSignatureParserService
import org.virtuslab.inkuire.engine.common.service._
import org.virtuslab.inkuire.engine.common.api.InkuireRunner
import org.virtuslab.inkuire.engine.http.cli.Cli
import org.virtuslab.inkuire.engine.http.http.HttpServer

object Main extends App {

val configReader = new Cli
val in = new Cli
val out = new HttpServer
val matchService: InkuireDb => FluffMatchService = (db: InkuireDb) => new FluffMatchService(db)
val matchQualityService: InkuireDb => TopLevelMatchQualityService = (db: InkuireDb) =>
new TopLevelMatchQualityService(db)
val prettifier = new ScalaExternalSignaturePrettifier
val resolver: InkuireDb => DefaultSignatureResolver = (db: InkuireDb) => new DefaultSignatureResolver(db)
val parser = new ScalaSignatureParserService

configReader
.readConfig(args)
.flatMap { config: AppConfig =>
in.readInput(config)
.semiflatMap { db: InkuireDb =>
out
.serveOutput()
.runA(
Env(db, matchService(db), matchQualityService(db), prettifier, parser, resolver(db), config)
)
}
}
.fold(str => println(s"Oooooh man, bad luck. Inkuire encountered an unexpected error. Caused by $str"), identity)
InkuireRunner
.scalaRunner(
configReader = new Cli,
inputHandler = new Cli,
outputHandler = new HttpServer
)
.run(args)
.unsafeRunSync()

}
Loading

0 comments on commit 8e8fcea

Please sign in to comment.