Giter VIP home page Giter VIP logo

jvm-repr's Introduction

JVM Repr

Build Status JVM repr on jitpack

Configuration | Usage for Library Authors | Usage for Kernel Authors

Standardizing object representation and inspection across JVM kernels (Scala, Clojure, Groovy, ...).

Purpose

JVM languages use various conventions to convert REPL outputs to forms that can be displayed. This project is an attempt to standardize by providing an API that libraries can use to register display methods for any jupyter frontend, whether console, notebook, or dashboard.

This API has two main uses:

  • For library authors to provide a way to convert from a library's JVM objects to useful representations by MIME type
  • For kernel authors to convert any JVM object to useful representations by MIME type

As it is with IPython, this is a contract between the libraries within the ecosystem, the kernel that inspects the objects, and the frontends that display them.

Configuration

See instructions on JitPack for gradle, maven, sbt, or leiningen.

Usage

Usage - Library authors

Library authors can register conversion code by implementing a Displayer and registering it with Displayers.

For example, the following will register a displayer for Vegas graphs:

import java.util.Map
import jupyter.Displayer
import jupyter.Displayers
import scala.collection.JavaConverters._
import vegas.DSL.ExtendedUnitSpecBuilder

...

  Displayers.register(classOf[ExtendedUnitSpecBuilder],
    new Displayer[ExtendedUnitSpecBuilder] {
      override def display(plot: ExtendedUnitSpecBuilder): Map[String, String] = {
        val plotAsJson = plot.toJson
        Map(
          "text/plain" -> plotAsJson,
          "application/json" -> plotAsJson,
          "text/html" -> new StaticHTMLRenderer(plotAsJson).frameHTML()
        ).asJava
      }
    })

Any kernel implementation can use the method to display Vegas graphs for the DSL objects.

Library authors can optionally implement setMimeTypes(String...) to receive hints for the MIME types that the kernel or front-end supports. It is recommended that library authors use these hints to avoid expensive conversions.

Usage - Kernel authors

Kernel authors can use this API to display registered objects:

import java.util.Map

// ...

  Object result = interpreter.eval(code);
  Map<String, String> resultByMIME = Displayers.display(result);
  Kernel.this.display(resultByMIME);

Kernel authors can optionally call Displayers.setMimeTypes(String...) to send hints to display implementations with the set of MIME types that can be used by the kernel or front-end.

jvm-repr's People

Contributors

rdblue avatar rgbkrk avatar scottdraves avatar

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.