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
|
use strict;
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More qw(no_plan);
use Data::Dumper;
$Data::Dumper::Indent = 1;
sub _chomp {
my $s = shift;
chomp $s;
return $s;
}
use TM;
use TM::PSI;
sub _parse {
my $text = shift;
my $ms = new TM (baseuri => 'tm:');
my $p = new TM::AsTMa::Fact2 (store => $ms);
my $i = $p->parse ($text);
return $ms;
}
sub _q_players {
my $ms = shift;
# my @res = $ms->match (TM->FORALL, @_);
# warn "res no filter ".Dumper \@res;
my @res = grep ($_ !~ m|^tm:|, map { ref($_) ? $_->[0] : $_ } map { @{$_->[TM->PLAYERS]} } $ms->match (TM->FORALL, @_));
# warn "res ".Dumper \@res;
return \@res;
}
##===================================================================================
my $astma = 'http://astma.topicmaps.bond.edu.au/2.0/';
#== TESTS ===========================================================================
require_ok( 'TM::AsTMa::Fact2' );
{ # class ok
my $p = new TM::AsTMa::Fact2;
ok (ref($p) eq 'TM::AsTMa::Fact2', 'class ok');
}
my $npa = scalar keys %{$TM::infrastructure->{assertions}};
my $npt = scalar values %{$TM::infrastructure->{mid2iid}};
{ #-- identification
my $ms = _parse ('aaa
');
is ($ms->tids ('aaa'), 'tm:aaa', 'aaa internalized');
eval {
my $ms = _parse ('aaa xxx ~ http://aaa/
');
}; like ($@, qr/duplicate/i, _chomp($@));
}
{
my $ms = _parse ('aaa ~ http://aaa/
bbb http://bbb/
ccc = http://ccc/
');
#warn Dumper $ms;
is ($ms->tids ('aaa'), 'tm:aaa', 'aaa internalized');
my $t = $ms->toplet ('tm:aaa');
ok (eq_set (
$t->[TM->INDICATORS],
[
'http://aaa/',
]), 'indicators');
is ($ms->tids ('bbb'), 'tm:bbb', 'bbb internalized');
$t = $ms->toplet ('tm:bbb');
ok (eq_set (
$t->[TM->INDICATORS],
[
'http://bbb/',
]), 'indicators');
is ($ms->tids ('ccc'), 'tm:ccc', 'ccc internalized');
is ($ms->tids ('http://ccc/'), 'tm:ccc', 'ccc internalized');
}
{
my $ms = _parse ('aaa ~ http://aaa/ ~ http://bbb/ ~ http://ccc/
aaa
~ http://ddd/
~ http://eee/
http://ccc/
');
#warn Dumper $ms;
is ($ms->tids ('aaa'), 'tm:aaa', 'aaa internalized');
my $t = $ms->toplet ('tm:aaa');
ok (eq_set (
$t->[TM->INDICATORS],
[
'http://aaa/',
'http://bbb/',
'http://ccc/',
'http://ddd/',
'http://eee/'
]), 'indicators');
}
#-- autogenerating ids
{
my $ms = _parse (q|
* = http://aaa/
* = http://bbb/
|);
#warn Dumper $ms;
like ($ms->tids ('http://aaa/'), qr/tm:uuid-\d{10}/, 'generated ids ok');
like ($ms->tids ('http://bbb/'), qr/tm:uuid-\d{10}/, 'generated ids ok');
eval {
$ms = _parse (q|
* xxx = http://aaa/
|); }; like ($@, qr/duplicate/i, '* xxx fails: '._chomp($@));
$ms = _parse (q|
xxx * = http://aaa/
|);
ok (1, 'xxx * works');
$ms = _parse (q|
* *
|);
ok (1, '* * works, but weird');
}
{ # subject locators stand-alone
my $ms = _parse (q|
= http://rumsti.com/ isa website
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, iplayer => $ms->tids ('http://rumsti.com/') ), 1, 'ext reification: finding');
}
{ #-- autogenerating date ids
my $ms = _parse (q|
2004-01-12
2004-01-12T15:15
|);
#warn Dumper $ms;
like ($ms->tids (\ 'urn:x-date:2004-01-12:00:00'), qr/tm:uuid-\d{10}/, 'generated dates ok');
like ($ms->tids (\ 'urn:x-date:2004-01-12:15:15'), qr/tm:uuid-\d{10}/, 'generated dates ok');
}
{ #-- using ids with baseuri as prefix
my $ms = _parse (q|
aaa
bbb isa tm:aaa
<< tm:bbb
tm:ccc : tm:aaa
|);
#warn Dumper $ms;
is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance' ], players => [ 'tm:aaa', 'tm:bbb' ] ), 1, 'using baseuri 1');
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc' ], players => [ 'tm:aaa' ] ), 1, 'using baseuri 2');
}
{ #-- predef inlineds (structural)
my $ms = _parse (q|
aaa isa bbb
aaa is-a ccc
aaa subclasses ddd
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:aaa' ), 3, 'assocs for aaa');
}
{ # predef inlineds (struct + reification)
my $ms = _parse (q|
xxx isa http://www.topicmaps.org/xtm/1.0/#psi-topic
|);
#warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'reification: type');
my $m = $ms->tids (\ 'http://www.topicmaps.org/xtm/1.0/#psi-topic');
ok ($ms->is_asserted (Assertion->new (scope => 'us',
type => 'isa',
roles => [ 'class', 'instance' ],
players => [ $m, 'tm:xxx' ])), 'predef inlineds (struct + reification): xxx isa found');
ok ($ms->is_asserted (Assertion->new (scope => 'us',
type => 'isa',
roles => [ 'class', 'instance' ],
players => [ $m, 'tm:xxx' ])), 'predef inlineds (struct + reification): xxx isa found (via tids)');
}
{ #-- characteristics (structural)
my $ms = _parse (q|
aaa has bn : AAA
bn: "BBB " has oc: 23
in: bla has oc: http:www
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:aaa' ), 4, 'chars/assoc for aaa');
is (scalar $ms->match (TM->FORALL, type => 'characteristic', irole => 'thing', iplayer => 'tm:aaa' ), 4, 'chars for aaa');
is (scalar $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:aaa' ), 2, 'occurrences for aaa');
is (scalar $ms->match (TM->FORALL, type => 'name', irole => 'thing', iplayer => 'tm:aaa' ), 2, 'basenames for aaa');
$ms = _parse (q|
bbb has nickname : "BBB"
firstname : CCC
lastname : "DDD " has middlename: EEE
rumsti : FFF
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, type => 'name', irole => 'thing', iplayer => 'tm:bbb' ), 4, 'names for bbb');
is (scalar $ms->match (TM->FORALL, type => 'tm:middlename', irole => 'thing', iplayer => 'tm:bbb' ), 1, 'names for bbb');
is (scalar $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:bbb' ), 1, 'occs for bbb');
is (scalar $ms->match (TM->FORALL, type => 'tm:rumsti', irole => 'thing', iplayer => 'tm:bbb' ), 1, 'occs for bbb');
$ms = _parse (q|
bbb has nickname : "BBB" and has firstname : CCC has lastname: "DDD"
bbb
nickname : BBB
bbb has nickname : "BBB" and which has firstname : CCC
bbb has nickname : "BBB" and which
firstname : "CCC" and which has lastname : DDD
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, type => 'name', irole => 'thing', iplayer => 'tm:bbb' ), 4, 'names for bbb');
}
{ #-- predef inlineds + relatives (structural)
my $ms = _parse (q|
aaa isa bbb , which isa ccc and which isa ddd and which has name : "BBB", and
name : "AAA" and which has nickname : "AAAAA" .
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:aaa' ), 3, 'assocs for aaa');
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:bbb' ), 4, 'assocs for bbb');
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:ccc' ), 1, 'assocs for ccc');
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:ddd' ), 1, 'assocs for ddd');
$ms = _parse (q|
aaa isa bbb, which isa ccc, which isa ddd and
name : "CCC" ,
name : "BBB", has name : "AAA"
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:aaa' ), 2, 'assocs for aaa');
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:bbb' ), 3, 'assocs for bbb');
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:ccc' ), 3, 'assocs for ccc');
is (scalar $ms->match (TM->FORALL, irole => 'thing', iplayer => 'tm:ddd' ), 1, 'assocs for ddd');
}
#-- inlined values
{ # checking inlined subclassing
my $ms = _parse (q|
aaa subclasses bbb
<< is-subclass-of
superclass: ddd
subclass: ccc
eee subclasses fff subclasses ggg
hhh < iii < jjj
|);
##warn Dumper $ms;
is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:aaa', 'tm:bbb' ] ), 1, 'intrinsic is-subclass-of, different forms 1');
is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:ccc', 'tm:ddd' ] ), 1, 'intrinsic is-subclass-of, different forms 2');
is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:eee', 'tm:fff' ] ), 1, 'intrinsic is-subclass-of, different forms 3');
is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:eee', 'tm:ggg' ] ), 1, 'intrinsic is-subclass-of, different forms 4');
is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:hhh', 'tm:iii' ] ), 1, 'intrinsic is-subclass-of, different forms 5');
is (scalar $ms->match(TM->FORALL, type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'tm:hhh', 'tm:jjj' ] ), 1, 'intrinsic is-subclass-of, different forms 6');
}
{
my $ms = _parse (q|
aaa
bbb isa thing
bbb isa ccc
ddd
eee isa bbb isa ccc isa ddd
|);
##warn Dumper $ms;
is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance' ], players => [ 'tm:ccc', 'tm:bbb' ] ), 1, 'explicit isa 2');
is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance' ], players => [ 'tm:ddd', 'tm:eee' ] ), 1, 'explicit isa 3');
is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance' ], players => [ 'tm:ccc', 'tm:eee' ] ), 1, 'explicit isa 4');
is (scalar $ms->match(TM->FORALL, type => 'isa', roles => [ 'class', 'instance' ], players => [ 'tm:bbb', 'tm:eee' ] ), 1, 'explicit isa 5');
}
#-- characteristics, values
{ # testing toplets with characteristics
my $ms = _parse (q|
xxx
bn: XXX
|);
##warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, type => 'name', roles => [ 'value', 'thing' ], players => [ undef, 'tm:xxx' ]), 1, 'basename characteristics');
}
{
# testing toplets with URI
my $ms = _parse (q|
http://xxx
bn: XXX
|);
##warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, type => 'name', roles => [ 'value', 'thing' ],
players => [ $ms->tids (undef, 'http://xxx') ]), 1, 'basename characterisistics (reification)');
}
{ #-- name guessing
my $ms = _parse (q|
bbb
nickname : BBB # should be name
firstname < oc : CCC # should be occurrence
lastname : http://xxx/ # should be occurrence
middlename < name: EEE # should be name
rumsti < name: FFF # should be name
remsti < ccc : FFF # should be nothing
|);
##warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, type => 'name', irole => 'thing', iplayer => 'tm:bbb' ), 3, 'name guessing: names for bbb');
is (scalar $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:bbb' ), 2, 'name guessing: occurrence for bbb');
is (scalar $ms->match (TM->FORALL, type => 'tm:ccc', irole => 'thing', iplayer => 'tm:bbb' ), 1, 'name guessing: bogus type');
is (scalar $ms->match (TM->FORALL, type => 'tm:remsti', irole => 'thing', iplayer => 'tm:bbb' ), 1, 'name guessing: bogus type');
}
{
my $ms = _parse (q|
aaa isa bbb
in: blabla
|);
##warn Dumper $ms;
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
[ 'blabla' ]), 'test blanks in resourceData 1');
}
{
my $ms = _parse (q|
xxx
oc: http://xxx.com
ex: http://yyy.com
|);
##warn Dumper $ms;
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:xxx' ) ] ,
[ 'http://yyy.com', 'http://xxx.com' ]), 'occurrence char, value ok');
}
{ # adding types to characteristics
my $ms = _parse (q|
aaa
bn: AAA
rumsti < name : AAAT
oc: http://xxx/
ramsti : http://xxxt/
rimsti : http://yyy/
rimsti : bla
|);
#warn Dumper $ms;
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] }
$ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
[ 'AAA', 'AAAT' ]), 'name typed & untyped char, value ok');
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] }
grep ($_->[TM->TYPE] eq 'name',
$ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' )) ] ,
[ 'AAA' ]), 'basename untyped char, value ok');
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'tm:rumsti', iplayer => 'tm:aaa' ) ] ,
[ 'AAAT' ]), 'basename typed char, value ok');
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
[ 'http://xxxt/',
'http://yyy/',
'http://xxx/',
'bla' ]), 'occurr typed char, value ok');
ok (eq_set (_q_players ($ms, type => 'tm:ramsti', iplayer => 'tm:aaa' ) ,
[ 'http://xxxt/' ]), 'occurr typed char, value ok');
ok (eq_set (_q_players ($ms, type => 'tm:rimsti', iplayer => 'tm:aaa' ) ,
[
'http://yyy/',
'bla' ]), 'occurr typed char, value ok');
}
{ # adding scopes to characteristics
my $ms = _parse (q|
aaa
bn: AAA
bn @ sss : AAAS
oc: III
oc @ sss : IIIS
oc: http://xxx/
oc @ sss : http://xxxs/
|);
#warn Dumper $ms;
ok (eq_set (_q_players ($ms, type => 'name', iplayer => 'tm:aaa' ),
[ 'AAA', 'AAAS' ]), 'basename untyped, scoped, value ok');
ok (eq_set (_q_players ($ms, scope => 'us', type => 'name', iplayer => 'tm:aaa' ),
[ 'AAA' ]), 'basename untyped, scoped, value ok');
ok (eq_set (_q_players ($ms, scope => 'tm:sss', type => 'name', iplayer => 'tm:aaa' ),
[ 'AAAS' ]), 'basename untyped, scoped, value ok');
ok (eq_set (_q_players ($ms, type => 'occurrence', iplayer => 'tm:aaa' ),
[ 'III', 'IIIS', 'http://xxx/', 'http://xxxs/' ]), 'occurrences untyped, mixscoped, value ok');
ok (eq_set (_q_players ($ms, scope => 'tm:sss', type => 'occurrence', iplayer => 'tm:aaa' ),
[ 'IIIS', 'http://xxxs/' ]), 'occurrences untyped, scoped, value ok');
}
{ # typed and scoped characteristics
my $ms = _parse (q|
aaa
ramsti < name: AAA
rumsti @ sss < bn: AAAS
oc: III
ramsti @ sss: IIIS
oc: http://xxx/
ramsti @ sss < oc: http://xxxs/
|);
# warn Dumper $ms;
ok (eq_set (_q_players ($ms, type => 'tm:ramsti', iplayer => 'tm:aaa' ),
[ 'AAA', 'IIIS', 'http://xxxs/' ]), 'basename typed, mixscoped, value ok');
ok (eq_set (_q_players ($ms, scope => 'us', type => 'tm:ramsti', iplayer => 'tm:aaa' ),
[ 'AAA' ]), 'basename untyped, scoped, value ok');
ok (eq_set (_q_players ($ms, scope => 'tm:sss', type => 'tm:rumsti', iplayer => 'tm:aaa' ),
[ 'AAAS' ]), 'basename untyped, scoped, value ok');
ok (eq_set (_q_players ($ms, type => 'name', iplayer => 'tm:aaa' ),
[ 'http://xxxs/', 'AAA', 'IIIS', 'AAAS' ]), 'basenames typed, mixscoped, value ok');
ok (eq_set (_q_players ($ms, type => 'occurrence', iplayer => 'tm:aaa' ),
[ 'http://xxxs/', 'http://xxx/', 'AAA', 'IIIS', 'III' ]), 'occurrences typed, mixscoped, value ok');
}
#-- structural: assocs ----------------------------------------------------------
{
my $ms = _parse (q|
yyy << xxx ( role : player )
|);
##warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'basic association');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:player' ), 1, 'finding basic association 1');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', iplayer => 'tm:player' ), 1, 'finding basic association 2');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role', iplayer => 'tm:player' ), 1, 'finding basic association 3');
$ms = _parse (q|
yyy << xxx ( role : p1 p2 p3 )
|);
## warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'basic association');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:p1' ), 1, 'finding basic association 4');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', iplayer => 'tm:p2' ), 1, 'finding basic association 5');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role', iplayer => 'tm:p3' ), 1, 'finding basic association 6');
$ms = _parse (q|
yyy << xxx ( role1 : aaa bbb , role2 : ccc )
|);
##warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'basic association');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:aaa' ), 1, 'finding basic association 10');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', iplayer => 'tm:ccc' ), 1, 'finding basic association 11');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role2', iplayer => 'tm:ccc' ), 1, 'finding basic association 12');
$ms = _parse (q|
* << xxx ( role : player )
|);
#warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'basic association *');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:player' ), 1, 'finding basic association 1 *');
like ( ($ms->match (TM->FORALL, iplayer => 'tm:player' ))[0]->[TM::LID], qr/tm:uuid-\d{10}/, 'generated id for * assoc ok');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:player' ), 1, 'finding basic association 1 *');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', iplayer => 'tm:player' ), 1, 'finding basic association 2 *');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role', iplayer => 'tm:player' ), 1, 'finding basic association 3 *');
$ms = _parse (q|
<< xxx ( role : player )
|);
#warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'basic association no *');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:player' ), 1, 'finding basic association 1 no *');
like ( ($ms->match (TM->FORALL, iplayer => 'tm:player' ))[0]->[TM->LID], qr/[0-9a-f]{32}/, 'generated id for no * assoc ok');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', iplayer => 'tm:player' ), 1, 'finding basic association 2 no *');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role', iplayer => 'tm:player' ), 1, 'finding basic association 3 no *');
$ms = _parse (q|
yyy << xxx
role1 : player1
role2 : player2
|);
#warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'basic association eol');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:player1' ), 1, 'finding basic association 1 eol');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', iplayer => 'tm:player2' ), 1, 'finding basic association 2 eol');
is (scalar $ms->match (TM->FORALL, type => 'tm:xxx', irole => 'tm:role1', iplayer => 'tm:player1' ), 1, 'finding basic association 3 eol');
}
{ # reified assoc/ value
my $ms = _parse (q|
yyy << xxx
role : player
|);
#warn Dumper $ms;
my ($a) = $ms->match (TM->FORALL, type => 'tm:xxx');
is ('tm:yyy', $a->[TM->LID], 'assoc reified: regained');
}
{ # scoping of assocs
my $ms = _parse (q|
<< aaa @ sss
role : player
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, type=> 'isa', iplayer => 'tm:sss' ), 1, 'association scoped 1');
is (scalar $ms->match, $npa+2, 'association scoped');
is (scalar $ms->match (TM->FORALL, iplayer => 'tm:player' ), 1, 'association scoped 2');
is (scalar $ms->match (TM->FORALL, scope => 'tm:sss', iplayer => 'tm:player' ), 1, 'association scoped 3');
}
{ # reification in assocs
my $ms = _parse (q|
<< http://xxx
http://role1 : aaa = http://bbb
http://role2 : ccc
|);
#warn Dumper $ms;
is (scalar $ms->match, $npa+1, 'reification: association');
is (scalar $ms->match (TM->FORALL, type => $ms->tids (\ 'http://xxx'),
roles => [ $ms->tids (\ 'http://role1', \ 'http://role2', \ 'http://role1') ],
players => [ $ms->tids ('tm:aaa', undef, 'http://bbb') ] ), 1, 'reification: association');
}
#-- prefixes --------------------------
{
my $ms = _parse (q|
xsd isa astma:ontology ~ http://www.w3c.org/xsd/
tmql isa astma:ontology ~ http://www.isotopicmaps.org/tmql/
aaa subclasses xsd:integer
bbb isa tmql:function
<< aaa
tmql:function : ccc
<< ddd
bbb: tmql:function
|);
#warn Dumper $ms;
is (scalar $ms->match (TM->FORALL, type => 'isa', iplayer => 'ontology' ), 2, 'finding all ontologies');
is (scalar $ms->match (TM->FORALL, type => 'is-subclass-of', iplayer => $ms->tids (\ 'http://www.w3.org/2001/XMLSchema#integer' )), 1, 'prefixed tid as player');
is (scalar $ms->match (TM->FORALL, type => 'tm:ddd', iplayer => $ms->tids (\ 'http://www.isotopicmaps.org/tmql/#function' )), 1, 'prefixed tid as assoc player');
is (scalar $ms->match (TM->FORALL, type => 'tm:aaa', irole => $ms->tids (\ 'http://www.isotopicmaps.org/tmql/#function' )), 1, 'prefixed tid as assoc role');
is (scalar $ms->match (TM->FORALL, type => 'isa', iplayer => $ms->tids (\ 'http://www.isotopicmaps.org/tmql/#function' )), 1, 'prefixed tid as class player');
}
eval {
my $ms = _parse (q|
tmql isa astma:ontology # this by itself is ok
xxx isa tmql:function # here is must crash
|);
}; like ($@, qr/subject indicator/i, _chomp($@));
#-- templates --------------------
#-- inline templates first
eval {
my $ms = _parse (q|
xxx bbb zzz
|);
}; like ($@, qr/duplicate ID/i, _chomp($@));
eval {
my $ms = _parse (q|
ttt isa astma:template
xxx ttt zzz
|);
}; like ($@, qr/does not have/i, _chomp($@));
eval {
my $ms = _parse (q|
ttt isa astma:template
return: xxxx
return: yyyy
xxx ttt zzz
|);
}; like ($@, qr/ambiguous/i, _chomp($@));
{ # static template
my $ms = _parse (q|
ttt isa astma:template
return: """
<< bbb
ccc: ddd
eee: fff
"""
xxx ttt zzz
uuu ttt vvv
|);
#warn Dumper $ms;
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee' ], players => [ 'tm:ddd', 'tm:fff' ] ), 1, 'template: static');
}
{ # left/right template
my $ms = _parse (q|
ttt isa astma:template
return: """
<< bbb
ccc: {$_left}
eee: { $_right }
"""
xxx ttt zzz
uuu ttt vvv
|);
#warn Dumper $ms;
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee' ], players => [ 'tm:xxx', 'tm:zzz' ] ), 1, 'template: dynamic');
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee' ], players => [ 'tm:uuu', 'tm:vvv' ] ), 1, 'template: dynamic');
}
{ # left/right template
my $ms = _parse (q|
ttt isa astma:template
return: """
<< bbb
ccc: {$_left}
eee: { $_right }
fff: { $aaa }
"""
xxx ttt (aaa : "ddd") zzz
uuu ttt (aaa : "ddd") vvv
|);
#warn Dumper $ms;
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee', 'tm:fff' ], players => [ 'tm:xxx', 'tm:zzz', 'tm:ddd' ] ), 1, 'template: dynamic');
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee', 'tm:fff' ], players => [ 'tm:uuu', 'tm:vvv', 'tm:ddd' ] ), 1, 'template: dynamic');
}
#-- standalone templates
{
my $ms = _parse (q|
ttt isa astma:template
return: """
<< bbb
ccc: {$aaa}
eee: { $bbb }
"""
ttt ( aaa : "xxx" , bbb : "yyy" )
ttt (aaa: "uuu", bbb: "vvv" )
ttt (aaa: "mmm", bbb: "nnn", ccc: "ooo" ) # one too much, is ignored
|);
#warn Dumper $ms;
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee' ], players => [ 'tm:xxx', 'tm:yyy' ] ), 1, 'standalone template: dynamic');
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee' ], players => [ 'tm:uuu', 'tm:vvv' ] ), 1, 'standalone template: dynamic');
is (scalar $ms->match(TM->FORALL, type => 'tm:bbb', roles => [ 'tm:ccc', 'tm:eee' ], players => [ 'tm:mmm', 'tm:nnn' ] ), 1, 'standalone template: dynamic');
}
eval {
my $ms = _parse (q|
ttt isa astma:template
return: """
<< bbb
ccc: {$aaa}
eee: { $bbb }
"""
ttt ( aaa : "xxx" )
|);
}; like ($@, qr/has no value/i, _chomp($@));
#-- template keep yes/no
{
my $ms = _parse (q|
ttt isa astma:template
return: """
whatever
"""
xxx
|);
#warn Dumper $ms;
ok (! $ms->tids ('ttt'), 'template ttt removed by default');
}
#-- syntactic issues ----------------------------------------------------------------
{ # comments
my $ms = _parse (q|
# this is AsTMa
|);
#warn Dumper $ms;
is (scalar $ms->match(), $npa, 'empty map 1 (assertions)');
is ($ms->toplets, $npt, 'empty map 2 (toplets)');
}
{
my $ms = _parse (q|
# comment1
aaa isa bbbbb
#comment2
#comment4
ccc isa bbb
#comment3
#comment4
ddd isa xxxx
#comment5
|);
##warn Dumper $ms;
is (scalar $ms->toplets, $npt+6, 'test comment/separation');
is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:aaa' ), 1, 'types for aaa');
is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:ccc' ), 1, 'type for ccc');
is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:ddd' ), 1, 'type for ddd');
}
{ # inline comments
my $ms = _parse (q|
aaa
bn: AAA # comment
bn: AAA# no-comment
oc: http://rumsti#no-comment
|);
# warn Dumper $ms;
is (scalar $ms->match, $npa+3, 'comment + assertions');
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
[ 'AAA',
'AAA# no-comment' ]), 'getting back commented basename');
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
[ 'http://rumsti#no-comment' ]), 'getting back commented occ');
}
#-- syntactic issues ----------------------------------------------------------------
{ # empty line with blanks
my $ms = _parse (q|
topic1
topic2
|);
##warn Dumper $ms;
is (scalar $ms->toplets(), $npt+2, 'empty line contains blanks');
}
{ # empty lines with \r
my $ms = _parse (q|
topic1
topic2
topic3
|);
is (scalar $ms->toplets(), $npt+3, 'empty line \r contains blanks');
}
{ # using TABs as separators
my $ms = _parse (q|
topic1 isa topic2
topic3 isa topic4
|);
#warn Dumper $ms;
is (scalar $ms->toplets, $npt+2+2, 'using TABs as separators');
}
#-- syntactic issues ----------------------------------------------------------------
{ # line continuation with comments
my $ms = _parse (q|
topic1
# comment \
topic2
|);
is (scalar $ms->toplets, $npt+1, 'continuation in comment');
}
{ # line continuation with comments
my $ms = _parse (q|
topic1
# comment \
topic2
|);
is (scalar $ms->toplets, $npt+2, 'continuation in comment, not 1');
}
{ # line continuation with comments
my $ms = _parse (q|
topic1
# comment \
topic2
|);
is (scalar $ms->toplets, $npt+2, 'continuation in comment, not 2');
}
{ # line continuation
my $ms = _parse (q|
aaa isa bbbbb \
isa cccc \
isa dddd
|
);
is (scalar $ms->toplets, $npt+4, 'line continuation');
is (scalar $ms->match (TM->FORALL, type => 'isa', irole => 'instance', iplayer => 'tm:aaa' ), 3, 'continuation: types for aaa');
}
{ # line continuation, not
my $ms = _parse (q|
aaa
bn: AAA
in: a \ within the text is ok
in: also one with a \\ followed by a blank: \\
in: this is a new one \\
in: this is not a new one
|);
##warn Dumper $ms;
my @res = $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:aaa' );
is (scalar @res, 3, 'ins for aaa');
#warn Dumper \@res;
##warn Dumper [ map { ${$_->[TM->PLAYERS]->[1]}} @res ];
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } @res ],
[ 'a \ within the text is ok',
'also one with a \ followed by a blank: \\', # blank is gone now
'this is a new one in: this is not a new one']), 'same text');
}
{ # line continuation, not \\
my $ms = _parse (q|
# this is a continuation
aaa isa bbbb \
has bn: but not this \\\\
in: should be separate
|
);
##warn Dumper $ms;
is (scalar $ms->match, $npa+3, 'line continuation, =3');
}
#-- syntactic issues ----------------------------------------------------------------
#-- line splitters -----------------------------------------------
{ # line separation
my $ms = _parse (q|
aaa isa bbb +++ bn: AAA +++ in: rumsti
ccc isa ddd +++ bn: CCC
|);
## warn Dumper $ms;
is (scalar $ms->match, $npa+5, '+++ assertions');
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'name', iplayer => 'tm:aaa' ) ] ,
[ 'AAA' ]), 'AAA basename');
}
{ # line no split
my $ms = _parse (q|
aaa isa bbb +++ bn: AAA +++ in: rumsti is using ++++ in: text
|);
## warn Dumper $ms;
is (scalar $ms->match, $npa+3, '++++ assertions');
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' ) ] ,
[ 'rumsti is using +++ in: text' ]), 'getting back ++++ text');
}
#-- syntactic issues ----------------------------------------------------------------
{ # multi string detection
my $ms = _parse (q|
bbb
in: """
xxxxxxxxxxxxx
yyyyyyyyyy
zzzzzz
"""
ccc
in: """\
rumsti
ramsti
romsti"""
|);
## warn Dumper $ms;
is (scalar $ms->match, $npa+2, 'multiline string detection');
my @res = $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:bbb' );
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0]} @res ],
[ '
xxxxxxxxxxxxx
yyyyyyyyyy
zzzzzz
',
]), 'multiline string: same text ["""]');
@res = $ms->match (TM->FORALL, type => 'occurrence', irole => 'thing', iplayer => 'tm:ccc' );
ok (eq_set ([ map { $_->[TM->PLAYERS]->[1]->[0] } @res ],
[ 'rumsti
ramsti
romsti',
]), 'multiline string: same text ["""]');
}
#-- syntax errors (assoc)
eval {
my $ms = _parse (q|
<< xxx zzz
member : aaa
|);
}; like ($@, qr/Found ID but expected EOL or LPAREN/i, _chomp($@));
eval {
my $ms = _parse (q|
<< xxx
|);
}; like ($@, qr/Found DOT but expected EOL or LPAREN/i, _chomp($@));
eval {
my $ms = _parse (q|
<< xxx
rumsti
|);
}; like ($@, qr/Found DOT but expected EOL or LPAREN/i, _chomp($@));
eval {
my $ms = _parse (q|
<< xxx
role : aaa
role2 :
|);
}; like ($@, qr/Found DOT but expected DATE or EQUAL or ID/i, _chomp($@));
eval {
my $ms = _parse (q|
<< aaa
aaa :
|);
fail ("raises except on empty role");
}; like ($@, qr/Found DOT but expected DATE or EQUAL or ID/i, _chomp($@));
eval {
my $ms = _parse (q|
<<
role : player
|);
}; like ($@, qr/Found HAS but expected DATE or EQUAL or ID/i, _chomp($@));
eval {
my $ms = _parse (q|
<< aaa
aaa:bbb
|);
fail ("raises except on empty role 2");
}; like ($@, qr/Found DOT but expected COLON/i, _chomp($@));
eval {
my $ms = _parse (q|
<< ddd
bbb:aaa:ccc
|);
fail ("raises except on empty role 3");
}; like ($@, qr/Found DOT but expected COLON/i, _chomp($@));
#-- syntax errors (topics)
eval {
my $ms = _parse (q|
ttt
bn:
|);
## warn Dumper $ms;
}; like ($@, qr/Found DOT but expected VALUE/i, _chomp($@));
eval {
my $ms = _parse (q|
ttt
oc:
|);
}; like ($@, qr/Found DOT but expected VALUE/i, _chomp($@));
eval {
my $ms = _parse (q|
ttt
in:
|);
}; like ($@, qr/Found DOT but expected VALUE/i, _chomp($@));
#-- directives ------------------------------------------------------------
open (STDERR, '>/dev/null');
{ # cancel
my $ms = _parse (q|
aaa
%cancel
bbb
|);
#warn Dumper $ms;
is (scalar $ms->toplets, $npt+1, 'cancelling');
}
{ # log
my $ms = _parse (q|
aaa
%log xxx
bbb
|);
is (scalar $ms->toplets, $npt+2, 'logging');
}
{ # version
my $ms = _parse (q|
%version 2.3
|);
ok (1, "version ok");
}
eval { # version, not good
my $ms = _parse (q|
%version 1.5
|);
}; like ($@, qr/unsupported/i, _chomp($@));
{
my $tmp;
use IO::File;
use POSIX qw(tmpnam);
do { $tmp = tmpnam().".atm" ; } until IO::File->new ($tmp, O_RDWR|O_CREAT|O_EXCL);
my $fh = IO::File->new ("> $tmp") || die "so what?";
print $fh q|
aaa
ccc
|;
$fh->close;
my $ms = _parse (qq|
eee
%include file:$tmp
|);
#warn Dumper $ms;
is ($ms->tids ('aaa'), 'tm:aaa', '%include: file, internalized');
is ($ms->tids ('ccc'), 'tm:ccc', '%include: file, internalized');
is ($ms->tids ('eee'), 'tm:eee', '%include: file, internalized');
}
{ # include with UNIX pipe
my $ms = _parse (qq|
eee
%include (echo "aaa" ; echo ; echo "ccc" ; echo ) \|
|);
is ($ms->tids ('aaa'), 'tm:aaa', '%include: pipe, internalized');
is ($ms->tids ('ccc'), 'tm:ccc', '%include: pipe, internalized');
is ($ms->tids ('eee'), 'tm:eee', '%include: pipe, internalized');
};
{ # encoding
my $ms = _parse (q|
%encoding iso-8859-2
aaa
in: Ich chan Glaas �sse, das tuet mir n�d weeh
bbb
in: Mohu j�st sklo, neubl�?� mi
|);
#warn Dumper $ms;
my ($a) = $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:aaa' );
like ($a->[TM->PLAYERS]->[1]->[0], qr/Ich/, 'encoding: iso-8859-2, normal text');
like ($a->[TM->PLAYERS]->[1]->[0], qr/\x{E4}sse/, 'encoding: iso-8859-2, normal text');
($a) = $ms->match (TM->FORALL, type => 'occurrence', iplayer => 'tm:bbb' );
like ($a->[TM->PLAYERS]->[1]->[0], qr/Mohu/, 'encoding: iso-8859-2, normal text');
like ($a->[TM->PLAYERS]->[1]->[0], qr/\x{ED}st/, 'encoding: iso-8859-2, normal text');
}
#-- scopes as dates
TODO: {
local $TODO = "scopes as dates";
my $ms = _parse (q|
aaa
bn : AAA
bn @ 2004-01-12 : XXX
bn @ 2004-01-12T12:23 : YYY
|);
#warn Dumper $ms;
ok (eq_set (_q_players ($ms, scope => $ms->tids (\ 'http://psi.semagia.com/iso8601/2004-01-12'), type => 'name', iplayer => 'tm:aaa' ),
[ 'XXX' ]), 'date scoped 1');
ok (eq_set (_q_players ($ms, scope => $ms->tids (\ 'http://psi.semagia.com/iso8601/2004-01-12T12:23'), type => 'name', iplayer => 'tm:aaa' ),
[ 'YYY' ]), 'date scoped 2');
}
__END__
|