Search in sources :

Example 1 with TinkerGraph

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;
}
Also used : TransformationNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode) Vertex(com.tinkerpop.blueprints.Vertex) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TreeToGraphVisitor(eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.TreeToGraphVisitor) GroupNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Example 2 with TinkerGraph

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;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph)

Example 3 with TinkerGraph

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;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) HashMap(java.util.HashMap) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with TinkerGraph

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);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IMetaverseObjectFactory(org.pentaho.metaverse.api.IMetaverseObjectFactory) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) MetaverseException(org.pentaho.metaverse.api.MetaverseException) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) IDocument(org.pentaho.metaverse.api.IDocument)

Example 5 with TinkerGraph

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);
            }
        }
    }
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) IDocumentController(org.pentaho.metaverse.api.IDocumentController) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentAnalyzer(org.pentaho.metaverse.api.IDocumentAnalyzer) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseException(org.pentaho.metaverse.api.MetaverseException)

Aggregations

TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)105 Vertex (com.tinkerpop.blueprints.Vertex)66 Graph (com.tinkerpop.blueprints.Graph)58 Test (org.junit.Test)42 Edge (com.tinkerpop.blueprints.Edge)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 JSONTokener (org.codehaus.jettison.json.JSONTokener)8 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)7 Map (java.util.Map)6 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)4 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)4