Skip to content

Commit 21bb0e9

Browse files
author
tholzheim
committed
Added acronym ratings
1 parent 3ce199f commit 21bb0e9

7 files changed

Lines changed: 97 additions & 9 deletions

File tree

migration/openresearch/event.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import os
1313
import time
1414

15+
from ormigrate.issue41 import AcronymLengthFixer
16+
from ormigrate.painscale import PainScale
17+
1518

1619
class OREntityList(JSONAbleList):
1720
'''
@@ -103,7 +106,7 @@ def getCachePath():
103106

104107
@classmethod
105108
def getResourcePath(cls):
106-
path = os.path.dirname(__file__) + "/../ormigrate/resources/"
109+
path = os.path.dirname(__file__) + "/../ormigrate/resources"
107110
return path
108111

109112
def getJsonFile(self):
@@ -395,12 +398,10 @@ def fixRecord(self,record):
395398
record.pop(key)
396399

397400
@classmethod
398-
def rateMigration(cls,event,eventRecord):
399-
acronymLength = len(eventRecord.get('acronym')) if 'acronym' in eventRecord else None
400-
acronymMarker = "❌-" if acronymLength is None else f"❌ - {acronymLength}" if acronymLength > 20 or acronymLength<6 else f"✅ {acronymLength}"
401-
eventRecord['acronym length'] = acronymMarker
401+
def rateMigration(cls,event,eventRecord):
402+
rating = AcronymLengthFixer.getRating(eventRecord)
403+
eventRecord['acronym length'] = PainScale.lookupPainImage(rating)
402404
pass
403-
404405

405406
def __str__(self):
406407
text=self.pageTitle

migration/ormigrate/issue41.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from ormigrate.fixer import PageFixer
2+
import re
3+
4+
class AcronymLengthFixer(PageFixer):
5+
'''
6+
fixer for acronym length
7+
https://github.com/SmartDataAnalytics/OpenResearch/issues/41
8+
'''
9+
10+
def __init__(self, wikiId="or", baseUrl="https://www.openresearch.org/wiki/", debug=False, restoreOut=False, suspicitionLength=20):
11+
'''
12+
Constructor
13+
'''
14+
# call super constructor
15+
super(AcronymLengthFixer, self).__init__(wikiId, baseUrl)
16+
self.debug = debug
17+
self.restoreOut = restoreOut
18+
self.suspicitionLength = suspicitionLength
19+
20+
@staticmethod
21+
def getRating(eventRecord):
22+
'''
23+
Returns the pain scale of this event
24+
https://cr.bitplan.com/index.php/Acronyms
25+
26+
Args:
27+
eventRecord:
28+
29+
Returns:
30+
int: pain rating of the acronym
31+
'''
32+
if 'acronym' not in eventRecord:
33+
return 6
34+
acronym = eventRecord['acronym']
35+
if acronym is None:
36+
return 6
37+
elif re.match(r'[A-Z]+\s*[0-9]+', acronym):
38+
# Regex based on the results of https://cr.bitplan.com/index.php/Acronyms
39+
if len(acronym) < 5:
40+
return 5
41+
elif len(acronym) > 45:
42+
return 5
43+
else:
44+
return 1
45+
else:
46+
return 6
47+

migration/ormigrate/painscale.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
class PainScale(object):
4+
5+
@staticmethod
6+
def lookupPainImage(rating: int):
7+
'''Returns html image tag to the corresponding pain rating'''
8+
painImages = {1: "http://rq.bitplan.com/images/rq/a/a3/Pain0.png",
9+
2: "https://rq.bitplan.com/images/rq/0/01/Pain1.png",
10+
3: "https://rq.bitplan.com/images/rq/0/0a/Pain4.png",
11+
4: "https://rq.bitplan.com/images/rq/b/b0/Pain6.png",
12+
5: "https://rq.bitplan.com/images/rq/6/6c/Pain7.png",
13+
6: "https://rq.bitplan.com/images/rq/2/29/Pain10.png"
14+
}
15+
if rating > 0 and rating < 7:
16+
return f'<img alt="{rating}" src="{painImages[rating]}" width="32" height="32"/>'
17+
else:
18+
return ""

migration/ormigrate/toolbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def inPublicCI():
2525

2626
@classmethod
2727
def getResourcePath(cls):
28-
path = os.path.dirname(__file__) + "/resources/"
28+
path = os.path.dirname(__file__) + "/resources"
2929
return path
3030

3131
@classmethod

migration/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pylodstorage>=0.0.29
33
# https://pypi.org/project/python-dateutil/
44
python-dateutil
55
# https://pypi.org/project/py-3rdparty-mediawiki/
6-
py-3rdparty-mediawiki>=0.4.3
6+
py-3rdparty-mediawiki>=0.4.5

migration/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
'Programming Language :: Python :: 3.8',
3434
'Programming Language :: Python :: 3.9'
3535
],
36-
packages=['ormigrate','openresearch','ormigrate.resources'],
36+
packages=['ormigrate','openresearch',''],
37+
package_data={'ormigrate': ['resources/*.json']},
3738
install_requires=[
3839
'pylodstorage',
3940
'python-dateutil',

migration/tests/testIssue41.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import unittest
2+
from ormigrate.issue41 import AcronymLengthFixer
3+
4+
5+
class TestIssue168(unittest.TestCase):
6+
'''
7+
test issue 41 fixer
8+
'''
9+
10+
11+
def testgetPainRating(self):
12+
painList = [
13+
(1,"IEEE 2020"),
14+
(1,"IEEE 2020a"),
15+
(6,"IEEE"),
16+
(6,"Title of the event used as acronym"),
17+
(6,None)
18+
]
19+
eventRecord = lambda acronym: {"acronym": acronym }
20+
for (painRating, sample) in painList:
21+
self.assertTrue(AcronymLengthFixer.getRating(eventRecord(sample)) == painRating)

0 commit comments

Comments
 (0)