Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. package ru.yandex.cloud.ml.platform.notebook;
  2.  
  3. import java.util.List;
  4. import java.util.stream.Collectors;
  5. import java.util.stream.Stream;
  6.  
  7. import com.fasterxml.jackson.annotation.JsonProperty;
  8. import com.fasterxml.jackson.databind.annotation.JsonSerialize;
  9.  
  10. class Cell {
  11. @JsonProperty("cell_type")
  12. private final CellType cellType;
  13.  
  14. @JsonProperty("source")
  15. private final String source;
  16.  
  17. @JsonProperty("metadata")
  18. private final Meta meta;
  19.  
  20. @JsonProperty("outputs")
  21. private final List<Output> outputs;
  22.  
  23. Cell(CellType cellType, String source, Meta meta, Stream<Output> outputs) {
  24. this.cellType = cellType;
  25. this.meta = meta;
  26. this.source = source;
  27. this.outputs = outputs.collect(Collectors.toList());
  28. }
  29.  
  30. static class Meta {
  31. @JsonProperty("collapsed")
  32. private final boolean collapsed;
  33. @JsonProperty("deletable")
  34. private final boolean deletable;
  35. @JsonProperty("name")
  36. private final String name;
  37.  
  38. Meta(boolean collapsed, boolean deletable, String name) {
  39. this.collapsed = collapsed;
  40. this.deletable = deletable;
  41. this.name = name;
  42. }
  43.  
  44. static Meta defaultMeta(String name) {
  45. return new Meta(false, false, name);
  46. }
  47. }
  48.  
  49. static class Output {
  50. @JsonProperty("output_type")
  51. private final OutputType type;
  52. @JsonProperty("metadata")
  53. private final Meta meta;
  54. @JsonProperty("data")
  55. private final Data data;
  56.  
  57. Output(OutputType type, Data data) {
  58. this.type = type;
  59. this.data = data;
  60. this.meta = new Meta();
  61. }
  62.  
  63. @JsonSerialize
  64. static class Meta {
  65. }
  66.  
  67. @JsonSerialize
  68. static class Data {
  69. }
  70. }
  71.  
  72. static class DataBlockOutput extends Output {
  73. DataBlockOutput(Data data) {
  74. super(OutputType.DISPLAY_DATA, data);
  75. }
  76.  
  77. static class Data extends Output.Data {
  78. @JsonProperty("application/nirvana-data")
  79. private final Payload payload;
  80.  
  81. Data(Payload payload) {
  82. this.payload = payload;
  83. }
  84.  
  85. static class Payload {
  86. @JsonProperty("type")
  87. private final String type;
  88. @JsonProperty("path")
  89. private final String path;
  90.  
  91. Payload(String type, String path) {
  92. this.type = type;
  93. this.path = path;
  94. }
  95. }
  96. }
  97. }
  98.  
  99. static class OpBlockOutput extends Output {
  100. OpBlockOutput(Data data) {
  101. super(OutputType.DISPLAY_DATA, data);
  102. }
  103.  
  104. static class Data extends Output.Data {
  105. @JsonProperty("application/nirvana-op")
  106. private final Payload payload;
  107.  
  108. Data(Payload payload) {
  109. this.payload = payload;
  110. }
  111.  
  112. static class Payload {
  113. @JsonProperty("logs")
  114. private final List<Log> logs;
  115. @JsonProperty("outputs")
  116. private final List<Out> outs;
  117.  
  118. Payload(Stream<Log> logs, Stream<Out> outs) {
  119. this.logs = logs.collect(Collectors.toList());
  120. this.outs = outs.collect(Collectors.toList());
  121. }
  122.  
  123. static class Log {
  124. @JsonProperty("name")
  125. private final String name;
  126. @JsonProperty("path")
  127. private final String path;
  128.  
  129. Log(String name, String path) {
  130. this.name = name;
  131. this.path = path;
  132. }
  133. }
  134.  
  135. static class Out {
  136. @JsonProperty("name")
  137. private final String name;
  138. @JsonProperty("path")
  139. private final String path;
  140.  
  141. Out(String name, String path) {
  142. this.name = name;
  143. this.path = path;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement