Turi Create
4.0
|
#include <core/storage/sframe_interface/unity_sgraph.hpp>
Public Member Functions | |
unity_sgraph (size_t npartitions=SGRAPH_DEFAULT_NUM_PARTITIONS) | |
Default constructor. | |
unity_sgraph (std::shared_ptr< sgraph >) | |
unity_sgraph (const unity_sgraph &)=default | |
unity_sgraph & | operator= (const unity_sgraph &)=default |
virtual | ~unity_sgraph () |
Destructor. | |
std::shared_ptr< unity_sgraph_base > | clone () |
std::shared_ptr< unity_sframe_base > | get_vertices (const std::vector< flexible_type > &vid_vec=std::vector< flexible_type >(), const options_map_t &field_constraint=options_map_t(), size_t group=0) |
std::shared_ptr< unity_sframe_base > | get_edges (const std::vector< flexible_type > &source_vids=std::vector< flexible_type >(), const std::vector< flexible_type > &target_vids=std::vector< flexible_type >(), const options_map_t &field_constraint=options_map_t(), size_t groupa=0, size_t groupb=0) |
options_map_t | summary () |
std::shared_ptr< unity_sgraph_base > | add_vertices (std::shared_ptr< unity_sframe_base > vertices, const std::string &id_field_name, size_t group=0) |
std::shared_ptr< unity_sgraph_base > | add_edges (std::shared_ptr< unity_sframe_base > edges, const std::string &source_field_name, const std::string &target_field_name, size_t groupa=0, size_t groupb=0) |
std::vector< std::string > | get_vertex_fields (size_t group=0) |
std::vector< flex_type_enum > | get_vertex_field_types (size_t group=0) |
std::vector< std::string > | get_edge_fields (size_t groupa=0, size_t groupb=0) |
std::vector< flex_type_enum > | get_edge_field_types (size_t groupa=0, size_t groupb=0) |
std::shared_ptr< unity_sgraph_base > | select_vertex_fields (const std::vector< std::string > &fields, size_t group=0) |
std::shared_ptr< unity_sgraph_base > | copy_vertex_field (std::string field, std::string newfield, size_t group=0) |
std::shared_ptr< unity_sgraph_base > | delete_vertex_field (std::string field, size_t group=0) |
std::shared_ptr< unity_sgraph_base > | add_vertex_field (std::shared_ptr< unity_sarray_base > column_data, std::string field) |
std::shared_ptr< unity_sgraph_base > | rename_vertex_fields (const std::vector< std::string > &oldnames, const std::vector< std::string > &newnames) |
std::shared_ptr< unity_sgraph_base > | swap_vertex_fields (const std::string &field1, const std::string &field2) |
std::shared_ptr< unity_sgraph_base > | select_edge_fields (const std::vector< std::string > &fields, size_t groupa=0, size_t groupb=0) |
std::shared_ptr< unity_sgraph_base > | copy_edge_field (std::string field, std::string newfield, size_t groupa=0, size_t groupb=0) |
std::shared_ptr< unity_sgraph_base > | delete_edge_field (std::string field, size_t groupa=0, size_t groupb=0) |
std::shared_ptr< unity_sgraph_base > | add_edge_field (std::shared_ptr< unity_sarray_base > column_data, std::string field) |
std::shared_ptr< unity_sgraph_base > | rename_edge_fields (const std::vector< std::string > &oldnames, const std::vector< std::string > &newnames) |
std::shared_ptr< unity_sgraph_base > | swap_edge_fields (const std::string &field1, const std::string &field2) |
sgraph & | get_graph () const |
void | save (oarchive &oarc) const |
void | save_reference (oarchive &oarc) const |
void | load (iarchive &iarc) |
void | save_reference (std::string target_dir) const |
bool | save_graph (std::string target_dir, std::string format) |
bool | load_graph (std::string target_dir) |
Static Public Member Functions | |
static unity_graph_dag_type * | get_dag () |
Gets the lazy evaluation DAG object. | |
Static Public Attributes | |
static unity_graph_dag_type * | dag_singleton |
Global lazy evaluation DAG object. | |
The turi::unity_sgraph and turi::unity_sgraph_base classes implement a graph object on the server side which is exposed to the client via the cppipc system.
The unity_sgraph is a lazily evaluated, immutable graph datastructure where most operations do not take time, and instead, the graph is only fully constructed when accessed. Furthermore we can further exploit immutability for efficiency, by allowing graphs to shared data/structure/etc through the use of shared_ptr, etc.
Definition at line 42 of file unity_sgraph.hpp.
turi::unity_sgraph::unity_sgraph | ( | std::shared_ptr< sgraph > | ) |
Constructs a unity_sgraph by taking over an existing sgraph object.
|
explicitdefault |
Makes a copy of a graph. (This is a shallow copy. The resultant graphs share pointers. But since graphs are immutable, this is safe and can be treated like a deep copy.)
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::add_edge_field | ( | std::shared_ptr< unity_sarray_base > | column_data, |
std::string | field | ||
) |
Add a new edge field with column_data and return as a new graph.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::add_edges | ( | std::shared_ptr< unity_sframe_base > | edges, |
const std::string & | source_field_name, | ||
const std::string & | target_field_name, | ||
size_t | groupa = 0 , |
||
size_t | groupb = 0 |
||
) |
Adds each row of the sframe as a new edge; A new graph corresponding to the current graph with new edges added will be returned. Columns of the dataframes are treated as fields (new fields will be created as appropriate). The columns with name 'source_field_name' and 'target_field_name' will be used to denote the source and target vertex IDs for the edge. These columns must therefore exist in the 'edges' dataframe. If the vertex does not exist, it will be created. Unlike add_vertices, edge "merging" is not performed, but instead, multiple edges can be created between any pair of vertices. Throws an exception on failure.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::add_vertex_field | ( | std::shared_ptr< unity_sarray_base > | column_data, |
std::string | field | ||
) |
Add a new vertex field with column_data and return as a new graph.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::add_vertices | ( | std::shared_ptr< unity_sframe_base > | vertices, |
const std::string & | id_field_name, | ||
size_t | group = 0 |
||
) |
Adds each row of the sframe as a new vertex; A new graph corresponding to the current graph with new vertices added will be returned. Columns of the dataframes are treated as fields (new fields will be created as appropriate). The column with name 'id_field_name' will be treated as the vertex ID field. The column with name 'id_field_name' must therefore exist in the 'vertices' dataframe. If the vertex with the given ID already exists, all field values will overwrite. This function can therefore be also used to perform modification of graph data. An exception is thrown on failure.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::clone | ( | ) |
Returns a new copy of this graph object
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::copy_edge_field | ( | std::string | field, |
std::string | newfield, | ||
size_t | groupa = 0 , |
||
size_t | groupb = 0 |
||
) |
Returns a new graph corresponding to the current graph with the field "field" renamed to "newfield".
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::copy_vertex_field | ( | std::string | field, |
std::string | newfield, | ||
size_t | group = 0 |
||
) |
Returns a new graph corresponding to the current graph with the field "field" renamed to "newfield".
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::delete_edge_field | ( | std::string | field, |
size_t | groupa = 0 , |
||
size_t | groupb = 0 |
||
) |
Returns a new graph corresponding to the curent graph with the field "field" deleted.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::delete_vertex_field | ( | std::string | field, |
size_t | group = 0 |
||
) |
Returns a new graph corresponding to the curent graph with the field "field" deleted.
std::vector<flex_type_enum> turi::unity_sgraph::get_edge_field_types | ( | size_t | groupa = 0 , |
size_t | groupb = 0 |
||
) |
Returns a list of of the edge field types in the graph
std::vector<std::string> turi::unity_sgraph::get_edge_fields | ( | size_t | groupa = 0 , |
size_t | groupb = 0 |
||
) |
Returns a list of of the edge fields in the graph
std::shared_ptr<unity_sframe_base> turi::unity_sgraph::get_edges | ( | const std::vector< flexible_type > & | source_vids = std::vector< flexible_type >() , |
const std::vector< flexible_type > & | target_vids = std::vector< flexible_type >() , |
||
const options_map_t & | field_constraint = options_map_t() , |
||
size_t | groupa = 0 , |
||
size_t | groupb = 0 |
||
) |
Returns a sframe of edges satisfying certain constraints. source_vids and target_vids arrays must match up in length, and denote source->target edges. For instance: i–>j will return the edge i–> if it exists. Wildcards are supported by setting the flexible_type to UNDEFINED. For instance, i–>UNDEFINED will match every edge with source i. And UNDEFINED–>j will match every edge with target j.
The returned edge will have source vertices from one group and target vertices from another group (can be the same).
The edge must further match the values specified by the field_constraint.
source_vids A list of source vertices or wildcards (UNDEFINED). Must match the length of target_vids. See above for semantics. target_vids A list of target vertices or wildcards (UNDEFINED). Must match the length of source_vids. See above for semantics. field_constraint A mapping of string–>value. Only edges which contain a field with the particular value will be returned. value can be UNDEFINED, in which case edges simply must contain the particular field.
groupa The vertex group id for source vertices.
groupb The vertex group id for target vertices.
sgraph& turi::unity_sgraph::get_graph | ( | ) | const |
Internal
Returns a reference to the underlying sgraph.
Note: This operation willforce the lazy operations to be performed.
std::vector<flex_type_enum> turi::unity_sgraph::get_vertex_field_types | ( | size_t | group = 0 | ) |
Returns a list of of the vertex fields in the graph
std::vector<std::string> turi::unity_sgraph::get_vertex_fields | ( | size_t | group = 0 | ) |
Returns a list of of the vertex fields in the graph
std::shared_ptr<unity_sframe_base> turi::unity_sgraph::get_vertices | ( | const std::vector< flexible_type > & | vid_vec = std::vector< flexible_type >() , |
const options_map_t & | field_constraint = options_map_t() , |
||
size_t | group = 0 |
||
) |
Returns a sframe of vertices satisfying the certain constraints.
vid_vec A list of vertices. If provided, will only return vertices in the list. Otherwise all vertices will be considered. field_constraint A mapping of string–>value. Only vertices which contain a field with the particular value will be returned. value can be UNDEFINED, in which case vertices simply must contain the particular field. group The vertex group id.
void turi::unity_sgraph::load | ( | iarchive & | iarc | ) |
Internal
Deep deserialization.
bool turi::unity_sgraph::load_graph | ( | std::string | target_dir | ) |
Loads the graph from the given file in a non-portable binary format. File can be on disk, or on HDFS. Returns true on success, false on failure.
|
default |
Copy assignment.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::rename_edge_fields | ( | const std::vector< std::string > & | oldnames, |
const std::vector< std::string > & | newnames | ||
) |
Rename the edge fields whoes names are in oldnames to the corresponding new names. Return the new graph.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::rename_vertex_fields | ( | const std::vector< std::string > & | oldnames, |
const std::vector< std::string > & | newnames | ||
) |
Rename the edge fields whoes names are in oldnames to the corresponding new names. Return the new graph.
void turi::unity_sgraph::save | ( | oarchive & | oarc | ) | const |
Internal
Deep serialization.
bool turi::unity_sgraph::save_graph | ( | std::string | target_dir, |
std::string | format | ||
) |
Saves the graph with the specified name to a given file in a non-portable binary format. File can be on disk, or on HDFS.
Supported formats are 'bin', 'json', 'csv'.
Returns true on success, false on failure.
void turi::unity_sgraph::save_reference | ( | oarchive & | oarc | ) | const |
Internal
Save to oarchive using sframe reference save.
void turi::unity_sgraph::save_reference | ( | std::string | target_dir | ) | const |
Save the sgraph using reference to SFrames in other locations.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::select_edge_fields | ( | const std::vector< std::string > & | fields, |
size_t | groupa = 0 , |
||
size_t | groupb = 0 |
||
) |
Returns a new graph corresponding to the curent graph with only the fields listed in "fields".
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::select_vertex_fields | ( | const std::vector< std::string > & | fields, |
size_t | group = 0 |
||
) |
Returns a new graph corresponding to the curent graph with only the fields listed in "fields".
options_map_t turi::unity_sgraph::summary | ( | ) |
Returns a summary of the basic graph information such as the number of vertices / number of edges.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::swap_edge_fields | ( | const std::string & | field1, |
const std::string & | field2 | ||
) |
Switch the column order of field1 and field2 in the vertex data. Return the new graph.
std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::swap_vertex_fields | ( | const std::string & | field1, |
const std::string & | field2 | ||
) |
Switch the column order of field1 and field2 in the vertex data. Return the new graph.