Spaces:
Sleeping
Sleeping
File size: 64,422 Bytes
9ddcd69 82679de 9ddcd69 82679de 0a24c59 9ddcd69 82679de 9ddcd69 82679de c84e88a 82679de d5bae16 400df1c d5bae16 c84e88a 400df1c c84e88a 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 82679de 9ddcd69 |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 |
# rules to be in the porttinari_check verificador
#
# function to be accessed:
#
# checkSent(b, dump, rep) - it performs all verifications over the sentence 'b',
# it prints out the report in the output file 'dump'
# it samples the sentences with problems at the 'rep'
# - it returns:
# - an array with verifications perceived to each rule
# - the sentence total number of verifications perceived
parserDef = ["P", 69, 64] # identifier of the parser problems, total number of rules, number of strict rules (not warning)
#########################
#### REGRAS
#########################
msg_Prule01 = "ERRO "+parserDef[0]+"01: Todo token dependente de det é DET (o inverso não é verdadeiro)."
msg_Prule02 = "ERRO "+parserDef[0]+"02: Todo token dependente de amod é ADJ (o inverso não é verdadeiro)."
msg_Prule03 = "ERRO "+parserDef[0]+"03: Todo token dependente de iobj é PRON, tem feature Case=Dat e lema: ['me', 'te', 'se', 'lhe', 'nos', 'vos', 'lhes'] (o inverso não é verdadeiro)."
msg_Prule04 = "ERRO "+parserDef[0]+"04: Todo token dependente de obj que é PRON, tem feature Case=Acc e lema: ['me', 'te', 'se', 'o', 'a', 'nos', 'vos', 'os', 'as', 'lo', 'la', 'los', 'las', 'no', 'na', 'nos', 'nas']."
msg_Prule05 = "ERRO "+parserDef[0]+"05: Nenhum ADP é head de relação - Exceções: pode ser head da relação fixed (e se for de fixed, pode ser de punct, cc e conj também), pode ser head de conj se o dependente for ADP, pode ser head de cc se o token ADP for dependente de conj."
msg_Prule06 = "ERRO "+parserDef[0]+"06: Nenhum token CCONJ é head de relação - Exceção: pode ser head da relação fixed (e se for de fixed, pode ser de punct também), pode ser head de conj dependente de CCONJ."
msg_Prule07 = "ERRO "+parserDef[0]+"07: Nenhum SCONJ é head de relação - Exceções: pode ser head da relação fixed (e se for de fixed, pode ser de punct, cc e conj também), pode ser head de conj se o dependente for SCONJ, pode ser head de cc se o token SCONJ for dependente de conj."
msg_Prule08 = "ERRO "+parserDef[0]+"08: Nenhum DET é head de relação - Exceções: pode ser head das relações punct e fixed (e se for de fixed, pode ser de cc e conj também), pode ser head de conj se o dependente for DET, pode ser head de cc se o token DET for dependente de conj."
msg_Prule09 = "ERRO "+parserDef[0]+"09: Um token AUX não pode ser head de relação (exceto punct) se for dependente de aux, aux:pass ou cop."
msg_Prule10 = "ERRO "+parserDef[0]+"10: Nenhum token dependente de fixed é head de relação."
msg_Prule11 = "ERRO "+parserDef[0]+"11: Todo token head de case só pode ser PROPN, NOUN, PRON, ADJ, NUM, X, INTJ, SYM ou ADV."
msg_Prule12 = "ERRO "+parserDef[0]+"12: Nenhum token SCONJ pode ser dependente de nsubj, nsubj:pass, nsubj:outer, csubj, csubj:pass, csubj:outer e obj."
msg_Prule13 = "ERRO "+parserDef[0]+"13: Todo token dependente de cop só pode ter lema 'estar' ou 'ser' e sempre deve ser AUX."
msg_Prule14 = "ERRO "+parserDef[0]+"14: Dois ou mais tokens dependentes de case não podem apontar para um mesmo token head."
msg_Prule15 = "ERRO "+parserDef[0]+"15: Nenhum token PRON pode ser dependente de mark, exceto se for head de fixed."
msg_Prule16 = "ERRO "+parserDef[0]+"16: Todo token dependente de aux só pode ter lema = 'ser', 'estar', 'ter', 'haver', 'ir' e 'vir' caso seja vir+Ger ou vir+'a'+Inf."
msg_Prule17 = "ERRO "+parserDef[0]+"17: Todo token que é ponto final não pode ter como head um token que não é head de outras relações (exceto se houver apenas um outro token)."
msg_Prule18 = "ERRO "+parserDef[0]+"18: Todo token dependente de nummod só pode ser head de advmod, nummod, flat, conj, case, appos, nmod e nmod:spec."
msg_Prule19 = "ERRO "+parserDef[0]+"19: Todo token VERB dependente de xcomp nunca é head de uma relação de sujeito: nsubj, nsubj:outer e nsubj:pass."
msg_Prule20 = "ERRO "+parserDef[0]+"20: Nenhum token ADJ pode ser head de det."
msg_Prule21 = "ERRO "+parserDef[0]+"21: Todo token dependente de aux, aux:pass ou cop tem que ter ser AUX (o inverso não é verdadeiro)."
msg_Prule22 = "ERRO "+parserDef[0]+"22: Todo token VERB não pode ser head de case."
msg_Prule23 = "ERRO "+parserDef[0]+"23: Todo token head de obl só pode ser VERB, ADJ, ADV ou X. Exceção: também pode ser AUX se o verbo estiver elíptico (o token head de AUX não é VERB)."
msg_Prule24 = "ERRO "+parserDef[0]+"24: Todo token dependente de advmod é ADV, ADJ ou qualquer token que seja head de fixed."
msg_Prule25 = "ERRO "+parserDef[0]+"25: Todo token dependente de nummod é NUM (o inverso não é verdadeiro)."
msg_Prule26 = "ERRO "+parserDef[0]+"26: Todo token dependente de nmod é PROPN, NOUN, NUM, INTJ, SYM, X ou PRON (o inverso não é verdadeiro)."
msg_Prule27 = "ERRO "+parserDef[0]+"27: Todo token PUNCT é dependente de punct e vice-versa."
msg_Prule28 = "ERRO "+parserDef[0]+"28: Todo token ADP que não é head de fixed e cujo token head é um verbo no infinitivo (VerbForm=Inf) deve ser dependente de mark."
msg_Prule29 = "ERRO "+parserDef[0]+"29: Nenhum token PROPN ou NOUN pode ser dependente de appos de um token PROPN ou NOUN. Exceção: se o token head for separado por pontuação do token dependente."
msg_Prule30 = "ERRO "+parserDef[0]+"30: Nenhum token head de case pode ser dependente de obj."
msg_Prule31 = "ERRO "+parserDef[0]+"31: Nenhum token head de case pode ser dependente de iobj."
msg_Prule32 = "ERRO "+parserDef[0]+"32: Todos tokens 'muito', 'muitos', 'muita', 'muitas' que forem ADJ devem ser dependentes de amod. Exceção: caso seja dependente de xcomp ou head de cop."
msg_Prule33 = "ERRO "+parserDef[0]+"33: Todos tokens 'pouco', 'poucos', 'pouca', 'poucas' que forem ADJ devem ser dependentes de amod. Exceção: caso seja dependente de xcomp ou head de cop."
msg_Prule34 = "ERRO "+parserDef[0]+"34: Todos tokens 'onde', 'quando', 'como' que forem ADV, e não forem head de cop ou fixed, devem ser dependentes de advmod, fixed ou conj (se estiverem coordenadas com outro ADV)."
msg_Prule35 = "ERRO "+parserDef[0]+"35: Todo token dependente de expl só pode ser PRON."
msg_Prule36 = "ERRO "+parserDef[0]+"36: Nenhum token head de cop é VERB."
msg_Prule37 = "ERRO "+parserDef[0]+"37: Não deve haver Deprel projetivas (cruzamento de arcos) para nenhum token."
msg_Prule38 = "ERRO "+parserDef[0]+"38: Uma sentença só pode ter um token root e ele deve ser bem formado (head 0, Deprel 'root')"
msg_Prule39 = "ERRO "+parserDef[0]+"39: Nenhum token é head de mais de um nsubj."
msg_Prule40 = "ERRO "+parserDef[0]+"40: Nenhum token é head de mais de um nsubj:pass."
msg_Prule41 = "ERRO "+parserDef[0]+"41: Nenhum token é head de mais de um nsubj:outer."
msg_Prule42 = "ERRO "+parserDef[0]+"42: Nenhum token é head de mais de um csubj."
msg_Prule43 = "ERRO "+parserDef[0]+"43: Nenhum token é head de mais de um obj."
msg_Prule44 = "ERRO "+parserDef[0]+"44: Nenhum token é head de mais de um xcomp."
msg_Prule45 = "ERRO "+parserDef[0]+"45: Nenhum token é head de mais de um ccomp."
msg_Prule46 = "ERRO "+parserDef[0]+"46: Nenhum token é head de mais de um case."
msg_Prule47 = "ERRO "+parserDef[0]+"47: Todo token dependente de appos tem seu head à esquerda."
msg_Prule48 = "ERRO "+parserDef[0]+"48: Todo token dependente de mark tem seu head à direita."
msg_Prule49 = "ERRO "+parserDef[0]+"49: Todo token dependente de case tem seu head à direita."
msg_Prule50 = "ERRO "+parserDef[0]+"50: Todo token dependente de fixed tem seu head à esquerda."
msg_Prule51 = "ERRO "+parserDef[0]+"51: Todo token dependente de flat:name tem seu head à esquerda."
msg_Prule52 = "ERRO "+parserDef[0]+"52: Nenhum token pode ser simultaneamente head de nsubj e head de nsubj:pass, nsubj e csubj ou nsubj:pass e csubj."
msg_Prule53 = "ERRO "+parserDef[0]+"53: Todo token dependente de flat:foreign tem seu head à esquerda."
msg_Prule54 = "ERRO "+parserDef[0]+"54: Todo token SCONJ só pode ser dependente de mark, fixed, conj ou discourse. Exceção: se for a palavra 'quanto' pode ser dependente de advcl."
msg_Prule55 = "ERRO "+parserDef[0]+"55: Todo token head de nsubj:pass deve ter feature Voice=Pass. Exceção: se o verbo for head de expl:pass."
msg_Prule56 = "ERRO "+parserDef[0]+"56: Todo token head de obl:agent deve ter feature Voice=Pass."
msg_Prule57 = "ERRO "+parserDef[0]+"57: Todo token head de aux:pass deve ter feature Voice=Pass."
msg_Prule58 = "ERRO "+parserDef[0]+"58: Todo token head e dependente de flat:foreign deve ser X."
msg_Prule59 = "ERRO "+parserDef[0]+"59: Todo token head e dependente de flat:name deve ser PROPN ou X."
msg_Prule60 = "ERRO "+parserDef[0]+"60: Todo token head e dependente de flat deve ser NUM, NOUN ou ADJ e ter NumType."
msg_Prule61 = "ERRO "+parserDef[0]+"61: Todo token head de aux ou aux:pass, que não for simultaneamente head de cop, deve ser VERB."
msg_Prule62 = "ERRO "+parserDef[0]+"62: A feature 'ExtPos={}' deveria ser utilizada (ou a DEPREL fixed deveria ser removida), mas a etiqueta 'ExtPos' está ausente."
msg_Prule63 = "ERRO "+parserDef[0]+"63: A feature 'ExtPos={}' deveria ser utilizada (ou a DEPREL fixed deveria ser removida), mas a etiqueta 'ExtPos={}' foi utilizada."
msg_Prule64 = "ERRO "+parserDef[0]+"64: A feature 'ExtPos={}' não deveria ser utilizada pois o token não é HEAD de fixed, retire 'ExtPos' ou corrija a DEPREL fixed."
#########################
#### AVISOS
#########################
msg_Prule65 = "AVISO "+parserDef[0]+"65: Normalmente, dois ou mais tokens dependentes de cop não podem apontar para um mesmo token head, exceto se o head for head de um nsubj:outer."
msg_Prule66 = "AVISO "+parserDef[0]+"66: Normalmente, dois ou mais tokens dependentes de mark não podem apontar para um mesmo token head, exceto se o head for head de um nsubj:outer."
msg_Prule67 = "AVISO "+parserDef[0]+"67: Normalmente, todo token dependente de flat:name só pode ser head de cc, case, det, punct, expl, nmod (se o dependente for um número cardinal - NUM NumType=Card) ou amod (se o dependente for um número ordinal - ADJ NumType=Ord)."
msg_Prule68 = "AVISO "+parserDef[0]+"68: Normalmente, um token dependente de nmod só pode ter como head tokens PROPN, NOUN, NUM, SYM, X e PRON."
msg_Prule69 = "AVISO "+parserDef[0]+"69: Normalmente, todo token PUNCT final tem como head o token root."
msg_Prule70 = "AVISO "+parserDef[0]+"70: Normalmente, pontuações pareadas (aspas, parênteses, colchetes, chaves) tem o mesmo head."
msg_Prule71 = "AVISO "+parserDef[0]+"71: Normalmente, nenhum token pode ser simultaneamente head de obj e head de ccomp."
msg_Prule72 = "AVISO "+parserDef[0]+"72: Normalmente, nenhum token ADJ pode ser head ou dependente de appos."
#########################
#### REGRAS
#########################
def check01(b,dump):
'''Todo dependente de det é DET (o inverso não é verdadeiro)'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "det") and (b[4][i][3] != "DET"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule01), sep="\t", file=dump)
return acc
def check02(b,dump):
'''Todo dependente de amod é ADJ (o inverso não é verdadeiro)'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "amod") and (b[4][i][3] != "ADJ"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule02), sep="\t", file=dump)
return acc
def check03(b,dump):
'''Todo dependente de iobj é PRON, Case=Dat e "me", "te", "se", "lhe", "nos", "vos", "lhes" (o inverso não é verdadeiro)'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "iobj") and \
((b[4][i][3] != "PRON") or ("Case=Dat" not in b[4][i][5]) or (b[4][i][2] not in ["me", "te", "se", "lhe", "nos", "vos", "lhes"])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule03), sep="\t", file=dump)
return acc
def check04(b,dump):
'''Todo dependente de obj que é PRON, Case=Acc e "me", "te", "se", "o", "a", "nos", "vos", "os", "as", "lo", "la", "los", "las", "no", "na", "nos", "nas" '''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if ((b[4][i][7] == "obj") and (b[4][i][3] == "PRON") and ("Case=Acc" in b[4][i][5])) and \
(b[4][i][2] not in ["me", "te", "se", "o", "a", "nos", "vos", "os", "as", "lo", "la", "los", "las", "no", "na", "nos", "nas"]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0],msg_Prule04 ), sep="\t", file=dump)
return acc
def check05(b,dump):
'''Nenhum ADP é head de relação - Exceções: pode ser head da relação fixed (e se for de fixed, pode ser de punct, cc e conj também), pode ser head de conj se o dependente for ADP, pode ser head de cc se o token ADP for dependente de conj.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "ADP"):
target = b[4][i][0]
wronghead, puncthead, fixedhead = False, False, False
for tk in b[4]:
if (tk[6] == target) and (tk[7] not in ["fixed", "punct", "conj", "cc"]):
wronghead = True
break
elif (tk[6] == target) and (tk[7] == "fixed"):
fixedhead = True
elif (tk[6] == target) and (tk[7] == "punct"):
puncthead = True
elif (tk[6] == target) and (tk[7] == "conj") and (tk[3] not in ["ADP"]):
wronghead = True
break
elif (tk[6] == target) and (tk[7] == "cc") and (b[4][i][7] != "conj"):
wronghead = True
break
if (wronghead or (puncthead and not fixedhead)):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule05), sep="\t", file=dump)
return acc
def check06(b,dump):
'''Nenhum CCONJ é head de relação - Exceção: pode ser head da relação fixed (e se for de fixed, pode ser de punct também), pode ser head de conj dependente de CCONJ.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "CCONJ"):
target = b[4][i][0]
wronghead, puncthead, fixedhead = False, False, False
for tk in b[4]:
if (tk[6] == target) and (tk[7] not in ["fixed", "punct", "conj"]):
wronghead = True
break
elif (tk[6] == target) and (tk[7] == "fixed"):
fixedhead = True
elif (tk[6] == target) and (tk[7] == "punct"):
puncthead = True
elif (tk[6] == target) and (tk[7] in ["conj"]) and (tk[3] not in ["CCONJ"]):
wronghead = True
break
if (wronghead and (not puncthead or not fixedhead)):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule06), sep="\t", file=dump)
return acc
def check07(b,dump):
'''Nenhum SCONJ é head de relação - Exceções: pode ser head da relação fixed (e se for de fixed, pode ser de punct, cc e conj também), pode ser head de conj se o dependente for SCONJ, pode ser head de cc se o token SCONJ for dependente de conj.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "SCONJ"):
target = b[4][i][0]
wronghead, puncthead, fixedhead = False, False, False
for tk in b[4]:
if (tk[6] == target) and (tk[7] not in ["fixed", "punct", "conj", "cc"]):
wronghead = True
break
elif (tk[6] == target) and (tk[7] == "fixed"):
fixedhead = True
elif (tk[6] == target) and (tk[7] == "punct"):
puncthead = True
elif (tk[6] == target) and (tk[7] in ["conj"]) and (tk[3] not in ["SCONJ"]):
wronghead = True
break
elif (tk[6] == target) and (tk[7] == "cc") and (b[4][i][7] != "conj"):
wronghead = True
break
if (wronghead or (puncthead and not fixedhead)):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule07), sep="\t", file=dump)
return acc
def check08(b,dump):
'''Nenhum DET é head de relação - Exceções: pode ser head da relação fixed (e se for de fixed, pode ser de punct, cc e conj também), pode ser head de conj se o dependente for DET, pode ser head de cc se o token DET for dependente de conj.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "DET"):
target = b[4][i][0]
wronghead = False
for tk in b[4]:
if (tk[6] == target) and (tk[7] not in ["fixed", "punct", "conj", "cc"]):
wronghead = True
break
elif (tk[6] == target) and (tk[7] in ["conj"]) and (tk[3] not in ["DET"]):
wronghead = True
break
elif (tk[6] == target) and (tk[7] == "cc") and (b[4][i][7] != "conj"):
wronghead = True
break
if (wronghead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule08), sep="\t", file=dump)
return acc
def check09(b,dump):
'''Um token AUX não pode ser head de relação (exceto punct) se for dependente de aux, aux:pass ou cop.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "AUX") and (b[4][i][7] in ["aux", "aux:pass", "cop"]):
target = b[4][i][0]
for tk in b[4]:
if (tk[6] == target) and (tk[7] != "punct"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule09), sep="\t", file=dump)
break
return acc
def check10(b,dump):
'''Nenhum token dependente de fixed é head de relação.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "fixed"):
target = b[4][i][0]
head = False
for tk in b[4]:
if (tk[6] == target):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule10), sep="\t", file=dump)
break
return acc
def check11(b,dump):
'''O head de case só pode ser "PROPN", "NOUN", "PRON", "ADJ", "NUM", "X", "INTJ", "SYM", "ADV" '''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "case"):
target = b[4][i][6]
wrongHead = False
for tk in b[4]:
if (tk[0] == target) and (tk[3] not in ["PROPN", "NOUN", "PRON", "ADJ", "NUM", "X", "INTJ", "SYM", "ADV"]):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule11), sep="\t", file=dump)
return acc
def check12(b,dump):
'''Regra 12 : Nenhum token SCONJ pode ser dependente de nsubj, nsubj:pass, nsubj:outer, csubj, csubj:pass, csubj:outer e obj.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "SCONJ"):
if (b[4][i][7] in ["nsubj", "nsubj:pass", "nsubj:outer", "csubj", "csubj:pass", "csubj:outer", "obj"]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule12), sep="\t", file=dump)
return acc
def check13(b,dump):
'''P13: O dependente de cop só pode ter lema "estar" ou "ser" e deve ser sempre AUX'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "cop") and ((b[4][i][2] not in ["ser", "estar"]) or (b[4][i][3] != "AUX")):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule13), sep="\t", file=dump)
return acc
def check14(b,dump):
'''Dois ou mais tokens dependentes de case não podem apontar para um mesmo token head.'''
acc = 0
heads = []
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "case") and (b[4][i][2] not in ["contra", "exceto", "menos", "salvo", "sem"]):
if (b[4][i][6] in heads):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule14), sep="\t", file=dump)
else:
heads.append(b[4][i][6])
return acc
def check15(b,dump):
'''Nenhum token PRON pode ser dependente de mark, exceto se for head de fixed.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "PRON"):
if (b[4][i][7] in ["mark"]):
headfixed = False
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] == "fixed"):
headfixed = True
break
if (not headfixed):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule15), sep="\t", file=dump)
return acc
def check16(b,dump):
'''Todo token dependente de aux só pode ter lema = 'ser', 'estar', 'ter', 'haver', 'ir' e 'vir' caso seja vir+Ger ou vir+'a'+Inf.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "aux") and (b[4][i][2] not in ["ser", "estar", "ter", "haver", "ir", "vir"]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule16), sep="\t", file=dump)
elif ((b[4][i][7] == "aux") and (b[4][i][2] == "vir")) and \
not ((b[4][i+1][3] in ["VERB", "AUX"]) and ("VerbForm=Ger" in b[4][i+1][5])) and \
not ((b[4][i+1][2] == "a") or (b[4][i+2][3] in ["VERB", "AUX"]) and ("VerbForm=Ger" in b[4][i+2][5])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule16), sep="\t", file=dump)
return acc
def check17(b,dump):
'''O ponto final não pode ter como head um token que não é head de outras relações (exceto se houver apenas um outro token)." '''
acc = 0
headTimes = 0
for i in range(len(b[4])):
if (b[4][i][6] == b[4][-1][6]):
headTimes += 1
if (headTimes < 2) and (b[2] > 2):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule17), sep="\t", file=dump)
return acc
def check18(b,dump):
'''Todo token dependente de nummod só pode ser head de advmod, nummod, flat, conj, case e appos.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "nummod"):
target = b[4][i][0]
wrongHead = False
for tk in b[4]:
if (tk[6] == target) and (tk[7] not in ["advmod", "nummod", "flat", "conj", "case", "appos", "nmod", "nmod:spec"]):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule18), sep="\t", file=dump)
return acc
def check19(b,dump):
'''Todo token VERB dependente de xcomp nunca é head de uma relação de sujeito: nsubj, nsubj:outer e nsubj:pass.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "xcomp"):
target = b[4][i][0]
wrongHead = False
for tk in b[4]:
if (tk[6] == target) and (tk[7] in ["nsubj", "nsubj:outer", "nsubj:pass"]):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule19), sep="\t", file=dump)
return acc
def check20(b,dump):
'''Nenhum token ADJ pode ser head de det.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "det"):
target = b[4][i][6]
wrongHead = False
for tk in b[4]:
if (tk[0] == target) and (tk[3] == "ADJ"):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule20), sep="\t", file=dump)
return acc
def check21(b,dump):
'''Todo dependente da deprel aux, aux:pass ou cop tem que ter POS = AUX (o inverso não é verdadeiro) '''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] in ["aux", "aux:pass" "cop"]) and (b[4][i][3] != "AUX"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule21), sep="\t", file=dump)
return acc
def check22(b,dump):
'''Todo token VERB não pode ser head de case.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "case"):
target = b[4][i][6]
wrongHead = False
for tk in b[4]:
if (tk[0] == target) and (tk[3] in ["VERB", "AUX"]):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule22), sep="\t", file=dump)
return acc
def check23(b,dump):
'''Todo token head de obl só pode ser VERB, ADJ, ADV ou X. Exceção: também pode ser AUX se o verbo estiver elíptico (o token head de AUX não é VERB).'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "obl"):
target = b[4][i][6]
wrongHead = False
for tk in b[4]:
if (tk[0] == target) and (tk[3] not in ["VERB", "ADJ", "ADV", "AUX", "X"]):
wrongHead = True
break
elif (tk[0] == target) and (tk[3] == "AUX"):
for ttk in b[4]:
if (ttk[0] == tk[6]):
if (ttk[3] == "VERB"):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule23), sep="\t", file=dump)
return acc
def check24(b,dump):
'''Todo token dependente de advmod é ADV, ADJ ou qualquer token que seja head de fixed.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "advmod") and (b[4][i][3] not in ["ADV", "ADJ"]):
target = b[4][i][0]
headFixed = False
for tk in b[4]:
if (tk[6] == target) and (tk[7] == "fixed"):
headFixed = True
break
if not headFixed:
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule24), sep="\t", file=dump)
return acc
def check25(b,dump):
'''Todo token dependente de nummod é NUM (o inverso não é verdadeiro).'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "nummod") and (b[4][i][3] != "NUM"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule25), sep="\t", file=dump)
return acc
def check26(b,dump):
'''Todo token dependente de nmod é PROPN, NOUN, NUM, SYM, INTJ, X ou PRON (o inverso não é verdadeiro).'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "nmod") and (b[4][i][3] not in ["PROPN", "NOUN", "NUM", "SYM", "INTJ", "X", "PRON"]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule26), sep="\t", file=dump)
return acc
def check27(b,dump):
'''Todo token PUNCT é dependente de punct e vice-versa.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if ((b[4][i][3] == "PUNCT") and (b[4][i][7] != "punct")) or \
((b[4][i][3] != "PUNCT") and (b[4][i][7] == "punct")):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule27), sep="\t", file=dump)
return acc
def check28(b,dump):
'''Todo token ADP que não é head de fixed e cujo token head é um verbo no infinitivo (VerbForm=Inf) deve ser dependente de mark.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "ADP"):
for tk in b[4]:
wrong = False
if (tk[6] == b[4][i][0]) and (tk[7] == "fixed"):
wrong = False
break
if (tk[0] == b[4][i][6]) and ("VerbForm=Inf" in tk[5]) and (b[4][i][7] != "mark"):
wrong = True
if (wrong):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule28), sep="\t", file=dump)
return acc
def check29(b,dump):
'''Nenhum token PROPN ou NOUN pode ser dependente de appos de um token PROPN ou NOUN. Exceção: se o token head for separado por token PUNCT do token dependente.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] in ["NOUN", "PROPN"]) and (b[4][i][7] == "appos"):
for j in range(len(b[4])):
if (b[4][j][0] == b[4][i][6]) and (b[4][j][3] in ["NOUN", "PROPN"]):
wrong = True
if (i < j):
for k in range(i+1,j):
if (b[4][k][3] == "PUNCT"):
wrong = False
break
else:
for k in range(j+1,i):
if (b[4][k][3] == "PUNCT"):
wrong = False
break
if (wrong):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule29), sep="\t", file=dump)
break
return acc
def check30(b,dump):
'''Nenhum token head de case pode ser dependente de obj.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "case"):
for tk in b[4]:
if (tk[0] == b[4][i][6]):
if (tk[7] == "obj"):
acc += 1
print("{}\t{}\t{}".format(b[0], tk[0], msg_Prule30), sep="\t", file=dump)
break
return acc
def check31(b,dump):
'''Nenhum token head de case pode ser dependente de iobj.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "case"):
for tk in b[4]:
if (tk[0] == b[4][i][6]):
if (tk[7] == "iobj"):
acc += 1
print("{}\t{}\t{}".format(b[0], tk[0], msg_Prule31), sep="\t", file=dump)
break
return acc
def check32(b,dump):
'''Todos tokens 'muito', 'muitos', 'muita', 'muitas' que forem ADJ devem ser dependentes de amod. Exceção: caso seja dependente de xcomp ou head de cop.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "ADJ") and (b[4][i][2] == "muito"):
if (b[4][i][7] not in ["amod", "xcomp"]):
wrong = True
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] == "cop"):
wrong = False
if (wrong):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule32), sep="\t", file=dump)
return acc
def check33(b,dump):
'''Todos tokens 'pouco', 'poucos', 'pouca', 'poucas' que forem ADJ devem ser dependentes de amod. Exceção: caso seja dependente de xcomp ou head de cop.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "ADJ") and (b[4][i][2] == "pouco"):
if (b[4][i][7] not in ["amod", "xcomp"]):
wrong = True
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] == "cop"):
wrong = False
if (wrong):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule33), sep="\t", file=dump)
return acc
def check34(b,dump):
'''Todos tokens 'onde', 'quando', 'como' que forem ADV, e não forem head de cop ou fixed, devem ser dependentes de advmod, fixed ou conj (se estiverem coordenadas com outro ADV).'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "ADV") and (b[4][i][2] in ["onde", "quando", "como"]):
headcopfix, conjADV = False, False
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] in ["cop", "fixed"]):
headcopfix = True
if (tk[0] == b[4][i][6]) and (tk[3] == "ADV"):
conjADV = True
if (b[4][i][7] != "advmod") and (b[4][i][7] != "fixed") and (not headcopfix) and (not conjADV):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule34), sep="\t", file=dump)
return acc
def check35(b,dump):
'''Todo token dependente de expl só pode ser PRON.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][7] == "expl") and (b[4][i][3] != "PRON"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule35), sep="\t", file=dump)
return acc
def check36(b,dump):
'''Nenhum token head de cop é VERB.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][7] == "cop"):
for tk in b[4]:
if (tk[0] == b[4][i][6]) and (tk[3] == "VERB"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule36), sep="\t", file=dump)
return acc
def check37(b,dump):
'''Não deve haver Deprel projetivas (cruzamento de arcos) para nenhum token '''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]) and (b[4][i][7] != "root") and (b[4][i][6] != "0"):
if (b[4][i][0].isdigit()):
tkID = eval(b[4][i][0])
else:
tkID = 0
if (b[4][i][6].isdigit()):
tkHead = eval(b[4][i][6])
else:
tkhead = 0
if (tkID < tkHead):
for j in range(i+1,len(b[4])):
if (b[4][j][0] == b[4][i][6]):
break
elif ("-" not in b[4][j][0]):
if (b[4][j][6].isdigit()):
middle = eval(b[4][j][6])
else:
middle = 0
if (middle < tkID) or (middle > tkHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule37), sep="\t", file=dump)
break
elif (tkID > tkHead):
for j in range(i-1,0,-1):
if (b[4][j][0] == b[4][i][6]):
break
elif ("-" not in b[4][j][0]):
if (b[4][j][6].isdigit()):
middle = eval(b[4][j][6])
else:
middle = 0
if (middle > tkID) or (middle < tkHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule37), sep="\t", file=dump)
break
return acc
def check38(b,dump):
'''Uma sentença só pode ter um root e ele deve ser bem formado (head 0, Deprel 'root') '''
acc = 0
count, x = 0, 0
for i in range(len(b[4])):
if (b[4][i][7] == "root") and (b[4][i][6] == "0"):
count += 1
if (count > 1):
x = i
elif ((b[4][i][7] == "root") and (b[4][i][6] != "0")) or \
((b[4][i][7] != "root") and (b[4][i][6] == "0")):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule38), sep="\t", file=dump)
if (count != 1):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][x][0], msg_Prule38), sep="\t", file=dump)
return acc
def check39(b,dump):
'''Nenhum token é head de mais de um nsubj.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "nsubj"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule39), sep="\t", file=dump)
return acc
def check40(b,dump):
'''Nenhum token é head de mais de um nsubj:pass.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "nsubj:pass"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule40), sep="\t", file=dump)
return acc
def check41(b,dump):
'''Nenhum token é head de mais de um nsubj:outer.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "nsubj:outer"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule41), sep="\t", file=dump)
return acc
def check42(b,dump):
'''Nenhum token é head de mais de um csubj.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "csubj"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule42), sep="\t", file=dump)
return acc
def check43(b,dump):
'''Nenhum token é head de mais de um obj.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "csubj"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule43), sep="\t", file=dump)
return acc
def check44(b,dump):
'''Nenhum token é head de mais de um xcomp.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "csubj"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule44), sep="\t", file=dump)
return acc
def check45(b,dump):
'''Nenhum token é head de mais de um ccomp.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "csubj"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule45), sep="\t", file=dump)
return acc
def check46(b,dump):
'''Nenhum token é head de mais de um case.'''
acc = 0
deps = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "case"):
if (b[4][i][6].isdigit()):
deps[eval(b[4][i][6])-1] += 1
for i in range(len(deps)):
if (deps[i] > 1):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule46), sep="\t", file=dump)
return acc
def check47(b,dump):
'''Todo token dependente de appos tem seu head à esquerda.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][6].isdigit()) and (b[4][i][0].isdigit()):
if (b[4][i][7] == "appos") and (eval(b[4][i][6]) > eval(b[4][i][0])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule47), sep="\t", file=dump)
return acc
def check48(b,dump):
'''Todo token dependente de mark tem seu head à direita.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][6].isdigit()) and (b[4][i][0].isdigit()):
if (b[4][i][7] == "mark") and (eval(b[4][i][6]) < eval(b[4][i][0])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule48), sep="\t", file=dump)
return acc
def check49(b,dump):
'''Todo token dependente de case tem seu head à direita.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][6].isdigit()) and (b[4][i][0].isdigit()):
if (b[4][i][7] == "case") and (eval(b[4][i][6]) < eval(b[4][i][0])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule49), sep="\t", file=dump)
return acc
def check50(b,dump):
'''Todo token dependente de fixed tem seu head à esquerda.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][6].isdigit()) and (b[4][i][0].isdigit()):
if (b[4][i][7] == "fixed") and (eval(b[4][i][6]) > eval(b[4][i][0])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule50), sep="\t", file=dump)
return acc
def check51(b,dump):
'''Todo token dependente de flat:name tem seu head à esquerda.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][6].isdigit()) and (b[4][i][0].isdigit()):
if (b[4][i][7] == "flat:name") and (eval(b[4][i][6]) > eval(b[4][i][0])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule51), sep="\t", file=dump)
return acc
def check52(b,dump):
'''Nenhum token pode ser simultaneamente head de nsubj e head de nsubj:pass, nsubj e csubj ou nsubj:pass e csubj.'''
acc = 0
nsubj = [0]*b[2]
npass = [0]*b[2]
csubj = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]) and (b[4][i][6].isdigit()):
if (b[4][i][7] == "nsubj"):
nsubj[eval(b[4][i][6])-1] += 1
elif (b[4][i][7] == "nsubj:pass"):
npass[eval(b[4][i][6])-1] += 1
elif (b[4][i][7] == "csubj"):
csubj[eval(b[4][i][6])-1] += 1
for i in range(b[2]):
if ((nsubj[i] > 0) and (npass[i] > 0)) or ((nsubj[i] > 0) and (csubj[i] > 0)) or ((npass[i] > 0) and (csubj[i] > 0)):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule52), sep="\t", file=dump)
return acc
def check53(b,dump):
'''Todo token dependente de flat:foreign tem seu head à esquerda.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][6].isdigit()) and (b[4][i][0].isdigit()):
if (b[4][i][7] == "flat:foreign") and (eval(b[4][i][6]) > eval(b[4][i][0])):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule53), sep="\t", file=dump)
return acc
def check54(b,dump):
'''Todo token SCONJ só pode ser dependente de mark, fixed, conj ou discourse. Exceção: se for a palavra 'quanto' pode ser dependente de advcl.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][3] == "SCONJ") and (b[4][i][7] not in ["mark", "fixed", "conj", "discourse"]):
if (b[4][i][2] != "quanto") or (b[4][i][7] != "advcl"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule54), sep="\t", file=dump)
return acc
def check55(b,dump):
'''Todo token head de nsubj:pass deve ter feature Voice=Pass. Exceção: se o verbo for head de expl:pass.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][7] == "nsubj:pass"):
missingpass, explpass = False, False
for tk in b[4]:
if (tk[0] == b[4][i][6]) and ("Voice=Pass" not in tk[5]):
missingpass = True
if (tk[6] == b[4][i][6]) and (tk[7] == "expl:pass"):
explpass = True
if (missingpass) and (not explpass):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule55), sep="\t", file=dump)
return acc
def check56(b,dump):
'''Todo token head de obl:agent deve ter feature Voice=Pass.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][7] == "obl:agent"):
for tk in b[4]:
if (tk[0] == b[4][i][6]) and ("Voice=Pass" not in tk[5]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule56), sep="\t", file=dump)
return acc
def check57(b,dump):
'''Todo token head de aux:pass deve ter feature Voice=Pass.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][7] == "aux:pass"):
for tk in b[4]:
if (tk[0] == b[4][i][6]) and ("Voice=Pass" not in tk[5]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule57), sep="\t", file=dump)
return acc
def check58(b,dump):
'''Todo token head ou dependente de flat:foreign deve ser X.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "flat:foreign"):
if (b[4][i][3] != "X"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule58), sep="\t", file=dump)
else:
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] == "flat:foreign"):
if (b[4][i][3] != "X"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule58), sep="\t", file=dump)
break
return acc
def check59(b,dump):
'''Todo token head ou dependente de flat:name deve ser PROPN ou X.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "flat:name"):
if (b[4][i][3] != "PROPN") and (b[4][i][3] != "X"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule59), sep="\t", file=dump)
else:
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] == "flat:name"):
if (b[4][i][3] != "PROPN") and (b[4][i][3] != "X"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule59), sep="\t", file=dump)
break
return acc
def check60(b,dump):
'''Todo token head e dependente de flat deve ser NUM, NOUN ou ADJ e ter NumType.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "flat"):
if (b[4][i][3] not in ["ADJ", "NOUN", "NUM"]) or ("NumType" not in b[4][i][5]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule60), sep="\t", file=dump)
else:
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] == "flat"):
if (b[4][i][3] not in ["ADJ", "NOUN", "NUM"]) or ("NumType" not in b[4][i][5]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule60), sep="\t", file=dump)
break
return acc
def check61(b,dump):
'''Todo token head de aux ou aux:pass, que não for simultaneamente head de cop, deve ser VERB.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] in ["aux", "aux:pass"]):
for tk in b[4]:
if (tk[0] == b[4][i][6]):
if (tk[3] != "VERB"):
wrong = True
for tkk in b[4]:
if (tkk[6] == tk[0]) and (tkk[7] == "cop"):
wrong = False
break
if (wrong):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule61), sep="\t", file=dump)
break
return acc
def check62(b,dump):
'''P62: A feature 'ExtPos={}' deveria ser utilizada (ou a DEPREL fixed deveria ser removida), mas a etiqueta 'ExtPos' está ausente.'''
'''P63: A feature 'ExtPos={}' deveria ser utilizada (ou a DEPREL fixed deveria ser removida), mas a etiqueta 'ExtPos={}' foi utilizada.'''
'''P64: A feature 'ExtPos={}' não deveria ser utilizada pois o token não é HEAD de fixed, retire 'ExtPos' ou corrija a DEPREL 'fixed'.'''
acc = 0
headFixed = []
for tk in b[4]:
if (tk[7] == 'fixed'):
if (tk[6] not in headFixed):
headFixed.append(tk[6])
for i in range(len(b[4])):
if (b[4][i][0] in headFixed):
if (b[4][i][7] == "cc"):
extpos = "CCONJ"
elif (b[4][i][7] == "advmod"):
extpos = "ADV"
elif (b[4][i][7] == "case"):
extpos = "ADP"
elif (b[4][i][7] == "mark"):
extpos = "SCONJ"
elif (b[4][i][3] == "PRON"):
extpos = "PRON"
else:
extpos = b[4][i][3]
if ('ExtPos=' not in b[4][i][5]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule62.format(extpos)), sep="\t", file=dump)
else:
errExtPosID = b[4][i][5].index('ExtPos=')+7
if ("|" in b[4][i][5][errExtPosID:]):
errExtPosEnd = b[4][i][5][errExtPosID:].index('|')+errExtPosID
errExtPos = b[4][i][5][errExtPosID:errExtPosEnd]
else:
errExtPos = b[4][i][5][errExtPosID:]
if (extpos != errExtPos):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule63.format(extpos, errExtPos)), sep="\t", file=dump)
elif ('ExtPos=' in b[4][i][5]):
errExtPosID = b[4][i][5].index('ExtPos=')+7
if ("|" in b[4][i][5][errExtPosID:]):
errExtPosEnd = b[4][i][5][errExtPosID:].index('|')+errExtPosID
errExtPos = b[4][i][5][errExtPosID:errExtPosEnd]
else:
errExtPos = b[4][i][5][errExtPosID:]
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule64.format(errExtPos)), sep="\t", file=dump)
return acc
def check63(b,dump):
return 0 # already handled in check62
def check64(b,dump):
return 0 # already handled in check62
#########################
#### AVISOS
#########################
def check65(b,dump):
'''Normalmente, dois ou mais tokens dependentes de cop não podem apontar para um mesmo token head, exceto se o head for head de um nsubj:outer.'''
acc = 0
heads = []
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "cop"):
if (b[4][i][6] in heads):
headNSUBJouter = False
for j in range(len(b[4])):
if (b[4][j][7] == "nsubj:outer") and (b[4][j][6] == b[4][i][6]):
headNSUBJouter = True
break
if not headNSUBJouter:
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule65), sep="\t", file=dump)
else:
heads.append(b[4][i][6])
return acc
def check66(b,dump):
'''Normalmente, dois ou mais tokens dependentes de mark não podem apontar para um mesmo token head, exceto se o head for head de um nsubj:outer.'''
acc = 0
heads = []
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "mark"):
if (b[4][i][6] in heads):
headNSUBJouter = False
for j in range(len(b[4])):
if (b[4][j][7] == "nsubj:outer") and (b[4][j][6] == b[4][i][6]):
headNSUBJouter = True
break
if not headNSUBJouter:
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule66), sep="\t", file=dump)
else:
heads.append(b[4][i][6])
return acc
def check67(b,dump):
'''Normalmente, todo token dependente de flat:name só pode ser head de cc, case, det, punct, expl, nmod (se o dependente for um número cardinal - NUM NumType=Card) ou amod (se o dependente for um número ordinal - ADJ NumType=Ord).'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "flat:name"):
target = b[4][i][0]
wrongHead = False
for tk in b[4]:
if (tk[6] == target) and (tk[7] not in ["cc", "case", "det", "punct", "expl", "nmod", "amod", "advcl"]):
wrongHead = True
break
elif (tk[6] == target) and (tk[7] == "nmod"):
if (tk[3] != "NUM") or ("NumType=Card" not in tk[5]):
wrongHead = True
break
elif (tk[6] == target) and (tk[7] == "amod"):
if (tk[3] != "ADJ") or ("NumType=Ord" not in tk[5]):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule67), sep="\t", file=dump)
return acc
def check68(b,dump):
'''Normalmente, um nmod só pode ter como head "PROPN", "NOUN", "NUM", "SYM", "X", "PRON" '''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "nmod"):
target = b[4][i][6]
wrongHead = False
for tk in b[4]:
if (tk[0] == target) and (tk[3] not in ["PROPN", "NOUN", "NUM", "SYM", "X", "PRON"]):
wrongHead = True
break
if (wrongHead):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule68), sep="\t", file=dump)
return acc
def check69(b,dump):
'''Normalmente, todo token PUNCT final tem como head o token root.'''
acc = 0
for i in range(len(b[4])):
if (b[4][i][0] == b[4][-1][6]):
if (b[4][i][7] != "root"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][-1][0], msg_Prule69), sep="\t", file=dump)
break
return acc
def check70(b,dump):
'''Normalmente, pontuações pareadas (aspas, parênteses, colchetes, chaves) tem o mesmo head.'''
acc = 0
pairedA = ['"', "'", "(", "[", "{"]
pairedB = ['"', "'", ")", "]", "}"]
visited = []
idxA, idxB, currentA, currentB = -1, -1, -1, -1
for i in range(len(b[4])):
if (b[4][i][0] not in visited) and (b[4][i][1] in pairedA):
A = b[4][i][1]
idxA = i
if (b[4][i][0].isdigit()):
currentA = eval(b[4][i][0])
else:
currentA = 0
B = pairedB[pairedA.index(A)]
for j in range(i+1,len(b[4])):
if (b[4][j][1] == B):
idxB = j
if (b[4][j][0].isdigit()):
currentB = eval(b[4][j][0])
else:
currentB = 0
break
if (currentA != -1) and (currentB != -1):
for k in range(idxA+1,idxB):
if ("-" not in b[4][k][0]) and (b[4][k][6].isdigit()):
if (eval(b[4][k][6]) < currentA) or (eval(b[4][k][6]) > currentB):
if (b[4][idxA][6] != b[4][k][0]) or (b[4][idxB][6] != b[4][k][0]):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule70), sep="\t", file=dump)
visited.append(b[4][idxA][0])
visited.append(b[4][idxB][0])
idxA, idxB, currentA, currentB = -1, -1, -1, -1
break
return acc
def check71(b,dump):
'''Normalmente, nenhum token pode ser simultaneamente head de obj e head de ccomp.'''
acc = 0
obj = [0]*b[2]
ccomp = [0]*b[2]
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][7] == "obj"):
if (b[4][i][6].isdigit()):
obj[eval(b[4][i][6])-1] += 1
elif (b[4][i][7] == "ccomp"):
if (b[4][i][6].isdigit()):
ccomp[eval(b[4][i][6])-1] += 1
for i in range(b[2]):
if (obj[i] > 0) and (ccomp[i] > 0):
acc += 1
print("{}\t{}\t{}".format(b[0], i+1, msg_Prule71), sep="\t", file=dump)
return acc
def check72(b,dump):
'''Normalmente, nenhum token ADJ pode ser head ou dependente de appos.'''
acc = 0
for i in range(len(b[4])):
if ("-" not in b[4][i][0]):
if (b[4][i][3] == "ADJ"):
if (b[4][i][7] == "appos"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule72), sep="\t", file=dump)
else:
for tk in b[4]:
if (tk[6] == b[4][i][0]) and (tk[7] == "appos"):
acc += 1
print("{}\t{}\t{}".format(b[0], b[4][i][0], msg_Prule72), sep="\t", file=dump)
break
return acc
def check(i,b,dump):
if (i==0):
return check01(b,dump)
elif (i==1):
return check02(b,dump)
elif (i==2):
return check03(b,dump)
elif (i==3):
return check04(b,dump)
elif (i==4):
return check05(b,dump)
elif (i==5):
return check06(b,dump)
elif (i==6):
return check07(b,dump)
elif (i==7):
return check08(b,dump)
elif (i==8):
return check09(b,dump)
elif (i==9):
return check10(b,dump)
elif (i==10):
return check11(b,dump)
elif (i==11):
return check12(b,dump)
elif (i==12):
return check13(b,dump)
elif (i==13):
return check14(b,dump)
elif (i==14):
return check15(b,dump)
elif (i==15):
return check16(b,dump)
elif (i==16):
return check17(b,dump)
elif (i==17):
return check18(b,dump)
elif (i==18):
return check19(b,dump)
elif (i==19):
return check20(b,dump)
elif (i==20):
return check21(b,dump)
elif (i==21):
return check22(b,dump)
elif (i==22):
#return check23(b,dump)
return 0
elif (i==23):
return check24(b,dump)
elif (i==24):
return check25(b,dump)
elif (i==25):
return check26(b,dump)
elif (i==26):
return check27(b,dump)
elif (i==27):
return check28(b,dump)
elif (i==28):
return check29(b,dump)
elif (i==29):
return check30(b,dump)
elif (i==30):
return check31(b,dump)
elif (i==31):
return check32(b,dump)
elif (i==32):
return check33(b,dump)
elif (i==33):
return check34(b,dump)
elif (i==34):
return check35(b,dump)
elif (i==35):
return check36(b,dump)
elif (i==36):
return check37(b,dump)
elif (i==37):
return check38(b,dump)
elif (i==38):
return check39(b,dump)
elif (i==39):
return check40(b,dump)
elif (i==40):
return check41(b,dump)
elif (i==41):
return check42(b,dump)
elif (i==42):
return check43(b,dump)
elif (i==43):
return check44(b,dump)
elif (i==44):
return check45(b,dump)
elif (i==45):
#return check46(b,dump)
return 0
elif (i==46):
return check47(b,dump)
elif (i==47):
return check48(b,dump)
elif (i==48):
return check49(b,dump)
elif (i==49):
return check50(b,dump)
elif (i==50):
return check51(b,dump)
elif (i==51):
return check52(b,dump)
elif (i==52):
return check53(b,dump)
elif (i==53):
return check54(b,dump)
elif (i==54):
return check55(b,dump)
elif (i==55):
return check56(b,dump)
elif (i==56):
return check57(b,dump)
elif (i==57):
return check58(b,dump)
elif (i==58):
return check59(b,dump)
elif (i==59):
return check60(b,dump)
elif (i==60):
return check61(b,dump)
elif (i==61):
return check62(b,dump)
elif (i==62):
return check63(b,dump)
elif (i==63):
return check64(b,dump)
elif (i==64):
return check65(b,dump)
elif (i==65):
return check66(b,dump)
elif (i==66):
return check67(b,dump)
elif (i==67):
return check68(b,dump)
elif (i==68):
return check69(b,dump)
elif (i==69):
return check70(b,dump)
elif (i==70):
return check71(b,dump)
elif (i==71):
return check72(b,dump)
def checkSent(b, dump, rep):
total, warn = 0, 0
acc = []
for i in range(parserDef[1]):
acc.append(check(i,b,dump))
if (acc[i] > 0):
rep.writeSent(parserDef[0], i+1, b)
if (i < parserDef[2]):
total += acc[i]
else:
warn += acc[i]
return acc, total, warn
|