use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project hale by halestudio.
the class TGraphFactory method create.
/**
* Create a transformation graph from a transformation tree.
*
* @param ttree the transformation tree
* @param functionService the function service
* @return an in-memory graph created from the transformation tree
*/
public static Graph create(TransformationTree ttree, FunctionService functionService) {
TreeToGraphVisitor graphVisitor = new TreeToGraphVisitor(functionService);
ttree.accept(graphVisitor);
SetMultimap<String, String> connections = graphVisitor.getAllConnections();
Set<String> ids = graphVisitor.getAllIds();
Graph graph = new TinkerGraph();
// add nodes to the graph
for (String key : ids) {
// create a vertex for each transformation node
TransformationNode node = graphVisitor.getNode(key);
Vertex vertex = graph.addVertex(key);
setVertexProperties(vertex, node);
}
for (String key : connections.keySet()) {
for (String value : connections.get(key)) {
Vertex targetSide = graph.getVertex(key);
Vertex sourceSide = graph.getVertex(value);
TransformationNode targetSideNode = graphVisitor.getNode(key);
TransformationNode sourceSideNode = graphVisitor.getNode(value);
String edgeLabel;
if (sourceSideNode instanceof SourceNode && targetSideNode instanceof SourceNode) {
edgeLabel = EDGE_CHILD;
} else if (sourceSideNode instanceof SourceNode && targetSideNode instanceof CellNode) {
edgeLabel = EDGE_VARIABLE;
} else if (sourceSideNode instanceof CellNode && targetSideNode instanceof GroupNode) {
edgeLabel = EDGE_RESULT;
} else if (sourceSideNode instanceof GroupNode && targetSideNode instanceof GroupNode) {
edgeLabel = EDGE_PARENT;
} else {
throw new IllegalStateException("Invalid relation in transformation tree");
}
Edge edge = graph.addEdge(null, sourceSide, targetSide, edgeLabel);
setEdgeProperties(edge, sourceSideNode, targetSideNode);
}
}
return graph;
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project pentaho-metaverse by pentaho.
the class BlueprintsGraphMetaverseReader method getGraph.
@Override
public Graph getGraph(String id) {
Vertex root = getGraph().getVertex(id);
if (root == null) {
return null;
}
Graph g = new TinkerGraph();
// find the upstream nodes
Vertex clone = GraphUtil.cloneVertexIntoGraph(root, g);
traceVertices(root, clone, Direction.IN, getGraph(), g, null);
traceVertices(root, clone, Direction.OUT, getGraph(), g, null);
g = enhanceGraph(g);
return g;
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project pentaho-metaverse by pentaho.
the class BlueprintsGraphMetaverseReader method search.
@Override
public Graph search(List<String> resultTypes, List<String> startNodeIDs, boolean shortestOnly) {
Graph g = new TinkerGraph();
for (String startNodeID : startNodeIDs) {
if (graph != null) {
// traverse look for paths to the results
Vertex startVertex = graph.getVertex(startNodeID);
GraphPath path = new GraphPath();
Set<Object> done = new HashSet<Object>();
Map<Object, GraphPath> shortestPaths = new HashMap<Object, GraphPath>();
traverseGraph(startVertex, graph, resultTypes, path, done, shortestPaths, Direction.IN, shortestOnly);
done = new HashSet<Object>();
traverseGraph(startVertex, graph, resultTypes, path, done, shortestPaths, Direction.OUT, shortestOnly);
Iterator<Map.Entry<Object, GraphPath>> paths = shortestPaths.entrySet().iterator();
while (paths.hasNext()) {
Map.Entry<Object, GraphPath> entry = paths.next();
GraphPath shortPath = entry.getValue();
shortPath.addToGraph(g);
}
}
}
g = enhanceGraph(g);
return g;
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project pentaho-metaverse by pentaho.
the class TransExtensionPointUtil method addLineageGraph.
public static void addLineageGraph(final TransMeta transMeta) throws MetaverseException {
if (transMeta == null) {
throw new MetaverseException(Messages.getString("ERROR.Document.IsNull"));
}
// Get the "natural" filename (repo-based if in repository, filesystem-based otherwise)
String filename = getFilename(transMeta);
final Graph graph = new TinkerGraph();
final IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
final IMetaverseObjectFactory objFactory = MetaverseUtil.getDocumentController().getMetaverseObjectFactory();
// Add the client design node
final String clientName = KettleClientEnvironment.getInstance().getClient().toString();
final INamespace namespace = new Namespace(clientName);
final IMetaverseNode designNode = objFactory.createNodeObject(clientName, clientName, DictionaryConst.NODE_TYPE_LOCATOR);
metaverseBuilder.addNode(designNode);
// Create a document object containing the transMeta
final IDocument document = MetaverseUtil.createDocument(namespace, transMeta, filename, transMeta.getName(), "ktr", URLConnection.getFileNameMap().getContentTypeFor("trans.ktr"));
MetaverseUtil.addLineageGraph(document, graph);
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project pentaho-metaverse by pentaho.
the class MetaverseUtil method addLineageGraph.
public static void addLineageGraph(final IDocument document, Graph graph) throws MetaverseException {
if (document == null) {
throw new MetaverseException(Messages.getString("ERROR.Document.IsNull"));
}
// Find the transformation analyzer(s) and create Futures to analyze the transformation.
// Right now we expect a single transformation analyzer in the system. If we need to support more,
// the lineageGraphMap needs to map the TransMeta to a collection of Futures, etc.
IDocumentController docController = MetaverseUtil.getDocumentController();
if (docController != null) {
// Create a new builder, setting it on the DocumentController if possible
IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
docController.setMetaverseBuilder(metaverseBuilder);
List<IDocumentAnalyzer> matchingAnalyzers = docController.getDocumentAnalyzers("ktr");
if (matchingAnalyzers != null) {
for (final IDocumentAnalyzer analyzer : matchingAnalyzers) {
Runnable analyzerRunner = getAnalyzerRunner(analyzer, document);
Graph g = (graph != null) ? graph : new TinkerGraph();
Future<Graph> transAnalysis = LineageGraphCompletionService.getInstance().submit(analyzerRunner, g);
// Save this Future, the client will call it when the analysis is needed
LineageGraphMap.getInstance().put(document.getContent(), transAnalysis);
}
}
}
}
Aggregations