#
# <one line to give the library's name and an idea of what it does.>
# Copyright (C) 2014  <copyright holder> <email>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program 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 General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
#

import abc
import networkx
import measureinterface
import grafon.constants as constants

class StructuralSimilarityMeasure(measureinterface.MeasureInterface):
  """!
  It is interface for any structural measure.
  """
  __metaclass__ = abc.ABCMeta

  def __init__(self, options, str_name):
    """!
    Only calls parent (MeasureInterface) constructor

    @param str_name: Name of similarity measure
    """
    super(StructuralSimilarityMeasure, self).__init__(options, str_name)

  @abc.abstractmethod
  def calculate(self, g1, g2):
    """!
    Same as MeasureInterface calculate() - calculate similarity bertween
    two given graphs.

    @param g1: first graph, a concret graph, for example networkx graph
    @param g2: second graph , a concret graph, for example networkx graph
    @return the value of similarity between g1 and g2
    """
    pass

  def copy_graph(self, g):
    """!
    Copy given graph g to new graph and returns it.

    @param  graph to copy
    type g: networkx.Graph/networkx.DiGraph/networkx.MultiDiGraph

    @return copy of graph g
    @rtype: networkx.MultiDiGraph
    """
    ng = networkx.MultiDiGraph()
    for n in g:
      ng.add_node(n, tokens=g.node[n][constants.NODE_TOKENS])
    ng.add_edges_from(g.edges(), data = True)
    return ng
