17.5.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.UnsupervisedEdgeWiseModel;
    import oracle.pgx.api.filter.EdgeFilter;
    import oracle.pgx.api.frames.*;
    import oracle.pgx.config.mllib.ActivationFunction;
    import oracle.pgx.config.mllib.GraphWiseConvLayerConfig;
    import oracle.pgx.config.mllib.GraphWiseDgiLayerConfig;
    import oracle.pgx.config.mllib.corruption.PermutationCorruption;
    import oracle.pgx.config.mllib.UnsupervisedEdgeWiseModelConfig;
    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("<movielens_graph>",GraphSource.PG_VIEW)
    opg4j> var filter = EdgeFilter.fromPgqlResultSet(session.queryPgql("SELECT e FROM movielens MATCH (v1) -[e]-> (v2) WHERE ID(e) % 4 > 0"), "e")
    opg4j> var trainGraph = fullGraph.filter(filter)
    opg4j> var testEdges = fullGraph.getEdges().
                         stream().
                         filter(e -> !trainGraph.hasEdge(e.getId())).
                         collect(Collectors.toList())
    ServerInstance instance = GraphServer.getInstance("https://localhost:7007", "<username>", "<password>".toCharArray());
    PgxSession session = instance.createSession("my-session");
    PgxGraph fullGraph = session.readGraphByName("<movielens_graph>",GraphSource.PG_VIEW);
    EdgeFilter filter = EdgeFilter.fromPgqlResultSet(session.queryPgql("SELECT e FROM movielens MATCH (v1) -[e]-> (v2) WHERE ID(e) % 4 > 0"), "e");
    PgxGraph trainGraph = fullGraph.filter(filter);
    List<PgxEdge> testEdges = fullGraph.getEdges()
        .stream()
        .filter(e -> !trainGraph.hasEdge(e.getId()))
        .collect(Collectors.toList());
    from pypgx.api.filters import EdgeFilter
    instance = graph_server.get_instance("https://localhost:7007","<username>","<password>")
    session = instance.create_session("my_session")
    full_graph = session.read_graph_by_name("<movielens_graph>", "pg_view")
    edge_filter = EdgeFilter.from_pgql_result_set(
        session.query_pgql("SELECT e FROM movielens MATCH (v1) -[e]-> (v2) WHERE ID(e) % 4 > 0"), "e"
    )
    train_graph = full_graph.filter(edge_filter)
    test_edges = []
    train_edges = train_graph.get_edges()
    for e in full_graph.get_edges():
        if(not train_edges.contains(e)):
            test_vertices.append(e)