Turi Create  4.0
turi::unity_sgraph Class Reference

#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_sgraphoperator= (const unity_sgraph &)=default
 
virtual ~unity_sgraph ()
 Destructor.
 
std::shared_ptr< unity_sgraph_baseclone ()
 
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_baseadd_vertices (std::shared_ptr< unity_sframe_base > vertices, const std::string &id_field_name, size_t group=0)
 
std::shared_ptr< unity_sgraph_baseadd_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_enumget_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_enumget_edge_field_types (size_t groupa=0, size_t groupb=0)
 
std::shared_ptr< unity_sgraph_baseselect_vertex_fields (const std::vector< std::string > &fields, size_t group=0)
 
std::shared_ptr< unity_sgraph_basecopy_vertex_field (std::string field, std::string newfield, size_t group=0)
 
std::shared_ptr< unity_sgraph_basedelete_vertex_field (std::string field, size_t group=0)
 
std::shared_ptr< unity_sgraph_baseadd_vertex_field (std::shared_ptr< unity_sarray_base > column_data, std::string field)
 
std::shared_ptr< unity_sgraph_baserename_vertex_fields (const std::vector< std::string > &oldnames, const std::vector< std::string > &newnames)
 
std::shared_ptr< unity_sgraph_baseswap_vertex_fields (const std::string &field1, const std::string &field2)
 
std::shared_ptr< unity_sgraph_baseselect_edge_fields (const std::vector< std::string > &fields, size_t groupa=0, size_t groupb=0)
 
std::shared_ptr< unity_sgraph_basecopy_edge_field (std::string field, std::string newfield, size_t groupa=0, size_t groupb=0)
 
std::shared_ptr< unity_sgraph_basedelete_edge_field (std::string field, size_t groupa=0, size_t groupb=0)
 
std::shared_ptr< unity_sgraph_baseadd_edge_field (std::shared_ptr< unity_sarray_base > column_data, std::string field)
 
std::shared_ptr< unity_sgraph_baserename_edge_fields (const std::vector< std::string > &oldnames, const std::vector< std::string > &newnames)
 
std::shared_ptr< unity_sgraph_baseswap_edge_fields (const std::string &field1, const std::string &field2)
 
sgraphget_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_typeget_dag ()
 Gets the lazy evaluation DAG object.
 

Static Public Attributes

static unity_graph_dag_typedag_singleton
 Global lazy evaluation DAG object.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ unity_sgraph() [1/2]

turi::unity_sgraph::unity_sgraph ( std::shared_ptr< sgraph )

Constructs a unity_sgraph by taking over an existing sgraph object.

◆ unity_sgraph() [2/2]

turi::unity_sgraph::unity_sgraph ( const unity_sgraph )
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.)

Member Function Documentation

◆ add_edge_field()

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.

◆ add_edges()

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.

◆ add_vertex_field()

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.

◆ add_vertices()

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.

◆ clone()

std::shared_ptr<unity_sgraph_base> turi::unity_sgraph::clone ( )

Returns a new copy of this graph object

◆ copy_edge_field()

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".

◆ copy_vertex_field()

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".

◆ delete_edge_field()

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.

◆ delete_vertex_field()

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.

◆ get_edge_field_types()

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

◆ get_edge_fields()

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

◆ get_edges()

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.

◆ get_graph()

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.

◆ get_vertex_field_types()

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

◆ get_vertex_fields()

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

◆ get_vertices()

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.

◆ load()

void turi::unity_sgraph::load ( iarchive iarc)

Internal

Deep deserialization.

◆ load_graph()

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.

◆ operator=()

unity_sgraph& turi::unity_sgraph::operator= ( const unity_sgraph )
default

Copy assignment.

◆ rename_edge_fields()

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.

◆ rename_vertex_fields()

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.

◆ save()

void turi::unity_sgraph::save ( oarchive oarc) const

Internal

Deep serialization.

◆ save_graph()

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.

◆ save_reference() [1/2]

void turi::unity_sgraph::save_reference ( oarchive oarc) const

Internal

Save to oarchive using sframe reference save.

◆ save_reference() [2/2]

void turi::unity_sgraph::save_reference ( std::string  target_dir) const

Save the sgraph using reference to SFrames in other locations.

See also
unity_sframe::save_frame_reference

◆ select_edge_fields()

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".

◆ select_vertex_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".

◆ summary()

options_map_t turi::unity_sgraph::summary ( )

Returns a summary of the basic graph information such as the number of vertices / number of edges.

◆ swap_edge_fields()

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.

◆ swap_vertex_fields()

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.


The documentation for this class was generated from the following file: