Page MenuHomePhabricator

Run edits through ORES
Open, Needs TriagePublic

Event Timeline

HTTP 500. But in any case, I thought ORES was for edits already on-wiki, is it possible to run proposed edits through it?

Now temporarily at

1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Revscoring rev_doc injection demo\n",
8 "In this notebook, we'll demonstrate injecting a revision document a scoring."
9 ]
10 },
11 {
12 "cell_type": "code",
13 "execution_count": 14,
14 "metadata": {
15 "collapsed": false
16 },
17 "outputs": [
18 {
19 "name": "stderr",
20 "output_type": "stream",
21 "text": [
22 "Sending requests with default User-Agent. Set 'user_agent' on mwapi.Session to quiet this message.\n"
23 ]
24 }
25 ],
26 "source": [
27 "import mwapi\n",
28 "\n",
29 "session = mwapi.Session(\"https://en.wikipedia.org\")\n",
30 "doc = session.get(action=\"query\", prop=\"revisions\", revids=[758676335], formatversion=2, rvprop=[\"ids\", \"user\", \"timestamp\", \"userid\", \"comment\", \"size\", \"contentmodel\", \"content\"])"
31 ]
32 },
33 {
34 "cell_type": "code",
35 "execution_count": 15,
36 "metadata": {
37 "collapsed": false
38 },
39 "outputs": [
40 {
41 "data": {
42 "text/plain": [
43 "{'comment': '',\n",
44 " 'content': '<gallery caption=\"123\">\\nFile:Project 1164 Moskva 2009 G1.jpg|test\\n</gallery>',\n",
45 " 'contentformat': 'text/x-wiki',\n",
46 " 'contentmodel': 'wikitext',\n",
47 " 'page': {'ns': 2, 'pageid': 45657000, 'title': 'User:Arlolra/sandbox'},\n",
48 " 'parentid': 758179841,\n",
49 " 'revid': 758676335,\n",
50 " 'size': 76,\n",
51 " 'timestamp': '2017-01-06T21:53:35Z',\n",
52 " 'user': 'Arlolra',\n",
53 " 'userid': 6127236}"
54 ]
55 },
56 "execution_count": 15,
57 "metadata": {},
58 "output_type": "execute_result"
59 }
60 ],
61 "source": [
62 "rev_doc = doc['query']['pages'][0]['revisions'][0]\n",
63 "rev_doc['page'] = {k: v for k, v in doc['query']['pages'][0].items() if k != 'revisions'}\n",
64 "rev_doc"
65 ]
66 },
67 {
68 "cell_type": "code",
69 "execution_count": 59,
70 "metadata": {
71 "collapsed": false
72 },
73 "outputs": [
74 {
75 "data": {
76 "text/plain": [
77 "{'*': 'I have a fucking shitty lively ass bunch of coconuts',\n",
78 " 'comment': '',\n",
79 " 'contentformat': 'text/x-wiki',\n",
80 " 'contentmodel': 'wikitext',\n",
81 " 'page': {'ns': 0, 'pageid': 45657000, 'title': 'User:Arlolra/sandbox'},\n",
82 " 'parentid': 642345234,\n",
83 " 'revid': 0,\n",
84 " 'size': 52,\n",
85 " 'timestamp': '2017-01-11T21:53:35Z',\n",
86 " 'user': '127.0.0.1',\n",
87 " 'userid': 0}"
88 ]
89 },
90 "execution_count": 59,
91 "metadata": {},
92 "output_type": "execute_result"
93 }
94 ],
95 "source": [
96 "pre_save_rev_doc = dict(rev_doc)\n",
97 "pre_save_rev_doc['*'] = \"I have a fucking shitty lively ass bunch of coconuts\"\n",
98 "del pre_save_rev_doc['content']\n",
99 "pre_save_rev_doc['parentid'] = 642345234\n",
100 "pre_save_rev_doc['revid'] = 0\n",
101 "pre_save_rev_doc['size'] = len(bytes(\"I have a fucking shitty lively ass bunch of coconuts\", 'utf-8'))\n",
102 "pre_save_rev_doc['timestamp'] = '2017-01-11T21:53:35Z'\n",
103 "pre_save_rev_doc['user'] = \"127.0.0.1\"\n",
104 "pre_save_rev_doc['userid'] = 0\n",
105 "pre_save_rev_doc['page']['ns'] = 0\n",
106 "\n",
107 "pre_save_rev_doc"
108 ]
109 },
110 {
111 "cell_type": "code",
112 "execution_count": 60,
113 "metadata": {
114 "collapsed": false
115 },
116 "outputs": [
117 {
118 "data": {
119 "text/plain": [
120 "{'scores': {'enwiki': {'damaging': {'scores': {'0': {'prediction': True,\n",
121 " 'probability': {'false': 0.36508932740844835,\n",
122 " 'true': 0.6349106725915517}}},\n",
123 " 'version': '0.3.0'}}}}"
124 ]
125 },
126 "execution_count": 60,
127 "metadata": {},
128 "output_type": "execute_result"
129 }
130 ],
131 "source": [
132 "import requests\n",
133 "import json\n",
134 "\n",
135 "response = requests.get(\n",
136 " \"https://ores-staging.wmflabs.org/v2/scores/enwiki/damaging/0\", \n",
137 " params={'datasource.revision.doc': json.dumps(pre_save_rev_doc),})\n",
138 "\n",
139 "response.json()"
140 ]
141 },
142 {
143 "cell_type": "code",
144 "execution_count": null,
145 "metadata": {
146 "collapsed": true
147 },
148 "outputs": [],
149 "source": []
150 }
151 ],
152 "metadata": {
153 "kernelspec": {
154 "display_name": "Python 3",
155 "language": "python",
156 "name": "python3"
157 },
158 "language_info": {
159 "codemirror_mode": {
160 "name": "ipython",
161 "version": 3
162 },
163 "file_extension": ".py",
164 "mimetype": "text/x-python",
165 "name": "python",
166 "nbconvert_exporter": "python",
167 "pygments_lexer": "ipython3",
168 "version": "3.4.2"
169 }
170 },
171 "nbformat": 4,
172 "nbformat_minor": 2
173}

But in any case, I thought ORES was for edits already on-wiki, is it possible to run proposed edits through it?

https://github.com/wikimedia/ores/issues/101

I finished the suggestor side of this...except it doesn't seem to work in ORES anymore?

>>> import requests
>>> x={'*': 'I have a fucking shitty lively ass bunch of coconuts',
...  'comment': '',
...  'contentformat': 'text/x-wiki',
...  'contentmodel': 'wikitext',
...  'page': {'ns': 0, 'pageid': 45657000, 'title': 'User:Arlolra/sandbox'},
...  'parentid': 642345234,
...  'revid': 0,
...  'size': 52,
...  'timestamp': '2017-01-11T21:53:35Z',
...  'user': '127.0.0.1',
...  'userid': 0}
>>> import json
>>> pre_save_rev_doc=x
>>> 
>>> response = requests.get(
...     "https://ores-staging.wmflabs.org/v2/scores/enwiki/damaging/0", 
...     params={'datasource.revision.doc': json.dumps(pre_save_rev_doc),})
>>> response.json()
{'scores': {'enwiki': {'damaging': {'scores': {'0': {'error': {'message': 'TextDeleted: Text deleted (datasource.revision.text)', 'type': 'TextDeleted'}}}, 'version': '0.5.0'}}}}

Figured it out by searching the revscoring code, it now needs to be in a MCR-like format https://github.com/wikimedia/revscoring/commit/087dd52ba6a6ab481fcb133e10369d1b00dfe549

Change 699318 had a related patch set uploaded (by Legoktm; author: Legoktm):

[labs/tools/suggestor@master] Run edits through ORES

https://gerrit.wikimedia.org/r/699318