<commit_before>import httplib
import urllib
import json
from py2neo import Graph
from phovea_server.ns import Namespace, request, Response, jsonify
from flask import g
from phovea_server.config import view as configview
import phovea_server.websocket as ws
import phovea_server.util as utils
import memcache
import logging

_log = logging.getLogger(__name__)
c = configview('pathfinder_graph')

app = Namespace(__name__)
websocket = ws.Socket(app)
mc = memcache.Client([c.memcached], debug=0)

mc_prefix = 'pathways_'


class Config(object):
  def __init__(self, id, sett):
    self.id = id
    self.raw = sett
    self.port = sett.get('port', c.port)
    self.host = sett.get('host', c.host)
    self.url = sett.get('url', 'http://' + self.host + ':' + str(self.port))

    self.node_label = sett.get('node_label', '_Network_Node')
    self.node_id = sett.get('node_id', 'id')
    self.set_label = sett.get('set_label', '_Set_Node')

    self.directions = sett.get('directions',
                               dict(Edge='out', ConsistsOfEdge='both'))  # both ConsistsOf for the reversal
    self.directions_neighbor = sett.get('directions_neighbor', self.directions)  # both ConsistsOf for the reversal
    # by default inline ConsistsOfEdges
    self.inline = sett.get('inline', dict(inline='ConsistsOfEdge', undirectional=False, flag='_isSetEdge',
                                          aggregate=dict(pathways='pathways'), toaggregate='id', type='Edge'))

    self.client_conf = sett.get('client')

def update_config(args):
  uc = args.get('uc', 'dblp')
  # print args, uc
  # store in request context
  g.config = Config(uc, c.uc.get(uc))


@app.before_request
def resolve_usecase():
  # print 'before'
  update_config(request.args)


def resolve_db(config=None):
  if config is None:
    config = g.config
  graph = Graph(config.url + '/db/data/')
  return graph


@app.route('/config.json')
def get_config():
  return jsonify(g.config.client_conf)
<commit_msg>support use cases configs from other plugins<commit_after>import httplib
import urllib
import json
from py2neo import Graph
from phovea_server.ns import Namespace, request, Response, jsonify
from flask import g
from phovea_server.config import view as configview, get as configget
import phovea_server.websocket as ws
import phovea_server.util as utils
import memcache
import logging

_log = logging.getLogger(__name__)
c = configview('pathfinder_graph')

app = Namespace(__name__)
websocket = ws.Socket(app)
mc = memcache.Client([c.memcached], debug=0)

mc_prefix = 'pathways_'


class Config(object):
  def __init__(self, id, sett):
    self.id = id
    self.raw = sett
    self.port = sett.get('port', c.port)
    self.host = sett.get('host', c.host)
    self.url = sett.get('url', 'http://' + self.host + ':' + str(self.port))

    self.node_label = sett.get('node_label', '_Network_Node')
    self.node_id = sett.get('node_id', 'id')
    self.set_label = sett.get('set_label', '_Set_Node')

    self.directions = sett.get('directions',
                               dict(Edge='out', ConsistsOfEdge='both'))  # both ConsistsOf for the reversal
    self.directions_neighbor = sett.get('directions_neighbor', self.directions)  # both ConsistsOf for the reversal
    # by default inline ConsistsOfEdges
    self.inline = sett.get('inline', dict(inline='ConsistsOfEdge', undirectional=False, flag='_isSetEdge',
                                          aggregate=dict(pathways='pathways'), toaggregate='id', type='Edge'))

    self.client_conf = sett.get('client')


def find_use_case(uc):
  base = c.uc.get(uc, None)
  if base is not None:
    return base
  # check extension configs
  view = configget('pathfinder_graph_' + uc)
  return view


def update_config(args):
  uc = args.get('uc', 'dblp')
  # print args, uc
  # store in request context
  g.config = Config(uc, find_use_case(uc))


@app.before_request
def resolve_usecase():
  # print 'before'
  update_config(request.args)


def resolve_db(config=None):
  if config is None:
    config = g.config
  graph = Graph(config.url + '/db/data/')
  return graph


@app.route('/config.json')
def get_config():
  return jsonify(g.config.client_conf)

{'fraction_non_alphanumeric': 0.1274556780067082, 'fraction_numerical': 0.0009583133684714902, 'mean_word_length': 3.8377752027809966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7528706', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1356, 'n_words': 333}