1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-09-16 19:42:21 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
J. Fernando Sánchez
48f5ffafa1 Defer plugin validation to init 2018-05-14 11:38:02 +02:00
9 changed files with 16 additions and 44 deletions

View File

@@ -6,6 +6,8 @@ RUN apt-get update && apt-get install -y \
libblas-dev liblapack-dev liblapacke-dev gfortran \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir --upgrade numpy scipy scikit-learn
RUN mkdir /cache/ /senpy-plugins /data/
VOLUME /data/

View File

@@ -9,6 +9,3 @@ jsonref
PyYAML
rdflib
rdflib-jsonld
numpy
scipy
scikit-learn

View File

@@ -147,7 +147,7 @@ def parse_params(indict, *specs):
for param, options in iteritems(spec):
for alias in options.get("aliases", []):
# Replace each alias with the correct name of the parameter
if alias in indict and alias != param:
if alias in indict and alias is not param:
outdict[param] = indict[alias]
del outdict[alias]
continue

View File

@@ -19,7 +19,7 @@ Blueprints for Senpy
"""
from flask import (Blueprint, request, current_app, render_template, url_for,
jsonify)
from .models import Error, Response, Help, Plugins, read_schema, dump_schema, Datasets
from .models import Error, Response, Help, Plugins, read_schema, Datasets
from . import api
from .version import __version__
from functools import wraps
@@ -67,9 +67,9 @@ def index():
@api_blueprint.route('/schemas/<schema>')
def schema(schema="definitions"):
try:
return dump_schema(read_schema(schema))
except Exception as ex: # Should be FileNotFoundError, but it's missing from py2
return Error(message="Schema not found: {}".format(ex), status=404).flask()
return jsonify(read_schema(schema))
except Exception: # Should be FileNotFoundError, but it's missing from py2
return Error(message="Schema not found", status=404).flask()
def basic_api(f):
@@ -133,7 +133,6 @@ def api_root():
req = api.parse_call(request.parameters)
return current_app.senpy.analyse(req)
@api_blueprint.route('/evaluate/', methods=['POST', 'GET'])
@basic_api
def evaluate():
@@ -146,7 +145,6 @@ def evaluate():
response = current_app.senpy.evaluate(params)
return response
@api_blueprint.route('/plugins/', methods=['POST', 'GET'])
@basic_api
def plugins():
@@ -165,10 +163,10 @@ def plugin(plugin=None):
return sp.get_plugin(plugin)
@api_blueprint.route('/datasets/', methods=['POST', 'GET'])
@api_blueprint.route('/datasets/', methods=['POST','GET'])
@basic_api
def datasets():
sp = current_app.senpy
datasets = sp.datasets
dic = Datasets(datasets=list(datasets.values()))
return dic
dic = Datasets(datasets = list(datasets.values()))
return dic

View File

@@ -51,10 +51,6 @@ def read_schema(schema_file, absolute=False):
return jsonref.load(f, base_uri=schema_uri)
def dump_schema(schema):
return jsonref.dumps(schema)
def load_context(context):
logging.debug('Loading context: {}'.format(context))
if not context:

View File

@@ -19,6 +19,8 @@ import importlib
import yaml
import threading
import numpy as np
from .. import models, utils
from .. import api
@@ -289,7 +291,7 @@ class Box(AnalysisPlugin):
return self
def transform(self, X):
return [self.predict_one(x) for x in X]
return np.array([self.predict_one(x) for x in X])
def predict(self, X):
return self.transform(X)

View File

@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"name": "Evaluation",
"name": "Evalation",
"properties": {
"@id": {
"type": "string"

View File

@@ -32,7 +32,7 @@ class APITest(TestCase):
query = {}
plug_params = {
'hello': {
'aliases': ['hiya', 'hello'],
'aliases': ['hello', 'hiya'],
'required': True
}
}
@@ -48,26 +48,6 @@ class APITest(TestCase):
assert 'hello' in p
assert p['hello'] == 'dlrow'
def test_parameters2(self):
in1 = {
'meaningcloud-key': 5
}
in2 = {
'apikey': 25
}
extra_params = {
"apikey": {
"aliases": [
"apikey",
"meaningcloud-key"
],
"required": True
}
}
p1 = parse_params(in1, extra_params)
p2 = parse_params(in2, extra_params)
assert (p2['apikey'] / p1['apikey']) == 5
def test_default(self):
spec = {
'hello': {

View File

@@ -8,8 +8,6 @@ from fnmatch import fnmatch
from jsonschema import RefResolver, Draft4Validator, ValidationError
from senpy.models import read_schema
root_path = path.join(path.dirname(path.realpath(__file__)), '..')
schema_folder = path.join(root_path, 'senpy', 'schemas')
examples_path = path.join(root_path, 'docs', 'examples')
@@ -17,8 +15,7 @@ bad_examples_path = path.join(root_path, 'docs', 'bad-examples')
class JSONSchemaTests(unittest.TestCase):
def test_definitions(self):
read_schema('definitions.json')
pass
def do_create_(jsfile, success):