Source code for ores.score_request
import json
[docs]class ScoreRequest:
def __init__(self, context_name, rev_ids, model_names, precache=False,
include_features=False, injection_caches=None,
model_info=None, ip=None):
"""
Construct a ScoreRequest from parameters.
:Parameters:
context_name : str
The name of the content for the query -- usually a wikidb name
rev_ids : `iterable` ( `int` )
A set of revision IDs to score
model_names : `iterable` ( `str` )
A set of model_names to use in scoring
precache : bool
If true, mark the request as a "precache" request
include_features : bool
If true, include feature values in the response
injection_caches : dict
A mapping of injection_cache to `rev_id` to use for injecting
cached data when extracting features/scoring.
model_info : `list` ( `str` )
A list of model information fields to include in the response
"""
self.context_name = context_name
self.rev_ids = set(rev_ids)
self.model_names = set(model_names)
self.precache = precache
self.include_features = include_features
self.injection_caches = injection_caches or {}
self.model_info = model_info
self.ip = ip
def __str__(self):
return self.format()
def __repr__(self):
return "{0}({1})".format(
self.__class__.__name__,
", ".join(repr(v) for v in [
self.context_name,
self.rev_ids,
self.model_names,
"precache={0!r}".format(self.precache),
"include_features={0!r}".format(self.include_features),
"injection_caches={0!r}".format(self.injection_caches),
"ip={0!r}".format(self.ip),
"model_info={0!r}".format(self.model_info)]))
[docs] def to_json(self):
return {
'context': self.context_name,
'rev_ids': list(self.rev_ids),
'model_names': list(self.model_names),
'precache': self.precache,
'include_features': self.include_features,
'injection_caches': self.injection_caches,
'ip': self.ip,
'model_info': self.model_info
}
[docs] @classmethod
def from_json(cls, data):
return cls(
data['context'],
set(data['rev_ids']),
set(data['model_names']),
precache=data['precache'],
include_features=data['include_features'],
injection_caches=data['injection_caches'],
model_info=data['model_info'],
ip=data['ip'])