示例#1
0
def errors(request):
    issues = defaultdict(list)
    frames_ok, frames_total = 0, 0

    for db_frame in VerbNetFrame.objects.select_related('frameset', 'frameset__verbnet_class', 'frameset__verbnet_class__levin_class').filter(removed=False):
        if db_frame.frameset.removed:
            continue
        if db_frame.frameset.verbnet_class.levin_class.translation_status != LevinClass.STATUS_TRANSLATED:
            continue

        frames_total += 1
        output = io.StringIO()
        try:
            merge_primary_and_syntax(db_frame.syntax, db_frame.roles_syntax, output)
            frames_ok += 1
        except WrongFrameException as e:
            issues[e.args[0]].append(db_frame)
        except Exception as e:
            exc_type, exc_value, exc_tb = sys.exc_info()
            tb_info = traceback.extract_tb(exc_tb)
            path, line, func, text = tb_info[-1]
            exception = traceback.format_exception_only(exc_type, exc_value)[0]
            filename = Path(path).name
            issues['{} ({}:{})'.format(exception, filename, line)].append(db_frame)


    return render(request, 'errors.html', {
        'issues': OrderedDict(sorted(issues.items(), reverse=True, key=lambda kv: len(kv[1]))),
        'frames_ok': frames_ok,
        'frames_total': frames_total,
        'ratio': '{:.1%}'.format(frames_ok / frames_total),
    })
示例#2
0
    def test_modifier(self):
        new_syntax = merge_primary_and_syntax("NP V NP", "Agent V Patient<+plural>")
        xml = xml_of_syntax(new_syntax)
        self.assertEqual(
            ET.tostring(xml, encoding="unicode"),
            '<SYNTAX><NP value="Agent"><SYNRESTRS /></NP><VERB /><NP modifier="+plural" value="Patient"><SYNRESTRS /></NP></SYNTAX>',
        )

        new_syntax = merge_primary_and_syntax("NP se V ADV", "Patient se V<+middle> ADV")
        xml = xml_of_syntax(new_syntax)
        self.assertEqual(
            ET.tostring(xml, encoding="unicode"),
            '<SYNTAX><NP value="Patient"><SYNRESTRS /></NP><VERB pronominal="true" restr="middle" /><ADV /></SYNTAX>',
        )
示例#3
0
 def test_simple_sentence(self):
     new_syntax = merge_primary_and_syntax("NP V NP", "Agent V Patient")
     xml = xml_of_syntax(new_syntax)
     self.assertEqual(
         ET.tostring(xml, encoding="unicode"),
         '<SYNTAX><NP value="Agent"><SYNRESTRS /></NP><VERB /><NP value="Patient"><SYNRESTRS /></NP></SYNTAX>',
     )
示例#4
0
 def test_pp_category(self):
     new_syntax = merge_primary_and_syntax("NP V PP", "Agent V {{+loc}} Patient")
     xml = xml_of_syntax(new_syntax)
     self.assertEqual(
         ET.tostring(xml, encoding="unicode"),
         '<SYNTAX><NP value="Agent"><SYNRESTRS /></NP><VERB /><PREP><SELRESTRS><SELRESTR Value="+" type="loc" /></SELRESTRS></PREP><NP value="Patient"><SYNRESTRS /></NP></SYNTAX>',
     )
示例#5
0
 def test_vinf_direct(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V de V-inf", "Pivot V Theme<+de VTheme-inf>"),
         [
             {"type": "NP", "role": "Pivot"},
             {"type": "V"},
             {"type": "VINF", "role": "Theme", "emptysubjectrole": "Theme", "introduced_by": {"de"}},
         ],
     )
示例#6
0
 def test_simple_vinf(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V V-inf", "Pivot V Theme<+VTheme-inf>"),
         [
             {"type": "NP", "role": "Pivot"},
             {"type": "V"},
             {"type": "VINF", "role": "Theme", "emptysubjectrole": "Theme"},
         ],
     )
示例#7
0
 def test_p(self):
     new_syntax = merge_primary_and_syntax("NP V Qu Psubj", "Agent V Topic<+Qu Psubj>")
     xml = xml_of_syntax(new_syntax)
     print(new_syntax)
     print(xml)
     self.assertEqual(
         ET.tostring(xml, encoding="unicode"),
         "<SYNTAX>" '<NP value="Agent"><SYNRESTRS /></NP>' "<VERB />" '<PSUBJ value="Topic" />' "</SYNTAX>",
     )
示例#8
0
 def test_comment(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V comment P", "Experiencer V Stimulus<+comment P>"),
         [
             {"type": "NP", "role": "Experiencer"},
             {"type": "V"},
             {"type": "P", "role": "Stimulus", "introduced_by": "comment"},
         ],
     )
示例#9
0
 def test_single_preposition(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V PP", "Agent V {foo} Patient"),
         [
             {"type": "NP", "role": "Agent"},
             {"type": "V"},
             {"type": "PREP", "Value": {"foo"}},
             {"type": "PP", "role": "Patient"},
         ],
     )
示例#10
0
 def test_interrogative_prep(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V de comment P", "Experiencer V {de} Stimulus<+comment P>"),
         [
             {"type": "NP", "role": "Experiencer"},
             {"type": "V"},
             {"type": "PREP", "Value": {"de"}},
             {"type": "P", "role": "Stimulus", "introduced_by": "comment"},
         ],
     )
示例#11
0
 def test_vinf_indirect(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V à V-inf", "Pivot V {à} Theme<+VAgent-inf>"),
         [
             {"type": "NP", "role": "Pivot"},
             {"type": "V"},
             {"Value": {"à"}, "type": "PREP"},
             {"type": "VINF", "role": "Theme", "emptysubjectrole": "Agent"},
         ],
     )
示例#12
0
 def test_preposition_class(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V PP", "Agent V {{+loc}} Patient"),
         [
             {"type": "NP", "role": "Agent"},
             {"type": "V"},
             {"type": "PREP", "type_": "loc", "Value": "+"},
             {"type": "PP", "role": "Patient"},
         ],
     )
示例#13
0
 def test_vinf_direct(self):
     new_syntax = merge_primary_and_syntax("NP V de V-inf", "Pivot V Theme<+de VPivot-inf>")
     xml = xml_of_syntax(new_syntax)
     self.assertEqual(
         ET.tostring(xml, encoding="unicode"),
         "<SYNTAX>"
         '<NP value="Pivot"><SYNRESTRS /></NP>'
         "<VERB />"
         '<VINF emptysubjectrole="Pivot" introduced_by="de" value="Theme" />'
         "</SYNTAX>",
     )
示例#14
0
    def test_preposition_list(self):
        self.assertEqual(
            merge_primary_and_syntax("NP V PP", "Agent V {à dans pour} Patient"),
            [
                {"type": "NP", "role": "Agent"},
                {"type": "V"},
                {"Value": {"à", "dans", "pour"}, "type": "PREP"},
                {"role": "Patient", "type": "PP"},
            ],
        )

        self.assertEqual(
            merge_primary_and_syntax("NP V PP", "Agent V {pour/de la part de} Patient"),
            [
                {"type": "NP", "role": "Agent"},
                {"type": "V"},
                {"Value": {"pour", "de la part de"}, "type": "PREP"},
                {"role": "Patient", "type": "PP"},
            ],
        )
示例#15
0
 def test_dece_quep(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V PP de ce Qu Pind", "Agent V {avec} Co-Agent {de} Topic<+Qu Pind>"),
         [
             {"type": "NP", "role": "Agent"},
             {"type": "V"},
             {"type": "PREP", "Value": {"avec"}},
             {"type": "PP", "role": "Co-Agent"},
             {"type": "PREP", "Value": {"de"}},
             {"type": "PIND", "role": "Topic", "introduced_by": "de"},
         ],
     )
示例#16
0
 def test_vinf_indirect(self):
     new_syntax = merge_primary_and_syntax("NP V de V-inf", "Pivot V {de} Theme<+VSource-inf>")
     xml = xml_of_syntax(new_syntax)
     self.assertEqual(
         ET.tostring(xml, encoding="unicode"),
         "<SYNTAX>"
         '<NP value="Pivot"><SYNRESTRS /></NP>'
         "<VERB />"
         '<PREP><SELRESTRS><SELRESTR Value="de" /></SELRESTRS></PREP>'
         '<VINF emptysubjectrole="Source" value="Theme" />'
         "</SYNTAX>",
     )
示例#17
0
 def test_dece_quep(self):
     self.maxDiff = None
     new_syntax = merge_primary_and_syntax("NP V PP de ce Qu Pind", "Agent V {avec} Co-Agent {de} Topic<+Qu Pind>")
     xml = xml_of_syntax(new_syntax)
     self.assertEqual(
         ET.tostring(xml, encoding="unicode"),
         "<SYNTAX>"
         '<NP value="Agent"><SYNRESTRS /></NP>'
         "<VERB />"
         '<PREP><SELRESTRS><SELRESTR Value="avec" /></SELRESTRS></PREP>'
         '<NP value="Co-Agent"><SYNRESTRS /></NP>'
         '<PREP><SELRESTRS><SELRESTR Value="de" /></SELRESTRS></PREP>'
         '<PIND introduced_by="de" value="Topic" />'
         "</SYNTAX>",
     )
示例#18
0
    def test_twoprep_vinf_indirect(self):
        """Test indirect V-inf with two prepositions

        Not really interesting because there is no code that is specific to
        this test case. Indeed, indirect V-inf is just prep + V-inf. But two
        prepositions in a direct V-inf is not currently supported"""
        self.assertEqual(
            merge_primary_and_syntax("NP V à/de V-inf", "Pivot V {à/de} Theme<+VAgent-inf>"),
            [
                {"type": "NP", "role": "Pivot"},
                {"type": "V"},
                {"Value": {"à", "de"}, "type": "PREP"},
                {"type": "VINF", "role": "Theme", "emptysubjectrole": "Agent"},
            ],
        )
示例#19
0
 def test_simple_sentence(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V NP", "Agent V Patient"),
         [{"type": "NP", "role": "Agent"}, {"type": "V"}, {"type": "NP", "role": "Patient"}],
     )
示例#20
0
 def test_neutral_verb(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V NP", "Agent V<+neutre> Patient"),
         [{"type": "NP", "role": "Agent"}, {"type": "V", "restr": "neutre"}, {"type": "NP", "role": "Patient"}],
     )
示例#21
0
 def test_adverb_as_role(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V ADV-Middle", "Patient V ADV"),
         [{"type": "NP", "role": "Patient"}, {"type": "V"}, {"type": "ADV"}],
     )
示例#22
0
 def test_adj_as_role(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V NP ADJ", "Pivot V Theme ADJ"),
         [{"type": "NP", "role": "Pivot"}, {"type": "V"}, {"type": "NP", "role": "Theme"}, {"type": "ADJ"}],
     )
示例#23
0
    def test_bad_vinf(self):
        with self.assertRaises(WrongFrameException):
            merge_primary_and_syntax("NP V V-inf", "Pivot V Theme<+deVAgent-inf>", output=sys.stdout)

        with self.assertRaises(WrongFrameException):
            merge_primary_and_syntax("NP V V-inf", "Pivot V {de} Theme<+VAgent-inf>", output=sys.stdout)
示例#24
0
 def test_quep(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V Qu Psubj", "Agent V Topic<+Qu Psubj>"),
         [{"type": "NP", "role": "Agent"}, {"type": "V"}, {"type": "PSUBJ", "role": "Topic", "introduced_by": None}],
     )
示例#25
0
 def test_sip(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V si P", "Agent V Topic<+si P>"),
         [{"type": "NP", "role": "Agent"}, {"type": "V"}, {"type": "P", "role": "Topic", "introduced_by": "si"}],
     )
示例#26
0
 def test_plural(self):
     self.assertEqual(
         merge_primary_and_syntax("NP V", "Patient<+plural> V"),
         [{"type": "NP", "role": "Patient", "modifier": "+plural"}, {"type": "V"}],
     )