Class: Teapot::TempestDB::TempestClient
- Inherits:
-
Object
- Object
- Teapot::TempestDB::TempestClient
- Defined in:
- lib/tempest_db.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_edge(edge_type, source_node, target_node) ⇒ Object
- #add_edges(edge_type, source_nodes, target_nodes) ⇒ Object
- #add_node(node) ⇒ Object
- #connected_component(source, edge_types, max_size = (1 << 31) - 1) ⇒ Array<Teapot::TempestDB::Node>
- #edge_count(edge_type) ⇒ Integer
- #get_multi_node_attribute(nodes, attribute_name) ⇒ Hash
- #get_node_attribute(node, attribute_name) ⇒ String
- #in_degree(edge_type, node) ⇒ Integer
- #in_neighbor(edge_type, node, i) ⇒ Teapot::TempestDB::Node
- #in_neighbors(edge_type, node) ⇒ Array<Teapot::TempestDB::Node>
-
#initialize(server, port) ⇒ TempestClient
constructor
A new instance of TempestClient.
- #k_step_in_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) ⇒ Teapot::TempestDB::Node
- #k_step_out_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) ⇒ Teapot::TempestDB::Node
- #node_count(edge_type) ⇒ Integer
- #nodes(node_type, sql_clause) ⇒ Teapot::TempestDB::Node
-
#out_degree(edge_type, node) ⇒ Integer
TODO: For methods that only need to be included (for irb auto-complete) and converted from camelCase to snake_case, is there a simple way of automating this?.
- #out_neighbor(edge_type, node, i) ⇒ Teapot::TempestDB::Node
- #out_neighbors(edge_type, node) ⇒ Array<Teapot::TempestDB::Node>
- #ppr_single_target(edge_type, seed_nodes, target_node, bi_ppr_params) ⇒ Double
- #set_node_attribute(node, attribute_name, attribute_value) ⇒ Object
-
#unique_node(node_type, sql_clause) ⇒ Teapot::TempestDB::Node
Convenience method to return the unique node node satisfying a condition.
Constructor Details
#initialize(server, port) ⇒ TempestClient
Returns a new instance of TempestClient.
40 41 42 |
# File 'lib/tempest_db.rb', line 40 def initialize(server, port) @thrift_client = Teapot::TempestDB::TempestThriftClient.new(server, port) end |
Class Method Details
.jsonToValue(json_attribute) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tempest_db.rb', line 46 def TempestClient.jsonToValue(json_attribute) if json_attribute[0] == '"' json_attribute[1...-1] elsif json_attribute == "true" true elsif json_attribute == "false" false elsif json_attribute == "null" nil else # If this isn't an int, the server made a mistake, and there isn't much the client can do. json_attribute.to_i end end |
Instance Method Details
#add_edge(edge_type, source_node, target_node) ⇒ Object
251 252 253 |
# File 'lib/tempest_db.rb', line 251 def add_edge(edge_type, source_node, target_node) add_edges(edge_type, [source_node], [target_node]) end |
#add_edges(edge_type, source_nodes, target_nodes) ⇒ Object
242 243 244 245 246 |
# File 'lib/tempest_db.rb', line 242 def add_edges(edge_type, source_nodes, target_nodes) @thrift_client.with_retries { |executor| executor.addEdges(edge_type, source_nodes, target_nodes) } end |
#add_node(node) ⇒ Object
224 225 226 227 228 |
# File 'lib/tempest_db.rb', line 224 def add_node(node) @thrift_client.with_retries { |executor| executor.addNode(node) } end |
#connected_component(source, edge_types, max_size = (1 << 31) - 1) ⇒ Array<Teapot::TempestDB::Node>
208 209 210 211 212 |
# File 'lib/tempest_db.rb', line 208 def connected_component(source, edge_types, max_size = (1 << 31) - 1) @thrift_client.with_retries { |executor| executor.connectedComponent(source, edge_types, max_size) } end |
#edge_count(edge_type) ⇒ Integer
187 188 189 190 191 |
# File 'lib/tempest_db.rb', line 187 def edge_count(edge_type) @thrift_client.with_retries { |executor| executor.edgeCount(edge_type) } end |
#get_multi_node_attribute(nodes, attribute_name) ⇒ Hash
64 65 66 67 68 69 |
# File 'lib/tempest_db.rb', line 64 def get_multi_node_attribute(nodes, attribute_name) node_to_json = @thrift_client.with_retries { |executor| executor.getMultiNodeAttributeAsJSON(nodes, attribute_name) } Hash[node_to_json.map{ |k,v| [k, TempestClient.jsonToValue(v)] }] end |
#get_node_attribute(node, attribute_name) ⇒ String
74 75 76 |
# File 'lib/tempest_db.rb', line 74 def get_node_attribute(node, attribute_name) self.get_multi_node_attribute([node], attribute_name)[node] end |
#in_degree(edge_type, node) ⇒ Integer
133 134 135 136 137 |
# File 'lib/tempest_db.rb', line 133 def in_degree(edge_type, node) @thrift_client.with_retries { |executor| executor.inDegree(edge_type, node) } end |
#in_neighbor(edge_type, node, i) ⇒ Teapot::TempestDB::Node
171 172 173 174 175 |
# File 'lib/tempest_db.rb', line 171 def in_neighbor(edge_type, node, i) @thrift_client.with_retries { |executor| executor.inNeighbor(edge_type, node, i) } end |
#in_neighbors(edge_type, node) ⇒ Array<Teapot::TempestDB::Node>
151 152 153 154 155 |
# File 'lib/tempest_db.rb', line 151 def in_neighbors(edge_type, node) @thrift_client.with_retries { |executor| executor.inNeighbors(edge_type, node) } end |
#k_step_in_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) ⇒ Teapot::TempestDB::Node
98 99 100 101 102 |
# File 'lib/tempest_db.rb', line 98 def k_step_in_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) @thrift_client.with_retries { |executor| executor.kStepInNeighborsFiltered(edge_type, source_node, k, sql_clause, degree_filter, alternating) } end |
#k_step_out_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) ⇒ Teapot::TempestDB::Node
85 86 87 88 89 |
# File 'lib/tempest_db.rb', line 85 def k_step_out_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) @thrift_client.with_retries { |executor| executor.kStepOutNeighborsFiltered(edge_type, source_node, k, sql_clause, degree_filter, alternating) } end |
#node_count(edge_type) ⇒ Integer
179 180 181 182 183 |
# File 'lib/tempest_db.rb', line 179 def node_count(edge_type) @thrift_client.with_retries { |executor| executor.nodeCount(edge_type) } end |
#nodes(node_type, sql_clause) ⇒ Teapot::TempestDB::Node
217 218 219 220 221 |
# File 'lib/tempest_db.rb', line 217 def nodes(node_type, sql_clause) @thrift_client.with_retries { |executor| executor.nodes(node_type, sql_clause) } end |
#out_degree(edge_type, node) ⇒ Integer
TODO: For methods that only need to be included (for irb auto-complete) and converted from camelCase to snake_case, is there a simple way of automating this?
124 125 126 127 128 |
# File 'lib/tempest_db.rb', line 124 def out_degree(edge_type, node) @thrift_client.with_retries { |executor| executor.outDegree(edge_type, node) } end |
#out_neighbor(edge_type, node, i) ⇒ Teapot::TempestDB::Node
161 162 163 164 165 |
# File 'lib/tempest_db.rb', line 161 def out_neighbor(edge_type, node, i) @thrift_client.with_retries { |executor| executor.outNeighbor(edge_type, node, i) } end |
#out_neighbors(edge_type, node) ⇒ Array<Teapot::TempestDB::Node>
142 143 144 145 146 |
# File 'lib/tempest_db.rb', line 142 def out_neighbors(edge_type, node) @thrift_client.with_retries { |executor| executor.outNeighbors(edge_type, node) } end |
#ppr_single_target(edge_type, seed_nodes, target_node, bi_ppr_params) ⇒ Double
198 199 200 201 202 |
# File 'lib/tempest_db.rb', line 198 def ppr_single_target(edge_type, seed_nodes, target_node, bi_ppr_params) @thrift_client.with_retries { |executor| executor.pprSingleTarget(edge_type, seed_nodes, target_node, bi_ppr_params) } end |
#set_node_attribute(node, attribute_name, attribute_value) ⇒ Object
233 234 235 236 237 |
# File 'lib/tempest_db.rb', line 233 def set_node_attribute(node, attribute_name, attribute_value) @thrift_client.with_retries { |executor| executor.setNodeAttribute(node, attribute_name, attribute_value) } end |
#unique_node(node_type, sql_clause) ⇒ Teapot::TempestDB::Node
Convenience method to return the unique node node satisfying a condition
108 109 110 111 112 113 114 115 116 |
# File 'lib/tempest_db.rb', line 108 def unique_node(node_type, sql_clause) matching_nodes = @thrift_client.with_retries { |executor| executor.nodes(node_type, sql_clause) } if matching_nodes.length != 1 raise "Error: clause '#{sql_clause}' had #{matching_nodes.length} results" end matching_nodes[0] end |