zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jongy...@apache.org
Subject [2/2] zeppelin git commit: [ZEPPELIN-2590] Convert jupyter's notebook to Zeppelin's note
Date Sat, 17 Jun 2017 14:02:19 GMT
[ZEPPELIN-2590] Convert jupyter's notebook to Zeppelin's note

### What is this PR for?
Converting jupyter's notebook to Zeppelin's note

### What type of PR is it?
[Feature]

### Todos
* [x] - Add command line interface

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-2590

### How should this be tested?

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jongyoul Lee <jongyoul@gmail.com>

Closes #2393 from jongyoul/ZEPPELIN-2590 and squashes the following commits:

30e970dc [Jongyoul Lee] Added getters
b6a50a2b [Jongyoul Lee] Added getters
45c1ec80 [Jongyoul Lee] Fixed the tests
ac89aa69 [Jongyoul Lee] Added AL header
a653aeae [Jongyoul Lee] Changed replaced string to contain "%"
794e3215 [Jongyoul Lee] Fixed the style
ac115b2c [Jongyoul Lee] Added object to support v3
e4d9ff3d [Jongyoul Lee] Called close method for inputStream Refactored gson logic
bd5fbdc0 [Jongyoul Lee] Removed unused spaces
4e4cfda0 [Jongyoul Lee] Added command line interface
621fe1f5 [Jongyoul Lee] Added note format manually
4945f32a [Jongyoul Lee] Fixed style
87d20047 [Jongyoul Lee] Fixed typo
a0f0c995 [Jongyoul Lee] Added asf header
655cc4d7 [Jongyoul Lee] Added jupyter file format


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/00243ea4
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/00243ea4
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/00243ea4

Branch: refs/heads/master
Commit: 00243ea430ece6fcf6d3d7b73f4b7605100aace2
Parents: e20f68b
Author: Jongyoul Lee <jongyoul@gmail.com>
Authored: Mon Jun 12 23:11:37 2017 +0900
Committer: Jongyoul Lee <jongyoul@apache.org>
Committed: Sat Jun 17 23:02:09 2017 +0900

----------------------------------------------------------------------
 pom.xml                                         |   8 +
 zeppelin-jupyter/pom.xml                        |  64 ++++
 .../apache/zeppelin/jupyter/JupyterUtil.java    | 204 +++++++++++
 .../zeppelin/jupyter/nbformat/Author.java       |  29 ++
 .../apache/zeppelin/jupyter/nbformat/Cell.java  |  47 +++
 .../zeppelin/jupyter/nbformat/CellMetadata.java |  33 ++
 .../zeppelin/jupyter/nbformat/CodeCell.java     |  33 ++
 .../zeppelin/jupyter/nbformat/DisplayData.java  |  33 ++
 .../apache/zeppelin/jupyter/nbformat/Error.java |  46 +++
 .../jupyter/nbformat/ExecuteResult.java         |  36 ++
 .../zeppelin/jupyter/nbformat/HeadingCell.java  |  32 ++
 .../zeppelin/jupyter/nbformat/Kernelspec.java   |  31 ++
 .../zeppelin/jupyter/nbformat/LanguageInfo.java |  41 +++
 .../zeppelin/jupyter/nbformat/MarkdownCell.java |  24 ++
 .../zeppelin/jupyter/nbformat/Metadata.java     |  61 ++++
 .../zeppelin/jupyter/nbformat/Nbformat.java     |  54 +++
 .../zeppelin/jupyter/nbformat/Output.java       |  28 ++
 .../zeppelin/jupyter/nbformat/RawCell.java      |  24 ++
 .../jupyter/nbformat/RawCellMetadata.java       |  28 ++
 .../zeppelin/jupyter/nbformat/Stream.java       |  36 ++
 .../apache/zeppelin/jupyter/zformat/Note.java   |  48 +++
 .../zeppelin/jupyter/zformat/Paragraph.java     |  70 ++++
 .../apache/zeppelin/jupyter/zformat/Result.java |  46 +++
 .../zeppelin/jupyter/zformat/TypeData.java      |  47 +++
 .../jupyter/nbformat/JupyterUtilTest.java       |  48 +++
 zeppelin-jupyter/src/test/resources/basic.ipynb | 149 ++++++++
 .../src/test/resources/examples.ipynb           | 355 +++++++++++++++++++
 27 files changed, 1655 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9232b9e..53d5945 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,6 +78,7 @@
     <module>scio</module>
     <module>zeppelin-web</module>
     <module>zeppelin-server</module>
+    <module>zeppelin-jupyter</module>
     <module>zeppelin-distribution</module>
   </modules>
 
@@ -105,6 +106,7 @@
     <commons.io.version>2.4</commons.io.version>
     <commons.collections.version>3.2.1</commons.collections.version>
     <commons.logging.version>1.1.1</commons.logging.version>
+    <commons.cli.version>1.3.1</commons.cli.version>
     <shiro.version>1.2.3</shiro.version>
 
     <!-- test library versions -->
@@ -233,6 +235,12 @@
       </dependency>
 
       <dependency>
+        <groupId>commons-cli</groupId>
+        <artifactId>commons-cli</artifactId>
+        <version>${commons.cli.version}</version>
+      </dependency>
+
+      <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>${guava.version}</version>

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/pom.xml
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/pom.xml b/zeppelin-jupyter/pom.xml
new file mode 100644
index 0000000..96dabd4
--- /dev/null
+++ b/zeppelin-jupyter/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>zeppelin</artifactId>
+    <groupId>org.apache.zeppelin</groupId>
+    <version>0.8.0-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
+
+  <artifactId>zeppelin-jupyter</artifactId>
+  <packaging>jar</packaging>
+  <version>0.8.0-SNAPSHOT</version>
+  <name>Zeppelin: Jupyter Support</name>
+  <description>Jupyter support for Apache Zeppelin</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.danilopianini</groupId>
+      <artifactId>gson-extras</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-cli</groupId>
+      <artifactId>commons-cli</artifactId>
+    </dependency>
+
+    <!-- Test -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+  </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/JupyterUtil.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/JupyterUtil.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/JupyterUtil.java
new file mode 100644
index 0000000..eb7db20
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/JupyterUtil.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.base.Joiner;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.typeadapters.RuntimeTypeAdapterFactory;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+import org.apache.zeppelin.jupyter.nbformat.Cell;
+import org.apache.zeppelin.jupyter.nbformat.CodeCell;
+import org.apache.zeppelin.jupyter.nbformat.DisplayData;
+import org.apache.zeppelin.jupyter.nbformat.Error;
+import org.apache.zeppelin.jupyter.nbformat.ExecuteResult;
+import org.apache.zeppelin.jupyter.nbformat.HeadingCell;
+import org.apache.zeppelin.jupyter.nbformat.MarkdownCell;
+import org.apache.zeppelin.jupyter.nbformat.Nbformat;
+import org.apache.zeppelin.jupyter.nbformat.Output;
+import org.apache.zeppelin.jupyter.nbformat.RawCell;
+import org.apache.zeppelin.jupyter.nbformat.Stream;
+import org.apache.zeppelin.jupyter.zformat.Note;
+import org.apache.zeppelin.jupyter.zformat.Paragraph;
+import org.apache.zeppelin.jupyter.zformat.Result;
+import org.apache.zeppelin.jupyter.zformat.TypeData;
+
+/**
+ *
+ */
+public class JupyterUtil {
+
+  private static final String TEXT_PLAIN = "text/plain";
+  private static final String IMAGE_PNG = "image/png";
+
+  private final RuntimeTypeAdapterFactory<Cell> cellTypeFactory;
+  private final RuntimeTypeAdapterFactory<Output> outputTypeFactory;
+
+  public JupyterUtil() {
+    this.cellTypeFactory = RuntimeTypeAdapterFactory.of(Cell.class, "cell_type")
+        .registerSubtype(MarkdownCell.class, "markdown").registerSubtype(CodeCell.class, "code")
+        .registerSubtype(RawCell.class, "raw").registerSubtype(HeadingCell.class, "heading");
+    this.outputTypeFactory = RuntimeTypeAdapterFactory.of(Output.class, "output_type")
+        .registerSubtype(ExecuteResult.class, "execute_result")
+        .registerSubtype(DisplayData.class, "display_data").registerSubtype(Stream.class, "stream")
+        .registerSubtype(Error.class, "error");
+  }
+
+  public Nbformat getNbformat(Reader in) {
+    return getNbformat(in, new GsonBuilder());
+  }
+
+  public Nbformat getNbformat(Reader in, GsonBuilder gsonBuilder) {
+    return getGson(gsonBuilder).fromJson(in, Nbformat.class);
+  }
+
+  public Note getNote(Reader in, String codeReplaced, String markdownReplaced) {
+    return getNote(in, new GsonBuilder(), codeReplaced, markdownReplaced);
+  }
+
+  public Note getNote(Reader in, GsonBuilder gsonBuilder, String codeReplaced,
+      String markdownReplaced) {
+    return getNote(getNbformat(in, gsonBuilder), codeReplaced, markdownReplaced);
+  }
+
+  public Note getNote(Nbformat nbformat, String codeReplaced, String markdownReplaced) {
+    Note note = new Note();
+
+    String name = nbformat.getMetadata().getTitle();
+    if (null == name) {
+      name = "Note converted from Jupyter";
+    }
+    note.setName(name);
+
+    String lineSeparator = System.lineSeparator();
+    Paragraph paragraph;
+    List<Paragraph> paragraphs = new ArrayList<>();
+    String interpreterName;
+    List<TypeData> typeDataList;
+    String type;
+    String result;
+
+    for (Cell cell : nbformat.getCells()) {
+      paragraph = new Paragraph();
+      typeDataList = new ArrayList<>();
+
+      if (cell instanceof CodeCell) {
+        interpreterName = codeReplaced;
+        for (Output output : ((CodeCell) cell).getOutputs()) {
+          TypeData typeData;
+          if (output instanceof Stream) {
+            type = TypeData.TEXT;
+            result = Joiner.on(lineSeparator).join(((Stream) output).getText());
+            typeData = new TypeData(type, result);
+            typeDataList.add(typeData);
+          } else if (output instanceof ExecuteResult || output instanceof DisplayData) {
+            Map<String, Object> data = (output instanceof ExecuteResult) ?
+                ((ExecuteResult) output).getData() :
+                ((DisplayData) output).getData();
+            for (Map.Entry<String, Object> datum : data.entrySet()) {
+              if (TEXT_PLAIN.equals(datum.getKey())) {
+                type = TypeData.TEXT;
+                result = Joiner.on(lineSeparator).join((List<String>) datum.getValue());
+              } else if (IMAGE_PNG.equals(datum.getKey())) {
+                type = TypeData.HTML;
+                result = makeHTML(((String) datum.getValue()).replace("\n", ""));
+              } else {
+                type = TypeData.TEXT;
+                result = datum.getValue().toString();
+              }
+              typeData = new TypeData(type, result);
+              typeDataList.add(typeData);
+            }
+          } else {
+            // Error
+            Error error = (Error) output;
+            type = TypeData.TEXT;
+            result =
+                Joiner.on(lineSeparator).join(new String[] {error.getEname(), error.getEvalue()});
+            typeData = new TypeData(type, result);
+            typeDataList.add(typeData);
+          }
+        }
+      } else if (cell instanceof MarkdownCell || cell instanceof HeadingCell) {
+        interpreterName = markdownReplaced;
+      } else {
+        interpreterName = "";
+      }
+
+      paragraph.setText(
+          interpreterName + lineSeparator + Joiner.on(lineSeparator).join(cell.getSource()));
+      paragraph.setResults(new Result(Result.SUCCESS, typeDataList));
+
+      paragraphs.add(paragraph);
+    }
+
+    note.setParagraphs(paragraphs);
+
+    return note;
+  }
+
+  private Gson getGson(GsonBuilder gsonBuilder) {
+    return gsonBuilder.registerTypeAdapterFactory(cellTypeFactory)
+        .registerTypeAdapterFactory(outputTypeFactory).create();
+  }
+
+  private String makeHTML(String image) {
+    return "<div style='width:auto;height:auto'><img src=data:image/png;base64," + image
+        + " style='width=auto;height:auto'/></div>";
+  }
+
+  public static void main(String[] args) throws ParseException, IOException {
+    Options options = new Options();
+    options.addOption("i", true, "Jupyter notebook file");
+    options.addOption("o", true, "Zeppelin note file. Default: note.json");
+
+    CommandLineParser parser = new DefaultParser();
+    CommandLine cmd = parser.parse(options, args);
+
+    if (!cmd.hasOption("i")) {
+      new HelpFormatter().printHelp("java " + JupyterUtil.class.getName(), options);
+      System.exit(1);
+    }
+
+    Path jupyterPath = Paths.get(cmd.getOptionValue("i"));
+    Path zeppelinPath = Paths.get(cmd.hasOption("o") ? cmd.getOptionValue("o") : "note.json");
+
+    try (BufferedReader in = new BufferedReader(new FileReader(jupyterPath.toFile()));
+        FileWriter fw = new FileWriter(zeppelinPath.toFile())) {
+      Note note = new JupyterUtil().getNote(in, "python", "md");
+      Gson gson = new GsonBuilder().setPrettyPrinting().create();
+      gson.toJson(note, fw);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Author.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Author.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Author.java
new file mode 100644
index 0000000..c3e23e5
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Author.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ */
+public class Author {
+
+  @SerializedName("name")
+  private String name;
+
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Cell.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Cell.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Cell.java
new file mode 100644
index 0000000..d44ec02
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Cell.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public abstract class Cell {
+
+  @SerializedName("cell_type")
+  private String cellType;
+
+  @SerializedName("metadata")
+  private CellMetadata metadata;
+
+  @SerializedName("source")
+  private List<String> source;
+
+  public String getCellType() {
+    return cellType;
+  }
+
+  public CellMetadata getMetadata() {
+    return metadata;
+  }
+
+  public List<String> getSource() {
+    return source;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CellMetadata.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CellMetadata.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CellMetadata.java
new file mode 100644
index 0000000..a35a262
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CellMetadata.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class CellMetadata {
+
+  @SerializedName("name")
+  private String name;
+
+  @SerializedName("tags")
+  private List<String> tags;
+
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CodeCell.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CodeCell.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CodeCell.java
new file mode 100644
index 0000000..973448c
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/CodeCell.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class CodeCell extends Cell {
+
+  @SerializedName("outputs")
+  private List<Output> outputs;
+
+  public List<Output> getOutputs() {
+    return outputs;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/DisplayData.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/DisplayData.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/DisplayData.java
new file mode 100644
index 0000000..68bfbfe
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/DisplayData.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.Map;
+
+/**
+ *
+ */
+public class DisplayData extends Output {
+
+  @SerializedName("data")
+  private Map<String, Object> data;
+
+  public Map<String, Object> getData() {
+    return data;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Error.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Error.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Error.java
new file mode 100644
index 0000000..61466fa
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Error.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class Error extends Output {
+  @SerializedName("ename")
+  private String ename;
+
+  @SerializedName("evalue")
+  private String evalue;
+
+  @SerializedName("traceback")
+  private List<String> traceback;
+
+  public String getEname() {
+    return ename;
+  }
+
+  public String getEvalue() {
+    return evalue;
+  }
+
+  public List<String> getTraceback() {
+    return traceback;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/ExecuteResult.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/ExecuteResult.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/ExecuteResult.java
new file mode 100644
index 0000000..01f0cea
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/ExecuteResult.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.Map;
+
+/**
+ *
+ */
+public class ExecuteResult extends Output {
+
+  @SerializedName("execution_count")
+  private int executionCount;
+
+  @SerializedName("data")
+  private Map<String, Object> data;
+
+  public Map<String, Object> getData() {
+    return data;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/HeadingCell.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/HeadingCell.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/HeadingCell.java
new file mode 100644
index 0000000..7007088
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/HeadingCell.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ */
+public class HeadingCell extends Cell {
+
+  @SerializedName("level")
+  private int level;
+
+  public int getLevel() {
+    return level;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Kernelspec.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Kernelspec.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Kernelspec.java
new file mode 100644
index 0000000..6232416
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Kernelspec.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ */
+public class Kernelspec {
+
+  @SerializedName("name")
+  private String name;
+
+  @SerializedName("display_name")
+  private String displayName;
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/LanguageInfo.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/LanguageInfo.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/LanguageInfo.java
new file mode 100644
index 0000000..cc74089
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/LanguageInfo.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ */
+public class LanguageInfo {
+
+  @SerializedName("name")
+  private String name;
+
+  @SerializedName("codemirror_mode")
+  private Object codemirrorMode;
+
+  @SerializedName("file_extension")
+  private String fileExtension;
+
+  @SerializedName("mimetype")
+  private String mimetype;
+
+  @SerializedName("pygments_lexer")
+  private String pygmentsLexer;
+
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/MarkdownCell.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/MarkdownCell.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/MarkdownCell.java
new file mode 100644
index 0000000..a1b220b
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/MarkdownCell.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+/**
+ *
+ */
+public class MarkdownCell extends Cell {
+
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Metadata.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Metadata.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Metadata.java
new file mode 100644
index 0000000..f2da8e4
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Metadata.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class Metadata {
+
+  @SerializedName("kernelspec")
+  private Kernelspec kernelspec;
+
+  @SerializedName("language_info")
+  private LanguageInfo languageInfo;
+
+  @SerializedName("orig_nbformat")
+  private int origNbformat;
+
+  @SerializedName("title")
+  private String title;
+
+  @SerializedName("authors")
+  private List<Author> authors;
+
+  public Kernelspec getKernelspec() {
+    return kernelspec;
+  }
+
+  public LanguageInfo getLanguageInfo() {
+    return languageInfo;
+  }
+
+  public int getOrigNbformat() {
+    return origNbformat;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public List<Author> getAuthors() {
+    return authors;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Nbformat.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Nbformat.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Nbformat.java
new file mode 100644
index 0000000..9ca4146
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Nbformat.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class Nbformat {
+
+  @SerializedName("metadata")
+  private Metadata metadata;
+
+  @SerializedName("nbformat")
+  private int nbformat;
+
+  @SerializedName("nbformat_minor")
+  private int nbformatMinor;
+
+  @SerializedName("cells")
+  private List<Cell> cells;
+
+  public Metadata getMetadata() {
+    return metadata;
+  }
+
+  public int getNbformat() {
+    return nbformat;
+  }
+
+  public int getNbformatMinor() {
+    return nbformatMinor;
+  }
+
+  public List<Cell> getCells() {
+    return cells;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Output.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Output.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Output.java
new file mode 100644
index 0000000..50722d7
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Output.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ */
+public abstract class Output {
+
+  @SerializedName("output_type")
+  private String outputType;
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCell.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCell.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCell.java
new file mode 100644
index 0000000..c5054b8
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCell.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+/**
+ *
+ */
+public class RawCell extends Cell {
+
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCellMetadata.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCellMetadata.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCellMetadata.java
new file mode 100644
index 0000000..1b667d7
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/RawCellMetadata.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ */
+public class RawCellMetadata extends CellMetadata {
+
+  @SerializedName("format")
+  private String format;
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Stream.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Stream.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Stream.java
new file mode 100644
index 0000000..a73f635
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/nbformat/Stream.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class Stream extends Output {
+
+  @SerializedName("name")
+  private String name;
+
+  @SerializedName("text")
+  private List<String> text;
+
+  public List<String> getText() {
+    return text;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Note.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Note.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Note.java
new file mode 100644
index 0000000..78922b5
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Note.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.zformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class Note {
+
+  @SerializedName("name")
+  private String name;
+
+  @SerializedName("paragraphs")
+  private List<Paragraph> paragraphs;
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public List<Paragraph> getParagraphs() {
+    return paragraphs;
+  }
+
+  public void setParagraphs(List<Paragraph> paragraphs) {
+    this.paragraphs = paragraphs;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Paragraph.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Paragraph.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Paragraph.java
new file mode 100644
index 0000000..f6a7ebf
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Paragraph.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.zformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ *
+ */
+public class Paragraph {
+  public static final String FINISHED = "FINISHED";
+
+  @SerializedName("text")
+  private String text;
+
+  @SerializedName("results")
+  private Result results; // It's a bit weird name
+
+  @SerializedName("id")
+  private String id;
+
+  @SerializedName("status")
+  private String status;
+
+  public Paragraph() {
+    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
+    this.id = dateFormat.format(new Date()) + "_" + super.hashCode();
+    this.status = FINISHED;
+  }
+
+  public String getText() {
+    return text;
+  }
+
+  public void setText(String text) {
+    this.text = text;
+  }
+
+  public Result getResults() {
+    return results;
+  }
+
+  public void setResults(Result results) {
+    this.results = results;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public String getStatus() {
+    return status;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Result.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Result.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Result.java
new file mode 100644
index 0000000..7efa5c9
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/Result.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.zformat;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+
+/**
+ *
+ */
+public class Result {
+  public static final String SUCCESS = "SUCCESS";
+
+  @SerializedName("code")
+  private String code;
+
+  @SerializedName("msg")
+  private List<TypeData> msg;
+
+  public Result(String code, List<TypeData> msg) {
+    this.code = code;
+    this.msg = msg;
+  }
+
+  public String getCode() {
+    return code;
+  }
+
+  public List<TypeData> getMsg() {
+    return msg;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/TypeData.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/TypeData.java b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/TypeData.java
new file mode 100644
index 0000000..4aaa642
--- /dev/null
+++ b/zeppelin-jupyter/src/main/java/org/apache/zeppelin/jupyter/zformat/TypeData.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.zformat;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ */
+public class TypeData {
+  public static final String TABLE = "TABLE";
+  public static final String HTML = "HTML";
+  public static final String TEXT = "TEXT";
+
+  @SerializedName("type")
+  private String type;
+
+  @SerializedName("data")
+  private String data;
+
+  public TypeData(String type, String data) {
+    this.type = type;
+    this.data = data;
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public String getData() {
+    return data;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/test/java/org/apache/zeppelin/jupyter/nbformat/JupyterUtilTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/test/java/org/apache/zeppelin/jupyter/nbformat/JupyterUtilTest.java b/zeppelin-jupyter/src/test/java/org/apache/zeppelin/jupyter/nbformat/JupyterUtilTest.java
new file mode 100644
index 0000000..be9a5ec
--- /dev/null
+++ b/zeppelin-jupyter/src/test/java/org/apache/zeppelin/jupyter/nbformat/JupyterUtilTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.jupyter.nbformat;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import org.apache.zeppelin.jupyter.JupyterUtil;
+import org.apache.zeppelin.jupyter.zformat.Note;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class JupyterUtilTest {
+
+  @Test
+  public void getNbFormat() {
+    InputStream resource = getClass().getResourceAsStream("/basic.ipynb");
+    Nbformat nbformat = new JupyterUtil().getNbformat(new InputStreamReader(resource));
+    assertTrue(nbformat.getCells().get(0) instanceof CodeCell);
+
+    resource = getClass().getResourceAsStream("/examples.ipynb");
+    nbformat = new JupyterUtil().getNbformat(new InputStreamReader(resource));
+  }
+
+  @Test
+  public void getNote() {
+    InputStream resource = getClass().getResourceAsStream("/examples.ipynb");
+    Note n = new JupyterUtil().getNote(new InputStreamReader(resource), "%python", "%md");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00243ea4/zeppelin-jupyter/src/test/resources/basic.ipynb
----------------------------------------------------------------------
diff --git a/zeppelin-jupyter/src/test/resources/basic.ipynb b/zeppelin-jupyter/src/test/resources/basic.ipynb
new file mode 100644
index 0000000..472f868
--- /dev/null
+++ b/zeppelin-jupyter/src/test/resources/basic.ipynb
@@ -0,0 +1,149 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ {
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "import numpy as np"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "# The first two lines of the A matrix represent the coordinates of each rotor in the X,Y plane,\n",
+    "# and the third line the direction in which they spin.\n",
+    "# Note that in this example the X axis is vertical, and the Y coordinates are in the top row of A.\n",
+    "A = np.array([[-0.17,  0.17, -0.25,  0.25, -0.33,  0.33],\n",
+    "             [-0.35, -0.35,  0.,    0.,    0.35,  0.35],\n",
+    "             [-0.1,   0.1,   0.1,  -0.1,  -0.1,   0.1 ]])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "# Moore-Penrose pseudoinverse of A\n",
+    "B = np.linalg.pinv(A)\n",
+    "# normalize roll/pitch to the largest of both\n",
+    "# normalize yaw to 0.5\n",
+    "# and transpose\n",
+    "rp_max = B[:,0:1].max()\n",
+    "n = np.array([rp_max, rp_max, 2*B[:,2].max()])\n",
+    "B_nt = (B / n).T"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "[[ -67   67 -256  256 -189  189]\n",
+      " [-197 -197    0    0  197  197]\n",
+      " [ -77   77  128 -128  -57   57]]\n"
+     ]
+    }
+   ],
+   "source": [
+    "# scale and round to 256 to return final coefficients\n",
+    "scale = 256\n",
+    "coeffs = np.around(scale * B_nt).astype(int)\n",
+    "print(coeffs)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "<define name=\"ROLL_COEF\"  value=\"{ -67,   67, -256,  256, -189,  189}\"/>\n",
+      "<define name=\"PITCH_COEF\" value=\"{-197, -197,    0,    0,  197,  197}\"/>\n",
+      "<define name=\"YAW_COEF\"   value=\"{ -77,   77,  128, -128,  -57,   57}\"/>\n"
+     ]
+    }
+   ],
+   "source": [
+    "# output defines\n",
+    "import string\n",
+    "rows = ['ROLL_COEF\"  ', 'PITCH_COEF\" ', 'YAW_COEF\"   ']\n",
+    "for i, r in enumerate(rows):\n",
+    "    print('<define name=\"' + r + 'value=\"{' + string.join(['{:>4d}'.format(c) for c in coeffs[i]], ', ') + '}\"/>')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    ""
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 2",
+   "language": "python",
+   "name": "python2"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 2.0
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython2",
+   "version": "2.7.6"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}


Mime
View raw message