17.2.1 Loading a Graph

The following describes the steps for loading a graph:
  1. Create a Session and an Analyst.
    cd /opt/oracle/graph/
    ./bin/opg4j
    // starting the shell will create an implicit session and analyst
    opg4j> import oracle.pgx.config.mllib.ActivationFunction
    opg4j> import oracle.pgx.config.mllib.WeightInitScheme
    import oracle.pgx.api.*;
    import oracle.pgx.api.mllib.SupervisedGraphWiseModel;
    import oracle.pgx.api.filter.VertexFilter;
    import oracle.pgx.api.frames.*;
    import oracle.pgx.config.mllib.ActivationFunction;
    import oracle.pgx.config.mllib.GraphWiseConvLayerConfig;
    import oracle.pgx.config.mllib.GraphWisePredictionLayerConfig;
    import oracle.pgx.config.mllib.SupervisedGraphWiseModelConfig;
    import oracle.pgx.config.mllib.WeightInitScheme;
    # starting the Python shell will create an implicit session and analyst
  2. Load the graph.
    opg4j> var instance = GraphServer.getInstance("https://localhost:7007", "<username>", "<password>".toCharArray())
    opg4j> var session=instance.createSession("mySession")
    opg4j> var fullGraph = session.readGraphByName("<cora_graph>",GraphSource.PG_VIEW)
    opg4j> var filter = VertexFilter.fromPgqlResultSet(session.queryPgql("SELECT v FROM cora MATCH (v) WHERE ID(v) % 4 > 0"), "v")
    opg4j> var trainGraph = fullGraph.filter(filter)
    opg4j> var testVertices = fullGraph.getVertices().
                     stream().
                     filter(v -> !trainGraph.hasVertex(v.getId())).
                     collect(Collectors.toList())
    ServerInstance instance = GraphServer.getInstance("https://localhost:7007", "<username>", "<password>".toCharArray());
    PgxSession session = instance.createSession("my-session");
    PgxGraph fullGraph = session.readGraphByName("<cora_graph>",GraphSource.PG_VIEW);
    VertexFilterfilter = VertexFilter.fromPgqlResultSet(session.queryPgql("SELECT v FROM cora MATCH (v) WHERE ID(v) % 4 > 0"),"v");PgxGraphtrainGraph=fullGraph.filter(filter);
    PgxGraph trainGraph = fullGraph.filter(filter);
    List<PgxVertex> testVertices = fullGraph.getVertices()
        .stream()
        .filter(v->!trainGraph.hasVertex(v.getId()))
        .collect(Collectors.toList());
    from pypgx.api.filters import VertexFilter
    instance = graph_server.get_instance("https://localhost:7007","<username>","<password>")
    session = instance.create_session("my_session")
    full_graph = session.read_graph_by_name("<cora_graph>", "pg_view")
    vertex_filter = VertexFilter.from_pgql_result_set(session.query_pgql("SELECT v FROM cora MATCH (v) WHERE ID(v) % 4 > 0"),"v")
    train_graph = full_graph.filter(vertex_filter)
    test_vertices = []
    train_vertices = train_graph.get_vertices()
    for v in full_graph.get_vertices():
        if(not train_vertices.contains(v)):
            test_vertices.append(v)