Skip to content

Commit

Permalink
Updates for revscoring 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
halfak committed Mar 15, 2016
1 parent 25453b7 commit 14f6c09
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 133 deletions.
Binary file removed models/enwiki.reverted.linear_svc.model
Binary file not shown.
9 changes: 4 additions & 5 deletions ores/scoring_contexts/scoring_context.py
Expand Up @@ -18,9 +18,9 @@ def __init__(self, name, scorer_models, extractor):
The that this scorer is being used for
scorer_models : dict
A mapping between names and
:class:`~revscoring.scorer_models.scorer_model.ScorerModel`
:class:`revscoring.ScorerModel`
instances
extractor : :class:`~revscoring.extractors.extractor.Extractor`
extractor : :class:`revscoring.Extractor`
An extractor to use for gathering feature values
"""
super().__init__()
Expand Down Expand Up @@ -63,15 +63,14 @@ def extract_roots(self, model, rev_ids, caches=None):
rev_ids : int | `iterable`
Revision IDs to extract for
model : str
The name of a
:class:`~revscoring.scorer_models.scorer_model.ScorerModel` to
The name of a :class:`~revscoring.ScorerModel` to
extract the roots for
"""
features = self[model].features
root_ds = [d for d in dependencies.dig(features)
if isinstance(d, Datasource)]
error_root_vals = self.extractor.extract(rev_ids, root_ds,
caches=caches)
cache=caches)
root_ds_caches = {}
for rev_id, (error, root_vals) in zip(rev_ids, error_root_vals):
if error is None:
Expand Down
112 changes: 0 additions & 112 deletions ores/utilities/label_reverted.py

This file was deleted.

7 changes: 4 additions & 3 deletions ores/wsgi/routes/__init__.py
@@ -1,17 +1,18 @@
from flask import render_template

from . import scores
from . import ui
from . import v1
from . import v2


def configure(config, bp, score_processor):

@bp.route("/", methods=["GET"])
def index():
return ui.render_template("home.html")
return render_template("home.html")

bp = scores.configure(config, bp, score_processor)
bp = ui.configure(config, bp)
bp = v1.configure(config, bp, score_processor)
bp = v2.configure(config, bp, score_processor)

return bp
14 changes: 14 additions & 0 deletions ores/wsgi/routes/v1/__init__.py
@@ -0,0 +1,14 @@
from flask import render_template

from . import scores


def configure(config, bp, score_processor):

@bp.route("/v1/", methods=["GET"])
def v1_index():
return render_template("v1.html")

bp = scores.configure(config, bp, score_processor)

return bp
10 changes: 7 additions & 3 deletions ores/wsgi/routes/scores.py → ores/wsgi/routes/v1/scores.py
Expand Up @@ -3,15 +3,16 @@
from flask import request
from flask.ext.jsonpify import jsonify

from .. import responses
from ... import errors
from ..util import ParamError, read_bar_split_param
from ... import responses
from .... import errors
from ...util import ParamError, read_bar_split_param


def configure(config, bp, score_processor):

# /scores/
@bp.route("/scores/", methods=["GET"])
@bp.route("/v1/scores/", methods=["GET"])
def scores():
contexts = [context for context in score_processor]

Expand All @@ -21,6 +22,7 @@ def scores():

# /scores/enwiki/?models=reverted&revids=456789|4567890
@bp.route("/scores/<context>/", methods=["GET"])
@bp.route("/v1/scores/<context>/", methods=["GET"])
def score_model_revisions(context):

# Check to see if we have the context available in our score_processor
Expand Down Expand Up @@ -73,6 +75,7 @@ def score_model_revisions(context):

# /scores/enwiki/reverted/?revids=456789|4567890
@bp.route("/scores/<context>/<model>/", methods=["GET"])
@bp.route("/v1/scores/<context>/<model>/", methods=["GET"])
def score_revisions(context, model):

# Check to see if we have the context available in our score_processor
Expand Down Expand Up @@ -106,6 +109,7 @@ def score_revisions(context, model):

# /scores/enwiki/reverted/4567890
@bp.route("/scores/<context>/<model>/<int:rev_id>/", methods=["GET"])
@bp.route("/v1/scores/<context>/<model>/<int:rev_id>/", methods=["GET"])
def score_revision(context, model, rev_id):

# Check to see if we have the context available in our score_processor
Expand Down
14 changes: 14 additions & 0 deletions ores/wsgi/routes/v2/__init__.py
@@ -0,0 +1,14 @@
from flask import render_template

from . import scores


def configure(config, bp, score_processor):

@bp.route("/v2/", methods=["GET"])
def v2_index():
return render_template("v2.html")

bp = scores.configure(config, bp, score_processor)

return bp
18 changes: 9 additions & 9 deletions ores/wsgi/routes/v2.py → ores/wsgi/routes/v2/scores.py
Expand Up @@ -3,9 +3,9 @@
from flask import request
from flask.ext.jsonpify import jsonify

from .. import responses
from ... import errors
from ..util import ParamError, read_bar_split_param, format_output
from ... import responses
from .... import errors
from ...util import ParamError, format_output, read_bar_split_param


def configure(config, bp, score_processor):
Expand All @@ -31,7 +31,7 @@ def score_model_revisions_v2(context):
# If no model is specified, return information on available models
if "models" not in request.args:
# Return the models that we have
models = {name: model.info()
models = {name: model.format_info(format="json")
for name, model in score_processor[context].items()}
return jsonify({"models": models})

Expand Down Expand Up @@ -74,7 +74,7 @@ def score_model_revisions_v2(context):
if model_info_req:
try:
for req in model_info_req:
model_info[model][req] = model_object.info()[req]
model_info[model][req] = model_object.format_info(format="json")[req]
except KeyError:
return responses.bad_request(
"Model '{0}' has not attribute {1}.".format(
Expand Down Expand Up @@ -109,7 +109,7 @@ def score_revisions_v2(context, model):
if len(rev_ids) == 0:
return responses.bad_request("No revids provided.")
else:
return jsonify(score_processor[context][model].info())
return jsonify(score_processor[context][model].format_info(format="json"))

# Get model info
try:
Expand All @@ -124,7 +124,7 @@ def score_revisions_v2(context, model):
if model_info_req:
for req in model_info_req:
try:
model_info[model][req] = model_object.info()[req]
model_info[model][req] = model_object.format_info(format="json")[req]
except KeyError:
return responses.bad_request(
"Model '{0}' has not attribute {1}.".format(
Expand Down Expand Up @@ -162,10 +162,10 @@ def score_revision_v2(context, model, rev_id):
if model_info_req:
for req in model_info_req:
try:
model_info[model][req] = model_object.info()[req]
model_info[model][req] = model_object.format_info(format="json")[req]
except KeyError:
return responses.bad_request(
"Model '{0}' has not attribute {1}.".format(
"Model '{0}' has no attribute {1}.".format(
model, req))
try:
scores = {model: score_processor.score(
Expand Down
19 changes: 19 additions & 0 deletions ores/wsgi/templates/home.html
Expand Up @@ -12,6 +12,25 @@
<p>
The Objective Revision Evaluation Service (ORES) is a web service running in Wikimedia Labs that provides machine learning as a service for Wikimedia Projects. The system is designed to help automate critical wiki-work -- for example, vandalism detection and removal. This service is developed as part of the <a href="https://meta.wikimedia.org/wiki/Research:Revision_scoring_as_a_service">Revision scoring as a service</a> research project.
</p>
<h2>Scores API</h2>
<p>
There are two versions of the scoring API that differ slightly in their
behavior. Version 2 provides access to model info in a scoring request.
Version 1 is preserved for backwards compatibiltiy.
</p>
<dl>
<dt>Version 1</dt>
<dd style="padding-left: 1em;">
Accessible via
<a href="/scores/">/scores/</a> and
<a href="/v1/scores/">/v1/scores/</a>
</dd>
<dt>Version 2</dt>
<dd style="padding-left: 1em;">
Accessible via
<a href="/v2/scores/">/v2/scores/</a>
</dd>
</dl>
<h2>User interface</h2>
<p>
ORES provides a simple user interface. See <a href="/ui/">/ui/</a>.
Expand Down
20 changes: 20 additions & 0 deletions ores/wsgi/templates/v1.html
@@ -0,0 +1,20 @@
<html>
<head>
<link rel="stylesheet" href="https://wikimedia-ui.wmflabs.org/MW/mediawiki.min.css">
</head>
<body>
<style type="text/css">
body {
max-width: 50em;
margin: 1em auto;
}
</style>
<p>
This is the base of the "v1" interface for ORES' API. See
<a href="/v1/scores/">/v1/scores</a> for a list of supported Wikis.
</p>
<p>
For more information, see <a href="//meta.wikimedia.org/wiki/ORES">meta.wikimedia.org/wiki/ORES</a>.
</p>
</body>
</html>
20 changes: 20 additions & 0 deletions ores/wsgi/templates/v2.html
@@ -0,0 +1,20 @@
<html>
<head>
<link rel="stylesheet" href="https://wikimedia-ui.wmflabs.org/MW/mediawiki.min.css">
</head>
<body>
<style type="text/css">
body {
max-width: 50em;
margin: 1em auto;
}
</style>
<p>
This is the base of the "v2" interface for ORES' API. See
<a href="/v2/scores/">/v2/scores</a> for a list of supported Wikis.
</p>
<p>
For more information, see <a href="//meta.wikimedia.org/wiki/ORES">meta.wikimedia.org/wiki/ORES</a>.
</p>
</body>
</html>
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -7,4 +7,4 @@ mwreverts >= 0.0.5, < 0.0.999
socketIO-client == 0.5.6
stopit >= 1.1.1, < 1.1.999
yamlconf >= 0.0.3, < 0.0.999
revscoring >= 0.7.10, < 0.7.999
revscoring >= 1.1.0, < 1.1.999

0 comments on commit 14f6c09

Please sign in to comment.