# Path: web/util.py
# REALM = 'Snowball'
# def auth(req, realm, name, password):
# def assert_string(name, value, max_length):
# def check_tags(tag_arg):
# def check_datetime(datetime_arg):
# def assert_direction(direction):
# def check_weight(weight):
# def error_handler(func):
#     def func_replacement(self, *args, **kwargs):
# def get_dynamic_setting(db, name):
# def save_dynamic_setting(db, name, value):
#     def __init__(self, *args, **kwargs):
# class SnowballHandler(OzHandler):
# 
# Path: web/engine.py
# def _weight(node, link):
# def _links(db, node):
# def _summation(node, links, func):
# def _parts(node, links):
# def similarity(node_store, first, second):
# def bridging(node_store, node):
# def recommendation(node_store, from_node, to_node, settings):
# def recommendations(node_store, node, tags, settings):
# def has_any_tag(node, tags):
# def _recommendation_comparator(first, second):
# def candidates(node_store, root, max_visit):
# def _visit(candidates, visited_links, next_visited_links, queue, uri, context_weight, weight, context_count):


import uuid, cache, datetime, model
from tornado import web
from oz.handler import *
from web import *
from web import util, engine
from web.serialization import *
# later version.
#
# Snowball 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 Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Snowball.  If not, see <http://www.gnu.org/licenses/>.




class RecommendationHandler(util.SnowballHandler):
    """Endpoint for handling recommendations between two nodes"""
    
    @util.error_handler
    def get(self, from_uri, to_uri):
        node_store = cache.NodeStore(self.db, 4)
        
        try:
            from_node = node_store[model.node_key(from_uri)]
        except KeyError:
            raise web.HTTPError(404, 'could not find from node')
        
        try:
            to_node = node_store[model.node_key(to_uri)]
        except KeyError:
            raise web.HTTPError(404, 'could not find to node')
        

# Path: web/util.py
# REALM = 'Snowball'
# def auth(req, realm, name, password):
# def assert_string(name, value, max_length):
# def check_tags(tag_arg):
# def check_datetime(datetime_arg):
# def assert_direction(direction):
# def check_weight(weight):
# def error_handler(func):
#     def func_replacement(self, *args, **kwargs):
# def get_dynamic_setting(db, name):
# def save_dynamic_setting(db, name, value):
#     def __init__(self, *args, **kwargs):
# class SnowballHandler(OzHandler):
# 
# Path: web/engine.py
# def _weight(node, link):
# def _links(db, node):
# def _summation(node, links, func):
# def _parts(node, links):
# def similarity(node_store, first, second):
# def bridging(node_store, node):
# def recommendation(node_store, from_node, to_node, settings):
# def recommendations(node_store, node, tags, settings):
# def has_any_tag(node, tags):
# def _recommendation_comparator(first, second):
# def candidates(node_store, root, max_visit):
# def _visit(candidates, visited_links, next_visited_links, queue, uri, context_weight, weight, context_count):


# Path: web/view/recommendations.py
import uuid, cache, datetime, model
from tornado import web
from oz.handler import *
from web import *
from web import util, engine
from web.serialization import *

# later version.
#
# Snowball 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 Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Snowball.  If not, see <http://www.gnu.org/licenses/>.




class RecommendationHandler(util.SnowballHandler):
    """Endpoint for handling recommendations between two nodes"""
    
    @util.error_handler
    def get(self, from_uri, to_uri):
        node_store = cache.NodeStore(self.db, 4)
        
        try:
            from_node = node_store[model.node_key(from_uri)]
        except KeyError:
            raise web.HTTPError(404, 'could not find from node')
        
        try:
            to_node = node_store[model.node_key(to_uri)]
        except KeyError:
            raise web.HTTPError(404, 'could not find to node')
        

        rec = engine.recommendation(node_store, from_node, to_node, self.application.settings)