File size: 4,532 Bytes
e12d99b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import json
import unittest
from evaluation.io import DATA,load_json,read_jsonl,comparable_text,mcq_fingerprint


class RepairedDataTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.manifest=load_json(DATA/'manifest.json')
        cls.rows={r['id']:r for task in cls.manifest['tasks'] for r in read_jsonl(DATA/task['path'])}

    def correct(self,uid):
        row=self.rows[uid];return row['options'][row['answer']]

    def test_normalization_preserves_mathematical_distinctions(self):
        self.assertEqual(comparable_text('The “chart” is shown.'),comparable_text('the chart is shown'))
        self.assertNotEqual(comparable_text('+2 degrees'),comparable_text('-2 degrees'))
        self.assertNotEqual(comparable_text('1.5 m'),comparable_text('15 m'))
        self.assertNotEqual(comparable_text("5'"),comparable_text('5'))
        self.assertNotEqual(comparable_text('5"'),comparable_text('5'))

    def test_no_duplicate_mcq_or_trajectory_problem(self):
        mcqs={};trajectories={}
        for uid,row in self.rows.items():
            if 'options' in row:
                key=mcq_fingerprint(row)
                self.assertNotIn(key,mcqs,uid);mcqs[key]=uid
            if row['task']=='route_prediction':
                key=json.dumps([row['context']['trajectory'],row['context']['target_time'],row['answer']],sort_keys=True)
                self.assertNotIn(key,trajectories,uid);trajectories[key]=uid
        self.assertEqual(len(trajectories),500)

    def test_recovered_unicode_labels_match_source_spelling(self):
        text='\n'.join(v for r in self.rows.values() if r['task']=='electronic_chart' for v in r['options'].values())
        self.assertNotIn('?',text)
        for label in ['Glückstadt','KØBENHAVN','Route recommandée','Baggensfjärden','São Lourenço','Baliza Punta Ángeles']:
            self.assertIn(label,text)

    def test_corrected_answers_survive_balancing(self):
        expected={
            'chart_usage/0119':'On a great circle chart, the straight lines on the chart are definitely great circle arcs.',
            'navigation_environment/0171':'A tropical cyclone is a warm cyclone.',
            'navigation_environment/0287':'It decreases',
            'ship_structure/1642':'Angle of vanishing stability',
            'ship_structure/0851':'Fresh-water timber load line in summer',
            'maritime_english/0148':'The bulk carrier itself presenting a poor radar target',
            'maritime_english/0321':'1–2°C',
            'maritime_english/0787':'10',
            'navigation_environment/0180':'Calendar date and Universal Time UT1',
            'navigation_environment/1313':'34.6 NM',
            'navigation_environment/1692':'Pressure rises',
            'ship_structure/0318':'1,309 kJ',
            'maritime_english/0656':'The outgoing officer doubts the reliever’s fitness',
            'maritime_english/0657':'After the manoeuvre is completed',
            'maritime_english/0709':'Down by the head'}
        for uid,answer in expected.items():self.assertEqual(self.correct(uid),answer,uid)

    def test_restored_reading_inputs_and_unrecoverable_exclusions(self):
        for sid in ['0071','0099','0149','0150','0175','0284','0322','0467','0510','0511','0567','0620','0664','0665','0789','0790','0791',
                    '0090','0092','0182','0184','0218','0220','0262','0263','0301','0303','0355','0356','0408','0409',
                    '0428','0430','0446','0448','0573','0575','0597','0599','0655','0657','0691','0693','0708','0710']:
            row=self.rows['maritime_english/'+sid]
            self.assertTrue(row['context']['passage'] if 'passage' in row['context'] else row['context']['ism_summary'])
        for uid in ['maritime_english/0212','maritime_english/0214','maritime_english/0466','maritime_english/0759','navigation_environment/0431','navigation_environment/0072']:
            self.assertNotIn(uid,self.rows)

    def test_ais_sentinels_are_declared_without_imputing_source_values(self):
        count=0
        for row in self.rows.values():
            if row['task']!='route_prediction':continue
            meanings=row['context']['ais_field_semantics']
            self.assertIn('511',meanings['Heading']);self.assertIn('360',meanings['COG']);self.assertIn('102.3',meanings['SOG'])
            for point in row['context']['trajectory']:
                if float(point.get('Heading',0))==511:count+=1
        self.assertGreater(count,0)


if __name__=='__main__':unittest.main()