# Jubatus: Online machine learning framework for distributed environment
# Copyright (C) 2011,2012 Preferred Networks and Nippon Telegraph and Telephone Corporation.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

%include "jubatus/core/graph/graph_type.hpp"

message node("jubatus::core::graph::node_info") {
  0: map<string, string> property
  1: list<ulong> in_edges
  2: list<ulong> out_edges
}

message query {
  0: string from_id
  1: string to_id
}

# query: { key => value }
# matches if all keys exist on the property and all value are equal
# or, empty list matches all node/edge with any property
message preset_query("jubatus::core::graph::preset_query") {
  0: list<query> edge_query
  1: list<query> node_query
}

message edge {
  0: map<string, string> property
  1: string source
  2: string target
}

message shortest_path_query {
  0: string source
  1: string target
  2: uint max_hop
  3: preset_query query
}

service graph {

  #@random #@nolock #@pass
  string create_node()

  #@cht(2) #@nolock #@pass
  bool remove_node(0: string node_id)

  #@cht #@update #@all_and
  bool update_node(0: string node_id, 1: map<string, string> property)

  #@cht(1) #@nolock #@pass
  ulong create_edge(0: string node_id, 1: edge e)

  #@cht #@update #@all_and
  bool update_edge(0: string node_id, 1: ulong edge_id, 2: edge e)

  #@cht #@update #@all_and
  bool remove_edge(0: string node_id, 1: ulong edge_id)

  #@random #@analysis #@pass
  double get_centrality(0: string node_id, 1: int centrality_type, 2: preset_query query)

  #@broadcast #@update #@all_and
  bool add_centrality_query(0: preset_query query)
  #@broadcast #@update #@all_and
  bool add_shortest_path_query(0: preset_query query)
  #@broadcast #@update #@all_and
  bool remove_centrality_query(0: preset_query query)
  #@broadcast #@update #@all_and
  bool remove_shortest_path_query(0: preset_query query)

  #@random #@analysis #@pass
  list<string> get_shortest_path(0: shortest_path_query query)

  #@broadcast #@update #@all_and
  bool update_index()

  #@broadcast #@update #@all_and
  bool clear()

  #@cht #@analysis #@pass
  node get_node(0: string node_id)

  #@cht #@analysis #@pass
  edge get_edge(0: string node_id, 1: ulong edge_id)


  #@internal #@update #@pass
  bool create_node_here(0: string node_id)
  #@internal #@update #@pass
  bool remove_global_node(0: string node_id)

  #@internal #@update #@pass
  bool create_edge_here(0: ulong edge_id, 1: edge e)
}
