mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Removed package org.apache.zeppelin.interpreter.graph
This commit is contained in:
parent
e98ca7a670
commit
b6062a0b09
6 changed files with 0 additions and 391 deletions
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* 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.interpreter.graph;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The base network entity
|
||||
*
|
||||
*/
|
||||
public abstract class GraphEntity {
|
||||
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* The data of the entity
|
||||
*
|
||||
*/
|
||||
private Map<String, Object> data;
|
||||
|
||||
/**
|
||||
* The primary type of the entity
|
||||
*/
|
||||
private String label;
|
||||
|
||||
//private String color;
|
||||
|
||||
public GraphEntity() {}
|
||||
|
||||
public GraphEntity(long id, Map<String, Object> data, String label) {
|
||||
super();
|
||||
this.setId(id);
|
||||
this.setData(data);
|
||||
this.setLabel(label);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<String, Object> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Map<String, Object> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* 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.interpreter.graph;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.zeppelin.interpreter.InterpreterResult;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* The intepreter result template for Networks
|
||||
*
|
||||
*/
|
||||
public class GraphResult extends InterpreterResult {
|
||||
|
||||
/**
|
||||
* The Graph structure parsed from the front-end
|
||||
*
|
||||
*/
|
||||
public static class Graph {
|
||||
private Collection<Node> nodes;
|
||||
|
||||
private Collection<Relationship> edges;
|
||||
|
||||
/**
|
||||
* The node types in the whole graph, and the related colors
|
||||
*
|
||||
*/
|
||||
private Map<String, String> labels;
|
||||
|
||||
/**
|
||||
* The relationship types in the whole graph
|
||||
*
|
||||
*/
|
||||
private Set<String> types;
|
||||
|
||||
/**
|
||||
* Is a directed graph
|
||||
*/
|
||||
private boolean directed;
|
||||
|
||||
public Graph() {}
|
||||
|
||||
public Graph(Collection<Node> nodes, Collection<Relationship> edges,
|
||||
Map<String, String> labels, Set<String> types, boolean directed) {
|
||||
super();
|
||||
this.setNodes(nodes);
|
||||
this.setEdges(edges);
|
||||
this.setLabels(labels);
|
||||
this.setTypes(types);
|
||||
this.setDirected(directed);
|
||||
}
|
||||
|
||||
public Collection<Node> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public void setNodes(Collection<Node> nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public Collection<Relationship> getEdges() {
|
||||
return edges;
|
||||
}
|
||||
|
||||
public void setEdges(Collection<Relationship> edges) {
|
||||
this.edges = edges;
|
||||
}
|
||||
|
||||
public Map<String, String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public void setLabels(Map<String, String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
public Set<String> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(Set<String> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public boolean isDirected() {
|
||||
return directed;
|
||||
}
|
||||
|
||||
public void setDirected(boolean directed) {
|
||||
this.directed = directed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public GraphResult(Code code, Graph graphObject) {
|
||||
super(code, Type.NETWORK, gson.toJson(graphObject));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* 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.interpreter.graph;
|
||||
|
||||
/**
|
||||
* An utiliy class for networks
|
||||
*
|
||||
*/
|
||||
public class GraphUtils {
|
||||
private GraphUtils() {}
|
||||
|
||||
private static final String[] LETTERS = "0123456789ABCDEF".split("");
|
||||
|
||||
public static final String COLOR_GREY = "#D3D3D3";
|
||||
|
||||
public static String getRandomColor() {
|
||||
char[] color = new char[7];
|
||||
color[0] = '#';
|
||||
for (int i = 1; i < color.length; i++) {
|
||||
color[i] = LETTERS[(int) Math.floor(Math.random() * 16)].charAt(0);
|
||||
}
|
||||
return new String(color);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* 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.interpreter.graph;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The Zeppelin Node Entity
|
||||
*
|
||||
*/
|
||||
public class Node extends GraphEntity {
|
||||
|
||||
/**
|
||||
* The labels (types) attached to a node
|
||||
*/
|
||||
private Set<String> labels;
|
||||
|
||||
public Node() {}
|
||||
|
||||
|
||||
public Node(long id, Map<String, Object> data, Set<String> labels) {
|
||||
super(id, data, labels.iterator().next());
|
||||
}
|
||||
|
||||
public Set<String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public void setLabels(Set<String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* 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.interpreter.graph;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Zeppelin Relationship entity
|
||||
*
|
||||
*/
|
||||
public class Relationship extends GraphEntity {
|
||||
|
||||
/**
|
||||
* Source node ID
|
||||
*/
|
||||
private long source;
|
||||
|
||||
/**
|
||||
* End node ID
|
||||
*/
|
||||
private long target;
|
||||
|
||||
public Relationship() {}
|
||||
|
||||
public Relationship(long id, Map<String, Object> data, long source,
|
||||
long target, String label, int count) {
|
||||
super(id, data, label);
|
||||
this.setSource(source);
|
||||
this.setTarget(target);
|
||||
}
|
||||
|
||||
public Relationship(long id, Map<String, Object> data, long source,
|
||||
long target, String label) {
|
||||
this(id, data, source, target, label, 0);
|
||||
}
|
||||
|
||||
public long getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(long startNodeId) {
|
||||
this.source = startNodeId;
|
||||
}
|
||||
|
||||
public long getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(long endNodeId) {
|
||||
this.target = endNodeId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
package org.apache.zeppelin.interpreter.graph;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.apache.zeppelin.interpreter.InterpreterResult;
|
||||
import org.apache.zeppelin.interpreter.graph.GraphResult.Graph;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class GraphResultTest {
|
||||
|
||||
@Test
|
||||
public void testGraphResult() {
|
||||
final String expected = "{\"nodes\":[{\"id\":1,\"label\":\"User\",\"data\":{\"fullname\":\"Andrea Santurbano\"}},"
|
||||
+ "{\"id\":2,\"label\":\"User\",\"data\":{\"fullname\":\"Moon soo Lee\"}}],"
|
||||
+ "\"edges\":[{\"source\":2,\"target\":1,\"id\":1,\"label\":\"HELPS\",\"data\":{\"project\":\"Zeppelin\",\"githubUrl\":\"https://github.com/apache/zeppelin/pull/1582\"}}]}";
|
||||
Graph graphExpected = new Gson().fromJson(expected, Graph.class);
|
||||
GraphResult intepreterResult = new GraphResult(InterpreterResult.Code.SUCCESS, graphExpected);
|
||||
assertEquals("The type is NETWORK", InterpreterResult.Type.NETWORK, intepreterResult.message().get(0).getType());
|
||||
Graph resultGraph = new Gson().fromJson(intepreterResult.toString().replace("%network ", ""), Graph.class);
|
||||
assertEquals("Nodes must have the same size", graphExpected.getNodes().size(), resultGraph.getNodes().size());
|
||||
assertEquals("Edges must have the same size", graphExpected.getEdges().size(), resultGraph.getEdges().size());
|
||||
|
||||
Node nodeSourceExpected = graphExpected.getNodes().iterator().next();
|
||||
Node nodeTargetExpected = graphExpected.getNodes().iterator().next();
|
||||
Relationship relExpected = graphExpected.getEdges().iterator().next();
|
||||
|
||||
Node nodeSourceResult = resultGraph.getNodes().iterator().next();
|
||||
Node nodeTargetResult = resultGraph.getNodes().iterator().next();
|
||||
Relationship relResult = resultGraph.getEdges().iterator().next();
|
||||
|
||||
assertEquals("Nodes source must have the same id", nodeSourceExpected.getId(), nodeSourceResult.getId());
|
||||
assertEquals("Nodes target must have the same id", nodeTargetExpected.getId(), nodeTargetResult.getId());
|
||||
assertEquals("Edges must have the same id", relExpected.getId(), relResult.getId());
|
||||
assertEquals("Edges must have the same id", relExpected.getId(), relResult.getId());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue