Permalink
Browse files

Added our own results to groups.json.

  • Loading branch information...
eventh committed Mar 24, 2012
1 parent 05e3510 commit 7230511f188dc789192fe1bb82f2297d4998e7e4
Showing with 127 additions and 25 deletions.
  1. +104 −16 src/etc/groups.json
  2. +23 −9 src/tasks.py
View
@@ -1,23 +1,111 @@
{
- "Group 2": {
- "1": ["G11", "G17", "G16"],
- "2": ["G13", "G10", "G22"],
- "3": ["G12", "G16", "G17"],
- "4": ["L1.4", "L1.7", "L1.5"],
- "5": ["G12", "G19", "G14"],
- "6": ["G12", "G8", "G7"],
- "7": ["G12", "G10", "G14"],
- "8": ["G4", "G23", "G18"]
- },
+ "Group 1": {
+ "1": [
+ "T3.1",
+ "T10.2.1",
+ "T14.5.1",
+ "T23.1.1.2",
+ "T5.4.1",
+ "T14.2.1",
+ "T10.2.1.1",
+ "T18.1.4",
+ "T16.13.1",
+ "T9.1.5"
+ ],
+ "2": [
+ "T10.2",
+ "T10.2.2",
+ "T8.4.1.2.2",
+ "T10.2.1",
+ "T8.3.2.2",
+ "T3.1",
+ "T10.8",
+ "T15.3.7",
+ "T5.3.1.3",
+ "T6.2.2"
+ ],
+ "3": [
+ "T1.10",
+ "T3.1",
+ "T1.11",
+ "T8.1",
+ "T16.7.1",
+ "T8.2.1",
+ "T19.1",
+ "T8.3.2.2",
+ "T8.2.2",
+ "T14.6.4"
+ ],
+ "4": [
+ "T8.3",
+ "T11.1.1.4.7",
+ "T8.2.4",
+ "T4.6.3",
+ "T8.3.1",
+ "T8.4.1.2",
+ "T10.2.2",
+ "T8.3.2.1",
+ "T24.2.1.7",
+ "T15.3.7"
+ ],
+ "5": [
+ "T12.10.1",
+ "T12.9.3",
+ "T4.1",
+ "T1.6.2.1",
+ "T12.10.3",
+ "T12.11",
+ "T5.5",
+ "T15.1.5",
+ "T4.1.3.2",
+ "T13.2.5"
+ ],
+ "6": [
+ "T2.2.5.1",
+ "T11.3.2.2",
+ "T11.3.1.2",
+ "T1.7.7",
+ "T11.4.4",
+ "T1.1.8",
+ "T11.3.2.1",
+ "T1.6.1",
+ "T10.3.4",
+ "T10.2.1.1"
+ ],
+ "7": [
+ "T6.2.3",
+ "T20.2.1",
+ "T21.1.1.2",
+ "T20.2.3.1",
+ "T22.4.1.1",
+ "T20.1.2.2",
+ "T20.2.2.1",
+ "T21.1.1.1",
+ "T20.2.3.2",
+ "T6.5.1"
+ ],
+ "8": [
+ "T11.3.2.1",
+ "T1.1.8",
+ "T1.7.5",
+ "T11.3.1.1",
+ "T1.3",
+ "T1.10",
+ "T16.5.1",
+ "T11.1.2.1",
+ "T10.3.4",
+ "T1.11"
+ ]
+ },
"Group 3": {
- "1": ["T3.1", "T8.10", "T3.1", "L20.1", "L3.1", "T8.1", "G12", "G23", "G6", "L3.2", "T7.3", "T8.3", "T10.2", "L5.3", "T19.1", "G12", "G12", "T1.6", "T10.2", "T10.2", "T21.1", "T22.3", "T2.1", "L2.1", "T15.1", "G7", "T23.1", "G7", "T9.1", "T24.2", "G6", "G16", "L3.15", "L1.2", "T10.3", "L1.4", "L2.1", "L8.13", "T1.8", "T3.1"],
- "2": ["G12", "T10.2", "G12", "T10.2", "T10.2", "G12", "L10.2", "G12", "T17.2", "T8.3", "T3.1", "T1.7", "T8.4", "T10.2", "L3.7", "T2.2", "T4.1", "G12", "T8.3", "L5.3", "T24.2", "G16", "G6", "L8.2", "L7.3", "T15.3", "L1.2", "T23.1", "G14", "T22.3", "T10.1", "L2.1", "L1.2", "T24.2", "L1.8", "G7", "T5.2", "T24.1", "T3.1", "G18", "G16", "T8.4", "T5.3", "L1.4", "L2.1", "L10.2", "T21.1", "T11.1", "G6", "T1.14", "T1.17", "T8.6", "L3.7", "T23.3", "T12.3", "T5.5"],
+ "1": ["T3.1", "T8.10", "L20.1", "L3.1", "T8.1", "G12", "G23", "G6", "L3.2", "T7.3", "T8.3", "T10.2", "L5.3", "T19.1", "T1.6", "T21.1", "T22.3", "T2.1", "L2.1", "T15.1", "G7", "T23.1", "G7", "T9.1", "T24.2", "G6", "G16", "L3.15", "L1.2", "T10.3", "L1.4", "L2.1", "L8.13", "T1.8"],
+ "2": ["G12", "T10.2", "G12", "G12", "L10.2", "G12", "T17.2", "T8.3", "T3.1", "T1.7", "T8.4", "L3.7", "T2.2", "T4.1", "G12", "L5.3", "T24.2", "G16", "G6", "L8.2", "L7.3", "T15.3", "L1.2", "T23.1", "G14", "T22.3", "T10.1", "L2.1", "L1.2", "L1.8", "G7", "T5.2", "T24.1", "G18", "G16", "T5.3", "L1.4", "L2.1", "L10.2", "T21.1", "T11.1", "G6", "T1.14", "T1.17", "T8.6", "L3.7", "T23.3", "T12.3", "T5.5"],
"3": ["L8.12", "G12", "T8.12", "T1.10", "G12", "T3.1", "G6", "L1.4", "T1.17", "T23.1", "G6", "T1.7", "L8.7", "L1.2", "T3.3", "L1.2", "T8.3", "T23.2"],
"4": ["G12", "T8.3", "T10.2", "T8.4", "G5", "T13.2", "L8.8", "T8.9", "G6", "L1.2"],
- "5": ["L2.1", "G10", "L12.10", "G12", "T12.9", "T10.2", "L23.4", "G12", "G7", "T17.2", "T5.3", "T23.1", "G6", "T4.1", "T16.5", "T24.2", "T5.2", "T5.5", "T12.10", "G14", "T3.3", "L3.10", "L1.8", "G8", "G15", "L1.4", "T12.10", "L23.8", "L2.1", "L23.4"],
- "6": ["L1.2", "G6", "T1.7", "T2.2", "T11.3", "T22.3", "G19", "L1.2", "G12", "G12", "T10.2", "T10.2", "T16.5", "L3.2", "T1.8", "L1.4", "T5.2", "T1.11", "L2.1", "G23"],
- "7": ["L4.5", "T6.2", "L20.1", "L20.1", "T24.2", "T20.2", "G12", "T21.1", "T17.3", "T21.1", "T20.2", "G6", "L3.7", "T10.2", "G6", "T22.4", "T4.6", "G12", "L2.1", "L5.3", "T2.2", "G7", "L6.1", "T2.1", "T14.1", "T23.1", "T18.1", "T23.1", "L1.4", "L1.2", "T3.1", "L4.5", "L2.1", "T16.6", "G18", "G12", "L3.13", "T20.1", "T8.3", "T23.3"],
- "8": ["G12", "T1.3", "G14", "T10.2", "T11.3", "L1.8", "T17.1", "L1.2", "T16.4", "G19", "G6", "L1.2", "L18.5", "T17.3", "T1.11", "L1.2", "T1.7", "T24.2", "L1.2", "G12", "T6.1", "T2.2", "T1.5", "T20.2", "T14.6", "T1.1", "T24.2", "T5.1", "T3.3", "T1.12", "L2.1", "T11.3", "L20.1", "T2.1", "T12.8", "T11.1", "T16.5", "T8.3", "L3.7", "T3.1", "L8.12", "T11.4", "G15", "T1.17", "G6", "T10.2", "*T1.10", "L1.4", "G12", "T1.7"]
+ "5": ["L2.1", "G10", "L12.10", "G12", "T12.9", "T10.2", "L23.4", "G12", "G7", "T17.2", "T5.3", "T23.1", "G6", "T4.1", "T16.5", "T24.2", "T5.2", "T5.5", "T12.10", "G14", "T3.3", "L3.10", "L1.8", "G8", "G15", "L1.4", "L23.8", "L2.1", "L23.4"],
+ "6": ["L1.2", "G6", "T1.7", "T2.2", "T11.3", "T22.3", "G19", "L1.2", "G12", "G12", "T10.2", "T16.5", "L3.2", "T1.8", "L1.4", "T5.2", "T1.11", "L2.1", "G23"],
+ "7": ["L4.5", "T6.2", "L20.1", "L20.1", "T24.2", "T20.2", "G12", "T21.1", "T17.3", "G6", "L3.7", "T10.2", "G6", "T22.4", "T4.6", "G12", "L2.1", "L5.3", "T2.2", "G7", "L6.1", "T2.1", "T14.1", "T23.1", "T18.1", "L1.4", "L1.2", "T3.1", "L4.5", "L2.1", "T16.6", "G18", "G12", "L3.13", "T20.1", "T8.3", "T23.3"],
+ "8": ["G12", "T1.3", "G14", "T10.2", "T11.3", "L1.8", "T17.1", "L1.2", "T16.4", "G19", "G6", "L1.2", "L18.5", "T17.3", "T1.11", "L1.2", "T1.7", "T24.2", "L1.2", "G12", "T6.1", "T2.2", "T1.5", "T20.2", "T14.6", "T1.1", "T5.1", "T3.3", "T1.12", "L2.1", "L20.1", "T2.1", "T12.8", "T11.1", "T16.5", "T8.3", "L3.7", "T3.1", "L8.12", "T11.4", "G15", "T1.17", "G6", "T1.10", "L1.4", "G12"]
},
"Group 4": {
"1": ["T3.1", "T10.2", "T23.1", "T14.5", "T15.1", "T21.1", "T19.3", "T8.1", "T19.2", "T16.13"],
View
@@ -19,7 +19,7 @@
from whoosh.qparser import QueryParser, OrGroup
from index import create_or_open_index, get_empty_indices
-from data import (ATC, ICD, Therapy, PatientCase,
+from data import (ATC, ICD, Therapy, PatientCase, BaseData,
populate_all, get_medical_terms)
@@ -70,13 +70,19 @@ def task_4(case, medical=get_medical_terms()):
#results2 = _task_4_search(case, medical, 'vector3')
#print("[%s]: Kendal Tau: %.3f" % (case.code, _kendall_tau(results, results2, 1000)))
#_task_4_print_terms(results)
- _task_4_precision(results)
- #_task_4_precision(results2)
+ _precision(results)
+ #_precision(results2)
-def task_5(case):
+def task_5(medical=get_medical_terms()):
"""Task 5: Exchange evaluations"""
- pass
+ relevant = lambda chapter: set(chapter.vector.keys()) & medical
+ with open('etc/groups.json', 'r') as f:
+ groups = json.load(f)
+ values = groups['Group 3']
+ for case_code, results in sorted(values.items(), key=itemgetter(0)):
+ filtered = [Therapy.ALL[i] for i in results if i in Therapy.ALL]
+ _precision([(c, None, None, relevant(c)) for c in filtered])
def task_6a(case, limit=10):
@@ -153,8 +159,8 @@ def _task_6_eval(case, medical=get_medical_terms()):
#result_3 = [(c,) for s, c in task_3(case, 1000)]
result_6a = [(c, s, None, relevant(c)) for s, c in task_6a(case, 1000)]
result_6b = [(c, s, None, relevant(c)) for s, c in task_6b(case, 1000)]
- #_task_4_precision(result_6a)
- #_task_4_precision(result_6b)
+ #_precision(result_6a)
+ #_precision(result_6b)
print("[%s]: Kendal Tau: %.3f" % (case.code,
_kendall_tau(result_6a, result_6b, 1000)))
@@ -225,7 +231,7 @@ def _task_4_search(case, medical, attr='vector'):
return sorted(results, key=itemgetter(1), reverse=True)
-def _task_4_precision(results, count=10, hack=[]):
+def _precision(results, count=10, hack=[]):
"""Calculate precision at 'count' and R-precision."""
rel_count = sum([0] + [1 for r in results[:count] if r[3]])
r_precision = sum([0] + [1 for r in results[:rel_count] if r[3]])
@@ -281,6 +287,11 @@ def output_json(task, results, fields=None):
with open(filename, 'w') as f:
output = OrderedDict()
for case, lines in results.items():
+ # Hack for tasks which returns score, object pairs
+ if lines[0] and isinstance(lines[0][1], BaseData):
+ output[case] = [i[1].code for i in lines if i[1]]
+ continue
+
obj = OrderedDict()
for i, codes in enumerate(lines, 1):
obj[i] = codes[:5]
@@ -409,8 +420,11 @@ def main(script, task='', case='', output=''):
populate_all()
+ if task == '5':
+ task_5()
+
# Perform a task which uses patient cases as input
- if task in CASE_TASKS:
+ elif task in CASE_TASKS:
cases = {name: obj for name, obj in PatientCase.ALL.items()
if (not case or name == case)}
if not cases:

0 comments on commit 7230511

Please sign in to comment.