File: rdfviewssamples.xml

package info (click to toggle)
virtuoso-opensource 6.1.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 245,116 kB
  • sloc: ansic: 639,631; sql: 439,225; xml: 287,085; java: 61,048; sh: 38,723; cpp: 36,889; cs: 25,240; php: 12,562; yacc: 9,036; lex: 7,149; makefile: 6,093; jsp: 4,447; awk: 1,643; perl: 1,017; ruby: 1,003; python: 329
file content (17292 lines) | stat: -rw-r--r-- 693,868 bytes parent folder | download
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
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
<sect1 id="rdfviewsenterpr"><title>Examples of Linked Data Views</title>
<sect2 id="rdfviewnorthwindexample1"><title>Simple Mapping Example -- Northwind RDF View</title>
<para>Here is example of the basic Northwind RDF Views deployment. The sequence of operations is very common for adding SPARQL access to existing application.</para>
<para>There exist few important questions to answer. Who should have access to data behind RDF View? Should someone have access to other sorts of RDF data but not to the new View? What are applications that should be interoperable with the new RDF data source? Are there any applications that produce similar data but that data sould be kept apart from data made by view? How to ensure that deployment the view will not cause problems for other applications?</para>
<para>First of all, we decide whether the default web service endpoint should have access to the data in question. If it should then we have to grant SELECT privileges to the account "SPARQL" that is used for the default endpoint; if it should not but some custom edpoint should then grant to the owner account of that account. Granting access is less trivial that it is usual. On one hand, those who can make SQL SELECT statements on application's tables can also make SPARQL queries on RDF View over that tables, because it makes SQL inside. On the other hand, those who do not intend to query that data at all may get unexpected &quot;permission denied&quot; errors on queries that worked fine before adding an RDF View. If SPARQL compiler can not prove that the query can not access data from the view then it will generate SQL code that will access tables behind the view. In some cases permission problems should be resolved by creating RDF View in a separate <link linkend="rdfviewconfiguringrdfstorages">RDF storage</link>. In this example, data are public:</para>
<programlisting><![CDATA[
use DB;

GRANT SELECT ON "Demo"."demo"."Products" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Suppliers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Shippers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Categories" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Customers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Employees" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Orders" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Order_Details" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Countries" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Provinces" TO "SPARQL";
]]></programlisting>

<para>Interoperability is the next question. The example is not
interoperable with anything so in can provide data of any form, a real
application will probably use some ontology from external
source. Sometimes data should be converted from internal application's
representation to something different (such as metric to imperial or
ATT country code to two-character country id); sometimes composed IRIs
should follow special rules; <link
linkend="rdfviewiriusingfunction">function-based IRI classes</link>
may help in that cases. As this is the first example, only plain
format-string-based IRI classes are used.</para>

<para>We should also ensure that data generated by the new view will
not be accidentally mixed with other data of the database. For that
purpose the example will use a unique graph name that includes both
application name and host name. In addition, the script will drop
declarations that might remain  from a previous run of the same script. The
script is executed many times during the development so erasing
previous version is worth writing. It will report an error if there's
nothing to erase but it's better than unpredictable errors due to
writing new declarations over existing ones.</para>


<note><para>Making graph name unique for every host is not needed if
the application is supposed to be &quot;local&quot; and nobody will
access more than one installation of the application. If this is
the case, use some fixed graph IRI, not necessarily starting with
hostname at all; this is much more convenient for querying because you
don't have to calculate the graph name in each query. With fixed graph
in use, it is still possible to clone the RDF View to map to a unique
graph as soon as the application become &quot;public&quot; and requires
merging data from many installations.</para></note>

<programlisting><![CDATA[
SPARQL drop quad map graph iri("http://^{URIQADefaultHost}^/Northwind")
;
SPARQL drop quad map virtrdf:NorthwindDemo
;
]]></programlisting>
<note><para>The <emphasis>^{URIQADefaultHost}^</emphasis> macro is replaced with the value of <emphasis>DefaultHost</emphasis> parameter of <link linkend="ini_URIQA">[URIQA]</link> section of configuration file. The IRI is written as <emphasis>iri("http://^{URIQADefaultHost}^/Northwind")</emphasis>, not as <emphasis>&lt;http://^{URIQADefaultHost}^/Northwind&gt;</emphasis> because macro of this sort works only inside SPARQL string values.</para></note>

<para>Now it's safe to create IRI classes needed for the view. If
these classes are used only in the view we define then it is safe to
create all of them in a single statement. If some of them are used
across multiple declarations then errors may occur. it is impossible
to redefine an IRI class that is in use; the compiler will try to
avoid reporting errors by checking whether the new declaration is
identical to the existing one and by trying garbage collection in hope
that the IRI class is used only in garbage, but errors may occur
anyway. Thus it is better to declare &quot;shared&quot; IRI classes by
individual statements and group together only &quot;private&quot; IRI
classes of a view. If a &quot;class redefinition&quot; error occurs in
the middle of a group then &quot;undefined class&quot; errors may
occur after because the processing of the group was interrupted before
rest of group was not executed. When in trouble, try <link
linkend="fn_rdf_audit_metadata"><function>DB.DBA.RDF_AUDIT_METADATA</function></link>
procedure.</para>


<programlisting><![CDATA[
SPARQL
create iri class northwind:Category "http://^{URIQADefaultHost}^/Northwind/Category/%d#this" (in category_id integer not null) .
create iri class northwind:Shipper "http://^{URIQADefaultHost}^/Northwind/Shipper/%d#this" (in shipper_id integer not null) .
create iri class northwind:Supplier "http://^{URIQADefaultHost}^/Northwind/Supplier/%d#this" (in supplier_id integer not null) .
create iri class northwind:Product   "http://^{URIQADefaultHost}^/Northwind/Product/%d#this" (in product_id integer not null) .
create iri class northwind:Customer "http://^{URIQADefaultHost}^/Northwind/Customer/%U#this" (in customer_id varchar not null) .
create iri class northwind:Employee "http://^{URIQADefaultHost}^/Northwind/Employee/%U%U%d#this" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class northwind:Order "http://^{URIQADefaultHost}^/Northwind/Order/%d#this" (in order_id integer not null) .
create iri class northwind:CustomerContact "http://^{URIQADefaultHost}^/Northwind/CustomerContact/%U#this" (in customer_id varchar not null) .
create iri class northwind:OrderLine "http://^{URIQADefaultHost}^/Northwind/OrderLine/%d/%d#this" (in order_id integer not null, in product_id integer not null) .
create iri class northwind:Province "http://^{URIQADefaultHost}^/Northwind/Province/%U/%U#this" (in country_name varchar not null, in province_name varchar not null) .
create iri class northwind:Country "http://^{URIQADefaultHost}^/Northwind/Country/%U#this" (in country_name varchar not null) .
create iri class northwind:Flag "http://^{URIQADefaultHost}^%U#this" (in flag_path varchar not null) .
create iri class northwind:dbpedia_iri "http://dbpedia.org/resource/%U" (in uname varchar not null) .
create iri class northwind:EmployeePhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/EMP%d#this" (in emp_id varchar not null) .
create iri class northwind:CategoryPhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/CAT%d#this" (in category_id varchar not null) .
;
]]></programlisting>
<para>One IRI class per subject type; format strings begin with same host but different directory names so this will let the compiler to guess the type of subject by the text of IRI. Most of declarations are <link linkend="rdfviewbijandreturns">bijections</link> and may get  <emphasis>option (bijection)</emphasis> hint but these format strings are so simple that the compiler may understand it by itself.
(<emphasis>northwind:Employee</emphasis> is not a bijection because <link linkend="fn_sprintf_inverse"><function>sprintf_inverse</function></link> will be unable to split the tail of IRI string and find the boundary between first and last name.)</para>
<para>The final operation is extending the default quad storage with new tree of quad map patterns.</para>
<programlisting><![CDATA[
SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>

alter quad storage virtrdf:DefaultQuadStorage
from Demo.demo.Products as products
from Demo.demo.Suppliers as suppliers
from Demo.demo.Shippers as shippers
from Demo.demo.Categories as categories
from Demo.demo.Customers as customers
from Demo.demo.Employees as employees
from Demo.demo.Orders as orders
from Demo.demo.Order_Details as order_lines
from Demo.demo.Countries as countries
from Demo.demo.Provinces as provinces
where (^{suppliers.}^.Country = ^{countries.}^.Name)
where (^{customers.}^.Country = ^{countries.}^.Name)
where (^{employees.}^.Country = ^{countries.}^.Name)
where (^{orders.}^.ShipCountry = ^{countries.}^.Name)
{
        create virtrdf:NorthwindDemo as graph iri ("http://^{URIQADefaultHost}^/Northwind") option (exclusive)
        {
                northwind:CustomerContact (customers.CustomerID)
                        a foaf:Person
                                as virtrdf:CustomerContact-foaf_Person .

                northwind:CustomerContact (customers.CustomerID)
                        a northwind:CustomerContact
                                as virtrdf:CustomerContact-CustomerContact;
                        foaf:name customers.ContactName
                                as virtrdf:CustomerContact-contact_name ;
                        foaf:phone customers.Phone
                                as virtrdf:CustomerContact-foaf_phone ;
                        northwind:is_contact_at northwind:Customer (customers.CustomerID)
                                as virtrdf:CustomerContact-is_contact_at ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:CustomerContact-country ;
                        rdfs:isDefinedBy northwind:customercontact_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy northwind:CustomerContact (customers.CustomerID) .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:CustomerContact (customers.CustomerID) as virtrdf:CustomerContact-is_country_of .

                northwind:Product (products.ProductID)
                        a northwind:Product
                                as virtrdf:Product-ProductID ;
                        northwind:has_category northwind:Category (products.CategoryID)
                                as virtrdf:Product-product_has_category ;
                        northwind:has_supplier northwind:Supplier (products.SupplierID)
                                as virtrdf:Product-product_has_supplier ;
                        northwind:productName products.ProductName
                                as virtrdf:Product-name_of_product ;
                        northwind:quantityPerUnit products.QuantityPerUnit
                                as virtrdf:Product-quantity_per_unit ;
                        northwind:unitPrice products.UnitPrice
                                as virtrdf:Product-unit_price ;
                        northwind:unitsInStock products.UnitsInStock
                                as virtrdf:Product-units_in_stock ;
                        northwind:unitsOnOrder products.UnitsOnOrder
                                as virtrdf:Product-units_on_order ;
                        northwind:reorderLevel products.ReorderLevel
                                as virtrdf:Product-reorder_level ;
                        northwind:discontinued products.Discontinued
                                as virtrdf:Product-discontinued ;
                        rdfs:isDefinedBy northwind:product_iri (products.ProductID) ;
                        rdfs:isDefinedBy northwind:Product (products.ProductID) .

                northwind:Category (products.CategoryID)
                        northwind:category_of northwind:Product (products.ProductID) as virtrdf:Product-category_of .

                northwind:Supplier (products.SupplierID)
                        northwind:supplier_of northwind:Product (products.ProductID) as virtrdf:Product-supplier_of .

                northwind:Supplier (suppliers.SupplierID)
                        a northwind:Supplier
                                as virtrdf:Supplier-SupplierID ;
                        northwind:companyName suppliers.CompanyName
                                as virtrdf:Supplier-company_name ;
                        northwind:contactName suppliers.ContactName
                                as virtrdf:Supplier-contact_name ;
                        northwind:contactTitle suppliers.ContactTitle
                                as virtrdf:Supplier-contact_title ;
                        northwind:address suppliers.Address
                                as virtrdf:Supplier-address ;
                        northwind:city suppliers.City
                                as virtrdf:Supplier-city ;
                        northwind:dbpedia_city northwind:dbpedia_iri(suppliers.City)
                                as virtrdf:Supplier-dbpediacity ;
                        northwind:region suppliers.Region
                                as virtrdf:Supplier-region ;
                        northwind:postalCode suppliers.PostalCode
                                as virtrdf:Supplier-postal_code ;
                        northwind:country northwind:Country(suppliers.Country)
                                as virtrdf:Supplier-country ;
                        northwind:phone suppliers.Phone
                                as virtrdf:Supplier-phone ;
                        northwind:fax suppliers.Fax
                                as virtrdf:Supplier-fax ;
                        northwind:homePage suppliers.HomePage
                                as virtrdf:Supplier-home_page ;
                        rdfs:isDefinedBy northwind:supplier_iri (suppliers.SupplierID) ;
                        rdfs:isDefinedBy northwind:Supplier (suppliers.SupplierID) .

                northwind:Country (suppliers.Country)
                        northwind:is_country_of
                northwind:Supplier (suppliers.SupplierID) as virtrdf:Supplier-is_country_of .

                northwind:Category (categories.CategoryID)
                        a northwind:Category
                                as virtrdf:Category-CategoryID ;
                        northwind:categoryName categories.CategoryName
                                as virtrdf:Category-home_page ;
                        northwind:description categories.Description
                                as virtrdf:Category-description ;
                        foaf:img northwind:CategoryPhoto(categories.CategoryID)
                                as virtrdf:Category-categories.CategoryPhoto ;
                        rdfs:isDefinedBy northwind:category_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy northwind:Category (categories.CategoryID) .

                northwind:CategoryPhoto(categories.CategoryID)
                        a northwind:CategoryPhoto
                                as virtrdf:Category-categories.CategoryPhotoID ;
                        rdfs:isDefinedBy northwind:categoryphoto_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy northwind:CategoryPhoto(categories.CategoryID) .

                northwind:Shipper (shippers.ShipperID)
                        a northwind:Shipper
                                as virtrdf:Shipper-ShipperID ;
                        northwind:companyName shippers.CompanyName
                                as virtrdf:Shipper-company_name ;
                        northwind:phone shippers.Phone
                                as virtrdf:Shipper-phone ;
                        rdfs:isDefinedBy northwind:shipper_iri (shippers.ShipperID) ;
                        rdfs:isDefinedBy northwind:Shipper (shippers.ShipperID) .

                northwind:Customer (customers.CustomerID)
                        a  northwind:Customer
                                as virtrdf:Customer-CustomerID2 ;
                        a  foaf:Organization
                                as virtrdf:Customer-CustomerID ;
                        foaf:name customers.CompanyName
                                as virtrdf:Customer-foaf_name ;
                        northwind:companyName customers.CompanyName
                                as virtrdf:Customer-company_name ;
                        northwind:has_contact northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:Customer-contact ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:Customer-country ;
                        northwind:contactName customers.ContactName
                                as virtrdf:Customer-contact_name ;
                        northwind:contactTitle customers.ContactTitle
                                as virtrdf:Customer-contact_title ;
                        northwind:address customers.Address
                                as virtrdf:Customer-address ;
                        northwind:city customers.City
                                as virtrdf:Customer-city ;
                        northwind:dbpedia_city northwind:dbpedia_iri(customers.City)
                                as virtrdf:Customer-dbpediacity ;
                        northwind:region customers.Region
                                as virtrdf:Customer-region ;
                        northwind:PostalCode customers.PostalCode
                                as virtrdf:Customer-postal_code ;
                        foaf:phone customers.Phone
                                as virtrdf:Customer-foaf_phone ;
                        northwind:phone customers.Phone
                                as virtrdf:Customer-phone ;
                        northwind:fax customers.Fax
                                as virtrdf:Customer-fax ;
                        rdfs:isDefinedBy northwind:customer_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy northwind:Customer (customers.CustomerID) .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:Customer (customers.CustomerID) as virtrdf:Customer-is_country_of .

                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a northwind:Employee
                                as virtrdf:Employee-EmployeeID2 ;
                        a foaf:Person
                                as virtrdf:Employee-EmployeeID ;
                        foaf:surname employees.LastName
                                as virtrdf:Employee-foaf_last_name ;
                        northwind:lastName employees.LastName
                                as virtrdf:Employee-last_name ;
                        foaf:firstName employees.FirstName
                                as virtrdf:Employee-foaf_first_name ;
                        northwind:firstName employees.FirstName
                                as virtrdf:Employee-first_name ;
                        foaf:title employees.Title
                                as virtrdf:Employee-title ;
                        northwind:titleOfCourtesy employees.TitleOfCourtesy
                                as virtrdf:Employee-title_of_courtesy ;
                        foaf:birthday employees.BirthDate
                                as virtrdf:Employee-foaf_birth_date ;
                        northwind:birthday employees.BirthDate
                                as virtrdf:Employee-birth_date ;
                        northwind:hireDate employees.HireDate
                                as virtrdf:Employee-hire_date ;
                        northwind:address employees.Address
                                as virtrdf:Employee-address ;
                        northwind:city employees.City
                                as virtrdf:Employee-city ;
                        northwind:dbpedia_city northwind:dbpedia_iri(employees.City)
                                as virtrdf:Employee-dbpediacity ;
                        northwind:region employees.Region
                                as virtrdf:Employee-region ;
                        northwind:postalCode employees.PostalCode
                                as virtrdf:Employee-postal_code ;
                        northwind:country northwind:Country(employees.Country)
                                as virtrdf:Employee-country ;
                        foaf:phone employees.HomePhone
                                as virtrdf:Employee-home_phone ;
                        northwind:extension employees.Extension
                                as virtrdf:Employee-extension ;
                        northwind:notes employees.Notes
                                as virtrdf:Employee-notes ;
                        northwind:reportsTo northwind:Employee(employees.FirstName, employees.LastName, employees.ReportsTo) where (^{employees.}^.ReportsTo = ^{employees.}^.EmployeeID)
                                as virtrdf:Employee-reports_to ;
                        foaf:img northwind:EmployeePhoto(employees.EmployeeID)
                                as virtrdf:Employee-employees.EmployeePhoto ;
                        rdfs:isDefinedBy northwind:employee_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) .

                northwind:EmployeePhoto(employees.EmployeeID)
                        a northwind:EmployeePhoto
                                as virtrdf:Employee-employees.EmployeePhotoId ;
                        rdfs:isDefinedBy northwind:employeephoto_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy northwind:EmployeePhoto (employees.EmployeeID) .

                northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID)
                        northwind:is_salesrep_of
                northwind:Order (orders.OrderID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID) as virtrdf:Order-is_salesrep_of .

                northwind:Country (employees.Country)
                        northwind:is_country_of
                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) as virtrdf:Employee-is_country_of .

                northwind:Order (orders.OrderID)
                        a northwind:Order
                                as virtrdf:Order-Order ;
                        northwind:has_customer northwind:Customer (orders.CustomerID)
                                as virtrdf:Order-order_has_customer ;
                        northwind:has_salesrep northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Customer-has_salesrep ;
                        northwind:has_employee northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Order-order_has_employee ;
                        northwind:orderDate orders.OrderDate
                                as virtrdf:Order-order_date ;
                        northwind:requiredDate orders.RequiredDate
                                as virtrdf:Order-required_date ;
                        northwind:shippedDate orders.ShippedDate
                                as virtrdf:Order-shipped_date ;
                        northwind:order_ship_via northwind:Shipper (orders.ShipVia)
                                as virtrdf:Order-order_ship_via ;
                        northwind:freight orders.Freight
                                as virtrdf:Order-freight ;
                        northwind:shipName orders.ShipName
                                as virtrdf:Order-ship_name ;
                        northwind:shipAddress orders.ShipAddress
                                as virtrdf:Order-ship_address ;
                        northwind:shipCity orders.ShipCity
                                as virtrdf:Order-ship_city ;
                        northwind:dbpedia_shipCity northwind:dbpedia_iri(orders.ShipCity)
                                as virtrdf:Order-dbpediaship_city ;
                        northwind:shipRegion orders.ShipRegion
                                as virtrdf:Order-ship_region ;
                        northwind:shipPostal_code orders.ShipPostalCode
                                as virtrdf:Order-ship_postal_code ;
                        northwind:shipCountry northwind:Country(orders.ShipCountry)
                                as virtrdf:ship_country ;
                        rdfs:isDefinedBy northwind:order_iri (orders.OrderID) ;
                        rdfs:isDefinedBy northwind:Order (orders.OrderID) .

                northwind:Country (orders.ShipCountry)
                        northwind:is_ship_country_of
                northwind:Order (orders.OrderID) as virtrdf:Order-is_country_of .

                northwind:Customer (orders.CustomerID)
                        northwind:has_order northwind:Order (orders.OrderID) as virtrdf:Order-has_order .

                northwind:Shipper (orders.ShipVia)
                        northwind:ship_order northwind:Order (orders.OrderID) as virtrdf:Order-ship_order .

                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                        a northwind:OrderLine
                                as virtrdf:OrderLine-OrderLines ;
                        northwind:has_order_id northwind:Order (order_lines.OrderID)
                                as virtrdf:order_lines_has_order_id ;
                        northwind:has_product_id northwind:Product (order_lines.ProductID)
                                as virtrdf:order_lines_has_product_id ;
                        northwind:unitPrice order_lines.UnitPrice
                                as virtrdf:OrderLine-unit_price ;
                        northwind:quantity order_lines.Quantity
                                as virtrdf:OrderLine-quantity ;
                        northwind:discount order_lines.Discount
                                as virtrdf:OrderLine-discount ;
                        rdfs:isDefinedBy northwind:orderline_iri (order_lines.OrderID, order_lines.ProductID) ;
                        rdfs:isDefinedBy northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) .

                northwind:Order (orders.OrderID)
                        northwind:is_order_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{orders.}^.OrderID = ^{order_lines.}^.OrderID) as virtrdf:Order-is_order_of .

                northwind:Product (products.ProductID)
                        northwind:is_product_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{products.}^.ProductID = ^{order_lines.}^.ProductID) as virtrdf:Product-is_product_of .

                northwind:Country (countries.Name)
                        a northwind:Country
                                as virtrdf:Country-Type2 ;
                        a wgs:SpatialThing
                                as virtrdf:Country-Type ;
                        owl:sameAs northwind:dbpedia_iri (countries.Name) ;
                        northwind:name countries.Name
                                as virtrdf:Country-Name ;
                        northwind:code countries.Code
                                as virtrdf:Country-Code ;
                        northwind:smallFlagDAVResourceName countries.SmallFlagDAVResourceName
                                as virtrdf:Country-SmallFlagDAVResourceName ;
                        northwind:largeFlagDAVResourceName countries.LargeFlagDAVResourceName
                                as virtrdf:Country-LargeFlagDAVResourceName ;
                        northwind:smallFlagDAVResourceURI northwind:Flag(countries.SmallFlagDAVResourceURI)
                                as virtrdf:Country-SmallFlagDAVResourceURI ;
                        northwind:largeFlagDAVResourceURI northwind:Flag(countries.LargeFlagDAVResourceURI)
                                as virtrdf:Country-LargeFlagDAVResourceURI ;
                        wgs:lat countries.Lat
                                as virtrdf:Country-Lat ;
                        wgs:long countries.Lng
                                as virtrdf:Country-Lng ;
                        rdfs:isDefinedBy northwind:country_iri (countries.Name) ;
                        rdfs:isDefinedBy northwind:Country (countries.Name) .

                northwind:Country (countries.Name)
                        northwind:has_province
                northwind:Province (provinces.CountryCode, provinces.Province) where (^{provinces.}^.CountryCode = ^{countries.}^.Code) as virtrdf:Country-has_province .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        a northwind:Province
                                as virtrdf:Province-Provinces ;
                        northwind:has_country_code provinces.CountryCode
                                as virtrdf:has_country_code ;
                        northwind:provinceName provinces.Province
                                as virtrdf:Province-ProvinceName ;
                        rdfs:isDefinedBy northwind:province_iri (provinces.CountryCode, provinces.Province) ;
                        rdfs:isDefinedBy northwind:Province (provinces.CountryCode, provinces.Province) .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        northwind:is_province_of
                northwind:Country (countries.Name) where  (^{countries.}^.Code = ^{provinces.}^.CountryCode) as virtrdf:Province-country_of .
        }.
}.
;
]]></programlisting>
<para>The created RDF View is sufficient for querying relational data via SPARQL but not for accessing data by dereferencing IRIs of subjects. Making IRIs dereferenceable requires configuring HTTP server; that is explained in <link linkend="rdfsparqlexnpointnorthwindexample">second part of the example</link>.</para>
</sect2>
<sect2 id="rdfviewsenterprbsm">
      <title>BSBM to RDF</title>
      <para>This section includes example mapping SQL Data to RDF for BSBM.</para>
      <para>Each BSBM installation includes a demonstration database that includes a simple management system schema and instance data. This sample database provides an easy route for introducing BSBM users and developers to the virtues of RDF based Linked Data Views built atop existing BSBM relational databases.</para>      
<programlisting><![CDATA[
use DB;

CREATE TABLE DB.DBA.ProductFeature (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar(1500) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.ProductFeature to public
;

CREATE TABLE DB.DBA.ProductType (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar(1500) not null,
  parent integer,
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.ProductType to public
;

CREATE TABLE DB.DBA.Producer (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar(1500) not null,
  homepage varchar(100) not null,
  country char(2) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.Producer to public
;
create index producer_homepage on DB.DBA.Producer (homepage)
;

CREATE TABLE DB.DBA.Product (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar not null,
  producer integer not null,
  propertyNum1 integer,
  propertyNum2 integer,
  propertyNum3 integer,
  propertyNum4 integer,
  propertyNum5 integer,
  propertyNum6 integer,
  propertyTex1 varchar(200),
  propertyTex2 varchar(200),
  propertyTex3 varchar(200),
  propertyTex4 varchar(200),
  propertyTex5 varchar(200),
  propertyTex6 varchar(200),
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.Product to public
;

create index product_lbl on DB.DBA.Product (label)
;
create unique index product_producer_nr on DB.DBA.Product (producer, nr)
;
create index product_pn1 on DB.DBA.Product (propertyNum1)
;
create index product_pn2 on DB.DBA.Product (propertyNum2)
;
create index product_pn3 on DB.DBA.Product (propertyNum3)
;

create text index on DB.DBA.Product (label) with key nr
;

CREATE TABLE DB.DBA.ProductTypeProduct (
  product integer not null,
  productType integer not null,
  PRIMARY KEY (product, productType)
)
;

grant SELECT on DB.DBA.ProductTypeProduct to public
;

create index ptype_inv on DB.DBA.ProductTypeProduct (productType, product)
;

CREATE TABLE DB.DBA.ProductFeatureProduct (
  product integer not null,
  productFeature integer not null,
  PRIMARY KEY (product, productFeature)
)
;

grant SELECT on DB.DBA.ProductFeatureProduct to public
;

create index pfeature_inv on DB.DBA.ProductFeatureProduct (productFeature, product)
;

CREATE TABLE DB.DBA.Vendor (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar not null,
  homepage varchar(100) not null,
  country char(2) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.Vendor to public
;

create index vendor_country on DB.DBA.Vendor (country)
;
create index vendor_homepage on DB.DBA.Vendor (homepage)
;

CREATE TABLE DB.DBA.Offer (
  nr integer primary key,
  product integer not null,
  producer integer,
  vendor integer not null,
  price double precision not null,
  validFrom date not null,
  validTo date not null,
  deliveryDays integer not null,
  offerWebpage varchar(100) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.Offer to public
;

create index offer_product on DB.DBA.Offer (product, deliveryDays)
;
create unique index offer_producer_product on DB.DBA.Offer (producer, product, nr)
;
create index offer_validto on DB.DBA.Offer (validTo)
;
create index offer_vendor_product on DB.DBA.Offer (vendor, product)
;
create index offer_webpage on DB.DBA.Offer (offerWebpage)
;

CREATE TABLE DB.DBA.Person (
  nr integer primary key,
  name varchar(30) not null,
  mbox_sha1sum char(40) not null,
  country char(2) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.Person to public
;

CREATE TABLE DB.DBA.Review (
  nr integer primary key,
  product integer not null,
  producer integer,
  person integer not null,
  reviewDate date not null,
  title varchar(200) not null,
  text long varchar not null,
  textlang char(2) not null,
  rating1 integer,
  rating2 integer,
  rating3 integer,
  rating4 integer,
  publisher integer not null,
  publishDate date not null
)
;

grant SELECT on DB.DBA.Review to public
;

create unique index review_product on DB.DBA.Review (product, producer, nr)
;

create unique index review_producer_product on DB.DBA.Review (producer, product, nr)
;

create bitmap index review_textlang on DB.DBA.Review (textlang)
;

DB.DBA.XML_SET_NS_DECL ('foaf', 'http://xmlns.com/foaf/0.1/', 2)
;
DB.DBA.XML_SET_NS_DECL ('dc', 'http://purl.org/dc/elements/1.1/', 2)
;
DB.DBA.XML_SET_NS_DECL ('xsd', 'http://www.w3.org/2001/XMLSchema-datatypes/', 2)
;
DB.DBA.XML_SET_NS_DECL ('rev', 'http://purl.org/stuff/rev#', 2)
;
DB.DBA.XML_SET_NS_DECL ('bsbm', 'http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/', 2)
;
DB.DBA.XML_SET_NS_DECL ('bsbm-inst', 'http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/', 2)
;

SPARQL drop quad map bsbm:SingleGraphView
;

SPARQL create iri class bsbm:ProductFeature-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductFeature%d" (in nr integer not null)
;

SPARQL create iri class bsbm:ProductType-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductType%d" (in nr integer not null)
;

SPARQL create iri class bsbm:Producer-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer%d/Producer%d" (in nr_ integer not null, in nr integer not null)
;

SPARQL create iri class bsbm:Product-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer%d/Product%d" (in producer integer not null, in nr integer not null)
;

SPARQL create iri class bsbm:Vendor-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromVendor%d/Vendor%d" (in nr_ integer not null, in nr integer not null)
;

SPARQL create iri class bsbm:Offer-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromVendor%d/Offer%d" (in vendor integer not null, in nr integer not null)
;

SPARQL create iri class bsbm:StdInst-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/StandardizationInstitution%d" (in publisher integer not null)
;

SPARQL create iri class bsbm:Person-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromRatingSite%d/Person%d" (in publisher integer not null, in nr integer not null)
;

SPARQL create iri class bsbm:Review-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromRatingSite%d/Review%d" (in site integer, in nr integer not null)
;

SPARQL create iri class bsbm:ISO3166-country-iri "http://downlode.org/rdf/iso-3166/countries#%s" (in code varchar not null)
;

SPARQL create iri class bsbm:homepage-iri "%s" (in homepage varchar not null) option (returns "http://%s")
;

SPARQL create iri class bsbm:RatingSite-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromRatingSite%d/RatingSite%d" (in nr_ integer not null, in nr integer not null)
;

SPARQL
alter quad storage virtrdf:DefaultQuadStorage
FROM DB.DBA.ProductFeature as pfeature
FROM DB.DBA.ProductType as ptype
FROM DB.DBA.Producer as producer
FROM DB.DBA.Product as product text literal product.label
FROM DB.DBA.ProductTypeProduct as ptypeproduct
FROM DB.DBA.ProductFeatureProduct as pfeatureproduct
FROM DB.DBA.Vendor as vendor
FROM DB.DBA.Offer as offer
FROM DB.DBA.Person as person
FROM DB.DBA.Review as review
where (^{product.}^.nr = ^{ptypeproduct.}^.product)
where (^{product.}^.nr = ^{pfeatureproduct.}^.product)
  {
    create bsbm:SingleGraphView as graph <BSBM> option (exclusive)
      {
	bsbm:Product-iri (product.producer, product.nr)
          a bsbm:Product ;
	  rdfs:label product.label ;
          rdfs:comment product.comment ;
          bsbm:producer bsbm:Producer-iri (product.producer, product.producer) ;
          bsbm:productPropertyTextual1 product.propertyTex1 ;
          bsbm:productPropertyTextual2 product.propertyTex2 ;
          bsbm:productPropertyTextual3 product.propertyTex3 ;
          bsbm:productPropertyTextual4 product.propertyTex4 ;
          bsbm:productPropertyTextual5 product.propertyTex5 ;
          bsbm:productPropertyTextual6 product.propertyTex6 ;
          bsbm:productPropertyNumeric1 product.propertyNum1 ;
          bsbm:productPropertyNumeric2 product.propertyNum2 ;
          bsbm:productPropertyNumeric3 product.propertyNum3 ;
          bsbm:productPropertyNumeric4 product.propertyNum4 ;
          bsbm:productPropertyNumeric5 product.propertyNum5 ;
          bsbm:productPropertyNumeric6 product.propertyNum6 ;
          rdf:type bsbm:ProductType-iri (ptypeproduct.productType) ;
          bsbm:productFeature bsbm:ProductFeature-iri (pfeatureproduct.productFeature) ;
          dc:publisher bsbm:Producer-iri (product.publisher, product.publisher) ;
          dc:date product.publishDate .

        bsbm:ProductType-iri (ptype.nr)
          a bsbm:ProductType ;
          rdfs:label ptype.label ;
          rdfs:comment ptype.comment ;
          rdfs:subClassOf bsbm:ProductType-iri (ptype.parent) ;
          dc:publisher bsbm:StdInst-iri (ptype.publisher) ;
          dc:date ptype.publishDate .

        bsbm:ProductFeature-iri (pfeature.nr)
          a bsbm:ProductFeature ;
          rdfs:label pfeature.label ;
          rdfs:comment pfeature.comment ;
          dc:publisher bsbm:StdInst-iri (pfeature.publisher) ;
          dc:date pfeature.publishDate .

        bsbm:Producer-iri (producer.nr, producer.nr)
          a bsbm:Producer ;
          rdfs:label producer.label ;
          rdfs:comment producer.comment ;
          foaf:homepage bsbm:homepage-iri (producer.homepage) ;
          bsbm:country bsbm:ISO3166-country-iri (producer.country) ;
          dc:publisher bsbm:Producer-iri (producer.nr, producer.nr) ;
          dc:date producer.publishDate .

        bsbm:Vendor-iri (vendor.nr, vendor.nr)
          a bsbm:Vendor ;
          rdfs:label vendor.label ;
          rdfs:comment vendor.comment ;
          foaf:homepage bsbm:homepage-iri (vendor.homepage) ;
          bsbm:country bsbm:ISO3166-country-iri (vendor.country) ;
          dc:publisher bsbm:Vendor-iri (vendor.publisher, vendor.publisher) ;
          dc:date vendor.publishDate .

        bsbm:Offer-iri (offer.vendor, offer.nr)
          a bsbm:Offer ;
          bsbm:product bsbm:Product-iri (offer.producer, offer.product) ;
          bsbm:vendor bsbm:Vendor-iri (offer.vendor, offer.vendor) ;
          bsbm:vendor bsbm:Vendor-iri (offer.vendor, offer.vendor) ;
          bsbm:price offer.price ;
          bsbm:validFrom offer.validFrom ;
          bsbm:validTo offer.validTo ;
          bsbm:deliveryDays offer.deliveryDays ;
          bsbm:offerWebpage bsbm:homepage-iri (offer.offerWebpage) ;
          dc:publisher bsbm:Vendor-iri (offer.publisher, offer.publisher) ;
          dc:date offer.publishDate .

        bsbm:Person-iri (person.publisher, person.nr)
          a foaf:Person ;
          foaf:name person.name ;
          foaf:mbox_sha1sum person.mbox_sha1sum ;
          bsbm:country bsbm:ISO3166-country-iri (person.country) ;
          dc:publisher bsbm:RatingSite-iri (person.publisher, person.publisher) ;
          dc:date person.publishDate .

        bsbm:Review-iri (review.publisher, review.nr)
          a rev:Review ;
          bsbm:reviewFor bsbm:Product-iri (review.producer, review.product) ;
          bsbm:producer bsbm:Producer-iri (review.producer, review.producer) ;
          rev:reviewer bsbm:Person-iri (review.publisher, review.person) ;
          bsbm:reviewDate review.reviewDate ;
          dc:title review.title ;
          rev:text review.text lang review.textlang ;
          bsbm:rating1 review.rating1 ;
          bsbm:rating2 review.rating2 ;
          bsbm:rating3 review.rating3 ;
          bsbm:rating4 review.rating4 ;
          dc:publisher bsbm:RatingSite-iri (review.publisher, review.publisher) ;
          dc:date review.publishDate .
      }
  }
;
]]></programlisting>
    </sect2>
<sect2 id="rdfviewsbusint"><title>TPCH to RDF</title>
<programlisting><![CDATA[
use DB;

GRANT SELECT ON TPCH.DBA.PARTSUPP  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.SUPPLIER  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.CUSTOMER  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.HISTORY   TO "SPARQL";
GRANT SELECT ON TPCH.DBA.PART      TO "SPARQL";
GRANT SELECT ON TPCH.DBA.LINEITEM  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.ORDERS    TO "SPARQL";
GRANT SELECT ON TPCH.DBA.NATION    TO "SPARQL";
GRANT SELECT ON TPCH.DBA.REGION    TO "SPARQL";

SPARQL
drop quad map virtrdf:TPCH
;

SPARQL
prefix tpch: <http://www.openlinksw.com/schemas/tpch#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
create iri class tpch:customer "http://^{URIQADefaultHost}^/tpch/customer/%U%d#this" (in custname varchar, in c_custkey integer not null) option (bijection, deref) .
create iri class tpch:lineitem "http://^{URIQADefaultHost}^/tpch/lineitem/%d/%d#this" (in l_orderkey integer not null, in l_linenumber integer not null) option (bijection, deref) .
create iri class tpch:nation "http://^{URIQADefaultHost}^/tpch/nation/%U%d#this" (in name varchar, in l_nationkey integer not null) option (bijection, deref) .
create iri class tpch:order "http://^{URIQADefaultHost}^/tpch/order/%d#this" (in o_orderkey integer not null) option (bijection, deref) .
create iri class tpch:part "http://^{URIQADefaultHost}^/tpch/part/%U%d#this" (in p_partname varchar, in p_partkey integer not null) option (bijection, deref) .
create iri class tpch:partsupp "http://^{URIQADefaultHost}^/tpch/partsupp/%d/%d#this" (in ps_partkey integer not null, in ps_suppkey integer not null) option (bijection, deref) .
create iri class tpch:region "http://^{URIQADefaultHost}^/tpch/region/%U%d#this" (in name varchar, in r_regionkey integer not null) option (bijection, deref) .
create iri class tpch:supplier "http://^{URIQADefaultHost}^/tpch/supplier/%U%d#this" (in name varchar, in s_supplierkey integer not null) option (bijection, deref) .
;

SPARQL
prefix tpch: <http://www.openlinksw.com/schemas/tpch#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
alter quad storage virtrdf:DefaultQuadStorage
FROM TPCH.DBA.LINEITEM as lineitems
FROM TPCH.DBA.CUSTOMER as customers
FROM TPCH.DBA.NATION as nations
FROM TPCH.DBA.ORDERS as orders
FROM TPCH.DBA.PART as parts
FROM TPCH.DBA.PARTSUPP as partsupps
FROM TPCH.DBA.REGION as regions
FROM TPCH.DBA.SUPPLIER as suppliers
where (^{suppliers.}^.S_NATIONKEY = ^{nations.}^.N_NATIONKEY)
where (^{customers.}^.C_NATIONKEY = ^{nations.}^.N_NATIONKEY)
{
    create virtrdf:TPCH as graph iri ("http://^{URIQADefaultHost}^/tpch") option (exclusive)
    {
# Customers
        tpch:customer (customers.C_NAME, customers.C_CUSTKEY)
            a  tpch:customer
                as virtrdf:customer-tpch-type ;
            a  foaf:Organization
                as virtrdf:customer-foaf-type ;
            tpch:custkey customers.C_CUSTKEY
                as virtrdf:customer-c_custkey ;
            foaf:name customers.C_NAME
                as virtrdf:customer-foaf_name ;
            tpch:companyName customers.C_NAME
                as virtrdf:customer-c_name ;
            tpch:has_nation tpch:nation (nations.N_NAME, customers.C_NATIONKEY)
                as virtrdf:customer-c_nationkey ;
            tpch:address customers.C_ADDRESS
                as virtrdf:customer-c_address ;
            foaf:phone customers.C_PHONE
                as virtrdf:customer-foaf_phone ;
            tpch:phone customers.C_PHONE
                as virtrdf:customer-phone ;
            tpch:acctbal customers.C_ACCTBAL
                as virtrdf:customer-acctbal ;
            tpch:mktsegment customers.C_MKTSEGMENT
                as virtrdf:customer-c_mktsegment ;
            tpch:comment customers.C_COMMENT
                as virtrdf:customer-c_comment .

# Nations
        tpch:nation (nations.N_NAME, customers.C_NATIONKEY)
            tpch:nation_of tpch:customer (customers.C_NAME, customers.C_CUSTKEY)
            as virtrdf:customer-nation_of .

        tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER)
            a tpch:lineitem
                as virtrdf:lineitem-lineitems ;
            tpch:has_order tpch:order (lineitems.L_ORDERKEY)
                as virtrdf:lineitem-l_orderkey ;
            tpch:has_part tpch:part (parts.P_NAME, lineitems.L_PARTKEY)
                where (^{parts.}^.P_PARTKEY = ^{lineitems.}^.L_PARTKEY)
                as virtrdf:lineitem-l_partkey ;
            tpch:has_supplier tpch:supplier (suppliers.S_NAME, lineitems.L_SUPPKEY)
                where (^{suppliers.}^.S_SUPPKEY = ^{lineitems.}^.L_SUPPKEY)
                as virtrdf:lineitem-l_suppkey ;
            tpch:linenumber lineitems.L_LINENUMBER
                as virtrdf:lineitem-l_linenumber ;
            tpch:linequantity lineitems.L_QUANTITY
                as virtrdf:lineitem-l_linequantity ;
            tpch:lineextendedprice lineitems.L_EXTENDEDPRICE
                as virtrdf:lineitem-l_lineextendedprice ;
            tpch:linediscount lineitems.L_DISCOUNT
                as virtrdf:lineitem-l_linediscount ;
            tpch:linetax lineitems.L_TAX
                as virtrdf:lineitem-l_linetax ;
            tpch:returnflag lineitems.L_RETURNFLAG
                as virtrdf:lineitem-l_returnflag ;
            tpch:linestatus lineitems.L_LINESTATUS
                as virtrdf:lineitem-l_linestatus ;
            tpch:shipdate lineitems.L_SHIPDATE
                as virtrdf:lineitem-l_shipdate ;
            tpch:commitdate lineitems.L_COMMITDATE
                as virtrdf:lineitem-l_commitdate ;
            tpch:receiptdate lineitems.L_RECEIPTDATE
                as virtrdf:lineitem-l_receiptdate ;
            tpch:shipinstruct lineitems.L_SHIPINSTRUCT
                as virtrdf:lineitem-l_shipinstruct ;
            tpch:shipmode lineitems.L_SHIPMODE
                as virtrdf:lineitem-l_shipmode ;
            tpch:comment lineitems.L_COMMENT
                as virtrdf:lineitem-l_comment .

        tpch:part (parts.P_NAME, lineitems.L_PARTKEY)
            tpch:part_of tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER)
            where (^{parts.}^.P_PARTKEY = ^{lineitems.}^.L_PARTKEY)
            as virtrdf:lineitem-part_of .

        tpch:order (lineitems.L_ORDERKEY)
            tpch:order_of tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER) as virtrdf:lineitem-order_of .

        tpch:supplier (suppliers.S_NAME, lineitems.L_SUPPKEY)
            tpch:supplier_of tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER)
            where (^{suppliers.}^.S_SUPPKEY = ^{lineitems.}^.L_SUPPKEY)
            as virtrdf:lineitem-supplier_of .

# Nation
        tpch:nation (nations.N_NAME, nations.N_NATIONKEY)
            a tpch:nation
                as virtrdf:nation-nations ;
            tpch:name nations.N_NAME
                as virtrdf:nation-n_name ;
            tpch:has_region tpch:region (regions.R_NAME, nations.N_REGIONKEY)
                where (^{regions.}^.R_REGIONKEY = ^{nations.}^.N_REGIONKEY)
                as virtrdf:nation-n_regionkey ;
            tpch:comment nations.N_COMMENT
                as virtrdf:nation-n_comment .

        tpch:region (regions.R_NAME, nations.N_REGIONKEY)
            tpch:region_of tpch:nation (nations.N_NAME, nations.N_NATIONKEY)
            where (^{regions.}^.R_REGIONKEY = ^{nations.}^.N_REGIONKEY)
            as virtrdf:nation-region_of .

# Order
        tpch:order (orders.O_ORDERKEY)
            a tpch:order
                as virtrdf:order-orders ;
            tpch:orderkey orders.O_ORDERKEY
                as virtrdf:order-o_orderkey ;
            tpch:has_customer tpch:customer (customers.C_NAME, orders.O_CUSTKEY)
                where (^{orders.}^.O_CUSTKEY = ^{customers.}^.C_CUSTKEY)
                as virtrdf:order-o_custkey ;
            tpch:orderstatus orders.O_ORDERSTATUS
                as virtrdf:order-o_orderstatus ;
            tpch:ordertotalprice orders.O_TOTALPRICE
                as virtrdf:order-o_totalprice ;
            tpch:orderdate orders.O_ORDERDATE
                as virtrdf:order-o_orderdate ;
            tpch:orderpriority orders.O_ORDERPRIORITY
                as virtrdf:order-o_orderpriority ;
            tpch:clerk orders.O_CLERK
                as virtrdf:order-o_clerk ;
            tpch:shippriority orders.O_SHIPPRIORITY
                as virtrdf:order-o_shippriority ;
            tpch:comment orders.O_COMMENT
                as virtrdf:order-o_comment .

        tpch:customer (customers.C_CUSTKEY, orders.O_CUSTKEY)
            tpch:customer_of tpch:order (orders.O_ORDERKEY)
            where (^{orders.}^.O_CUSTKEY = ^{customers.}^.C_CUSTKEY)
            as virtrdf:order-customer_of .

# Part
        tpch:part (parts.P_NAME, parts.P_PARTKEY)
            a tpch:part
                as virtrdf:part-parts ;
            tpch:partkey parts.P_PARTKEY
                as virtrdf:part-p_partkey ;
            tpch:name parts.P_NAME
                as virtrdf:part-p_name ;
            tpch:mfgr parts.P_MFGR
                as virtrdf:part-p_mfgr ;
            tpch:brand parts.P_BRAND
                as virtrdf:part-p_brand ;
            tpch:type parts.P_TYPE
                as virtrdf:part-p_type ;
            tpch:size parts.P_SIZE
                as virtrdf:part-p_size ;
            tpch:container parts.P_CONTAINER
                as virtrdf:part-p_container ;
            tpch:comment parts.P_COMMENT
                as virtrdf:part-p_comment .

# Partsupp
        tpch:partsupp (partsupps.PS_PARTKEY, partsupps.PS_SUPPKEY)
            a tpch:partsupp
                as virtrdf:partsupp-partsupps ;
            tpch:has_part tpch:part (parts.P_NAME, partsupps.PS_PARTKEY)
                where (^{parts.}^.P_PARTKEY = ^{partsupps.}^.PS_PARTKEY)
                as virtrdf:partsupp-ps_partkey ;
            tpch:has_supplier tpch:supplier (suppliers.S_NAME, partsupps.PS_SUPPKEY)
                where (^{suppliers.}^.S_SUPPKEY = ^{partsupps.}^.PS_SUPPKEY)
                as virtrdf:partsupp-ps_suppkey ;
            tpch:availqty partsupps.PS_AVAILQTY
                as virtrdf:partsupp-ps_availqty ;
            tpch:supplycost partsupps.PS_SUPPLYCOST
                as virtrdf:partsupp-ps_supplycost ;
            tpch:comment partsupps.PS_COMMENT
                as virtrdf:partsupp-ps_comment .

        tpch:part (parts.P_NAME, partsupps.PS_PARTKEY)
            tpch:part_of tpch:partsupp (partsupps.PS_PARTKEY, partsupps.PS_SUPPKEY)
            where (^{parts.}^.P_PARTKEY = ^{partsupps.}^.PS_PARTKEY)
            as virtrdf:partsupp-part_of .

        tpch:supplier (suppliers.S_NAME, partsupps.PS_SUPPKEY)
            tpch:supplier_of tpch:partsupp (partsupps.PS_PARTKEY, partsupps.PS_SUPPKEY)
            where (^{suppliers.}^.S_SUPPKEY = ^{partsupps.}^.PS_SUPPKEY)
            as virtrdf:partsupp-supplier_of .

# Region
        tpch:region (regions.R_NAME, regions.R_REGIONKEY)
            a tpch:region
                as virtrdf:region-regions ;
            tpch:name regions.R_NAME
                as virtrdf:region-r_name ;
            tpch:comment regions.R_COMMENT
                as virtrdf:region-r_comment .

# Supplier
        tpch:supplier (suppliers.S_NAME, suppliers.S_SUPPKEY)
            a tpch:supplier
                as virtrdf:supplier-suppliers ;
            tpch:name suppliers.S_NAME
                as virtrdf:supplier-s_name ;
            tpch:address suppliers.S_ADDRESS
                as virtrdf:supplier-s_address ;
            tpch:has_nation tpch:nation (nations.N_NAME, suppliers.S_NATIONKEY)
                where (^{nations.}^.N_NATIONKEY = ^{suppliers.}^.S_NATIONKEY)
                as virtrdf:supplier-s_nationkey ;
            foaf:phone suppliers.S_PHONE
                as virtrdf:supplier-foaf_phone ;
            tpch:phone suppliers.S_PHONE
                as virtrdf:supplier-s_phone ;
            tpch:acctbal suppliers.S_ACCTBAL
                as virtrdf:supplier-s_acctbal ;
            tpch:comment suppliers.S_COMMENT
                as virtrdf:supplier-s_comment .

        tpch:nation (nations.N_NAME, suppliers.S_NATIONKEY)
            tpch:nation_of tpch:supplier (suppliers.S_NAME, suppliers.S_SUPPKEY)
            where (^{nations.}^.N_NATIONKEY = ^{suppliers.}^.S_NATIONKEY)
            as virtrdf:supplier-nation_of .
    } .
} .
;

DELETE FROM db.dba.url_rewrite_rule_list WHERE urrl_list like 'tpch_rule%';
DELETE FROM db.dba.url_rewrite_rule WHERE urr_rule like 'tpch_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tpch_rule2',
    1,
    '([^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/tpch%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tpch_rule1',
    1,
    '([^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s%%23this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tpch_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%s',
    vector('path'),
    null,
    null,
    0,
    null
    );

create procedure DB.DBA.REMOVE_TPCH_RDF_DET()
{
  declare colid int;
  colid := DAV_SEARCH_ID('/DAV/home/demo/tpch', 'C');
  if (colid < 0)
    return;
  update WS.WS.SYS_DAV_COL set COL_DET=null where COL_ID = colid;
}
;

DB.DBA.REMOVE_TPCH_RDF_DET();

drop procedure DB.DBA.REMOVE_TPCH_RDF_DET;

create procedure DB.DBA.TPCH_MAKE_RDF_DET()
{
    declare uriqa_str varchar;
    uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
    uriqa_str := 'http://' || uriqa_str || '/tpch';
    DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/home/demo/tpch/RDFData/', uriqa_str, NULL);
    VHOST_REMOVE (lpath=>'/tpch/data/rdf');
    DB.DBA.VHOST_DEFINE (lpath=>'/tpch/data/rdf', ppath=>'/DAV/home/demo/tpch/RDFData/All/', is_dav=>1, vsp_user=>'dba');
}
;

DB.DBA.TPCH_MAKE_RDF_DET();

drop procedure DB.DBA.TPCH_MAKE_RDF_DET;

create procedure DB.DBA.TPCH_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  declare uriqa_str varchar;
  uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  uriqa_str := 'http://' || uriqa_str || '/tpch';
  iri := uriqa_str || val;
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tpch_rdf', 1,
    '/tpch/(.*)', vector('path'), 1,
    '/tpch/data/rdf/%U', vector('path'),
    'DB.DBA.TPCH_DET_REF',
    'application/rdf.xml',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tpch_rule_list1',
    1,
    vector (
                'tpch_rule1',
                'tpch_rule2',
                'tpch_rule3',
                'tpch_rdf'
          ));

DB.DBA.VHOST_REMOVE (lpath=>'/tpch');
DB.DBA.VHOST_DEFINE (lpath=>'/tpch', ppath=>'/DAV/home/demo/tpch/', vsp_user=>'dba', is_dav=>1,
          is_brws=>0, opts=>vector ('url_rewrite', 'tpch_rule_list1'));


DB.DBA.VHOST_REMOVE (lpath=>'/tpch/linkeddata');
DB.DBA.VHOST_DEFINE (lpath=>'/tpch/linkeddata', ppath=>'/DAV/home/demo/tpch/', vsp_user=>'dba', is_dav=>1,
          is_brws=>1);
]]></programlisting>
</sect2>
<sect2 id="rdfviewsbusinttpcd">
      <title>TPCD to RDF</title>
<para>Please load ~\binsrc\dav\DET_RDFData.sql before loadding this script (tpc-d has no vad to do this automatic)</para>
<programlisting><![CDATA[
use DB;

create procedure DB.DBA.exec_no_error (in expr varchar) {
  declare state, message, meta, result any;
  exec(expr, state, message, vector(), 0, meta, result);
}
;

DB.DBA.exec_no_error('GRANT \"SPARQL_UPDATE\" TO \"SPARQL\"')
;
GRANT SELECT ON tpcd.DBA.partsupp  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.supplier  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.customer  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.history   TO "SPARQL";
GRANT SELECT ON tpcd.DBA.part      TO "SPARQL";
GRANT SELECT ON tpcd.DBA.lineitem  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.orders    TO "SPARQL";
GRANT SELECT ON tpcd.DBA.nation    TO "SPARQL";
GRANT SELECT ON tpcd.DBA.region    TO "SPARQL";

--SPARQL
--prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
--prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
--prefix sioc: <http://rdfs.org/sioc/ns#>
--prefix foaf: <http://xmlns.com/foaf/0.1/>
--prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
--drop quad map graph iri("http://^{URIQADefaultHost}^/tpcd") .
--;

SPARQL
prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
drop silent quad map virtrdf:TpcdDemo .
;

SPARQL
prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
create iri class tpcd:customer "http://^{URIQADefaultHost}^/tpcd/customer/%d#this" (in c_custkey integer not null) .
create iri class tpcd:lineitem "http://^{URIQADefaultHost}^/tpcd/lineitem/%d/%d#this" (in l_orderkey integer not null, in l_linenumber integer not null) .
create iri class tpcd:nation "http://^{URIQADefaultHost}^/tpcd/nation/%d#this" (in l_nationkey integer not null) .
create iri class tpcd:order "http://^{URIQADefaultHost}^/tpcd/order/%d#this" (in o_orderkey integer not null) .
create iri class tpcd:part "http://^{URIQADefaultHost}^/tpcd/part/%d#this" (in p_partkey integer not null) .
create iri class tpcd:partsupp "http://^{URIQADefaultHost}^/tpcd/partsupp/%d/%d#this" (in ps_partkey integer not null, in ps_suppkey integer not null) .
create iri class tpcd:region "http://^{URIQADefaultHost}^/tpcd/region/%d#this" (in r_regionkey integer not null) .
create iri class tpcd:supplier "http://^{URIQADefaultHost}^/tpcd/supplier/%d#this" (in s_supplierkey integer not null) .
;

SPARQL
prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
alter quad storage virtrdf:DefaultQuadStorage
from tpcd.DBA.lineitem as lineitems
from tpcd.DBA.customer as customers
from tpcd.DBA.nation as nations
from tpcd.DBA.orders as orders
from tpcd.DBA.part as parts
from tpcd.DBA.partsupp as partsupps
from tpcd.DBA.region as regions
from tpcd.DBA.supplier as suppliers
where (^{suppliers.}^.s_nationkey = ^{nations.}^.n_nationkey)
where (^{customers.}^.c_nationkey = ^{nations.}^.n_nationkey)
{
    create virtrdf:TpcdDemo as graph iri ("http://^{URIQADefaultHost}^/tpcd") option (exclusive)
    {
# Customers
        tpcd:customer (customers.c_custkey)
            a  tpcd:customer
                as virtrdf:tpcdcustomer-type ;
            a  foaf:Organization
                as virtrdf:tpcdcustomer-foaf-type ;
            tpcd:custkey customers.c_custkey
                as virtrdf:tpcdcustomer-c_custkey ;
            foaf:name customers.c_name
                as virtrdf:tpcdcustomer-foaf_name ;
            tpcd:companyName customers.c_name
                as virtrdf:tpcdcustomer-c_name ;
            tpcd:has_nation tpcd:nation (customers.c_nationkey)
                as virtrdf:tpcdcustomer-c_nationkey ;
            tpcd:address customers.c_address
                as virtrdf:tpcdcustomer-c_address ;
            foaf:phone customers.c_phone
                as virtrdf:tpcdcustomer-foaf_phone ;
            tpcd:phone customers.c_phone
                as virtrdf:tpcdcustomer-phone ;
            tpcd:acctbal customers.c_acctbal
                as virtrdf:tpcdcustomer-acctbal ;
            tpcd:mktsegment customers.c_mktsegment
                as virtrdf:tpcdcustomer-c_mktsegment ;
            tpcd:comment customers.c_comment
                as virtrdf:tpcdcustomer-c_comment .

# Nations
        tpcd:nation (customers.c_nationkey)
            tpcd:nation_of tpcd:customer (customers.c_custkey) as virtrdf:tpcdcustomer-nation_of .

# Lineitems
        tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber)
            a tpcd:lineitem
                as virtrdf:tpcdlineitem-lineitems ;
            tpcd:has_order tpcd:order (lineitems.l_orderkey)
                as virtrdf:tpcdlineitem-l_orderkey ;
            tpcd:has_part tpcd:part (lineitems.l_partkey)
                as virtrdf:tpcdlineitem-l_partkey ;
            tpcd:has_supplier tpcd:supplier (lineitems.l_suppkey)
                as virtrdf:tpcdlineitem-l_suppkey ;
            tpcd:linenumber lineitems.l_linenumber
                as virtrdf:tpcdlineitem-l_linenumber ;
            tpcd:linequantity lineitems.l_quantity
                as virtrdf:tpcdlineitem-l_linequantity ;
            tpcd:lineextendedprice lineitems.l_extendedprice
                as virtrdf:tpcdlineitem-l_lineextendedprice ;
            tpcd:linediscount lineitems.l_discount
                as virtrdf:tpcdlineitem-l_linediscount ;
            tpcd:linetax lineitems.l_tax
                as virtrdf:tpcdlineitem-l_linetax ;
            tpcd:returnflag lineitems.l_returnflag
                as virtrdf:tpcdlineitem-l_returnflag ;
            tpcd:linestatus lineitems.l_linestatus
                as virtrdf:tpcdlineitem-l_linestatus ;
            tpcd:shipdate lineitems.l_shipdate
                as virtrdf:tpcdlineitem-l_shipdate ;
            tpcd:commitdate lineitems.l_commitdate
                as virtrdf:tpcdlineitem-l_commitdate ;
            tpcd:receiptdate lineitems.l_receiptdate
                as virtrdf:tpcdlineitem-l_receiptdate ;
            tpcd:shipinstruct lineitems.l_shipinstruct
                as virtrdf:tpcdlineitem-l_shipinstruct ;
            tpcd:shipmode lineitems.l_shipmode
                as virtrdf:tpcdlineitem-l_shipmode ;
            tpcd:comment lineitems.l_comment
                as virtrdf:tpcdlineitem-l_comment .

        tpcd:part (lineitems.l_partkey)
            tpcd:part_of tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber) as virtrdf:tpcdlineitem-part_of .

        tpcd:order (lineitems.l_orderkey)
            tpcd:order_of tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber) as virtrdf:tpcdlineitem-order_of .

        tpcd:supplier (lineitems.l_suppkey)
            tpcd:supplier_of tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber) as virtrdf:tpcdlineitem-supplier_of .

# Nation
        tpcd:nation (nations.n_nationkey)
            a tpcd:nation
                as virtrdf:tpcdnation-nations ;
            tpcd:name nations.n_name
                as virtrdf:tpcdnation-n_name ;
            tpcd:has_region tpcd:region (nations.n_regionkey)
                as virtrdf:tpcdnation-n_regionkey ;
            tpcd:comment nations.n_comment
                as virtrdf:tpcdnation-n_comment .

        tpcd:region (nations.n_regionkey)
            tpcd:region_of tpcd:nation (nations.n_nationkey) as virtrdf:tpcdnation-region_of .

# Order
        tpcd:order (orders.o_orderkey)
            a tpcd:order
                as virtrdf:tpcdorder-orders ;
            tpcd:orderkey orders.o_orderkey
                as virtrdf:tpcdorder-o_orderkey ;
            tpcd:has_customer tpcd:customer (orders.o_custkey)
                as virtrdf:tpcdorder-o_custkey ;
            tpcd:orderstatus orders.o_orderstatus
                as virtrdf:tpcdorder-o_orderstatus ;
            tpcd:ordertotalprice orders.o_totalprice
                as virtrdf:tpcdorder-o_totalprice ;
            tpcd:orderdate orders.o_orderdate
                as virtrdf:tpcdorder-o_orderdate ;
            tpcd:orderpriority orders.o_orderpriority
                as virtrdf:tpcdorder-o_orderpriority ;
            tpcd:clerk orders.o_clerk
                as virtrdf:tpcdorder-o_clerk ;
            tpcd:shippriority orders.o_shippriority
                as virtrdf:tpcdorder-o_shippriority ;
            tpcd:comment orders.o_comment
                as virtrdf:tpcdorder-o_comment .

        tpcd:customer (orders.o_custkey)
            tpcd:customer_of tpcd:order (orders.o_orderkey) as virtrdf:tpcdorder-customer_of .

# Part
        tpcd:part (parts.p_partkey)
            a tpcd:part
                as virtrdf:tpcdpart-parts ;
            tpcd:partkey parts.p_partkey
                as virtrdf:tpcdpart-p_partkey ;
            tpcd:name parts.p_name
                as virtrdf:tpcdpart-p_name ;
            tpcd:mfgr parts.p_mfgr
                as virtrdf:tpcdpart-p_mfgr ;
            tpcd:brand parts.p_brand
                as virtrdf:tpcdpart-p_brand ;
            tpcd:type parts.p_type
                as virtrdf:tpcdpart-p_type ;
            tpcd:size parts.p_size
                as virtrdf:tpcdpart-p_size ;
            tpcd:container parts.p_container
                as virtrdf:tpcdpart-p_container ;
            tpcd:comment parts.p_comment
                as virtrdf:tpcdpart-p_comment .

# Partsupp
        tpcd:partsupp (partsupps.ps_partkey, partsupps.ps_suppkey)
            a tpcd:partsupp
                as virtrdf:tpcdpartsupp-partsupps ;
            tpcd:has_part tpcd:part (partsupps.ps_partkey)
                as virtrdf:tpcdpartsupp-ps_partkey ;
            tpcd:has_supplier tpcd:supplier (partsupps.ps_suppkey)
                as virtrdf:tpcdpartsupp-ps_suppkey ;
            tpcd:availqty partsupps.ps_availqty
                as virtrdf:tpcdpartsupp-ps_availqty ;
            tpcd:supplycost partsupps.ps_supplycost
                as virtrdf:tpcdpartsupp-ps_supplycost ;
            tpcd:comment partsupps.ps_comment
                as virtrdf:tpcdpartsupp-ps_comment .

        tpcd:part (partsupps.ps_partkey)
            tpcd:part_of tpcd:partsupp (partsupps.ps_partkey, partsupps.ps_suppkey) as virtrdf:tpcdpartsupp-part_of .

        tpcd:supplier (partsupps.ps_suppkey)
            tpcd:supplier_of tpcd:partsupp (partsupps.ps_partkey, partsupps.ps_suppkey) as virtrdf:tpcdpartsupp-supplier_of .

# Region
        tpcd:region (regions.r_regionkey)
            a tpcd:region
                as virtrdf:tpcdregion-regions ;
            tpcd:name regions.r_name
                as virtrdf:tpcdregion-r_name ;
            tpcd:comment regions.r_comment
                as virtrdf:tpcdregion-r_comment .

# Supplier
        tpcd:supplier (suppliers.s_suppkey)
            a tpcd:supplier
                as virtrdf:tpcdsupplier-suppliers ;
            tpcd:name suppliers.s_name
                as virtrdf:tpcdsupplier-s_name ;
            tpcd:address suppliers.s_address
                as virtrdf:tpcdsupplier-s_address ;
            tpcd:has_nation tpcd:nation (suppliers.s_nationkey)
                as virtrdf:tpcdsupplier-s_nationkey ;
            foaf:phone suppliers.s_phone
                as virtrdf:tpcdsupplier-foaf_phone ;
            tpcd:phone suppliers.s_phone
                as virtrdf:tpcdsupplier-s_phone ;
            tpcd:acctbal suppliers.s_acctbal
                as virtrdf:tpcdsupplier-s_acctbal ;
            tpcd:comment suppliers.s_comment
                as virtrdf:tpcdsupplier-s_comment .

        tpcd:nation (suppliers.s_nationkey)
            tpcd:nation_of tpcd:supplier (suppliers.s_suppkey) as virtrdf:tpcdsupplier-nation_of .
    }
}
;

create procedure tcpd_rdf_doc (in path varchar)
{
  declare r any;
  r := regexp_match ('[^/]*\x24', path);
  return r||'#this';
};

create procedure tcpd_html_doc (in path varchar)
{
  declare r any;
  r := regexp_match ('[^/]*#', path);
  return subseq (r, 0, length (r)-1);
};

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tcpd_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/tpcd%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tcpd_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/rdfbrowser/index.html?uri=http%%3A//^{URIQADefaultHost}^%U%%23this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tcpd_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%s',
    vector('path'),
    null,
    null,
    0,
    null
    );

DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/home/tpcd/RDFData/', 'http://^{URIQADefaultHost}^/tpcd', NULL);
VHOST_REMOVE (lpath=>'/tpcd/data/rdf');
DB.DBA.VHOST_DEFINE (lpath=>'/tpcd/data/rdf', ppath=>'/DAV/home/tpcd/RDFData/All/', is_dav=>1, vsp_user=>'dba');

-- procedure to convert path to DET resource name
create procedure DB.DBA.TPCD_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  iri := 'http://^{URIQADefaultHost}^/tpcd' || val;
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tpcd_rdf', 1,
    '/tpcd/(.*)', vector('path'), 1,
    '/tpcd/data/rdf/%U', vector('path'),
    'DB.DBA.TPCD_DET_REF',
    'application/rdf.xml',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tpcd_rule_list1',
    1,
    vector (
                'tcpd_rule1',
                'tcpd_rule2',
                'tcpd_rule3',
                'tpcd_rdf'
          ));


VHOST_REMOVE (lpath=>'/tpcd');
DB.DBA.VHOST_DEFINE (lpath=>'/tpcd', ppath=>'/DAV/home/', vsp_user=>'dba', is_dav=>1, def_page=>'sfront.vspx',
    is_brws=>0, opts=>vector ('url_rewrite', 'tpcd_rule_list1'));

create procedure DB.DBA.LOAD_TPCD_ONTOLOGY_FROM_DAV()
{
	declare content, urihost varchar;
	select cast (RES_CONTENT as varchar) into content from WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/VAD/tpcd/tpcd.owl';
	DB.DBA.RDF_LOAD_RDFXML (content, 'http://demo.openlinksw.com/schemas/tpcd#', 'http://demo.openlinksw.com/schemas/TPCDOntology/1.0/');
	urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
	if (urihost = 'demo.openlinksw.com')
	{
		DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tpcd');
		DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tpcd', ppath=>'/DAV/VAD/tpcd/tpcd.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
	}
}
;
DB.DBA.LOAD_TPCD_ONTOLOGY_FROM_DAV()
;
drop procedure DB.DBA.LOAD_TPCD_ONTOLOGY_FROM_DAV
;

XML_SET_NS_DECL ('virt-tpcd', 'http://demo.openlinksw.com/schemas/tpcd#', 2)
;

]]></programlisting>
</sect2>
<sect2 id="rdfviewsbusintthalia">
      <title>Thalia to RDF</title>
<programlisting><![CDATA[

use DB
;

SPARQL drop quad map virtrdf:ThaliaDemo
;

create procedure DB.DBA.SPARQL_THALIA_RUN (in txt varchar)
{
  declare REPORT, stat, msg, sqltext varchar;
  declare metas, rowset any;
  result_names (REPORT);
  sqltext := string_output_string (sparql_to_sql_text (txt));
  stat := '00000';
  msg := '';
  rowset := null;
  exec (sqltext, stat, msg, vector (), 1000, metas, rowset);
}
;

create procedure DB.DBA.exec_no_error(in expr varchar)
{
	declare state, message, meta, result any;
	exec(expr, state, message, vector(), 0, meta, result);
}
;

DB.DBA.exec_no_error('drop View thalia.Demo.asu_v');
DB.DBA.exec_no_error('create View thalia.Demo.asu_v as select left(Title,3) code,* from thalia.Demo.asu');
DB.DBA.exec_no_error('drop View thalia.Demo.gatech_v');
DB.DBA.exec_no_error('create View thalia.Demo.gatech_v as select *, Room||\' \'||Building Place from thalia.Demo.gatech');
DB.DBA.SPARQL_THALIA_RUN('drop quad map graph iri("http://^{URIQADefaultHost}^/Thalia") .
')
;

GRANT SELECT ON thalia.Demo.asu TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.asu_v TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.brown TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.cmu TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.gatech TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.gatech_v TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.toronto TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.ucsd TO "SPARQL"
;
GRANT SELECT ON thalia.Demo.umd TO "SPARQL"
;

DB.DBA.SPARQL_THALIA_RUN('drop quad map graph iri("http://^{URIQADefaultHost}^/thalia") .
');

DB.DBA.SPARQL_THALIA_RUN('drop quad map virtrdf:ThaliaDemo .
');


DB.DBA.SPARQL_THALIA_RUN('
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix time: <http://www.w3.org/2006/time#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix th: <http://demo.openlinksw.com/schemas/thalia#>

create iri class th:Asu "http://^{URIQADefaultHost}^/thalia/asu/course/%U#this" (in code varchar not null) .
create iri class th:Brown "http://^{URIQADefaultHost}^/thalia/brown/course/%U#this" (in Code varchar not null) .
create iri class th:BrownInstructor "http://^{URIQADefaultHost}^/thalia/brown/instructor/%U#this" (in Code varchar not null) .
create iri class th:BrownLecture "http://^{URIQADefaultHost}^/thalia/brown/lecture/%U#this" (in Code varchar not null) .
create iri class th:BrownPlace "http://^{URIQADefaultHost}^/thalia/brown/place/%U#this" (in Code varchar not null) .

create iri class th:Cmu "http://^{URIQADefaultHost}^/thalia/cmu/course/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuInstructor "http://^{URIQADefaultHost}^/thalia/cmu/instructor/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuLecture "http://^{URIQADefaultHost}^/thalia/cmu/lecture/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuPlace "http://^{URIQADefaultHost}^/thalia/cmu/place/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuEventTime "http://^{URIQADefaultHost}^/thalia/cmu/eventtime/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuDatetime "http://^{URIQADefaultHost}^/thalia/cmu/datetime/%U/%U#this" (in Code varchar not null, in Sec varchar) .

create iri class th:Gatech "http://^{URIQADefaultHost}^/thalia/gatech/course/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechInstructor "http://^{URIQADefaultHost}^/thalia/gatech/instructor/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechLecture "http://^{URIQADefaultHost}^/thalia/gatech/lecture/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechEventTime "http://^{URIQADefaultHost}^/thalia/gatech/eventtime/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechDatetime "http://^{URIQADefaultHost}^/thalia/gatech/datetime/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechPlace "http://^{URIQADefaultHost}^/thalia/gatech/place/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .

create iri class th:Toronto "http://^{URIQADefaultHost}^/thalia/toronto/course/%U#this" (in No_ varchar) .
create iri class th:TorontoInstructor "http://^{URIQADefaultHost}^/thalia/toronto/instructor/%U#this" (in No_ varchar) .
create iri class th:TorontoLecture "http://^{URIQADefaultHost}^/thalia/toronto/lecture/%U#this" (in No_ varchar) .
create iri class th:TorontoPlace "http://^{URIQADefaultHost}^/thalia/toronto/place/%U#this" (in No_ varchar) .

create iri class th:Ucsd "http://^{URIQADefaultHost}^/thalia/ucsd/course/%U#this" (in Number varchar) .
create iri class th:UcsdInstructor1 "http://^{URIQADefaultHost}^/thalia/ucsd/instructor1/%U#this" (in Number varchar) .
create iri class th:UcsdInstructor2 "http://^{URIQADefaultHost}^/thalia/ucsd/instructor2/%U#this" (in Number varchar) .
create iri class th:UcsdInstructor3 "http://^{URIQADefaultHost}^/thalia/ucsd/instructor3/%U#this" (in Number varchar) .

create iri class th:Umd "http://^{URIQADefaultHost}^/thalia/umd/course/%U#this" (in Code varchar) .
create iri class th:UmdLecture "http://^{URIQADefaultHost}^/thalia/umd/lecture/%U#this" (in Code varchar) .
create iri class th:UmdEventTime "http://^{URIQADefaultHost}^/thalia/umd/eventtime/%U#this" (in Code varchar) .
create iri class th:UmdDatetime "http://^{URIQADefaultHost}^/thalia/umd/datetime/%U#this" (in Code varchar) .
')
;

DB.DBA.SPARQL_THALIA_RUN('prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix time: <http://www.w3.org/2006/time#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix th: <http://demo.openlinksw.com/schemas/thalia#>
alter quad storage virtrdf:DefaultQuadStorage
from thalia.demo.asu_v as asus
from thalia.demo.brown as browns
from thalia.demo.cmu as cmus
from thalia.demo.gatech_v as gatechs
from thalia.demo.toronto as torontos
from thalia.demo.ucsd as ucsds
from thalia.demo.umd as umds
{
        create virtrdf:ThaliaDemo as graph iri ("http://^{URIQADefaultHost}^/thalia") option (exclusive)
        {
                th:Asu (asus.code)
                    a th:Course
                        as virtrdf:Asu-Course ;
                    dc:title asus.Title
                        as virtrdf:Asu-Title ;
                    dc:description asus.Description
                        as virtrdf:Asu-Description ;
                    rdfs:seeAlso asus.MoreInfoURL
                        as virtrdf:Asu-MoreInfoURL ;
                        th:forUniversity "http://purl.org/thalia/university/asu/university/asu"
                            as virtrdf:Asu-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                            as virtrdf:Asu-Subject
                            .

                th:Brown (browns.Code)
                        a th:Course
                                as virtrdf:Brown-Course ;
                        dc:title browns.Title
                            as virtrdf:Brown-Title ;
                        th:hasInstructor th:BrownInstructor (browns.Code)
                            as virtrdf:Brown-hasInstructor ;
                        th:hasLecture th:BrownLecture(browns.Code)
                            as virtrdf:Brown-hasLecture ;
                        th:forUniversity "http://purl.org/thalia/university/brown"
                            as virtrdf:Brown-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                            as virtrdf:Brown-Subject
                            .
                th:BrownInstructor (browns.Code)
                        a th:Instructor
                                as virtrdf:Brown-Instructor ;
                        dc:homepage browns.Instructor
                            as virtrdf:Brown-Instructor-Homepage
                            .
                th:BrownLecture (browns.Code)
                        a event:Event
                                as virtrdf:Brown-Lecture ;
                        event:place th:BrownPlace(browns.Code)
                            as virtrdf:Brown-hasPlace
                            .
                th:BrownPlace (browns.Code)
                        a geo:Point
                                as virtrdf:Brown-Place;
                        dc:title browns.Room
                            as virtrdf:Brown-Room
                            .

                th:Cmu (cmus.Code, cmus.Sec)
                    a th:Course
                        as virtrdf:Cmu-Course ;
                    dc:title cmus.CourseTitle
                        as virtrdf:Cmu-CourseTitle ;
                        th:hasInstructor th:CmuInstructor (cmus.Code, cmus.Sec)
                            as virtrdf:Cmu-hasInstructor ;
                        th:hasLecture th:CmuLecture(cmus.Code, cmus.Sec)
                            as virtrdf:Cmu-hasLecture ;
                        th:hasUnits cmus.Units
                            as virtrdf:Cmu-hasUnits ;
                        th:forUniversity "http://purl.org/thalia/university/cmu"
                            as virtrdf:Cmu-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                            as virtrdf:Cmu-Subject
                        .
        th:CmuInstructor (cmus.Code, cmus.Sec)
                        a th:Instructor
                                as virtrdf:Cmu-Instructor ;
                    foaf:name cmus.Lecturer
                        as virtrdf:Cmu-Lecturer
                            .
        th:CmuLecture (cmus.Code, cmus.Sec)
                        a event:Event
                                as virtrdf:Cmu-Lecture ;
                        event:time th:CmuEventTime(cmus.Code, cmus.Sec)
                            as virtrdf:Cmu-hasEventTime ;
                        event:place th:CmuPlace(cmus.Code, cmus.Sec)
                            as virtrdf:Cmu-hasPlace
                            .
        th:CmuPlace (cmus.Code, cmus.Sec)
                        a geo:Point
                                as virtrdf:Cmu-Place;
                        dc:title cmus.Room
                            as virtrdf:Cmu-Room
                            .
        th:CmuEventTime (cmus.Code, cmus.Sec)
                        a time:Interval
                                as virtrdf:Cmu-EventTime;
                        time:inDateTime th:CmuDatetime(cmus.Code, cmus.Sec)
                            as virtrdf:Cmu-inDateTime
                            .
        th:CmuDatetime (cmus.Code, cmus.Sec)
                        a time:DateTimeDescription
                                as virtrdf:Cmu-Datetime;
                    time:dayOfWeek cmus.Day_
                        as virtrdf:Cmu-Day ;
                    time:hour cmus.Time_
                        as virtrdf:Cmu-Time
                            .

                th:Gatech (gatechs.Department, gatechs.Code, gatechs.Section)
                    a th:Course
                        as virtrdf:Gatech-Course ;
                    dc:title gatechs.Title
                        as virtrdf:Gatech-Title ;
                        th:hasInstructor th:GatechInstructor(gatechs.Department, gatechs.Code, gatechs.Section)
                            as virtrdf:Gatech-hasInstructor ;
                    dc:description gatechs.Description
                        as virtrdf:Gatech-Description ;
                        th:hasLecture th:GatechLecture(gatechs.Department, gatechs.Code, gatechs.Section)
                            as virtrdf:Gatech-hasLecture ;
                        th:forUniversity "http://purl.org/thalia/university/gatech"
                            as virtrdf:Gatech-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                            as virtrdf:Gatech-Subject
                            .
        th:GatechInstructor (gatechs.Department, gatechs.Code, gatechs.Section)
                        a th:Instructor
                                as virtrdf:Gatech-Instructor ;
                    foaf:name gatechs.Instructor
                        as virtrdf:Gatech-InstructorName
                .
        th:GatechLecture (gatechs.Department, gatechs.Code, gatechs.Section)
                        a event:Event
                                as virtrdf:Gatech-Lecture ;
                        event:time th:GatechEventTime(gatechs.Department, gatechs.Code, gatechs.Section)
                            as virtrdf:Gatech-hasEventTime ;
                        event:place th:GatechPlace(gatechs.Department, gatechs.Code, gatechs.Section)
                            as virtrdf:Gatech-hasPlace
                .
        th:GatechEventTime (gatechs.Department, gatechs.Code, gatechs.Section)
                        a time:Interval
                                as virtrdf:Gatech-EventTime ;
                        time:inDateTime th:GatechDatetime(gatechs.Department, gatechs.Code, gatechs.Section)
                            as virtrdf:Gatech-inDateTime
                .
        th:GatechDatetime (gatechs.Department, gatechs.Code, gatechs.Section)
                        a time:DateTimeDescription
                                as virtrdf:Gatech-Datetime ;
                    time:dayOfWeek gatechs.Days
                        as virtrdf:Gatech-Days ;
                    time:hour gatechs.Time_
                        as virtrdf:Gatech-Time_
                .
        th:GatechPlace (gatechs.Department, gatechs.Code, gatechs.Section)
                        a geo:Point
                                as virtrdf:Gatech-Place ;
                        dc:title gatechs.Place
                            as virtrdf:Gatech-RoomBuilding
                .

                th:Toronto (torontos.No_)
                        a th:Course
                                as virtrdf:Toronto-Course ;
                        dc:title torontos.title
                            as virtrdf:Toronto-Title ;
                        dc:description torontos.text_
                            as virtrdf:Toronto-Description ;
                        th:hasInstructor th:TorontoInstructor(torontos.No_)
                            as virtrdf:Toronto-hasInstructor ;
                        th:hasLecture th:TorontoLecture(torontos.No_)
                            as virtrdf:Toronto-hasLecture ;
                        rdfs:seeAlso torontos.coursewebsite
                            as virtrdf:Toronto-CourseWebSite ;
                        th:hasPrerequisite torontos.prereq
                            as virtrdf:Toronto-prereq ;
                        th:text torontos.text_
                            as virtrdf:Toronto-text;
                        th:forUniversity "http://purl.org/thalia/university/toronto"
                            as virtrdf:Toronto-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                            as virtrdf:Toronto-Subject
                            .
        th:TorontoInstructor (torontos.No_)
                        a th:Instructor
                                as virtrdf:Toronto-Instructor ;
                        foaf:name torontos.instructorName
                            as virtrdf:Toronto-InstructorName ;
                        foaf:mbox torontos.instructorEmail
                            as virtrdf:Toronto-InstructorEmail
                .
        th:TorontoLecture (torontos.No_)
                        a event:Event
                                as virtrdf:Toronto-Lecture ;
                        event:place th:TorontoPlace(torontos.No_)
                            as virtrdf:Toronto-hasPlace
                .
        th:TorontoPlace (torontos.No_)
                        a geo:Point
                                as virtrdf:Toronto-Place ;
                        dc:title torontos.location
                            as virtrdf:Toronto-Location
                .

                th:Ucsd (ucsds.Number)
                        a th:Course
                                as virtrdf:Ucsd-Course ;
                        dc:title ucsds.Title
                            as virtrdf:Ucsd-Title ;
                        th:hasInstructor1 th:UcsdInstructor1 (ucsds.Number)
                            as virtrdf:Ucsd-hasInstructor1 ;
                        th:hasInstructor2 th:UcsdInstructor2 (ucsds.Number)
                            as virtrdf:Ucsd-hasInstructor2 ;
                        th:hasInstructor3 th:UcsdInstructor3 (ucsds.Number)
                            as virtrdf:Ucsd-hasInstructor3 ;
                        th:forUniversity "http://purl.org/thalia/university/ucsd"
                            as virtrdf:Ucsd-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                            as virtrdf:Ucsd-Subject
                            .
                th:UcsdInstructor1 (ucsds.Number)
                        a th:Instructor
                                as virtrdf:Ucsd-Instructor1 ;
                        foaf:name ucsds.Fall2003
                            as virtrdf:Ucsd-Instructor-Fall2003
                            .
                th:UcsdInstructor2 (ucsds.Number)
                        a th:Instructor
                                as virtrdf:Ucsd-Instructor2 ;
                        foaf:name ucsds.Winter2004
                            as virtrdf:Ucsd-Instructor-Winter2004
                            .
                th:UcsdInstructor3 (ucsds.Number)
                        a th:Instructor
                                as virtrdf:Ucsd-Instructor3 ;
                        foaf:name ucsds.Spring2004
                            as virtrdf:Ucsd-Instructor-Spring2004
                            .

                th:Umd (umds.Code)
                    a th:Course
                        as virtrdf:Umd-Course ;
                    dc:title umds.CourseName
                        as virtrdf:Umd-Title ;
                        th:hasSection th:SectionTitle
                            as virtrdf:Umd-hasSection ;
                        th:hasLecture th:UmdLecture(umds.Code)
                            as virtrdf:Umd-hasLecture ;
                        th:forUniversity "http://purl.org/thalia/university/umd"
                            as virtrdf:Umd-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                            as virtrdf:Umd-Subject
                            .
        th:UmdLecture (umds.Code)
                        a event:Event
                                as virtrdf:Umd-Lecture ;
                        event:time th:UmdEventTime(umds.Code)
                            as virtrdf:Umd-hasEventTime
                .
        th:UmdEventTime (umds.Code)
                        a time:Interval
                                as virtrdf:Umd-EventTime ;
                        time:inDateTime th:UmdDatetime(umds.Code)
                            as virtrdf:Umd-inDateTime
                .
        th:UmdDatetime (umds.Code)
                        a time:DateTimeDescription
                                as virtrdf:Umd-Datetime ;
                    time:hour umds.SectionTime
                        as virtrdf:Umd-SectionTime
                .
        }
}
')
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'tut_th_%';
delete from db.dba.url_rewrite_rule where urr_rule like 'tut_th_%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_th_rule1',
    1,
    '([^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s%%01this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_th_rule2',
    1,
    '([^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/thalia%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_th_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%U',
    vector('path'),
    null,
    null,
    0,
    null
    );

create procedure DB.DBA.REMOVE_THALIA_RDF_DET()
{
  declare colid int;
  colid := DAV_SEARCH_ID('/DAV/Thalia', 'C');
  if (colid < 0)
    return;
  update WS.WS.SYS_DAV_COL set COL_DET=null where COL_ID = colid;
}
;

DB.DBA.REMOVE_THALIA_RDF_DET();

drop procedure DB.DBA.REMOVE_THALIA_RDF_DET;

create procedure DB.DBA.THALIA_MAKE_RDF_DET()
{
    declare uriqa_str varchar;
    uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
    uriqa_str := 'http://' || uriqa_str || '/thalia';
    DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/Thalia/RDFData/', uriqa_str, NULL);
    VHOST_REMOVE (lpath=>'/thalia/data/rdf');
    DB.DBA.VHOST_DEFINE (lpath=>'/thalia/data/rdf', ppath=>'/DAV/Thalia/RDFData/All/', is_dav=>1, vsp_user=>'dba');
}
;

DB.DBA.THALIA_MAKE_RDF_DET();

drop procedure DB.DBA.THALIA_MAKE_RDF_DET;

-- procedure to convert path to DET resource name
create procedure DB.DBA.THALIA_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  declare uriqa_str varchar;
  uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  uriqa_str := 'http://' || uriqa_str || '/thalia';
  iri := uriqa_str || replace(val, '/', '_');
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tut_th_rdf', 1,
    '/thalia/(.*)', vector('path'), 1,
    '/thalia/data/rdf/%U', vector('path'),
    'DB.DBA.THALIA_DET_REF',
    'application/rdf.xml',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tut_th_rule_list1',
    1,
    vector (
                'tut_th_rule1',
                'tut_th_rule2',
                'tut_th_rule3',
                'tut_th_rdf'
          ));

DB.DBA.VHOST_REMOVE (lpath=>'/thalia');
DB.DBA.VHOST_DEFINE (lpath=>'/thalia', ppath=>'/DAV/Thalia/', vsp_user=>'dba', is_dav=>1,
           is_brws=>0, opts=>vector ('url_rewrite', 'tut_th_rule_list1'));

create procedure DB.DBA.LOAD_THALIA_ONTOLOGY_FROM_DAV()
{
	declare content, urihost varchar;
	select cast (RES_CONTENT as varchar) into content from WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/Thalia/thalia.owl';
	DB.DBA.RDF_LOAD_RDFXML (content, 'http://demo.openlinksw.com/schemas/thalia#', 'http://demo.openlinksw.com/schemas/ThaliaOntology/1.0/');
	urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
	if (urihost = 'demo.openlinksw.com')
	{
		DB.DBA.VHOST_REMOVE (lpath=>'/schemas/thalia');
		DB.DBA.VHOST_DEFINE (lpath=>'/schemas/thalia', ppath=>'/DAV/Thalia/thalia.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
	}
}
;
DB.DBA.LOAD_THALIA_ONTOLOGY_FROM_DAV()
;
drop procedure DB.DBA.LOAD_THALIA_ONTOLOGY_FROM_DAV
;

DB.DBA.XML_SET_NS_DECL ('thalia', 'http://demo.openlinksw.com/schemas/thalia#', 2)
;


    * Demo : Thalia test queries


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?room
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
	      th:hasLecture ?lecture.
    ?lecture event:place [dc:title ?room].
    FILTER regex(?title, "Software Engineering")
}


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT ?day, ?hour ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
    th:hasLecture [event:time ?time];
    dc:title ?title.
    ?time time:inDateTime [time:dayOfWeek ?day];
    time:inDateTime [time:hour ?hour].
    FILTER regex(?title, "Computer Networks")
  }



#service:/sparql
#should-sponge:soft

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?Title;
              th:hasLecture ?lecture.
    ?lecture event:time [time:inDateTime ?dateTime].
    ?dateTime time:hour ?hour.
    FILTER regex(?Title, "Database System")
    FILTER regex(?hour, "1:30 - 2:50")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course ?instructor ?name
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              th:hasInstructor ?instructor.
    ?instructor foaf:name ?name.

  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?instructor
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
	      th:hasInstructor ?instructor;
	      dc:title  ?title.
    FILTER regex(?title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?instructor
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
              th:hasInstructor ?instructor.
    FILTER regex(?title, "Software")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT DISTINCT ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
              th:forUniversity 'http://purl.org/thalia/university/umd'.
    FILTER regex(?title, "Data Structures")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?Title;
              th:hasUnits ?credits.
    FILTER (xsd:integer(?credits) > 10)
    FILTER regex(?Title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FORM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
              th:forUniversity 'http://purl.org/thalia/university/umd'.
    FILTER regex(?title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?Title;
              th:hasUnits ?credits.
    FILTER (xsd:integer(?credits) > 10)
    FILTER regex(?Title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?text_
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
             dc:title ?title;
             th:text ?text_.
    FILTER regex(?title, "Verification")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX : <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:description ?description;
              th:forUniversity 'http://purl.org/thalia/university/gatech'.
    FILTER regex(?description, "JR")
  }
]]></programlisting>
</sect2>
<sect2 id="rdfviewsbusintmbr">
      <title>Musicbrainz to RDF</title>
<para>The following code creates the Musicbrainz RDF Views Deployment and Demo Scripts:</para>
<programlisting><![CDATA[
create text index on ZITGIST.MO.artist ("name") with key id;
create text index on ZITGIST.MO.artistalias ("name") with key id;
create text index on ZITGIST.MO.album ("name") with key id;
create text index on ZITGIST.MO.track ("name") with key id;
vt_batch_update (fix_identifier_case ('ZITGIST.MO.artist'), 'ON', NULL);
vt_batch_update (fix_identifier_case ('ZITGIST.MO.artistalias'), 'ON', NULL);
vt_batch_update (fix_identifier_case ('ZITGIST.MO.album'), 'ON', NULL);
vt_batch_update (fix_identifier_case ('ZITGIST.MO.track'), 'ON', NULL);
VT_INC_INDEX_DB_MO_artist ();
VT_INC_INDEX_DB_MO_artistalias ();
VT_INC_INDEX_DB_MO_album ();
VT_INC_INDEX_DB_MO_track ();
]]></programlisting>
<para>Note: Making sure that the graphs and views are deleting to clean Virtuoso from the old definitions</para>
<programlisting><![CDATA[
SPARQL
drop quad storage virtrdf:MBZROOT.
;

SPARQL
prefix mbz: <http://musibrainz.org/schemas/mbz#>
drop literal class mbz:duration
;

SPARQL
prefix mbz: <http://musibrainz.org/schemas/mbz#>
drop literal class mbz:created.
drop literal class mbz:official_iri.
drop literal class mbz:bootleg_iri.
drop literal class mbz:promotion_iri.
drop literal class mbz:album_iri.
drop literal class mbz:single_iri.
drop literal class mbz:ep_iri.
drop literal class mbz:compilation_iri.
drop literal class mbz:soundtrack_iri.
drop literal class mbz:spokenword_iri.
drop literal class mbz:interview_iri.
drop literal class mbz:audiobook_iri.
drop literal class mbz:live_iri.
drop literal class mbz:remix_iri.
;
]]></programlisting>
<para>The following SPARQL query will fix an issue Virtuoso has with its JSO system. Perform this query for now, the issue should be fixed in a future release</para>
<programlisting><![CDATA[
SPARQL define input:storage ""
DELETE FROM GRAPH (iri(bif:JSO_SYS_GRAPH NIL)) { ?s virtrdf:version ?o }
WHERE { graph `iri(bif:JSO_SYS_GRAPH NIL)` {?s virtrdf:version ?o}};
SPARQL_RELOAD_QM_GRAPH();
]]></programlisting>
<para>Creation of IRIs classes.</para>
<programlisting><![CDATA[
SPARQL

prefix mbz: <http://musibrainz.org/schemas/mbz#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix bio: <http://vocab.org/bio/0.1/#>
prefix rel: <http://vocab.org/relationship/#>
prefix mo: <http://purl.org/ontology/mo/>
prefix timeline: <http://purl.org/NET/c4dm/timeline.owl#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix sim: <http://purl.org/ontology/sim/>

create iri class mbz:artist_iri  "http://zitgist.com/music/artist/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:artist_birth_event_iri  "http://zitgist.com/music/artist/birth/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:artist_death_event_iri  "http://zitgist.com/music/artist/death/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:sim_link_iri  "http://zitgist.com/music/artist/simlink/%U" (in gid varchar not null) option (bijection) .

#create iri class mbz:band_iri  "http://zitgist.com/music/band/%U" (in gid varchar not null) option (bijection) .
#create iri class mbz:band_birth_event_iri  "http://zitgist.com/music/band/birth/%U" (in gid varchar not null) option (bijection) .
#create iri class mbz:band_death_event_iri  "http://zitgist.com/music/band/death/%U" (in gid varchar not null) option (bijection) .

create iri class mbz:record_iri  "http://zitgist.com/music/record/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:performance_iri  "http://zitgist.com/music/performance/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:composition_iri  "http://zitgist.com/music/composition/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:musicalwork_iri  "http://zitgist.com/music/musicalwork/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:sound_iri  "http://zitgist.com/music/sound/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:recording_iri  "http://zitgist.com/music/recording/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:signal_iri  "http://zitgist.com/music/signal/%U" (in gid varchar not null) option (bijection) .

create iri class mbz:track_iri  "http://zitgist.com/music/track/%U" (in gid varchar not null) option (bijection) .

create iri class mbz:image_iri  "http://ec1.images-amazon.com/images/P/%U.01.MZZZZZZZ.jpg" (in image varchar not null) option (bijection) .

create iri class mbz:amazon_asin_iri  "http://amazon.com/exec/obidos/ASIN/%U/searchcom07-20" (in gid varchar not null) option (bijection) .


create literal class mbz:created using
    function ZITGIST.MO.RECORD_CREATION_DATE (in datestring varchar) returns varchar,
    function ZITGIST.MO.RECORD_CREATION_DATE_INVERSE (in datestring varchar) returns varchar .

create iri class mbz:official_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_OFFICIAL (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/official') .

create iri class mbz:promotion_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_PROMOTION (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/promotion') .

create iri class mbz:bootleg_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_BOOTLEG (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/bootleg') .

create iri class mbz:album_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_ALBUM (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/album') .

create iri class mbz:single_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_SINGLE (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/single') .

create iri class mbz:ep_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_EP (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/ep') .

create iri class mbz:compilation_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_COMPILATION (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/compilation') .

create iri class mbz:soundtrack_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_SOUNDTRACK (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/soundtrack') .

create iri class mbz:spokenword_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_SPOKENWORD (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/spokenword') .

create iri class mbz:interview_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_INTERVIEW (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/interview') .

create iri class mbz:audiobook_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_AUDIOBOOK (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/audiobook') .

create iri class mbz:live_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_LIVE (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/live') .

create iri class mbz:remix_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_REMIX (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/remix') .

create iri class mbz:duration_iri  "http://zitgist.com/music/track/duration/%U" (in gid varchar not null) .

create literal class mbz:duration using
    function ZITGIST.MO.TRACK_DURATION (in duration integer) returns varchar ,
    function ZITGIST.MO.TRACK_DURATION_INVERSE (in durationXSD varchar) returns integer .

create iri class mbz:geoname_country_iri  "http://www.geonames.org/countries/#%U" (in country varchar not null) .

create iri class mbz:url_iri  "%s" (in url varchar not null) .
create iri class mbz:mbz_release_url_iri  "http://musicbrainz.org/release/%s.html" (in mbz_gid varchar not null) .
create iri class mbz:mbz_track_url_iri  "http://musicbrainz.org/track/%s.html" (in mbz_gid varchar not null) .
create iri class mbz:mbz_artist_url_iri  "http://musicbrainz.org/artist/%s.html" (in mbz_gid varchar not null) .
;
]]></programlisting>
<para><emphasis>List of functions used to compute some IRI classes:</emphasis></para>
<para>Note:These functions have been developed to handle some weird user cases of the Musicbrainz data model (like the Attribute column of the album table, etc).</para>
<programlisting><![CDATA[
create function ZITGIST.MO.TRACK_DURATION_INVERSE(in durationXSD varchar)
{
    return null;
};

create function ZITGIST.MO.TRACK_DURATION(in duration integer)
{
    declare minutes, seconds, milliseconds integer;

    minutes := ((duration / 1000) / 60);

    if(minutes >= 1)
    {
        minutes := cast(minutes as integer);
    }
    else
    {
        minutes := 0;
    }

    seconds := (duration / 1000) - (minutes * 60);

    if(seconds >= 1)
    {
        seconds := cast(seconds as integer);
    }

    milliseconds := duration - (seconds * 1000) - (minutes * 60000);

    return sprintf('PT%dM%dS', minutes, seconds);
}
;


create function ZITGIST.MO.RECORD_CREATION_DATE(in datestring varchar)
{
    return sprintf('%sT00:00:00Z', datestring);
};

create function ZITGIST.MO.RECORD_CREATION_DATE_INVERSE(in datestring varchar)
{
    declare pos integer;
    pos := locate('T00:00:00Z', datestring) - 1;
    return substring(datestring, 1, pos);
};


create function ZITGIST.MO.RECORD_ATTRIBUTE(in attribute integer, in attributes varchar)
{
    declare attributes_array any;

    attributes_array := split_and_decode(ltrim(rtrim(attributes, '}'), '{'), 0, '\0\0,');

    foreach(int attr in attributes_array) do
    {
        attr := cast(attr as integer);
        if(attr = attribute)
        {
            if(attr = 100) return 'http://purl.org/ontology/mo/official';
            if(attr = 101) return 'http://purl.org/ontology/mo/promotion';
            if(attr = 102) return 'http://purl.org/ontology/mo/bootleg';
            if(attr = 1)   return 'http://purl.org/ontology/mo/album';
            if(attr = 2)   return 'http://purl.org/ontology/mo/single';
            if(attr = 3)   return 'http://purl.org/ontology/mo/ep';
            if(attr = 4)   return 'http://purl.org/ontology/mo/compilation';
            if(attr = 5)   return 'http://purl.org/ontology/mo/soundtrack';
            if(attr = 6)   return 'http://purl.org/ontology/mo/spokenword';
            if(attr = 7)   return 'http://purl.org/ontology/mo/interview';
            if(attr = 8)   return 'http://purl.org/ontology/mo/audiobook';
            if(attr = 9)   return 'http://purl.org/ontology/mo/live';
            if(attr = 10)  return 'http://purl.org/ontology/mo/remix';
        }
    }
    return null;
}
;

create function ZITGIST.MO.RECORD_ATTRIBUTE_OFFICIAL(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(100, attributes); }
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_PROMOTION(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(101, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_BOOTLEG(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(102, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_ALBUM(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(1, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_SINGLE(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(2, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_EP(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(3, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_COMPILATION(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(4, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_SOUNDTRACK(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(5, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_SPOKENWORD(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(6, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_INTERVIEW(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(7, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_AUDIOBOOK(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(8, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_LIVE(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(9, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_REMIX(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(10, attributes);}
;
]]></programlisting>
<para><emphasis>Definition of the quad map patterns</emphasis></para>
<para>This what creates the RDF triples from the musicbrainz relational database schema.</para>
<programlisting><![CDATA[
SPARQL
prefix mbz: <http://musibrainz.org/schemas/mbz#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dcterms: <http://purl.org/dc/terms/>
prefix bio: <http://vocab.org/bio/0.1/#>
prefix rel: <http://vocab.org/relationship/#>
prefix mo: <http://purl.org/ontology/mo/>
prefix timeline: <http://purl.org/NET/c4dm/timeline.owl#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix sim: <http://purl.org/ontology/sim/>

create quad storage virtrdf:MBZROOT


#
# Definition of the source tables from the mbz relational database and their joints.
#########

FROM ZITGIST.MO.track as track text literal name
FROM ZITGIST.MO.artist as track_artist
FROM ZITGIST.MO.puid as track_puid
FROM ZITGIST.MO.track as track_track
FROM ZITGIST.MO.url as track_url

FROM ZITGIST.MO.artist as track_artist_creator where (^{track.}^.artist = ^{track_artist_creator.}^.id)

FROM ZITGIST.MO.albumjoin as track_albumjoin where (^{track.}^.id = ^{track_albumjoin.}^.track)

FROM ZITGIST.MO.l_artist_track as l_artist_track2 where (^{track.}^.id = ^{l_artist_track2.}^.link1)
                                                      where (^{track_artist.}^.id = ^{l_artist_track2.}^.link0)


FROM ZITGIST.MO.puidjoin as puidjoin where (^{track.}^.id = ^{puidjoin.}^.track)
                                         where (^{puidjoin.}^.puid = ^{track_puid.}^.id)


FROM ZITGIST.MO.l_track_track as l_track_track where (^{track.}^.id = ^{l_track_track.}^.link0)
                                                   where (^{track_track.}^.id = ^{l_track_track.}^.link1)


FROM ZITGIST.MO.l_track_url as l_track_url where (^{track.}^.id = ^{l_track_url.}^.link0)
                                               where (^{track_url.}^.id = ^{l_track_url.}^.link1)



FROM ZITGIST.MO.album as album text literal name
FROM ZITGIST.MO.artist as album_artist
FROM ZITGIST.MO.album as album_album
FROM ZITGIST.MO.url as album_url
FROM ZITGIST.MO.country as album_release_country
FROM ZITGIST.MO.track as album_albumjoin_track

FROM ZITGIST.MO.artist as album_artist_creator where (^{album.}^.artist = ^{album_artist_creator.}^.id)

FROM ZITGIST.MO.album_amazon_asin as album_amazon_asin where (^{album.}^.id = ^{album_amazon_asin.}^.album)


FROM ZITGIST.MO.albumjoin as album_albumjoin where (^{album.}^.id = ^{album_albumjoin.}^.album)
                                                 where (^{album_albumjoin.}^.track = ^{album_albumjoin_track.}^.id)


FROM ZITGIST.MO.l_album_artist as l_album_artist2 where (^{album.}^.id = ^{l_album_artist2.}^.link0)
                                                      where (^{album_artist.}^.id = ^{l_album_artist2.}^.link1)


FROM ZITGIST.MO.l_album_album as l_album_album where (^{album.}^.id = ^{l_album_album.}^.link0)
                                                   where (^{album_album.}^.id = ^{l_album_album.}^.link1)


FROM ZITGIST.MO.l_album_url as l_album_url where (^{album.}^.id = ^{l_album_url.}^.link0)
                                               where (^{album_url.}^.id = ^{l_album_url.}^.link1)


FROM ZITGIST.MO.release as album_release where (^{album.}^.id = ^{album_release.}^.album)
                                             where (^{album_release.}^.country = ^{album_release_country.}^.id)





FROM ZITGIST.MO.artist as sim_band
FROM ZITGIST.MO.artist as sim_artist
FROM ZITGIST.MO.url as band_url
FROM ZITGIST.MO.artist as band_member
FROM ZITGIST.MO.album as band_album
FROM ZITGIST.MO.track as band_track
FROM ZITGIST.MO.artist as band text literal name where (^{band.}^.type = 2)
#FROM ZITGIST.MO.artist as artist text literal name where (^{artist.}^.type <> 2)
FROM ZITGIST.MO.artist as artist text literal name where (__or (neq(^{artist.}^.type, 2), isnull (^{artist.}^.type)))
FROM ZITGIST.MO.artist as artist_untyped text literal name where (^{artist_untyped.}^.type <> 2)
                                                      where (^{artist.}^.gid = ^{artist_untyped.}^.gid)



FROM ZITGIST.MO.album as band_album_creatorOf where (^{band_album_creatorOf.}^.artist = ^{band.}^.id)
FROM ZITGIST.MO.track as band_track_creatorOf where (^{band_track_creatorOf.}^.artist = ^{band.}^.id)

FROM ZITGIST.MO.artistalias as bandalias text literal name where (^{band.}^.id = ^{bandalias.}^."ref")

FROM ZITGIST.MO.l_artist_artist as band_l_artist_artist where (^{band_member.}^.id = ^{band_l_artist_artist.}^.link0)
                                                            where (^{band.}^.id = ^{band_l_artist_artist.}^.link1)
                                                            where (^{band_l_artist_artist.}^.link_type = 2)


FROM ZITGIST.MO.artist_relation as band_relation
where (^{artist.}^.id = ^{band_relation.}^.artist)
where (^{band.}^.id = ^{band_relation.}^.artist)
where (^{sim_band.}^.id = ^{band_relation.}^."ref")

FROM ZITGIST.MO.artist_relation as artist_relation
where (^{artist.}^.id = ^{artist_relation.}^.artist)
where (^{band.}^.id = ^{artist_relation.}^.artist)
where (^{sim_artist.}^.id = ^{artist_relation.}^."ref")



FROM ZITGIST.MO.l_artist_url as l_artist_url3 where (^{band.}^.id = ^{l_artist_url3.}^.link0)
                                                  where (^{band_url.}^.id = ^{l_artist_url3.}^.link1)


FROM ZITGIST.MO.l_album_artist as l_album_artist3 where (^{band.}^.id = ^{l_album_artist3.}^.link1)
                                                      where (^{band_album.}^.id = ^{l_album_artist3.}^.link0)


FROM ZITGIST.MO.l_artist_track as l_artist_track3 where (^{band.}^.id = ^{l_artist_track3.}^.link0)
                                                      where (^{band_track.}^.id = ^{l_artist_track3.}^.link1)

FROM ZITGIST.MO.url as artist_url
FROM ZITGIST.MO.artist as artist_artist
FROM ZITGIST.MO.track as artist_track
FROM ZITGIST.MO.album as artist_album

FROM ZITGIST.MO.album as artist_album_creatorOf where (^{artist_album_creatorOf.}^.artist = ^{artist.}^.id)
FROM ZITGIST.MO.track as artist_track_creatorOf where (^{artist_track_creatorOf.}^.artist = ^{artist.}^.id)

FROM ZITGIST.MO.artistalias as artistalias text literal name where (^{artist.}^.id = ^{artistalias.}^."ref")
FROM ZITGIST.MO.l_artist_url as l_artist_url where (^{artist.}^.id = ^{l_artist_url.}^.link0)
                                                 where (^{artist_url.}^.id = ^{l_artist_url.}^.link1)

FROM ZITGIST.MO.l_artist_artist as l_artist_artist where (^{artist.}^.id = ^{l_artist_artist.}^.link0)
                                                       where (^{artist_artist.}^.id = ^{l_artist_artist.}^.link1)

FROM ZITGIST.MO.l_artist_track as l_artist_track where (^{artist.}^.id = ^{l_artist_track.}^.link0)
                                                     where (^{artist_track.}^.id = ^{l_artist_track.}^.link1)
FROM ZITGIST.MO.l_album_artist as l_album_artist where (^{artist.}^.id = ^{l_album_artist.}^.link1)
                                                     where (^{artist_album.}^.id = ^{l_album_artist.}^.link0)

{
  create virtrdf:MBZ as graph iri ("http://musicbrainz.org/") option (exclusive)
    {

        # Track Composition Event
        mbz:composition_iri (track.gid)
            a mo:Composition as mbz:track_is_composition;
            dc:title track.name as mbz:title_of_track;
            mo:composer mbz:artist_iri (track_artist_creator.gid) as mbz:creator_composer_of_track;
            mo:composer mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 14) option (using l_artist_track2) as mbz:composer14_of_track;
            mo:producesWork mbz:musicalwork_iri (track.gid) as mbz:track_producesWork.

        # Track Musical Work
        mbz:musicalwork_iri (track.gid)
            a mo:MusicalWork as mbz:track_is_mw;
            dc:title track.name as mbz:name_of_mw;

            mo:productOfComposition mbz:composition_iri(track.gid) as mbz:mw_is_productOfComposition_of;
            mo:usedInPerformance mbz:performance_iri(track.gid) as mbz:mw_usedInPerformance.

        # Track Performance Event
        mbz:performance_iri (track.gid)
            a mo:Performance;
            dc:title track.name;
            mo:performer mbz:artist_iri (track_artist_creator.gid);
            mo:performer mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 2) option (using l_artist_track2);
            mo:conductor mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 9) option (using l_artist_track2);

            mo:usesWork mbz:musicalwork_iri (track.gid);
            mo:producesSound mbz:sound_iri (track.gid);

            mo:recordedAs mbz:signal_iri(track.gid).

        # Track Sound
        mbz:sound_iri (track.gid)
            a mo:Sound;
            dc:title track.name;

            mo:productOfPerformance mbz:performance_iri (track.gid);
            mo:usedInRecording mbz:recording_iri (track.gid).

        # Track Recording Event
        mbz:recording_iri (track.gid)
            a mo:Recording;
            dc:title track.name;

            mo:recordsSound mbz:sound_iri (track.gid);
            mo:producesSignal mbz:signal_iri (track.gid).

        # Track Signal (Musical Expression)
        mbz:signal_iri (track.gid)
            a mo:Signal;
            dc:title track.name;

            mo:remixer mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 11) option (using l_artist_track2);
            mo:sampler mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 12) option (using l_artist_track2);
            mo:djmixed mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 40) option (using l_artist_track2);

            mo:djmix_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 13) option (using l_track_track);
            mo:remix_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 6) option (using l_track_track);
            mo:remix_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 11) option (using l_track_track);
            mo:mashup_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 8) option (using l_track_track);
            mo:mashup_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 4) option (using l_track_track);
            mo:remaster_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 3) option (using l_track_track);
            mo:compilation_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 10) option (using l_track_track);
            mo:compilation_of mbz:track_iri (track_track.gid) where (^{l_track_track.}^.link_type = 12) option (using l_track_track);
            mo:medley_of mbz:record_iri (track_track.gid) where (^{l_track_track.}^.link_type = 14) option (using l_track_track);

            mo:published_as mbz:track_iri (track.gid);
            mo:signalTime mbz:duration_iri(track.gid);
            mo:puid track_puid.puid option (using puidjoin).

        # Track duration
        mbz:duration_iri(track.gid)
            a timeline:Interval;
            timeline:durationXSD mbz:duration(track.length).


        mbz:track_iri(track.gid)
            a mo:Track;
            dc:title track.name;

            mo:trackNum track_albumjoin.sequence;


            dc:creator mbz:artist_iri (track_artist_creator.gid);
            dc:creator mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 14) option (using l_artist_track2);
			mo:compiler mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 39) option (using l_artist_track2);
            mo:producer mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 18) option (using l_artist_track2);
            mo:publisher mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 35) option (using l_artist_track2);
            mo:engineer mbz:artist_iri (track_artist.gid) where (^{l_artist_track2.}^.link_type = 19) option (using l_artist_track2);


            mo:licence mbz:url_iri(track_url.url) where (^{l_track_url.}^.link_type = 21) option (using l_track_url);
            mo:paiddownload mbz:url_iri(track_url.url) where (^{l_track_url.}^.link_type = 16) option (using l_track_url);
            mo:freedownload mbz:url_iri(track_url.url) where (^{l_track_url.}^.link_type = 17) option (using l_track_url);
            mo:olga mbz:url_iri(track_url.url) where (^{l_track_url.}^.link_type = 19) option (using l_track_url);

            mo:musicbrainz mbz:mbz_track_url_iri(track.gid);

            mo:duration track.length.

        # Record Composition Event
        mbz:composition_iri (album.gid)
            a mo:Composition;
            dc:title album.name;

            mo:composer mbz:artist_iri (album_artist_creator.gid);
            mo:composer mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 14) option (using l_album_artist2);

            mo:producesWork mbz:musicalwork_iri (album.gid).

        # Record Musical Work
        mbz:musicalwork_iri (album.gid)
            a mo:MusicalWork;
            dc:title album.name;

            mo:productOfComposition mbz:composition_iri(album.gid);
            mo:usedInPerformance mbz:performance_iri(album.gid).


        # Record Performance Event
        mbz:performance_iri (album.gid)
            a mo:Performance;
            dc:title album.name;
            mo:performer mbz:artist_iri (album_artist_creator.gid);
            mo:performer mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 2) option (using l_album_artist2);
            mo:conductor mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 9) option (using l_album_artist2);

            mo:usesWork mbz:musicalwork_iri (album.gid);
            mo:producesSound mbz:sound_iri (album.gid);

            mo:recordedAs mbz:record_iri(album.gid).


        # Record Sound
        mbz:sound_iri (album.gid)
            a mo:Sound;
            dc:title album.name;

            mo:productOfPerformance mbz:performance_iri (album.gid);
            mo:usedInRecording mbz:recording_iri (album.gid).

        # Record Recording Event
        mbz:recording_iri (album.gid)
            a mo:Recording;
            dc:title album.name;

            mo:recordsSound mbz:sound_iri (album.gid);
            mo:producesSignal mbz:signal_iri (album.gid).

        # Record Signal (Musical Expression)
        mbz:signal_iri (album.gid)
            a mo:Signal;
            dc:title album.name;

            mo:djmix_of mbz:record_iri (album_album.gid) where (^{l_album_album.}^.link_type = 9) option (using l_album_album);
            mo:remix_of mbz:record_iri (album_album.gid) where (^{l_album_album.}^.link_type = 7) option (using l_album_album);
            mo:remix_of mbz:record_iri (album_album.gid) where (^{l_album_album.}^.link_type = 4) option (using l_album_album);
            mo:mashup_of mbz:record_iri (album_album.gid) where (^{l_album_album.}^.link_type = 5) option (using l_album_album);
            mo:remaster_of mbz:record_iri (album_album.gid) where (^{l_album_album.}^.link_type = 3) option (using l_album_album);
            mo:tribute_to mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 44) option (using l_album_artist2);

            mo:remixer mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 11) option (using l_album_artist2);
            mo:djmixed mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 38) option (using l_album_artist2);
            mo:sampler mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 12) option (using l_album_artist2);

            mo:published_as mbz:record_iri (album.gid).


        # Record (Musical Manifestation)
        mbz:record_iri (album.gid)
            a mo:Record;
            dc:title album.name;

            dc:date mbz:created(album_release.releasedate);
            mo:image mbz:image_iri(album_amazon_asin.asin);

            #Empty for now.
            mo:compilation_of mbz:record_iri (album_album.gid) where (^{l_album_album.}^.link_type = 8) option (using l_album_album);
            mo:releaseStatus mbz:official_iri(album.attributes);
            mo:releaseStatus mbz:promotion_iri(album.attributes);
            mo:releaseStatus mbz:bootleg_iri(album.attributes);

            mo:releaseType mbz:album_iri(album.attributes);
            mo:releaseType mbz:single_iri(album.attributes);
            mo:releaseType mbz:ep_iri(album.attributes);
            mo:releaseType mbz:compilation_iri(album.attributes);
            mo:releaseType mbz:soundtrack_iri(album.attributes);
            mo:releaseType mbz:spokenword_iri(album.attributes);
            mo:releaseType mbz:interview_iri(album.attributes);
            mo:releaseType mbz:audiobook_iri(album.attributes);
            mo:releaseType mbz:live_iri(album.attributes);
            mo:releaseType mbz:remix_iri(album.attributes);


            dc:creator mbz:artist_iri (album_artist_creator.gid);
            dc:creator mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 14) option (using l_album_artist2);

            mo:compiler mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 41) option (using l_album_artist2);
            mo:producer mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 18) option (using l_album_artist2);
            mo:publisher mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 35) option (using l_album_artist2);
            mo:engineer mbz:artist_iri (album_artist.gid) where (^{l_album_artist2.}^.link_type = 19) option (using l_album_artist2);


            mo:musicbrainz mbz:mbz_release_url_iri(album.gid);

            mo:musicmoz mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 25) option (using l_album_url);
            mo:discogs mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 24) option (using l_album_url);
            mo:wikipedia mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 23) option (using l_album_url);
            mo:discography mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 1) option (using l_album_url);
            mo:freedownload mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 21) option (using l_album_url);
            mo:discography mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 16) option (using l_album_url);
            mo:mailorder mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 19) option (using l_album_url);
            mo:imdb mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 27) option (using l_album_url);
            mo:paiddownload mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 20) option (using l_album_url);
            mo:licence mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 32) option (using l_album_url);
            mo:review mbz:url_iri(album_url.url) where (^{l_album_url.}^.link_type = 17) option (using l_album_url);


            mo:amazon_asin mbz:amazon_asin_iri(album_amazon_asin.asin);

            mo:has_track mbz:track_iri (album_albumjoin_track.gid) option (using album_albumjoin).

       # Music Group (Band)
#       mbz:band_iri(band.gid)
        mbz:artist_iri(band.gid)
            a mo:MusicArtist;
            a mo:MusicGroup;
            a foaf:Group;
            foaf:name band.name;
            foaf:nick bandalias.name;

#           bio:event mbz:band_birth_event_iri(band.gid);
#           bio:event mbz:band_death_event_iri(band.gid);
            bio:event mbz:artist_birth_event_iri(band.gid);
            bio:event mbz:artist_death_event_iri(band.gid);

#           mo:similar_to mbz:band_iri(sim_band.gid) option (using band_relation);
            mo:similar_to mbz:artist_iri(sim_band.gid) option (using band_relation);
            mo:similar_to mbz:artist_iri(sim_artist.gid) option (using artist_relation);
#            sim:link mbz:sim_link_iri(sim_band.gid)  option (using band_relation);
#            sim:link mbz:sim_link_iri(sim_artist.gid)  option (using artist_relation);

            foaf:member mbz:artist_iri(band_member.gid) option (using band_l_artist_artist);

            # l_artist_url
            mo:myspace mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 19) option (using l_artist_url3);
            mo:musicmoz mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 12) option (using l_artist_url3);
            mo:discogs mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 11) option (using l_artist_url3);
            mo:wikipedia mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 10) option (using l_artist_url3);
            mo:discography mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 1) option (using l_artist_url3);
            mo:freedownload mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 8) option (using l_artist_url3);
            mo:fanpage mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 3) option (using l_artist_url3);
            mo:biography mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 4) option (using l_artist_url3);
            mo:discography mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 5) option (using l_artist_url3);
            mo:mailorder mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 15) option (using l_artist_url3);
            mo:imdb mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 17) option (using l_artist_url3);
            mo:paiddownload mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 7) option (using l_artist_url3);
            foaf:depiction mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 14) option (using l_artist_url3);
            foaf:homepage mbz:url_iri(band_url.url) where (^{l_artist_url3.}^.link_type = 2) option (using l_artist_url3);

            mo:musicbrainz mbz:mbz_artist_url_iri(band.gid);


            # l_album_artist
            mo:composed mbz:composition_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 14) option (using l_album_artist3);
            mo:performed mbz:performance_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 14) option (using l_album_artist3);
            mo:performed mbz:performance_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 2) option (using l_album_artist3);
            mo:conducted mbz:performance_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 9) option (using l_album_artist3);
            mo:compiled mbz:record_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 41) option (using l_album_artist3);
            mo:djmixed mbz:record_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 38) option (using l_album_artist3);
            mo:remixed mbz:record_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 11) option (using l_album_artist3);
            mo:sampled mbz:record_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 12) option (using l_album_artist3);
            mo:produced mbz:record_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 18) option (using l_album_artist3);
            mo:published mbz:record_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 35) option (using l_album_artist3);
            mo:engineered mbz:record_iri (band_album.gid) where (^{l_album_artist3.}^.link_type = 19) option (using l_album_artist3);

#    #      mo:creatorOfRecord mbz:record_iri(band_album_creatorOf.gid);
            foaf:made mbz:record_iri(band_album_creatorOf.gid);

            # l_artist_track
            mo:composed mbz:composition_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 14) option (using l_artist_track3);
            mo:performed mbz:performance_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 14) option (using l_artist_track3);
            mo:performed mbz:performance_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 2) option (using l_artist_track3);
            mo:conducted mbz:performance_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 9) option (using l_artist_track3);
            mo:compiled mbz:record_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 39) option (using l_artist_track3);
            mo:djmixed mbz:track_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 40) option (using l_artist_track3);
            mo:remixed mbz:track_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 11) option (using l_artist_track3);
            mo:sampled mbz:track_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 12) option (using l_artist_track3);
            mo:produced mbz:track_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 18) option (using l_artist_track3);
            mo:published mbz:track_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 35) option (using l_artist_track3);
            mo:engineered mbz:track_iri (band_track.gid) where (^{l_artist_track3.}^.link_type = 19) option (using l_artist_track3).

#    #      mo:creatorOfTrack mbz:track_iri(band_track_creatorOf.gid).




        # Music Group (Band)'s Birth Event
#       mbz:band_birth_event_iri(band.gid)
        mbz:artist_birth_event_iri(band.gid)
            a bio:Birth;
            bio:date band.begindate.

        # Music Group (Band)'s Death Event
#       mbz:band_death_event_iri(band.gid)
        mbz:artist_death_event_iri(band.gid)
            a bio:Death;
            bio:date band.enddate.

        # Similarity link
        #mbz:sim_link_iri(sim_band.gid)
        #    sim:relation mo:similar_to;
        #    sim:level band_relation.weight;
        #    sim:to sim_band.gid.


        # Music Artist
        mbz:artist_iri (artist.gid)

            # artist
            a mo:MusicArtist;
            a mo:SoloMusicArtist where (^{artist_untyped.}^.gid is not null) option (using artist_untyped);
            a foaf:Person where (^{artist_untyped.}^.gid is not null) option (using artist_untyped);
            foaf:name artist.name;
            foaf:nick artistalias.name;
            bio:event mbz:artist_birth_event_iri(artist.gid);
            bio:event mbz:artist_death_event_iri(artist.gid);

            mo:member_of mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 2) option (using l_artist_artist);

            # l_artist_artist
            rel:siblingOf mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 7) option (using l_artist_artist);
            rel:friendOf mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 5) option (using l_artist_artist);
            rel:parentOf mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 6) option (using l_artist_artist);
            rel:collaborated_with mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 11) option (using l_artist_artist);
            rel:engagedTo mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 9) option (using l_artist_artist);
            rel:spouseOf mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 8) option (using l_artist_artist);
            mo:supporting_musician mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 13) option (using l_artist_artist);
            mo:supporting_musician mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 14) option (using l_artist_artist);
            mo:supporting_musician mbz:artist_iri(artist_artist.gid) where (^{l_artist_artist.}^.link_type = 15) option (using l_artist_artist);

            mo:similar_to mbz:artist_iri(sim_artist.gid) option (using artist_relation);
#           mo:similar_to mbz:band_iri(sim_band.gid) option (using band_relation);
            mo:similar_to mbz:artist_iri(sim_band.gid) option (using band_relation);

#            sim:link mbz:sim_link_iri(sim_band.gid)  option (using band_relation);
#            sim:link mbz:sim_link_iri(sim_artist.gid)  option (using artist_relation);


            # l_artist_url
            mo:myspace mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 19) option (using l_artist_url);
            mo:musicmoz mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 12) option (using l_artist_url);
            mo:discogs mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 11) option (using l_artist_url);
            mo:wikipedia mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 10) option (using l_artist_url);
            mo:discography mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 1) option (using l_artist_url);
            mo:freedownload mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 8) option (using l_artist_url);
            mo:fanpage mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 3) option (using l_artist_url);
            mo:biography mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 4) option (using l_artist_url);
            mo:discography mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 5) option (using l_artist_url);
            mo:mailorder mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 15) option (using l_artist_url);
            mo:imdb mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 17) option (using l_artist_url);
            mo:paiddownload mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 7) option (using l_artist_url);
            foaf:depiction mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 14) option (using l_artist_url);
            foaf:homepage mbz:url_iri(artist_url.url) where (^{l_artist_url.}^.link_type = 2) option (using l_artist_url);

            mo:musicbrainz mbz:mbz_artist_url_iri(artist.gid);


            # l_album_artist
            mo:composed mbz:composition_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 14) option (using l_album_artist);
            mo:performed mbz:performance_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 14) option (using l_album_artist);
            mo:performed mbz:performance_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 2) option (using l_album_artist);
            mo:conducted mbz:performance_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 9) option (using l_album_artist);
            mo:compiled mbz:record_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 41) option (using l_album_artist);
            mo:djmixed mbz:record_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 38) option (using l_album_artist);
            mo:remixed mbz:record_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 11) option (using l_album_artist);
            mo:sampled mbz:record_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 12) option (using l_album_artist);
            mo:produced mbz:record_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 18) option (using l_album_artist);
            mo:published mbz:record_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 35) option (using l_album_artist);
            mo:engineered mbz:record_iri (artist_album.gid) where (^{l_album_artist.}^.link_type = 19) option (using l_album_artist);

     #      mo:creatorOfRecord mbz:record_iri(artist_album_creatorOf.gid);
            foaf:made mbz:record_iri(artist_album_creatorOf.gid);


            # l_artist_track
            mo:composed mbz:composition_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 14) option (using l_artist_track);
            mo:performed mbz:performance_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 14) option (using l_artist_track);
            mo:performed mbz:performance_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 2) option (using l_artist_track);
            mo:conducted mbz:performance_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 9) option (using l_artist_track);
            mo:compiled mbz:track_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 39) option (using l_artist_track);
            mo:djmixed mbz:track_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 40) option (using l_artist_track);
            mo:remixed mbz:track_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 11) option (using l_artist_track);
            mo:sampled mbz:track_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 12) option (using l_artist_track);
            mo:produced mbz:track_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 18) option (using l_artist_track);
            mo:published mbz:track_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 35) option (using l_artist_track);
            mo:engineered mbz:track_iri (artist_track.gid) where (^{l_artist_track.}^.link_type = 19) option (using l_artist_track).

     #       mo:creatorOfTrack mbz:track_iri(artist_track_creatorOf.gid).


        # Music Artist''s Birth Event
        mbz:artist_birth_event_iri(artist.gid)
            a bio:Birth;
            bio:date artist.begindate.

        # Music Artist''s Death Event
        mbz:artist_death_event_iri(artist.gid)
            a bio:Death;
            bio:date artist.enddate.

        # Similarity link
        #mbz:sim_link_iri(sim_artist.gid)
        #    sim:relation mo:similar_to;
        #    sim:level artist_relation.weight;
        #    sim:to sim_artist.gid.

        }
  }
;


grant execute on ZITGIST.MO.RECORD_CREATION_DATE to "SPARQL";
grant execute on ZITGIST.MO.RECORD_CREATION_DATE_INVERSE to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_OFFICIAL to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_PROMOTION to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_BOOTLEG to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_ALBUM to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_SINGLE to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_EP to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_COMPILATION to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_SOUNDTRACK to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_SPOKENWORD to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_INTERVIEW to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_AUDIOBOOK to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_LIVE to "SPARQL";
grant execute on ZITGIST.MO.RECORD_ATTRIBUTE_REMIX to "SPARQL";
grant execute on ZITGIST.MO.TRACK_DURATION to "SPARQL";
grant execute on ZITGIST.MO.TRACK_DURATION_INVERSE to "SPARQL";
grant execute on ZITGIST.MO.album_amazon_asin to "SPARQL";
grant execute on ZITGIST.MO.album_name_WORDS to "SPARQL";
grant execute on ZITGIST.MO.albumjoin to "SPARQL";
grant execute on ZITGIST.MO.albummeta to "SPARQL";
grant execute on ZITGIST.MO.artist to "SPARQL";
grant execute on ZITGIST.MO.artist_name_WORDS to "SPARQL";
grant execute on ZITGIST.MO.artist_relation to "SPARQL";
grant execute on ZITGIST.MO.artistalias to "SPARQL";
grant execute on ZITGIST.MO.artistalias_name_WORDS to "SPARQL";
grant execute on ZITGIST.MO.country to "SPARQL";
grant execute on ZITGIST.MO.l_album_album to "SPARQL";
grant execute on ZITGIST.MO.l_album_artist to "SPARQL";
grant execute on ZITGIST.MO.l_album_url to "SPARQL";
grant execute on ZITGIST.MO.l_artist_artist to "SPARQL";
grant execute on ZITGIST.MO.l_artist_track to "SPARQL";
grant execute on ZITGIST.MO.l_artist_url to "SPARQL";
grant execute on ZITGIST.MO.l_track_track to "SPARQL";
grant execute on ZITGIST.MO.l_track_url to "SPARQL";
grant execute on ZITGIST.MO."language" to "SPARQL";
grant execute on ZITGIST.MO.puid to "SPARQL";
grant execute on ZITGIST.MO.puidjoin to "SPARQL";
grant execute on ZITGIST.MO.release to "SPARQL";
grant execute on ZITGIST.MO.track to "SPARQL";
grant execute on ZITGIST.MO.track_name_WORDS to "SPARQL";
grant execute on ZITGIST.MO.url to "SPARQL";

DB.DBA.XML_SET_NS_DECL ('mbz', 'http://musibrainz.org/schemas/mbz#', 2);
]]></programlisting>
</sect2>
<sect2 id="rdfviewsbusintods">
      <title>Virtuoso ODS to RDF</title>
<para><emphasis>RDF View for ODS (the consolidated Graph)</emphasis></para>
<programlisting><![CDATA[
SPARQL drop quad map virtrdf:ODS_DS . ;

SPARQL prefix ods: <http://www.openlinksw.com/virtuoso/ods/>
       create iri class ods:graph "http://^{URIQADefaultHost}^/dataspace/%U" (in uname varchar not null)
			    option (returns "http://^{URIQADefaultHost}^/dataspace/%U") .
       create iri class ods:user "http://^{URIQADefaultHost}^/dataspace/%U#user" (in uname varchar not null)
			    option (returns "http://^{URIQADefaultHost}^/dataspace/%U#user") .
       create iri class ods:user_group "http://^{URIQADefaultHost}^/dataspace/%U#group" (in uname varchar not null)
			    option (returns "http://^{URIQADefaultHost}^/dataspace/%U#group") .
       create iri class ods:person "http://^{URIQADefaultHost}^/dataspace/%U#this" (in uname varchar not null)
			    option (returns "http://^{URIQADefaultHost}^/dataspace/%U#this") .
       create iri class ods:mbox "mailto:%s" (in email varchar not null)
			    option (returns "mailto:%s") .
       create iri class ods:phone "tel:%s" (in tel varchar not null)
       			    option (returns "tel:%s") .
       create iri class ods:geo_point "http://^{URIQADefaultHost}^/dataspace/%U#geo" (in uname varchar not null)
       			    option (returns "http://^{URIQADefaultHost}^/dataspace/%U#geo") .
       create iri class ods:forum "http://^{URIQADefaultHost}^/dataspace/%U/%U/%U"
	    ( in uname varchar not null, in forum_type varchar not null, in forum_name varchar not null)
	    		    option (returns "http://^{URIQADefaultHost}^/dataspace/%U/%U/%U") .
       create iri class ods:proxy "http://^{URIQADefaultHost}^/proxy/%U" (in url varchar not null)
       			    option (returns  "http://^{URIQADefaultHost}^/proxy/%U") .
       create iri class ods:site "http://^{URIQADefaultHost}^/dataspace/%U#site" (in uname varchar not null)
       			    option (returns "http://^{URIQADefaultHost}^/dataspace/%U#site") .
       create iri class ods:role "http://^{URIQADefaultHost}^/dataspace/%U/%U/%U#%U"
	    (in uname varchar not null, in tp varchar not null, in inst varchar not null, in role_name varchar not null)
			    option (returns  "http://^{URIQADefaultHost}^/dataspace/%U/%U/%U#%U" ) .
	# Blog
	create iri class ods:blog_forum "http://^{URIQADefaultHost}^/dataspace/%U/weblog/%U"
		(in uname varchar not null, in forum_name varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/weblog/%U") .
	create iri class ods:blog_post "http://^{URIQADefaultHost}^/dataspace/%U/weblog/%U/%U"
		(in uname varchar not null, in forum_name varchar not null, in postid varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/weblog/%U/%U" ) .
	create iri class ods:blog_comment "http://^{URIQADefaultHost}^/dataspace/%U/weblog/%U/%U/%d"
		(in uname varchar not null, in forum_name varchar not null, in postid varchar not null, in comment_id int not null)
 	        option (returns  "http://^{URIQADefaultHost}^/dataspace/%U/weblog/%U/%U/%d" ) .
	create iri class ods:tag "http://^{URIQADefaultHost}^/dataspace/%U/concept#%U"
		(in uname varchar not null, in tag varchar not null)
                option (returns  "http://^{URIQADefaultHost}^/dataspace/%U/concept#%U") .
	create iri class ods:blog_post_text "http://^{URIQADefaultHost}^/dataspace/%U/weblog-text/%U/%U"
		(in uname varchar not null, in forum_name varchar not null, in postid varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/weblog-text/%U/%U" ) .
	#Feeds
	create iri class ods:feed "http://^{URIQADefaultHost}^/dataspace/feed/%d" (in feed_id integer not null)
          	option (returns "http://^{URIQADefaultHost}^/dataspace/feed/%d" ) .
	create iri class ods:feed_item "http://^{URIQADefaultHost}^/dataspace/feed/%d/%d" (in feed_id integer not null, in item_id integer not null)
	 	option (returns  "http://^{URIQADefaultHost}^/dataspace/feed/%d/%d" ) .
	create iri class ods:feed_item_text "http://^{URIQADefaultHost}^/dataspace/feed/%d/%d/text" (in feed_id integer not null, in item_id integer not null)
		option (returns  "http://^{URIQADefaultHost}^/dataspace/feed/%d/%d/text" ) .
	create iri class ods:feed_mgr "http://^{URIQADefaultHost}^/dataspace/%U/feeds/%U" (in uname varchar not null, in inst_name varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/feeds/%U" ) .
	create iri class ods:feed_comment "http://^{URIQADefaultHost}^/dataspace/%U/feeds/%U/%d/%d"
		(in uname varchar not null, in inst_name varchar not null, in item_id integer not null, in comment_id integer not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/feeds/%U/%d/%d" ) .
	#Bookmark
	create iri class ods:bmk_post "http://^{URIQADefaultHost}^/dataspace/%U/bookmark/%U/%d"
		(in uname varchar not null, in inst_name varchar not null, in bmk_id integer not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/bookmark/%U/%d") .
	create iri class ods:bmk_post_text "http://^{URIQADefaultHost}^/dataspace/%U/bookmark/%U/%d/text"
		(in uname varchar not null, in inst_name varchar not null, in bmk_id integer not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/bookmark/%U/%d/text" ) .
	create iri class ods:bmk_forum "http://^{URIQADefaultHost}^/dataspace/%U/bookmark/%U"
		( in uname varchar not null, in forum_name varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/bookmark/%U") .
	#Photo
	create iri class ods:photo_forum "http://^{URIQADefaultHost}^/dataspace/%U/photos/%U"
		(in uname varchar not null, in inst_name varchar not null)
		option (returns  "http://^{URIQADefaultHost}^/dataspace/%U/photos/%U") .
	create iri class ods:photo_post "http://^{URIQADefaultHost}^%s"
		(in path varchar not null) option (returns "http://^{URIQADefaultHost}^/DAV/%s") .
	create iri class ods:photo_post_text "http://^{URIQADefaultHost}^%s/text"
		(in path varchar not null) option (returns "http://^{URIQADefaultHost}^/DAV/%s/text") .
	create iri class ods:photo_comment "http://^{URIQADefaultHost}^%s:comment_%d"
		(in path varchar not null, in comment_id int not null)
		option (returns "http://^{URIQADefaultHost}^/DAV/%s:comment_%d") .
	# Community
	create iri class ods:community_forum "http://^{URIQADefaultHost}^/dataspace/%U/community/%U"
		(in uname varchar not null, in forum_name varchar not null)
		option (returns  "http://^{URIQADefaultHost}^/dataspace/%U/community/%U") .
	# Briefcase
	create iri class ods:odrive_forum "http://^{URIQADefaultHost}^/dataspace/%U/briefcase/%U"
		(in uname varchar not null, in inst_name varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/briefcase/%U" ) .
	create iri class ods:odrive_post "http://^{URIQADefaultHost}^%s"
		(in path varchar not null) option (returns "http://^{URIQADefaultHost}^/DAV/%s") .
	create iri class ods:odrive_post_text "http://^{URIQADefaultHost}^%s/text"
		(in path varchar not null) option (returns "http://^{URIQADefaultHost}^/DAV/%s/text") .
	# Wiki
	create iri class ods:wiki_post "http://^{URIQADefaultHost}^/dataspace/%U/wiki/%U/%U"
		(in uname varchar not null, in inst_name varchar not null, in topic_id varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/wiki/%U/%U") .
	create iri class ods:wiki_post_text "http://^{URIQADefaultHost}^/dataspace/%U/wiki/%U/%U/text"
		(in uname varchar not null, in inst_name varchar not null, in topic_id varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/wiki/%U/%U/text" ) .
	create iri class ods:wiki_forum "http://^{URIQADefaultHost}^/dataspace/%U/wiki/%U"
		( in uname varchar not null, in forum_name varchar not null)
		option (returns  "http://^{URIQADefaultHost}^/dataspace/%U/wiki/%U" ) .
	#Calendar
	create iri class ods:calendar_event "http://^{URIQADefaultHost}^/dataspace/%U/calendar/%U/%d"
		(in uname varchar not null, in inst_name varchar not null, in calendar_id integer not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/calendar/%U/%d" ) .
	create iri class ods:calendar_event_text "http://^{URIQADefaultHost}^/dataspace/%U/calendar/%U/%d/text"
		(in uname varchar not null, in inst_name varchar not null, in calendar_id integer not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/%U/calendar/%U/%d/text" ) .
	create iri class ods:calendar_forum "http://^{URIQADefaultHost}^/dataspace/%U/calendar/%U"
		( in uname varchar not null, in forum_name varchar not null)
		option (returns  "http://^{URIQADefaultHost}^/dataspace/%U/calendar/%U") .
	# NNTPF
	create iri class ods:nntp_forum "http://^{URIQADefaultHost}^/dataspace/discussion/%U"
		( in forum_name varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/discussion/%U").
	create iri class ods:nntp_post "http://^{URIQADefaultHost}^/dataspace/discussion/%U/%U"
		( in group_name varchar not null, in message_id varchar not null)
		option (returns  "http://^{URIQADefaultHost}^/dataspace/discussion/%U/%U" ) .
	create iri class ods:nntp_post_text "http://^{URIQADefaultHost}^/dataspace/discussion/%U/%U/text"
		( in group_name varchar not null, in message_id varchar not null)
		option (returns  "http://^{URIQADefaultHost}^/dataspace/discussion/%U/%U/text") .
	create iri class ods:nntp_role "http://^{URIQADefaultHost}^/dataspace/discussion/%U#reader"
		(in forum_name varchar not null)
		option (returns "http://^{URIQADefaultHost}^/dataspace/discussion/%U#reader") .
       ;


SPARQL
    prefix sioc: <http://rdfs.org/sioc/ns#>
    prefix sioct: <http://rdfs.org/sioc/types#>
    prefix atom: <http://atomowl.org/ontologies/atomrdf#>
    prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    prefix foaf: <http://xmlns.com/foaf/0.1/>
    prefix dc: <http://purl.org/dc/elements/1.1/>
    prefix dct: <http://purl.org/dc/terms/>
    prefix skos: <http://www.w3.org/2004/02/skos/core#>
    prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
    prefix bm: <http://www.w3.org/2002/01/bookmark#>
    prefix exif: <http://www.w3.org/2003/12/exif/ns/>
    prefix ann: <http://www.w3.org/2000/10/annotation-ns#>
    prefix wikiont: <http://sw.deri.org/2005/04/wikipedia/wikiont.owl#>
    prefix calendar: <http://www.w3.org/2002/12/cal#>
    prefix ods: <http://www.openlinksw.com/virtuoso/ods/>

    alter quad storage virtrdf:DefaultQuadStorage
      FROM DB.DBA.SIOC_USERS as users
      FROM DB.DBA.SIOC_ODS_FORUMS as forums
      FROM DB.DBA.SIOC_ROLES as roles
      FROM DB.DBA.SIOC_ROLE_GRANTS as grants
      FROM DB.DBA.SIOC_KNOWS as knows
      FROM DB.DBA.ODS_FOAF_PERSON as person
      where (^{person.}^.U_NAME = ^{users.}^.U_NAME)
      where (^{forums.}^.U_NAME = ^{users.}^.U_NAME)
      where (^{knows.}^.TO_NAME = ^{users.}^.U_NAME)
      where (^{knows.}^.FROM_NAME = ^{users.}^.U_NAME)
      where (^{grants.}^.U_NAME = ^{users.}^.U_NAME)
      where (^{roles.}^.U_NAME = ^{users.}^.U_NAME)

      FROM DB.DBA.ODS_BLOG_POSTS as blog_posts
      where (^{blog_posts.}^.B_OWNER = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_BLOG_POST_LINKS as blog_links
      where (^{blog_links.}^.B_OWNER = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_BLOG_POST_ATTS as blog_atts
      where (^{blog_atts.}^.B_OWNER = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_BLOG_POST_TAGS as blog_tags
      where (^{blog_tags.}^.U_NAME = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_BLOG_COMMENTS as blog_comms
      where (^{blog_comms.}^.U_NAME = ^{users.}^.U_NAME)

      FROM DB.DBA.ODS_BMK_POSTS as bmk_posts
      where (^{bmk_posts.}^.U_NAME = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_BMK_TAGS as bmk_tags
      where (^{bmk_tags.}^.U_NAME = ^{users.}^.U_NAME)

      FROM DB.DBA.ODS_ODRIVE_POSTS as odrv_posts
      where (^{odrv_posts.}^.U_MEMBER = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_ODRIVE_TAGS as odrv_tags
      where (^{odrv_tags.}^.U_OWNER = ^{users.}^.U_NAME)

      FROM DB.DBA.ODS_FEED_FEED_DOMAIN as feed_domain
      where (^{feed_domain.}^.U_NAME = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_FEED_POSTS as feed_posts
      where (^{feed_posts.}^.EFI_FEED_ID = ^{feed_domain.}^.EF_ID)
      FROM DB.DBA.ODS_FEED_COMMENTS as feed_comments
      where (^{feed_comments.}^.U_NAME = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_FEED_TAGS as feed_tags
      where (^{feed_tags.}^.U_NAME = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_FEED_LINKS as feed_links
      where (^{feed_links.}^.EFI_FEED_ID = ^{feed_domain.}^.EF_ID)
      FROM DB.DBA.ODS_FEED_ATTS as feed_atts
      where (^{feed_atts.}^.EFI_FEED_ID = ^{feed_domain.}^.EF_ID)

      FROM DB.DBA.ODS_PHOTO_POSTS as photo_posts
      where (^{photo_posts.}^.U_MEMBER = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_PHOTO_COMMENTS as photo_comments
      where (^{photo_comments.}^.U_MEMBER = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_PHOTO_TAGS as photo_tags
      where (^{photo_tags.}^.U_MEMBER = ^{users.}^.U_NAME)

      FROM DB.DBA.ODS_WIKI_POSTS as wiki_posts
      where (^{wiki_posts.}^.U_NAME = ^{users.}^.U_NAME)

      FROM DB.DBA.ODS_COMMUNITIES as community
      where (^{community.}^.C_OWNER = ^{users.}^.U_NAME)

      FROM DB.DBA.ODS_NNTP_GROUPS as nntp_groups
      FROM DB.DBA.ODS_NNTP_POSTS as nntp_posts
      FROM DB.DBA.ODS_NNTP_USERS as nntp_users
      where (^{nntp_users.}^.U_NAME = ^{users.}^.U_NAME)
      FROM DB.DBA.ODS_NNTP_LINKS as nntp_links


    {
	create virtrdf:ODS_DS as graph ods:graph (users.U_NAME) option (exclusive)
	  {
	    ods:user (users.U_NAME) a sioc:User ;
            sioc:id users.U_NAME ;
            sioc:name users.U_FULL_NAME ;
            sioc:email ods:mbox (users.E_MAIL) ;
            sioc:email_sha1 users.E_MAIL_SHA1 ;
            sioc:account_of ods:person (users.U_NAME) .

	    ods:person (person.U_NAME) a foaf:Person ;
            foaf:nick person.U_NAME ;
	    foaf:name person.U_FULL_NAME ;
	    foaf:mbox ods:mbox (person.E_MAIL) ;
            foaf:mbox_sha1sum person.E_MAIL_SHA1 ;
            foaf:holdsAccount ods:user (person.U_NAME) ;
            foaf:firstName person.FIRST_NAME ;
            foaf:family_name person.LAST_NAME ;
            foaf:gender person.GENDER ;
            foaf:icqChatID person.ICQ ;
            foaf:msnChatID person.MSN ;
            foaf:aimChatID person.AIM ;
            foaf:yahooChatID person.YAHOO ;
            foaf:birthday person.BIRTHDAY ;
            foaf:organization person.ORG ;
            foaf:phone ods:phone (person.PHONE) ;
	    foaf:based_near ods:geo_point (person.U_NAME)
	    .

	    ods:geo_point (person.U_NAME) a geo:Point ;
		 geo:lat person.LAT ;
		 geo:lng person.LNG .

	    ods:person (knows.FROM_NAME) foaf:knows ods:person (knows.TO_NAME) .
	    ods:person (knows.TO_NAME) foaf:knows ods:person (knows.FROM_NAME) .

	    ods:user_group (grants.G_NAME) a sioc:Usergroup ;
	    	sioc:id grants.G_NAME ;
		sioc:has_member ods:user (grants.U_NAME) .
	    ods:user (grants.U_NAME)  sioc:member_of ods:user_group (grants.G_NAME) .

	    ods:role (roles.U_NAME, roles.APP_TYPE, roles.WAM_INST, roles.WMT_NAME)
	      sioc:has_scope ods:forum (roles.U_NAME, roles.APP_TYPE, roles.WAM_INST) ;
	      sioc:function_of ods:user (roles.U_NAME) .

            ods:forum (roles.U_NAME, roles.APP_TYPE, roles.WAM_INST)
	    	sioc:scope_of ods:role (roles.U_NAME, roles.APP_TYPE, roles.WAM_INST, roles.WMT_NAME) .
            ods:user (roles.U_NAME)
	    	sioc:has_function ods:role (roles.U_NAME, roles.APP_TYPE, roles.WAM_INST, roles.WMT_NAME) .

	    ods:forum (forums.U_NAME, forums.APP_TYPE, forums.WAM_INST) a sioc:Container ;
            sioc:id forums.WAM_INST ;
	    sioc:type forums.APP_TYPE ;
            sioc:description forums.WAI_DESCRIPTION ;
            sioc:link ods:proxy (forums.LINK) ;
            sioc:has_space ods:site (forums.U_NAME) .

            # Weblog
	    ods:blog_post (blog_posts.B_OWNER, blog_posts.B_INST, blog_posts.B_POST_ID) a sioct:BlogPost ;
	    sioc:link ods:proxy (blog_posts.B_LINK) ;
	    sioc:has_creator ods:user (blog_posts.B_CREATOR) ;
	    foaf:maker ods:person (blog_posts.B_CREATOR) ;
	    sioc:has_container ods:blog_forum (blog_posts.B_OWNER, blog_posts.B_INST) ;
	    dc:title blog_posts.B_TITLE ;
	    dct:created blog_posts.B_CREATED ;
	    dct:modified blog_posts.B_MODIFIED ;
	    sioc:content blog_posts.B_CONTENT .

	    ods:blog_forum (blog_posts.B_OWNER, blog_posts.B_INST)
	    sioc:container_of
	    ods:blog_post (blog_posts.B_OWNER, blog_posts.B_INST, blog_posts.B_POST_ID) .

	    ods:user (blog_posts.B_CREATOR)
	    sioc:creator_of
	    ods:blog_post (blog_posts.B_OWNER, blog_posts.B_INST, blog_posts.B_POST_ID) .

	    ods:blog_post (blog_links.B_OWNER, blog_links.B_INST, blog_links.B_POST_ID)
	    sioc:links_to
	    ods:proxy (blog_links.PL_LINK) .
	    # end Weblog

            # Bookmark
	    ods:bmk_post (bmk_posts.U_NAME, bmk_posts.WAI_NAME, bmk_posts.BD_BOOKMARK_ID)
            a bm:Bookmark ;
	    dc:title bmk_posts.BD_NAME;
	    dct:created bmk_posts.BD_CREATED ;
	    dct:modified bmk_posts.BD_LAST_UPDATE ;
	    dc:date bmk_posts.BD_LAST_UPDATE ;
	    ann:created bmk_posts.BD_CREATED ;
	    dc:creator bmk_posts.U_NAME ;
	    bm:recalls ods:proxy (bmk_posts.B_URI) ;
	    sioc:link ods:proxy (bmk_posts.B_URI) ;
	    sioc:content bmk_posts.BD_DESCRIPTION ;
	    sioc:has_creator ods:user (bmk_posts.U_NAME) ;
	    foaf:maker ods:person (bmk_posts.U_NAME) ;
	    sioc:has_container ods:bmk_forum (bmk_posts.U_NAME, bmk_posts.WAI_NAME) .

            ods:bmk_forum (bmk_posts.U_NAME, bmk_posts.WAI_NAME)
	    sioc:container_of
	    ods:bmk_post (bmk_posts.U_NAME, bmk_posts.WAI_NAME, bmk_posts.BD_BOOKMARK_ID) .

	    ods:user (bmk_posts.U_NAME)
	    sioc:creator_of
	    ods:bmk_post (bmk_posts.U_NAME, bmk_posts.WAI_NAME, bmk_posts.BD_BOOKMARK_ID) .

	    ods:bmk_post (bmk_tags.U_NAME, bmk_tags.WAM_INST, bmk_tags.ITEM_ID)
	    sioc:topic
	    ods:tag (bmk_tags.U_NAME, bmk_tags.BD_TAG) .

	    ods:tag (bmk_tags.U_NAME, bmk_tags.BD_TAG) a skos:Concept ;
	    skos:prefLabel bmk_tags.BD_TAG ;
	    skos:isSubjectOf ods:bmk_post (bmk_tags.U_NAME, bmk_tags.WAM_INST, bmk_tags.ITEM_ID) .
	    # end Bookmark

            # Briefcase
	    ods:odrive_post (odrv_posts.RES_FULL_PATH) a foaf:Document ;
	    dc:title odrv_posts.RES_NAME ;
	    dct:created odrv_posts.RES_CREATED ;
	    dct:modified odrv_posts.RES_MODIFIED ;
	    sioc:content odrv_posts.RES_DESCRIPTION ;
	    sioc:has_creator ods:user (odrv_posts.U_OWNER) ;
	    foaf:maker ods:person (odrv_posts.U_OWNER) ;
	    sioc:has_container ods:odrive_forum (odrv_posts.U_MEMBER, odrv_posts.WAI_NAME) .

	    ods:odrive_forum (odrv_posts.U_MEMBER, odrv_posts.WAI_NAME)
	    sioc:container_of
	    ods:odrive_post (odrv_posts.RES_FULL_PATH) .

	    ods:user (odrv_posts.U_OWNER)
	    sioc:creator_of
	    ods:odrive_post (odrv_posts.RES_FULL_PATH) .

	    ods:odrive_post (odrv_tags.RES_FULL_PATH)
	    sioc:topic
	    ods:tag (odrv_tags.U_OWNER, odrv_tags.TAG) .

	    ods:tag (odrv_tags.U_OWNER, odrv_tags.TAG) a skos:Concept ;
	    skos:prefLabel odrv_tags.TAG ;
	    skos:isSubjectOf ods:odrive_post (odrv_tags.RES_FULL_PATH) .
            # end Briefcase

            # Feeds
	    ods:feed (feed_domain.EF_ID) a atom:Feed ;
	    sioc:link ods:proxy (feed_domain.EF_URI) ;
	    atom:link ods:proxy (feed_domain.EF_URI) ;
	    atom:title feed_domain.EF_TITLE ;
	    sioc:has_parent ods:feed_mgr (feed_domain.U_NAME, feed_domain.WAI_NAME) .

	    ods:feed_mgr (feed_domain.U_NAME, feed_domain.WAI_NAME)
	    sioc:parent_of ods:feed (feed_domain.EF_ID) .


	    ods:feed_item (feed_tags.EFI_FEED_ID, feed_tags.EFID_ITEM_ID)
	    sioc:topic
	    ods:tag (feed_tags.U_NAME, feed_tags.EFID_TAG) .

	    ods:tag (feed_tags.U_NAME, feed_tags.EFID_TAG) a skos:Concept ;
	    skos:prefLabel feed_tags.EFID_TAG ;
	    skos:isSubjectOf ods:feed_item (feed_tags.EFI_FEED_ID, feed_tags.EFID_ITEM_ID) .

	    ods:feed_comment (feed_comments.U_NAME, feed_comments.WAI_NAME, feed_comments.EFIC_ITEM_ID, feed_comments.EFIC_ID)
	    a sioct:Comment ;
	    dc:title feed_comments.EFIC_TITLE ;
	    sioc:content feed_comments.EFIC_COMMENT ;
	    dct:modified feed_comments.LAST_UPDATE ;
	    dct:created feed_comments.LAST_UPDATE ;
	    sioc:link ods:proxy (feed_comments.LINK) ;
	    sioc:has_container ods:feed (feed_comments.EFI_FEED_ID) ;
	    sioc:reply_of ods:feed_item (feed_comments.EFI_FEED_ID, feed_comments.EFIC_ITEM_ID) ;
	    foaf:maker ods:proxy (feed_comments.EFIC_U_URL) .

	    ods:proxy (feed_comments.EFIC_U_URL) a foaf:Person ;
	    foaf:name feed_comments.EFIC_U_NAME;
	    foaf:mbox ods:mbox (feed_comments.EFIC_U_MAIL) .

            ods:feed (feed_comments.EFI_FEED_ID)
	    sioc:container_of
            ods:feed_comment (feed_comments.U_NAME, feed_comments.WAI_NAME, feed_comments.EFIC_ITEM_ID, feed_comments.EFIC_ID) .

            ods:feed_item (feed_comments.EFI_FEED_ID, feed_comments.EFIC_ITEM_ID)
	    sioc:has_reply
	    ods:feed_comment (feed_comments.U_NAME, feed_comments.WAI_NAME, feed_comments.EFIC_ITEM_ID, feed_comments.EFIC_ID) .

            ods:feed_item (feed_links.EFI_FEED_ID, feed_links.EFI_ID)
	    sioc:links_to
	    ods:proxy (feed_links.EFIL_LINK) .

	    ods:feed_item (feed_atts.EFI_FEED_ID, feed_atts.EFI_ID)
	    sioc:attachment
	    ods:proxy (feed_atts.EFIE_URL) .

	    ods:feed_item (feed_posts.EFI_FEED_ID, feed_posts.EFI_ID) a atom:Entry ;
	    sioc:has_container ods:feed (feed_posts.EFI_FEED_ID) ;
	    dc:title feed_posts.EFI_TITLE ;
	    dct:created feed_posts.PUBLISH_DATE ;
	    dct:modified feed_posts.PUBLISH_DATE ;
	    sioc:link ods:proxy (feed_posts.EFI_LINK) ;
	    sioc:content feed_posts.EFI_DESCRIPTION ;
	    atom:title feed_posts.EFI_TITLE ;
	    atom:source ods:feed (feed_posts.EFI_FEED_ID) ;
	    atom:published feed_posts.PUBLISH_DATE ;
	    atom:updated feed_posts.PUBLISH_DATE ;
	    atom:content ods:feed_item_text (feed_posts.EFI_FEED_ID, feed_posts.EFI_ID) .

	    ods:feed (feed_posts.EFI_FEED_ID) sioc:container_of ods:feed_item (feed_posts.EFI_FEED_ID, feed_posts.EFI_ID) .

	    ods:feed_item_text (feed_posts.EFI_FEED_ID, feed_posts.EFI_ID) a atom:Content ;
	    atom:type "text/xhtml" ;
	    atom:lang "en-US" ;
	    atom:body feed_posts.EFI_DESCRIPTION .

	    ods:feed (feed_posts.EFI_FEED_ID)
	    atom:contains
	    ods:feed_item (feed_posts.EFI_FEED_ID, feed_posts.EFI_ID) .
            # end Feeds

	    # Photo
	    ods:photo_post (photo_posts.RES_FULL_PATH) a exif:IFD ;
	    dc:title photo_posts.RES_NAME ;
	    dct:created photo_posts.RES_CREATED ;
	    dct:modified photo_posts.RES_MODIFIED ;
	    sioc:content photo_posts.RES_DESCRIPTION ;
	    sioc:has_creator ods:user (photo_posts.U_OWNER) ;
	    foaf:maker ods:person (photo_posts.U_OWNER) ;
	    sioc:link ods:proxy (photo_posts.RES_LINK) ;
	    sioc:has_container ods:photo_forum (photo_posts.U_MEMBER, photo_posts.WAI_NAME) .

	    ods:photo_forum (photo_posts.U_MEMBER, photo_posts.WAI_NAME)
	    sioc:container_of
	    ods:photo_post (photo_posts.RES_FULL_PATH) .

	    ods:user (photo_posts.U_OWNER)
	    sioc:creator_of
	    ods:photo_post (photo_posts.RES_FULL_PATH) .

	    ods:photo_post (photo_tags.RES_FULL_PATH)
	    sioc:topic
	    ods:tag (photo_tags.U_MEMBER, photo_tags.RES_TAG) .

	    ods:tag (photo_tags.U_MEMBER, photo_tags.RES_TAG) a skos:Concept ;
	    skos:prefLabel photo_tags.RES_TAG ;
	    skos:isSubjectOf ods:photo_post (photo_tags.RES_FULL_PATH) .

	    ods:photo_comment (photo_comments.RES_FULL_PATH, photo_comments.COMMENT_ID) a sioct:Comment ;
	    sioc:reply_of ods:photo_post (photo_comments.RES_FULL_PATH) ;
	    sioc:has_container ods:photo_forum (photo_comments.U_MEMBER, photo_comments.WAI_NAME) ;
	    dc:title photo_comments.RES_NAME ;
	    dct:created photo_comments.CREATE_DATE ;
	    dct:modified photo_comments.MODIFY_DATE ;
	    sioc:content photo_comments.TEXT ;
	    foaf:maker ods:person (photo_comments.U_MAKER) .

	    ods:photo_post (photo_comments.RES_FULL_PATH)
	    sioc:has_reply
	    ods:photo_comment (photo_comments.RES_FULL_PATH, photo_comments.COMMENT_ID) .
	    # end Photo

	    # Polls
	    # end Polls

	    # Mail
	    # end Mail

	    # Wiki
            ods:wiki_post (wiki_posts.U_NAME, wiki_posts.CLUSTERNAME, wiki_posts.LOCALNAME) a wikiont:Article ;
	    dc:title wiki_posts.LOCALNAME ;
	    dct:created wiki_posts.RES_CREATED ;
	    dct:modified wiki_posts.RES_MODIFIED ;
	    sioc:content wiki_posts.RES_CONTENT ;
	    sioc:has_creator ods:user (wiki_posts.U_NAME) ;
	    foaf:maker ods:person (wiki_posts.U_NAME) ;
	    sioc:has_container ods:wiki_forum (wiki_posts.U_NAME, wiki_posts.CLUSTERNAME) .

	    ods:wiki_forum (wiki_posts.U_NAME, wiki_posts.CLUSTERNAME)
	    sioc:container_of
	    ods:wiki_post (wiki_posts.U_NAME, wiki_posts.CLUSTERNAME, wiki_posts.LOCALNAME) .

	    ods:user (wiki_posts.U_NAME)
	    sioc:creator_of
	    ods:wiki_post (wiki_posts.U_NAME, wiki_posts.CLUSTERNAME, wiki_posts.LOCALNAME) .

	    # end Wiki

            # Community
	    ods:community_forum (community.C_OWNER, community.CM_COMMUNITY_ID) a sioc:Community ;
	    sioc:has_part ods:forum (community.A_OWNER, community.A_TYPE, community.CM_MEMBER_APP) .

	    ods:forum (community.A_OWNER, community.A_TYPE, community.CM_MEMBER_APP)
	    sioc:part_of
	    ods:community_forum (community.C_OWNER, community.CM_COMMUNITY_ID) .
            # end Community

	    # NNTP
	    ods:nntp_forum (nntp_groups.NG_NAME) a sioct:MessageBoard ;
	    sioc:id nntp_groups.NG_NAME ;
	    sioc:description nntp_groups.NG_DESC .

	    ods:nntp_post (nntp_posts.NG_NAME, nntp_posts.NM_ID) a sioct:BoardPost ;
	    sioc:content nntp_posts.NM_BODY ;
	    dc:title nntp_posts.FTHR_SUBJ ;
	    dct:created  nntp_posts.REC_DATE ;
	    dct:modified nntp_posts.REC_DATE ;
	    foaf:maker ods:proxy (nntp_posts.MAKER) ;
	    sioc:reply_of ods:nntp_post (nntp_posts.NG_NAME, nntp_posts.FTHR_REFER) ;
	    sioc:has_container ods:nntp_forum (nntp_posts.NG_NAME) .

	    ods:nntp_post (nntp_posts.NG_NAME, nntp_posts.FTHR_REFER)
	    sioc:has_reply
	    ods:nntp_post (nntp_posts.NG_NAME, nntp_posts.NM_ID) .

	    ods:nntp_forum (nntp_posts.NG_NAME)
	    sioc:container_of
	    ods:nntp_post (nntp_posts.NG_NAME, nntp_posts.NM_ID) .


	    ods:nntp_role (nntp_groups.NG_NAME)
	    sioc:has_scope
	    ods:nntp_forum (nntp_groups.NG_NAME) .

	    ods:nntp_forum (nntp_groups.NG_NAME)
	    sioc:scope_of
	    ods:nntp_role (nntp_groups.NG_NAME) .

	    ods:user (nntp_users.U_NAME)
	    sioc:has_function
	    ods:nntp_role (nntp_users.NG_NAME) .

	    ods:nntp_role (nntp_users.NG_NAME)
	    sioc:function_of
	    ods:user (nntp_users.U_NAME) .

	    ods:nntp_post (nntp_links.NG_NAME, nntp_links.NML_MSG_ID)
	    sioc:links_to
	    ods:proxy (nntp_links.NML_URL) .
	    # end NNTP

	  } .
    } .
;
]]></programlisting>
<para><emphasis>URL Rewrite Rules for ODS</emphasis></para>
<programlisting><![CDATA[
create procedure DB.DBA.URL_REW_ODS_ACCEPT ()
{
  declare accept, ret any;
  accept := http_request_header (http_request_header (), 'Accept');
  if (not isstring (accept))
    return null;
  ret := null;
  if (regexp_match ('(application|text)/rdf.(xml|n3|turtle|ttl)', accept) is not null)
    {
      if (regexp_match ('application/rdf.xml', accept) is not null)
	{
	  ret := 'rdf';
	}
      else if (regexp_match ('text/rdf.n3', accept) is not null)
	{
	  ret := 'n3';
	}
      else if (regexp_match ('application/rdf.turtle', accept) is not null or
	    regexp_match ('application/rdf.ttl', accept) is not null)
	{
	  ret := 'n3';
	}
    }
  return ret;
};

create procedure  DB.DBA.URL_REW_ODS_SPQ (in graph varchar, in iri varchar, in acc varchar)
{
  declare q, ret any;
  iri := replace (iri, '''', '%27');
  iri := replace (iri, '<', '%3C');
  iri := replace (iri, '>', '%3E');
  q := sprintf ('define input:inference <%s> DESCRIBE <%s> FROM <%s>', graph, iri, graph);
  ret := sprintf ('/sparql?query=%U&format=%U', q, acc);
  return ret;
};

create procedure DB.DBA.URL_REW_ODS_USER (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (current_proc_name ());
  declare acc, ret any;
  declare q, iri, graph any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      graph := sioc..get_graph ();
      iri := sprintf ('%s/%U', graph, val);
      if (val like 'person/%')
	{
	  val := substring (val, 8, length (val));
	  ret := sprintf ('/ods/foaf.vsp?uname=%U&fmt=%U', val, acc);
	}
      else
        ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
    }
  else
    {
      http_header (http_header_get ()||sprintf ('X-XRDS-Location: %s\r\n',
	    DB.DBA.wa_link (1, '/dataspace/'||val||'/yadis.xrds')));

      if (val like 'person/%')
	val := substring (val, 8, length (val));
      ret := sprintf ('/ods/uhome.vspx?page=1&ufname=%s', val);
    }
  return ret;
};

create procedure DB.DBA.URL_REW_ODS_USER_GEM (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (current_proc_name ());
  declare acc, ret any;
  declare q, iri, graph, path, is_person any;

  path := http_path ();
  if (path like '%.rdf')
    acc := 'rdf';
  else if (path like '%.n3')
    acc := 'n3';
  else if (path like '%.ttl')
    acc := 'n3';
  else if (path like '%/yadis.xrds')
    acc := 'yadis';
  else
    acc := 'rdf';

  if (acc <> 'yadis')
    {
      is_person := matches_like (path, '%/about.%');
      graph := sioc..get_graph ();
      if (is_person)
	{
          --iri := sprintf ('%s/person/%U', graph, val);
	  ret := sprintf ('/ods/foaf.vsp?uname=%U&fmt=%U', val, acc);
	}
      else
	{
          iri := sprintf ('%s/%U', graph, val);
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
	}
    }
  else
    {
      ret := sprintf ('/ods/yadis.vsp?uname=%U', val);
    }
  return ret;
};

create procedure DB.DBA.URL_REW_ODS_GEM (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (current_proc_name ());
  declare acc, ret any;
  declare q, iri, graph, path, pos any;

  path := http_path ();
  if (path like '%.rdf')
    acc := 'rdf';
  else if (path like '%.n3')
    acc := 'n3';
  else if (path like '%.ttl')
    acc := 'n3';
  else
    acc := 'rdf';
  graph := sioc..get_graph ();
  pos := strrchr (path, '/');
  path := subseq (path, 0, pos);

  if (val = 'person')
    {
      pos := strrchr (path, '/');
      val := subseq (path, pos+1, length (path));
      ret := sprintf ('/ods/foaf.vsp?uname=%U&fmt=%U', val, acc);
    }
  else
    {
      iri := sprintf ('http://%s%s', sioc..get_cname (), path);
      ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
    }
  return ret;
};


create procedure DB.DBA.URL_REW_ODS_APP (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (current_proc_name (), val);
  if (par = 'app')
    return sprintf (fmt, wa_app_to_type (val));
  return sprintf (fmt, val);
};

create procedure DB.DBA.URL_REW_ODS_BLOG (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (par, fmt, val);
--  dbg_obj_print (current_proc_name (), val);
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      if (par = 'inst')
	{
          declare q, iri, graph any;
          graph := sioc..get_graph ();
          iri := 'http://' || sioc..get_cname () || http_path ();
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
          return ret;
	}
      else
	return '';
    }
  else if (par = 'inst')
    {
      declare url any;
      val := split_and_decode (val)[0];
      url := (SELECT WAM_HOME_PAGE FROM WA_MEMBER WHERE WAM_INST = val AND WAM_MEMBER_TYPE = 1);
      if (url is not null)
        val := url;
      return sprintf (fmt, val);
    }
  else if (par = 'id' and val <> '')
    {
      if (atoi (val) = 0 and val <> '0')
	fmt := '%s';
      else
        fmt := '?id=%s';
      return sprintf (fmt, val);
    }
};

create procedure DB.DBA.URL_REW_ODS_NNTP (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (par, fmt, val);
--  dbg_obj_print (current_proc_name (), val);
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
       declare q, iri, graph any;
       graph := sioc..get_graph ();
       iri := 'http://' || sioc..get_cname () || http_path ();
--       dbg_obj_print (iri);
       ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
       return ret;
    }
  else if (par = 'grp')
    {
      declare gid int;
      val := split_and_decode (val)[0];
      gid := (SELECT NG_GROUP FROM DB.DBA.NEWS_GROUPS WHERE NG_NAME = val);
      ret := sprintf ('/nntpf/nntpf_nthread_view.vspx?group=%d', gid);
      return ret;
    }
  else if (par = 'post')
    {
      ret := sprintf ('/nntpf/nntpf_disp_article.vspx?id=%U', encode_base64 (val));
      return ret;
    }
}
;

create procedure DB.DBA.URL_REW_ODS_XD (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (par, fmt, val);
--  dbg_obj_print (current_proc_name (), val);
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
       declare q, iri, graph any;
       graph := sioc..get_graph ();
       iri := 'http://' || sioc..get_cname () || http_path ();
--       dbg_obj_print (iri);
       ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
       return ret;
    }
  else if (par = 'inst')
    {
      val := split_and_decode (val)[0];
      ret := (SELECT WAM_HOME_PAGE FROM WA_MEMBER WHERE WAM_INST = val and WAM_MEMBER_TYPE = 1);
      return ret;
    }
}
;

create procedure DB.DBA.URL_REW_ODS_WIKI (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (par, fmt, val);
--  dbg_obj_print (current_proc_name (), val);
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
       declare q, iri, graph any;
       graph := sioc..get_graph ();
       iri := 'http://' || sioc..get_cname () || http_path ();
--       dbg_obj_print (iri);
       ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
       return ret;
    }
  else if (par = 'inst')
    {
      declare _inst DB.DBA.web_app;
      _inst := (SELECT WAI_INST FROM WA_INSTANCE WHERE WAI_NAME = val);
      ret := _inst.wa_post_url (null, null, val, val);
--      dbg_obj_print ('ret', ret);
      return ret;
    }
  else if (par = 'post')
    {
      return '/'||val;
    }
}
;

create procedure DB.DBA.URL_REW_ODS_PHOTO (in par varchar, in fmt varchar, in val varchar)
{
--  dbg_obj_print (par, fmt, val);
--  dbg_obj_print (current_proc_name (), val);
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
       declare q, iri, graph any;
       graph := sioc..get_graph ();
       iri := 'http://' || sioc..get_cname () || http_path ();
--       dbg_obj_print (iri);
       ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
       return ret;
    }
  else if (par = 'inst')
    {
      val := split_and_decode (val)[0];
      ret := (SELECT WAM_HOME_PAGE FROM WA_MEMBER WHERE WAM_INST = val AND WAM_MEMBER_TYPE = 1);
      return ret;
    }
  else if (par = 'post')
    {
      declare id int;
      declare col, nam varchar;
      declare exit handler for not found
	{
	  signal ('22023', sprintf ('The resource %d doesn''t exists', id));
	};
      id := atoi(ltrim(val, '/'));
      SELECT RES_FULL_PATH INTO nam FROM WS.WS.SYS_DAV_RES WHERE RES_ID = id;
      return nam;
    }
}
;

create procedure DB.DBA.URL_REW_ODS_ADDRESSBOOK (in par varchar, in fmt varchar, in val varchar)
{
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      if (par = 'instance')
      	{
          declare q, iri, graph any;
          graph := sioc..get_graph ();
          iri := 'http://' || sioc..get_cname () || http_path ();
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
          return ret;
	      }
      else
	      return '';
    }
  else if (par = 'instance')
    {
      declare id, url any;
      val := split_and_decode (val)[0];
      id := AB.WA.domain_id (val);
      if (id is not null) {
        url := AB.WA.ab_url (id);
        if (url is not null)
          val := url;
      }
      return sprintf (fmt, val);
    }
  else if (par = 'params')
    {
      if (atoi (val) = 0 and val <> '0')
       	fmt := '%s';
      else
        fmt := '?id=%s';
      return sprintf (fmt, val);
    }
}
;

create procedure DB.DBA.URL_REW_ODS_BOOKMARK (in par varchar, in fmt varchar, in val varchar)
{
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      if (par = 'instance')
      	{
          declare q, iri, graph any;
          graph := sioc..get_graph ();
          iri := 'http://' || sioc..get_cname () || http_path ();
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
          return ret;
	      }
      else
	      return '';
    }
  else if (par = 'instance')
    {
      declare id, url any;
      val := split_and_decode (val)[0];
      id := BMK.WA.domain_id (val);
      if (id is not null) {
        url := BMK.WA.bookmark_url (id);
        if (url is not null)
          val := url;
      }
      return sprintf (fmt, val);
    }
  else if (par = 'params')
    {
      if (atoi (val) = 0 and val <> '0')
       	fmt := '%s';
      else
        fmt := '?id=%s';
      return sprintf (fmt, val);
    }
}
;

create procedure DB.DBA.URL_REW_ODS_BRIEFCASE (in par varchar, in fmt varchar, in val varchar)
{
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      if (par = 'instance')
      	{
          declare q, iri, graph any;
          graph := sioc..get_graph ();
          iri := 'http://' || sioc..get_cname () || http_path ();
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
          return ret;
	      }
      else
	      return '';
    }
  else if (par = 'instance')
    {
      declare id, url any;
      val := split_and_decode (val)[0];
      id := ODRIVE.WA.domain_id (val);
      if (id is not null) {
        url := ODRIVE.WA.odrive_url (id);
        if (url is not null)
          val := url;
      }
      return sprintf (fmt, val);
    }
  else if (par = 'params')
    {
      if (atoi (val) = 0 and val <> '0')
       	fmt := '%s';
      else
        fmt := '?id=%s';
      return sprintf (fmt, val);
    }
}
;

create procedure DB.DBA.URL_REW_ODS_CALENDAR (in par varchar, in fmt varchar, in val varchar)
{
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      if (par = 'instance')
      	{
          declare q, iri, graph any;
          graph := sioc..get_graph ();
          iri := 'http://' || sioc..get_cname () || http_path ();
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
          return ret;
	      }
      else
	      return '';
    }
  else if (par = 'instance')
    {
      declare id, url any;
      val := split_and_decode (val)[0];
      id := CAL.WA.domain_id (val);
      if (id is not null) {
        url := CAL.WA.calendar_url (id);
        if (url is not null)
          val := url;
      }
      return sprintf (fmt, val);
    }
  else if (par = 'params')
    {
      if (atoi (val) = 0 and val <> '0')
       	fmt := '%s';
      else
        fmt := '?id=%s';
      return sprintf (fmt, val);
    }
}
;

create procedure DB.DBA.URL_REW_ODS_FEEDS (in par varchar, in fmt varchar, in val varchar)
{
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      if (par = 'instance')
      	{
          declare q, iri, graph any;
          graph := sioc..get_graph ();
          iri := 'http://' || sioc..get_cname () || http_path ();
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
          return ret;
	      }
      else
	      return '';
    }
  else if (par = 'instance')
    {
      declare id, url any;
      val := split_and_decode (val)[0];
      id := ENEWS.WA.domain_id (val);
      if (id is not null) {
        url := ENEWS.WA.enews_url (id) || 'news.vspx';
        if (url is not null)
          val := url;
      }
      return sprintf (fmt, val);
    }
  else if (par = 'params')
    {
      if (atoi (val) = 0 and val <> '0')
       	fmt := '%s';
      else
        fmt := '?id=%s';
      return sprintf (fmt, val);
    }
}
;

create procedure DB.DBA.URL_REW_ODS_POLLS (in par varchar, in fmt varchar, in val varchar)
{
  declare acc, ret any;

  acc := DB.DBA.URL_REW_ODS_ACCEPT ();
  if (acc is not null)
    {
      if (par = 'instance')
      	{
          declare q, iri, graph any;
          graph := sioc..get_graph ();
          iri := 'http://' || sioc..get_cname () || http_path ();
          ret := DB.DBA.URL_REW_ODS_SPQ (graph, iri, acc);
          return ret;
	      }
      else
	      return '';
    }
  else if (par = 'instance')
    {
      declare id, url any;
      val := split_and_decode (val)[0];
      id := POLLS.WA.domain_id (val);
      if (id is not null) {
        url := POLLS.WA.polls_url (id);
        if (url is not null)
          val := url;
      }
      return sprintf (fmt, val);
    }
  else if (par = 'params')
    {
      if (atoi (val) = 0 and val <> '0')
       	fmt := '%s';
      else
        fmt := '?id=%s';
      return sprintf (fmt, val);
    }
}
;

create procedure DB.DBA.URL_REW_ODS_FOAF_EXT (in par varchar, in fmt varchar, in val varchar)
{
  if (par = '*accept*')
    {
      declare ext any;
      ext := 'rdf';
      if (val = 'text/rdf+n3')
	ext := 'n3';
      return sprintf (fmt, ext);
    }
  else
    return sprintf (fmt, val);
}
;

create procedure ur_ods_rdf_doc (in path varchar)
{
  declare r any;
  r := regexp_match ('[^/]*\x24', path);
  return r||'#this';
};

create procedure ur_ods_html_doc (in path varchar)
{
  declare pos, r any;
  if (path like '%/foaf.%')
    {
      pos := strrchr (path, '/');
    }
  else if (path like '%#%')
    {
      pos := strrchr (path, '#');
    }
  if (pos > 0)
    r := subseq (path, 0, pos);
  else
    r := '/';
  return r;
};
-- ODS Rules

-- http://cname/dataspace/uname
-- http://cname/dataspace/person/uname

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_rule1', 1,
    '/dataspace/((person/)?[^/#]*)', vector('ufname'), 1,
    '%s', vector('ufname'),
    'DB.DBA.URL_REW_ODS_USER');

-- http://cname/dataspace/uname with Accept will do 303 to the /sparql
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_rule2', 1,
    '/dataspace/([^/]*)', vector('ufname'), 1,
    '/sparql?query=define+input%%3Ainference+%%3Chttp%%3A//^{URIQADefaultHost}^/dataspace%%3E+DESCRIBE+%%3Chttp%%3A//^{URIQADefaultHost}^/dataspace/%U%%3E+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/dataspace%%3E&format=%U', vector('ufname', '*accept*'),
    null,
    '(application|text)/rdf.(xml|n3|turtle|ttl)',
    0,
    303);

-- http://cname/dataspace/uname/app_type
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_rule3', 1,
    '/dataspace/((?!person)[^/]*)/([^\\./]*)', vector('ufname', 'app'), 2,
    '/ods/app_inst.vspx?app=%s&ufname=%s&l=1', vector('app', 'ufname'),
    'DB.DBA.URL_REW_ODS_APP');

-- http://cname/dataspace/uname/file.ext
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_rule4', 1,
    '/dataspace/([^/]*)/(sioc|about|yadis)\\.(rdf|n3|ttl|xrds)', vector('ufname', 'file', 'fmt'), 3,
    '%s', vector('ufname'),
    'DB.DBA.URL_REW_ODS_USER_GEM');

-- Rules for FOAF profile

-- http://cname/dataspace/person/uname with Accept, do 303 to http://cname/dataspace/person/uname/foaf.ext
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_rule5', 1,
    '/dataspace/person/([^/#]*)/?', vector('ufname'), 1,
    '/dataspace/person/%U/foaf.%s', vector('ufname', '*accept*'),
    'DB.DBA.URL_REW_ODS_FOAF_EXT',
    '(application|text)/rdf.(xml|n3|turtle|ttl)',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_rule6', 1,
    '/dataspace/person/([^/]*)/page/([^/]*)/?', vector('ufname', 'page'), 1,
    '/dataspace/person/%U/foaf.%s?page=%s', vector('ufname', '*accept*', 'page'),
    'DB.DBA.URL_REW_ODS_FOAF_EXT',
    '(application|text)/rdf.(xml|n3|turtle|ttl)',
    2,
    303);

-- http://cname/dataspace/person/uname/foaf.ext
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_rule7', 1,
    '/dataspace/person/([^/]*)/foaf.(rdf|n3|ttl)', vector('ufname', 'fmt'), 1,
    '/ods/foaf.vsp?uname=%U&fmt=%U', vector('ufname', 'fmt'),
    null,
    null,
    2,
    null);

-- App Instance Gem

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_post_gem_rule', 1,
    '/dataspace/([^/]*)/([^/]*)/([^/]*/)?([^/]*/)?(sioc|about)\\.(rdf|n3|ttl)', vector('ufname', 'app', 'inst'), 4,
    '%s', vector('ufname'),
    'DB.DBA.URL_REW_ODS_GEM');


-- Weblog Rules

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_blog_rule1', 1,
    '/dataspace/([^/]*)/weblog/([^/]*)', vector('ufname', 'inst'), 2,
    '%s', vector('inst'),
    'DB.DBA.URL_REW_ODS_BLOG');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_blog_rule2', 1,
    '/dataspace/([^/]*)/weblog/([^/]*)/([^/]*)', vector('ufname', 'inst', 'id'), 3,
    '%s%s', vector('inst', 'id'),
    'DB.DBA.URL_REW_ODS_BLOG');

-- Discussion rules

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_nntp_rule1', 1,
    '/dataspace/discussion/([^/]*)', vector('grp'), 1,
    '%s', vector('grp'),
    'DB.DBA.URL_REW_ODS_NNTP');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_nntp_rule2', 1,
    '/dataspace/discussion/([^/]*)/((?!sioc)(?!about)[^/]*)', vector('grp', 'post'), 2,
    '%s', vector('post'),
    'DB.DBA.URL_REW_ODS_NNTP');

-- Community

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_xd_rule1', 1,
    '/dataspace/([^/]*)/community/([^/]*)', vector('ufname', 'inst'), 2,
    '%s', vector('inst'),
    'DB.DBA.URL_REW_ODS_XD');

-- Wiki

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_wiki_rule1', 1,
    '/dataspace/([^/]*)/wiki/([^/]*)', vector('ufname', 'inst'), 2,
    '%s', vector('inst'),
    'DB.DBA.URL_REW_ODS_WIKI');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_wiki_rule2', 1,
    '/dataspace/([^/]*)/wiki/([^/]*)/([^/]*)', vector('ufname', 'inst', 'post'), 2,
    '%s%s', vector('inst', 'post'),
    'DB.DBA.URL_REW_ODS_WIKI');

-- Gallery

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_photo_rule1', 1,
    '/dataspace/([^/]*)/photos/([^/]*)', vector('ufname', 'inst'), 2,
    '%s', vector('inst'),
    'DB.DBA.URL_REW_ODS_PHOTO');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('ods_photo_rule2', 1,
    '/dataspace/([^/]*)/photos/([^/]*)/([^/]*)', vector('ufname', 'inst', 'post'), 2,
    '%s', vector('post'),
    'DB.DBA.URL_REW_ODS_PHOTO');


-- AddressBook

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_addressbook_rule1',
    1,
    '/dataspace/([^/]*)/addressbook/([^/]*)',
    vector('uname', 'instance'),
    2,
    '%s', vector('instance'),
    'DB.DBA.URL_REW_ODS_ADDRESSBOOK');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_addressbook_rule2',
    1,
    '/dataspace/([^/]*)/addressbook/([^/]*)/(.*)',
    vector('uname', 'instance', 'params'),
    3,
    '%s%s',
    vector('instance', 'params'),
    'DB.DBA.URL_REW_ODS_ADDRESSBOOK');

-- Bookmark

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_bookmark_rule1',
    1,
    '/dataspace/([^/]*)/bookmark/([^/]*)',
    vector('uname', 'instance'),
    2,
    '%s', vector('instance'),
    'DB.DBA.URL_REW_ODS_BOOKMARK');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_bookmark_rule2',
    1,
    '/dataspace/([^/]*)/bookmark/([^/]*)/(.*)',
    vector('uname', 'instance', 'params'),
    3,
    '%s%s',
    vector('instance', 'params'),
    'DB.DBA.URL_REW_ODS_BOOKMARK');

-- Briefcase

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_briefcase_rule1',
    1,
    '/dataspace/([^/]*)/briefcase/([^/]*)',
    vector('uname', 'instance'),
    2,
    '%s', vector('instance'),
    'DB.DBA.URL_REW_ODS_BRIEFCASE');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_briefcase_rule2',
    1,
    '/dataspace/([^/]*)/briefcase/([^/]*)/(.*)',
    vector('uname', 'instance', 'params'),
    3,
    '%s%s',
    vector('instance', 'params'),
    'DB.DBA.URL_REW_ODS_BRIEFCASE');

-- Calendar

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_calendar_rule1',
    1,
    '/dataspace/([^/]*)/calendar/([^/]*)',
    vector('uname', 'instance'),
    2,
    '%s', vector('instance'),
    'DB.DBA.URL_REW_ODS_CALENDAR');


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_calendar_rule2',
    1,
    '/dataspace/([^/]*)/calendar/([^/]*)/(.*)',
    vector('uname', 'instance', 'params'),
    3,
    '%s%s',
    vector('instance', 'params'),
    'DB.DBA.URL_REW_ODS_CALENDAR');

-- Feeds

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_feeds_rule1',
    1,
    '/dataspace/([^/]*)/feeds/([^/]*)',
    vector('uname', 'instance'),
    2,
    '%s', vector('instance'),
    'DB.DBA.URL_REW_ODS_FEEDS');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_feeds_rule2',
    1,
    '/dataspace/([^/]*)/feeds/([^/]*)/(.*)',
    vector('uname', 'instance', 'params'),
    3,
    '%s%s',
    vector('instance', 'params'),
    'DB.DBA.URL_REW_ODS_FEEDS');

-- Polls

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_polls_rule1',
    1,
    '/dataspace/([^/]*)/polls/([^/]*)',
    vector('uname', 'instance'),
    2,
    '%s', vector('instance'),
    'DB.DBA.URL_REW_ODS_POLLS');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ods_polls_rule2',
    1,
    '/dataspace/([^/]*)/polls/([^/]*)/(.*)',
    vector('uname', 'instance', 'params'),
    3,
    '%s%s',
    vector('instance', 'params'),
    'DB.DBA.URL_REW_ODS_POLLS');

-- ODS Base rules
DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_base_rule_list1', 1,
    	vector(
	        'ods_rule1', 'ods_rule2', 'ods_rule3', 'ods_rule4'
	      ));

DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_foaf_rule_list1', 1,
    	vector(
	        'ods_rule5', 'ods_rule6', 'ods_rule7'
	      ));

DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_gems_rule_list1', 1,
    	vector(
	        'ods_post_gem_rule'
	      ));

-- ODS Blog rules
DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_blog_rule_list1', 1,
    	vector(
	   	'ods_blog_rule1', 'ods_blog_rule2'
	      ));

-- ODS Discussion rules
DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_nntp_rule_list1', 1,
    	vector(
	   	'ods_nntp_rule1', 'ods_nntp_rule2'
	      ));

-- ODS Community rules
DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_xd_rule_list1', 1,
    	vector(
	   	'ods_xd_rule1'
	      ));

-- ODS Wiki rules
DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_wiki_rule_list1', 1,
    	vector(
	   	'ods_wiki_rule1', 'ods_wiki_rule2'
	      ));

-- ODS Gallery rules
DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_photo_rule_list1', 1,
    	vector(
	   	'ods_photo_rule1', 'ods_photo_rule2'
	      ));

-- ODS AddressBook rules
DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ods_addressbook_rule_list1',
    1,
    vector (
  	 	'ods_addressbook_rule1',
	    'ods_addressbook_rule2'
	  ));

-- ODS Bookmark rules
DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ods_bookmark_rule_list1',
    1,
    vector (
  	 	'ods_bookmark_rule1',
	    'ods_bookmark_rule2'
	  ));

-- ODS Briefcase rules
DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ods_briefcase_rule_list1',
    1,
    vector (
  	 	'ods_briefcase_rule1',
	    'ods_briefcase_rule2'
	  ));

-- ODS Calendar rules
DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ods_calendar_rule_list1',
    1,
    vector (
  	 	'ods_calendar_rule1',
	    'ods_calendar_rule2'
	  ));

-- ODS Feeds rules
DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ods_feeds_rule_list1',
    1,
    vector (
  	 	'ods_feeds_rule1',
	    'ods_feeds_rule2'
	  ));

-- ODS Polls rules
DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ods_polls_rule_list1',
    1,
    vector (
  	 	'ods_polls_rule1',
	    'ods_polls_rule2'
	  ));

-- All ODS Rules
DB.DBA.URLREWRITE_CREATE_RULELIST ('ods_rule_list1', 1,
    	vector(
	  'ods_base_rule_list1',
	  'ods_foaf_rule_list1',
	  'ods_blog_rule_list1',
	  'ods_nntp_rule_list1',
	  'ods_xd_rule_list1',
	  'ods_wiki_rule_list1',
	  'ods_photo_rule_list1',
	  'ods_addressbook_rule_list1',
	  'ods_bookmark_rule_list1',
	  'ods_briefcase_rule_list1',
	  'ods_calendar_rule_list1',
	  'ods_feeds_rule_list1',
	  'ods_polls_rule_list1',
	  'ods_gems_rule_list1'
	      ));

DB.DBA.XML_SET_NS_DECL ('ods', 'http://www.openlinksw.com/virtuoso/ods/', 2);
]]></programlisting>
</sect2>
<sect2 id="rdfviewsbusintoplweb">
      <title>Oplweb to RDF</title>
<programlisting><![CDATA[
-- Setup script for RDF view of OpenLink Product Portfolio version 2
--

/*
 * This view is currently designed to SPECIFICALLY load on data.openlinksw.com. We recommend you
 * search for `openlinksw.com'  (as `http://' is sometimes encoded) and replace with either the default
 * URIQA macro or your own hostname as appropriate.
 */

-- views to get the codes out instead of the id's
---- in hindsight these should ALL have been handled with
---- proper IRI functions like the rest, oh well, no harm AFAIK
---- will know for next time or might even replace this later.
DROP VIEW oplweb2.oplweb.product_formats_categories;

CREATE VIEW oplweb2.oplweb.product_formats_categories (
    product_cat_code, product_cat_id, product_format_code, product_format_id, product_family_id
  ) as
SELECT distinct
  pc.product_cat_code,
  pc.product_cat_id,
  pf.product_format_code,
  pf.product_format_id,
  pc.product_family_id
FROM
  oplweb2.oplweb.product_category pc,
  oplweb2.oplweb.product_format pf,
  oplweb2.oplweb.product p
WHERE
  p.product_cat_id = pc.product_cat_id and
  p.product_format_id = pf.product_format_id
  AND EXISTS (
	SELECT 1 FROM oplweb2.oplweb.component_archive ca
	WHERE ca.product_id = p.product_id
	)
;


DROP VIEW oplweb2.oplweb.product_with_code;

CREATE VIEW oplweb2.oplweb.product_with_code as
  SELECT p.*, pc.product_cat_code, pf.product_format_code
  FROM
  oplweb2.oplweb.product_category pc,
  oplweb2.oplweb.product_format pf,
  oplweb2.oplweb.product p
WHERE
  p.product_cat_id = pc.product_cat_id and
  p.product_format_id = pf.product_format_id ;


DROP VIEW oplweb2.oplweb.product_category_with_code;

CREATE VIEW oplweb2.oplweb.product_category_with_code as
  SELECT pc.*, pf.product_family_code
  from
  oplweb2.oplweb.product_category pc,
  oplweb2.oplweb.product_family pf
where
  pc.product_family_id = pf.product_family_id ;


DROP VIEW oplweb2.oplweb.product_family_features_with_code;

CREATE VIEW oplweb2.oplweb.product_family_features_with_code as
  SELECT a.*, b.product_family_code
  from
  oplweb2.oplweb.product_family_features a,
  oplweb2.oplweb.product_family b
where
  a.product_family_id = b.product_family_id
;

DROP VIEW oplweb2.oplweb.product_format_features_with_code;

CREATE VIEW oplweb2.oplweb.product_format_features_with_code as
  SELECT a.*, b.product_format_code
  from
  oplweb2.oplweb.product_format_features a,
  oplweb2.oplweb.product_format b
where
  a.product_format_id = b.product_format_id
;

DROP VIEW oplweb2.oplweb.product_category_features_with_code;

CREATE VIEW oplweb2.oplweb.product_category_features_with_code as
  SELECT a.*, b.product_cat_code
  from
  oplweb2.oplweb.product_category_features a,
  oplweb2.oplweb.product_category b
where
  a.product_cat_id = b.product_cat_id
;

DROP VIEW oplweb2.oplweb.components_for_rdfs;

CREATE VIEW oplweb2.oplweb.components_for_rdfs as
  SELECT *, cast(filesize as varchar) as str_filesize
  from
  oplweb2.oplweb.components
;


DROP VIEW oplweb2.oplweb.product_release_with_family;

CREATE VIEW oplweb2.oplweb.product_release_with_family as
  SELECT a.*, b.opsys_family_id, c.dbms_family_id
  from
  oplweb2.oplweb.product_release a,
  oplweb2.oplweb.opsys b,
  oplweb2.oplweb.dbms_engine c
where
  a.opsys_name = b.opsys_name and
  a.dbms_name = c.dbms_name
;

drop view oplweb2.oplweb.archive_coverage_osdb;

create view oplweb2.oplweb.archive_coverage_osdb as
	SELECT distinct
	  pfam.product_family_id, pfam.product_family_code,
	  p.product_format_id, pf.product_format_code,
	  p.product_cat_id, pc.product_cat_code,
	  p.product_id,
	  ca.opsys_name,
	  os.opsys_family_id,
	  ca.dbms_name,
	  db.dbms_family_id,
	  pr.processor_name,
	  pr.processor_mode_id,
	  pr.processor_family_id
	from
	   oplweb2.oplweb.product p
  join oplweb2.oplweb.product_category pc on (p.product_cat_id = pc.product_cat_id)
  join oplweb2.oplweb.product_format pf on (p.product_format_id = pf.product_format_id)
  join oplweb2.oplweb.product_family pfam on (pc.product_family_id = pfam.product_family_id)
  join oplweb2.oplweb.component_archive ca on (ca.product_id = p.product_id)
  join oplweb2.oplweb.opsys os on (os.opsys_name = ca.opsys_name)
  join oplweb2.oplweb.dbms_engine db on (db.dbms_name = ca.dbms_name)
  join oplweb2.oplweb.processors pr on (pr.processor_name = os.processor_name and pr.processor_mode_id = os.processor_mode_id)
;

GRANT SELECT ON oplweb2.oplweb.component_archive TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.component_archive_type TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.component_category TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.component_mode TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.component_type TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.components TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.components_for_rdfs TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.dbms_engine TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.dbms_family TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.download_location TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.download_protocol TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.download_partner TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.opsys TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.opsys_family TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.opsys_type TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.processor_family TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.processor_mode TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.processors TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_benefits TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_benefits_category TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_category TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_category_with_code TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_category_features TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_family TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_family_features TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_features TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_format TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_format_features TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_feature_category TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_release TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_release_features TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.vendor_category TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.vendor_category_family TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.vendors TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_formats_categories TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_with_code TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_family_features_with_code TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_format_features_with_code TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_category_features_with_code TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.product_release_with_family TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON oplweb2.oplweb.archive_coverage_osdb TO "SPARQL", "SPARQL_UPDATE";


drop index oplweb2_product_price_format_cat;

create index oplweb2_product_price_format_cat on oplweb2.oplweb.product_price(product_cat_id, product_format_id, product_price_type_id);

drop index oplweb2_product_discount_format_cat;

create index oplweb2_product_discount_format_cat on oplweb2.oplweb.product_general_discount(product_cat_id, product_format_id, product_price_type_id);


drop view oplweb2.DBA.license_model_type;

create view oplweb2.DBA.license_model_type (
	product_release_id, product_cat_id, product_format_id, product_id, product_price_type_id
	)
	as
	SELECT distinct
	product_release_id,
	pp.product_cat_id, pp.product_format_id, product_id,
	product_price_type_id
	FROM
	  oplweb2.oplweb.product_price pp,
	  oplweb2.oplweb.product p
	WHERE p.product_cat_id = pp.product_cat_id AND
	p.product_format_id = pp.product_format_id
	;

grant SELECT on oplweb2.DBA.license_model_type to "SPARQL", "SPARQL_UPDATE";--, rdf;



drop view oplweb2.DBA.license_model;

create view oplweb2.DBA.license_model as
  SELECT  distinct
      product_release_id,
      pc.product_cat_id,
      pc.product_format_id,
      pc.product_cat_code,
      pc.product_format_code,
      pc.product_id,
      pp.opsys_family_id, pp.dbms_family_id,
      replace(oo.opsys_family_name, ' ', '') as opsys_family_name,
      replace(dd.dbms_family_name,  ' ', '') as dbms_family_name,
      pp.opsys_type_id,
      pp.product_price_type_id,
	  pp.product_price_unit_type_id
    from
      oplweb2.oplweb.product_price pp,
      oplweb2.oplweb.product_with_code pc, --category pc,
      --oplweb2.oplweb.product_format pf,
      oplweb2.oplweb.opsys os,
      oplweb2.oplweb.dbms_engine dbe,
      oplweb2.oplweb.dbms_family dd,
      oplweb2.oplweb.opsys_family oo
      --oplweb2.oplweb.product p
    where
      pp.product_format_id = pc.product_format_id and
      pp.product_cat_id = pc.product_cat_id and
      pp.opsys_family_id = oo.opsys_family_id and
      pp.dbms_family_id = dd.dbms_family_id
      --p.product_cat_id = pc.product_cat_id and
      --p.product_format_id = pf.product_format_id and
  ;

grant SELECT on oplweb2.DBA.license_model to "SPARQL", "SPARQL_UPDATE";--, rdf;


drop view oplweb2.DBA.license_model_units;

create view oplweb2.DBA.license_model_units as
  SELECT distinct
      lm1.product_release_id,
	  lm1.product_id,
	  lm1.opsys_family_
      pp.opsys_family_id, pp.dbms_family_id,
      replace(oo.opsys_family_name, ' ', '') as opsys_family_name,
      replace(dd.dbms_family_name,  ' ', '') as dbms_family_name,
      pp.opsys_type_id, ot.short_description as opsys_type_code
    from
      oplweb2.oplweb.product_price pp,
      oplweb2.oplweb.opsys_type ot,
      oplweb2.oplweb.dbms_family dd,
      oplweb2.oplweb.opsys_family oo
    where
      pp.opsys_type_id = ot.opsys_type_id and
      pp.opsys_family_id = oo.opsys_family_id and
      pp.dbms_family_id = dd.dbms_family_id
      and
      pp.product_release_id = '6.1'
  ;

grant SELECT on oplweb2.DBA.license_model_units to "SPARQL", "SPARQL_UPDATE";--, rdf;



drop view oplweb2.DBA.product_general_discount_vc;

create view oplweb2.DBA.product_general_discount_vc as
  SELECT  distinct
      product_release_id,
      pgd.product_cat_id, pc.product_cat_code,
      pgd.product_format_id, pc.product_format_code,
	  pc.product_id,
      pgd.opsys_family_id, pgd.dbms_family_id,
      pgd.opsys_type_id,
      product_discount_description,
      product_price_type_id,
      cast(unit_discount as varchar) as unit_discount,
      discount_start,
      discount_end,
      discount_token
    from
      oplweb2.oplweb.product_general_discount pgd,
      oplweb2.oplweb.product_with_code pc
    where
      pgd.product_format_id = pc.product_format_id and
      pgd.product_cat_id = pc.product_cat_id
  ;

drop view oplweb2.DBA.product_price_varchar;

create view oplweb2.DBA.product_price_varchar as
  select
      pp.product_price_id,
      pp.product_release_id,
      pp.product_cat_id, pc.product_cat_code,
      pp.product_format_id, pf.product_format_code,
      pp.opsys_family_id, pp.dbms_family_id,
      replace(oo.opsys_family_name, ' ', '') as opsys_family_name,
      replace(dd.dbms_family_name,  ' ', '') as dbms_family_name,
      pp.opsys_type_id, ot.short_description as opsys_type_code,
			pp.product_price_type_id,
      pp.product_price_unit_type_id, cast(pp.unit_price as varchar) as unit_price,
      pp.component_archive_available
    from
      oplweb2.oplweb.product_price pp,
      oplweb2.oplweb.product_category pc,
      oplweb2.oplweb.product_format pf,
      oplweb2.oplweb.opsys_type ot,
      oplweb2.oplweb.dbms_family dd,
      oplweb2.oplweb.opsys_family oo
    where
      pp.product_format_id = pf.product_format_id and
      pp.product_cat_id = pc.product_cat_id and
      pp.opsys_type_id = ot.opsys_type_id and
      pp.opsys_family_id = oo.opsys_family_id and
      pp.dbms_family_id = dd.dbms_family_id
      --and
      --pp.product_release_id = '6.1'
  ;

grant SELECT on oplweb2.oplweb.product_price to "SPARQL", "SPARQL_UPDATE";--, rdf;
grant SELECT on oplweb2.oplweb.product_price_type to "SPARQL", "SPARQL_UPDATE";--, rdf;
grant SELECT on oplweb2.oplweb.product_price_unit_type to "SPARQL", "SPARQL_UPDATE";--, rdf;
grant SELECT on oplweb2.DBA.product_general_discount_vc to "SPARQL", "SPARQL_UPDATE";--, rdf;
grant SELECT on oplweb2.DBA.product_price_varchar to "SPARQL", "SPARQL_UPDATE";--, rdf;
grant SELECT on oplweb2.DBA.license_model_type to "SPARQL", "SPARQL_UPDATE";--, rdf;



DB.DBA.RDF_AUDIT_METADATA (1, '*');
--DB.DBA.RDF_AUDIT_METADATA (2, '*');

--sparql drop graph <http://www.openlinksw.com/dataspace/organization/openlink/ProductPortfolioOntology/1.0/>;

--possible previous graph now merging with this oplweb graph
sparql drop graph <http://data.openlinksw.com/shop_pricing/>;

--others that have a dependency on this graph that may need kicking first
--sparql drop graph <http://data.openlinksw.com/customer/>;
--sparql drop graph <http://data.openlinksw.com/support/>;
--sparql drop graph <http://data.openlinksw.com/shop_pricing/>;

SPARQL drop graph <http://www.openlinksw.com/schemas/oplweb#> ;

SPARQL drop graph <http://www.openlinksw.com/dataspace/organization/openlink/oplweb#> ;
SPARQL drop graph <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/> ;


-- should now use <http://www.openlinksw.com/dataspace/organization/openlink#this>

SPARQL drop quad map virtrdf:product_portfolio ;

--only use this if you really really mean it, it will totally nuke your RDF data, useful on
--test boxes in a bit of jam (hasn't happened to me for a while now)
--rdf_global_reset();

--utility for stripping url killing stuff from friendly strings used as ids
create function oplweb2.oplweb.FIXUP4URI (in _string varchar)
	returns varchar
	{
	  declare _s varchar;
      _s := replace (_string, ' ', '');
      _s := replace (_s, '&', '_');
      _s := replace (_s, '/', '');
      return _s;
	}
	;

--URI-IRI mapping functions
create function oplweb2.oplweb.DOWNLOAD_LOCATION_URI (in uri varchar)
returns varchar
{
  return sprintf('http://data.openlinksw.com/oplweb/download_location/%s#this',
  	replace(uri, 'http://', ''));
};

create function oplweb2.oplweb.DOWNLOAD_LOCATION_URI_INVERSE (in dl_iri varchar)
returns varchar
{
  declare parts any;

  parts := sprintf_inverse(dl_iri,
  	'http://data.openlinksw.com/oplweb/download_location/%s#this', 1);
  if (parts is not null)
    {
      return sprintf('http://%s', parts[0]);
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.DOWNLOAD_LOCATION_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.DOWNLOAD_LOCATION_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.DBMS_FAMILY_URI (in _family_id integer)
returns varchar
{
  declare _family_string varchar;
  SELECT dbms_family_name into _family_string
    FROM oplweb2.oplweb.dbms_family
    WHERE dbms_family_id = _family_id ;

  return sprintf('http://data.openlinksw.com/oplweb/dbms_family/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_family_string));
};

create function oplweb2.oplweb.DBMS_FAMILY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _family_id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/dbms_family/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 dbms_family_id into _family_id FROM oplweb2.oplweb.dbms_family
        WHERE lower(oplweb2.oplweb.FIXUP4URI(dbms_family_name)) = lower(parts[0]);
      return _family_id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.DBMS_FAMILY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.DBMS_FAMILY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.COMPONENT_CATEGORY_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.component_category
    WHERE component_category_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/component_category/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.COMPONENT_CATEGORY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/component_category/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 component_category_id into _id FROM oplweb2.oplweb.component_category
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_CATEGORY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_CATEGORY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.COMPONENT_MODE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.component_mode
    WHERE component_mode_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/component_mode/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.COMPONENT_MODE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/component_mode/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 component_mode_id into _id FROM oplweb2.oplweb.component_mode
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_MODE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_MODE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.COMPONENT_TYPE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.component_type
    WHERE component_type_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/component_type/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.COMPONENT_TYPE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/component_type/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 component_type_id into _id FROM oplweb2.oplweb.component_type
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_TYPE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_TYPE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";



create function oplweb2.oplweb.COMPONENT_ARCHIVE_TYPE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT component_archive_short_name into _string
    FROM oplweb2.oplweb.component_archive_type
    WHERE component_archive_type_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/component_archive_type/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.COMPONENT_ARCHIVE_TYPE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/component_archive_type/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 component_archive_type_id into _id FROM oplweb2.oplweb.component_archive_type
        WHERE lower(oplweb2.oplweb.FIXUP4URI(component_archive_short_name)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_ARCHIVE_TYPE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.COMPONENT_ARCHIVE_TYPE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";



create function oplweb2.oplweb.FEATURE_BENEFIT_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT product_benefit_desc into _string
    FROM oplweb2.oplweb.product_benefits
    WHERE product_benefit_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/feature_benefit/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.FEATURE_BENEFIT_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/feature_benefit/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_benefit_id into _id FROM oplweb2.oplweb.product_benefits
        WHERE lower(oplweb2.oplweb.FIXUP4URI(product_benefit_desc)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.FEATURE_BENEFIT_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.FEATURE_BENEFIT_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";



create function oplweb2.oplweb.OPSYS_FAMILY_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT opsys_family_name into _string
    FROM oplweb2.oplweb.opsys_family
    WHERE opsys_family_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/opsys_family/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.OPSYS_FAMILY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/opsys_family/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 opsys_family_id into _id FROM oplweb2.oplweb.opsys_family
        WHERE lower(oplweb2.oplweb.FIXUP4URI(opsys_family_name)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.OPSYS_FAMILY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.OPSYS_FAMILY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";



create function oplweb2.oplweb.OPSYS_TYPE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.opsys_type
    WHERE opsys_type_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/opsys_type/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.OPSYS_TYPE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/opsys_type/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT TOP 1 opsys_type_id into _id FROM oplweb2.oplweb.opsys_type
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.OPSYS_TYPE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.OPSYS_TYPE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PROCESSOR_FAMILY_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT processor_family_name into _string
    FROM oplweb2.oplweb.processor_family
    WHERE processor_family_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/processor_family/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PROCESSOR_FAMILY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/processor_family/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 processor_family_id into _id FROM oplweb2.oplweb.processor_family
        WHERE lower(oplweb2.oplweb.FIXUP4URI(processor_family_name)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PROCESSOR_FAMILY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PROCESSOR_FAMILY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";

--FIXME might have to do something with possible & symbols
create function oplweb2.oplweb.PROCESSOR_MODE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT processor_mode_name into _string
    FROM oplweb2.oplweb.processor_mode
    where processor_mode_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/processor_mode/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PROCESSOR_MODE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/processor_mode/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 processor_mode_id into _id FROM oplweb2.oplweb.processor_mode
        WHERE lower(oplweb2.oplweb.FIXUP4URI(processor_mode_name)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PROCESSOR_MODE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PROCESSOR_MODE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_CATEGORY_FEATURE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.product_category_features
    WHERE product_category_feature_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_category_feature/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_CATEGORY_FEATURE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_category_feature/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_category_feature_id into _id FROM oplweb2.oplweb.product_category_features
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_CATEGORY_FEATURE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_CATEGORY_FEATURE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_FAMILY_FEATURE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.product_family_features
    WHERE product_family_feature_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_family_feature/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_FAMILY_FEATURE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_family_feature/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_family_feature_id into _id FROM oplweb2.oplweb.product_family_features
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FAMILY_FEATURE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FAMILY_FEATURE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_FEATURE_CATEGORY_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_desc into _string
    FROM oplweb2.oplweb.product_feature_category
    WHERE product_feature_category_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_feature_category/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_FEATURE_CATEGORY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_feature_category/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_feature_category_id into _id FROM oplweb2.oplweb.product_feature_category
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_desc)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FEATURE_CATEGORY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FEATURE_CATEGORY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_FEATURE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.product_features
    WHERE product_feature_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_feature/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_FEATURE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_feature/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_feature_id into _id FROM oplweb2.oplweb.product_features
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FEATURE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FEATURE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_FORMAT_FEATURE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.product_format_features
    WHERE product_format_feature_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_format_feature/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_FORMAT_FEATURE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_format_feature/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_format_feature_id into _id FROM oplweb2.oplweb.product_format_features
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FORMAT_FEATURE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_FORMAT_FEATURE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_RELEASE_FEATURE_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT short_description into _string
    FROM oplweb2.oplweb.product_release_features
    WHERE product_release_feature_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_release_feature/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_RELEASE_FEATURE_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_release_feature/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_release_feature_id into _id FROM oplweb2.oplweb.product_release_features
        WHERE lower(oplweb2.oplweb.FIXUP4URI(short_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_RELEASE_FEATURE_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_RELEASE_FEATURE_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_BENEFIT_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT product_benefit_desc into _string
    FROM oplweb2.oplweb.product_benefits
    WHERE product_benefit_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_benefit/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_BENEFIT_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_benefit/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_benefit_id into _id FROM oplweb2.oplweb.product_benefits
        WHERE lower(oplweb2.oplweb.FIXUP4URI(product_benefit_desc)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_BENEFIT_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_BENEFIT_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.PRODUCT_BENEFIT_CATEGORY_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT description into _string
    FROM oplweb2.oplweb.product_benefits_category
    WHERE product_benefit_category_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/product_benefit_category/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.PRODUCT_BENEFIT_CATEGORY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/product_benefit_category/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 product_benefit_category_id into _id FROM oplweb2.oplweb.product_benefits_category
        WHERE lower(oplweb2.oplweb.FIXUP4URI(description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_BENEFIT_CATEGORY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.PRODUCT_BENEFIT_CATEGORY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.VENDOR_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT vendor_name into _string
    FROM oplweb2.oplweb.vendors
    where vendor_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/vendor/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.VENDOR_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/vendor/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 vendor_id into _id FROM oplweb2.oplweb.vendors
        WHERE lower(oplweb2.oplweb.FIXUP4URI(vendor_name)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.VENDOR_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.VENDOR_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.VENDOR_CATEGORY_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT vendor_category_description into _string
    FROM oplweb2.oplweb.vendor_category
    where vendor_category_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/vendor_category/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.VENDOR_CATEGORY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/vendor_category/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 vendor_category_id into _id FROM oplweb2.oplweb.vendor_category
        WHERE lower(oplweb2.oplweb.FIXUP4URI(vendor_category_description)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.VENDOR_CATEGORY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.VENDOR_CATEGORY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.VENDOR_CATEGORY_FAMILY_URI (in _id integer)
returns varchar
{
  declare _string varchar;
  SELECT vendor_category_family_desc into _string
    FROM oplweb2.oplweb.vendor_category_family
    where vendor_category_family_id = _id ;

  return sprintf('http://data.openlinksw.com/oplweb/vendor_category_family/%s#this',
  	oplweb2.oplweb.FIXUP4URI(_string));
};

create function oplweb2.oplweb.VENDOR_CATEGORY_FAMILY_URI_INVERSE (in _iri varchar)
returns integer
{
  declare parts any;
  declare _id integer;

  parts := sprintf_inverse(_iri,
  	'http://data.openlinksw.com/oplweb/vendor_category_family/%s#this', 1);
  if (parts is not null)
    {
      declare exit handler for not found return null;
      SELECT top 1 vendor_category_family_id into _id FROM oplweb2.oplweb.vendor_category_family
        WHERE lower(oplweb2.oplweb.FIXUP4URI(vendor_category_family_desc)) = lower(parts[0]);
      return _id;
    }
  return NULL;
};

GRANT EXECUTE ON oplweb2.oplweb.VENDOR_CATEGORY_FAMILY_URI TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON oplweb2.oplweb.VENDOR_CATEGORY_FAMILY_URI_INVERSE TO "SPARQL", "SPARQL_UPDATE";





create function oplweb2.oplweb.LIT_PRODUCT_RELEASE_LABEL (
	in _product_id varchar, in _id integer, in _opsys_name varchar, in _dbms_name varchar
	)
returns varchar
{
  declare _string varchar;
  SELECT 'OpenLink ' || poduct_description || ' (Release ' || product_release_id || ') on ' || commercial_name into _string
    FROM oplweb2.oplweb.product_release pr,
      oplweb2.oplweb.product p,
      oplweb2.oplweb.opsys o
    where
      p.product_id = pr.product_id and
      o.opsys_name = pr.opsys_name and
      pr.product_release_id = _id and
      pr.product_id = _product_id and
      pr.opsys_name = _opsys_name and
      pr.dbms_name = _dbms_name ;

  return _string;
};

GRANT EXECUTE ON oplweb2.oplweb.LIT_PRODUCT_RELEASE_LABEL TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LIT_FORMAT_CAT_LABEL (
	in _format integer, in _cat integer
	)
returns varchar
{
  declare _string varchar;
  SELECT top 1 'OpenLink ' || cast(product_format_description as varchar) || ' ' || cast(product_category_description as varchar) into _string
    from
      oplweb2.oplweb.product_formats_categories fc,
      oplweb2.oplweb.product_format f,
      oplweb2.oplweb.product_category c
    where
fc.product_format_id = f.product_format_id and
fc.product_cat_id = c.product_cat_id and
    fc.product_format_id = _format and
    fc.product_cat_id = _cat;

  return _string;
};

GRANT EXECUTE ON oplweb2.oplweb.LIT_FORMAT_CAT_LABEL TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LITRDF_openlink_logo (in _code varchar)
returns varchar
{
  declare _string varchar;
  SELECT top 1 product_family_logo_url into _string
    FROM oplweb2.oplweb.product_family
    WHERE product_family_code = _code;

  return _string;
};

GRANT EXECUTE ON oplweb2.oplweb.LITRDF_openlink_logo TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LITRDF_homepage (in _code varchar)
returns varchar
{
  declare _string varchar;
  SELECT top 1 product_family_homepage into _string
    FROM oplweb2.oplweb.product_family
    WHERE product_family_code = _code;

  return _string;
};

GRANT EXECUTE ON oplweb2.oplweb.LITRDF_homepage TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LITRDF_opsys_icon (in _id integer)
returns varchar
{
  declare _string varchar; _string := '';
  SELECT top 1 opsys_icon_name into _string
    FROM oplweb2.oplweb.opsys_family
    where opsys_family_id = _id;

  _string := 'http://download.openlinksw.com/download/images/'||_string;

  return _string;
};

GRANT EXECUTE ON oplweb2.oplweb.LITRDF_opsys_icon TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LITRDF_to_shop (
	in release_id varchar,
	in product_id varchar,
	in opsys varchar,
	in dbms varchar
	)
returns varchar
{
  declare _string varchar; _string := '';
  declare _cat, _format, _prod varchar;

  _prod := product_id;

  SELECT top 1 cast(product_cat_id as varchar), cast(product_format_id as varchar)
      into _cat, _format
    FROM oplweb2.oplweb.product p
    WHERE p.product_id = _prod;

  _string := sprintf(
	'https://shop.openlinksw.com/?product_release_id=%s&product=%s&product_cat=%V&product_format=%V&os=%s&db=%s&buyme=yes',
	release_id, product_id, _cat, _format, opsys, dbms
	);

  return _string;
};

GRANT EXECUTE ON oplweb2.oplweb.LITRDF_to_shop TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LITRDF_license_model_type (
		in _product_price_type_id integer
	)
returns varchar
{
  declare _string varchar; _string := '';

  SELECT top 1 product_price_type_description into _string FROM oplweb2.oplweb.product_price_type
    WHERE product_price_type_id = _product_price_type_id;

  return _string || ' License';
};

GRANT EXECUTE ON oplweb2.oplweb.LITRDF_license_model_type TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LITRDF_license_model_explain (
		in _product_price_type_id integer
	)
returns varchar
{
  declare _string varchar; _string := '';

  SELECT top 1 product_price_type_long_description into _string FROM oplweb2.oplweb.product_price_type
    WHERE product_price_type_id = _product_price_type_id;

  return _string;
};

GRANT EXECUTE ON oplweb2.oplweb.LITRDF_license_model_explain TO "SPARQL", "SPARQL_UPDATE";


create function oplweb2.oplweb.LITRDF_shop_sample (
	in release_id varchar,
	in product_id varchar,
	in opsys varchar,
	in dbms varchar
	)
returns varchar
{
  declare _string varchar; _string := '';
  declare _cat, _format, _prod, _pricetype varchar;

  _prod := product_id;

  SELECT top 1 cast(product_cat_id as varchar), cast(product_format_id as varchar), cast(product_price_type_id as varchar)
      into _cat, _format, _pricetype
    FROM oplweb2.DBA.license_model p, oplweb2.oplweb.opsys o, oplweb2.oplweb.dbms_engine e
    WHERE p.product_id = _prod and product_release_id = release_id and o.opsys_name = opsys and e.dbms_name = dbms
      and p.dbms_family_id = e.dbms_family_id and o.opsys_family_id = p.opsys_family_id;

  _string := sprintf(
	'https://shop.openlinksw.com/price_calc.vsp?release=%s&cat=%V&format=%V&os=%s&db=%s&lictype=%V',
	release_id, _cat, _format, opsys, dbms, _pricetype
	);

  return http_client(_string);
};

GRANT EXECUTE ON oplweb2.oplweb.LITRDF_shop_sample TO "SPARQL", "SPARQL_UPDATE";


-- $Id: rdfviewssamples.xml,v 1.1.2.2 2011/09/09 14:09:19 source Exp $
-- Setup script for RDF view of OpenLink Product Portfolio version 2
--

--
-- This view is currently designed to SPECIFICALLY load on data.openlinksw.com. The default URI macro has NOT
-- been used here because it makes no sense on the target box which is actually my.usnet.private:8891 or
-- something similar. If you want to use this view on another box, a simple search-replace should do the trick,
-- but search-replace just`data.openlinksw.com' because http:// is sometimes encoded and you would miss it.
--
--



SPARQL drop quad map virtrdf:product_portfolio2 ;
SPARQL drop quad map virtrdf:product_portfolio ;

SPARQL

prefix opl: <http://www.openlinksw.com/schemas/oplweb#>

drop iri class opl:DownloadLocation .
drop iri class opl:ComponentCategory .
drop iri class opl:Component .
drop iri class opl:ComponentArchive .
drop iri class opl:ComponentArchiveType .
drop iri class opl:ComponentCategory .
drop iri class opl:ComponentMode .
drop iri class opl:ComponentType .
drop iri class opl:DbmsEngine .
drop iri class opl:DbmsFamily .
drop iri class opl:DownloadProtocol .
drop iri class opl:DownloadPartner .
drop iri class opl:FeatureBenefit .
drop iri class opl:Opsys .
drop iri class opl:OpsysFamily .
drop iri class opl:OpsysType .
drop iri class opl:Processor .
drop iri class opl:ProcessorFamily .
drop iri class opl:ProcessorMode .
drop iri class opl:ProductRelease .
drop iri class opl:Product .
drop iri class opl:ProductCategory .
drop iri class opl:ProductCategoryFeature .
drop iri class opl:ProductPortfolio .
drop iri class opl:ProductFamily .
drop iri class opl:ProductFamilyFeature .
drop iri class opl:ProductFeatureCategory .
drop iri class opl:ProductFeature .
drop iri class opl:ProductFormat .
drop iri class opl:ProductFormatCategory .
drop iri class opl:ProductFormatFeature .
drop iri class opl:ProductReleaseFeature .
drop iri class opl:ProductBenefit .
drop iri class opl:ProductBenefitCategory .
drop iri class opl:Vendor .
drop iri class opl:VendorCategory .
drop iri class opl:VendorCategoryFamily .
drop iri class opl:PriceType .
drop iri class opl:PriceUnitType .
drop iri class opl:PriceUnitIncrementalDiscount .
drop iri class opl:ProductPrice .
drop iri class opl:LicenseType .
drop iri class opl:LicenseModel .
drop iri class opl:LicenseClass .
drop iri class opl:Discount .
drop literal class opl:lit_product_release_label .
drop literal class opl:lit_format_cat_label .
drop literal class opl:lit_openlink_logo .
drop iri class opl:lit_openlink_logo .
drop literal class opl:lit_homepage .
drop iri class opl:lit_homepage .
drop literal class opl:lit_opsys_icon .
drop iri class opl:lit_opsys_icon .
drop literal class opl:lit_to_shop .
drop iri class opl:lit_to_shop .
drop literal class opl:lit_license_model_type .
drop literal class opl:lit_license_model_explain .
drop literal class opl:lit_shop_sample .
drop literal class opl:lit_wikipedia_to_dbpedia .
drop iri class opl:lit_wikipedia_to_dbpedia .
drop literal class opl:lit_to_string .
drop iri class opl:wwwsitefamily .
drop iri class opl:wwwsiteformat .
drop iri class opl:wwwsitecategory .
drop iri class opl:wwwsiteproduct .
;

DB.DBA.RDF_AUDIT_METADATA (1, '*');


SPARQL

prefix opl: <http://www.openlinksw.com/schemas/oplweb#>

create iri class opl:Component "http://data.openlinksw.com/oplweb/component/%s#this"
	(in component_name varchar not null) .

create iri class opl:ComponentArchive "http://data.openlinksw.com/oplweb/component_archive/%s#this"
	(in component_archive_name varchar not null) .

create iri class opl:ComponentArchiveType using
	function oplweb2.oplweb.COMPONENT_CATEGORY_URI (in _id integer not null)
		returns varchar,
	function oplweb2.oplweb.COMPONENT_CATEGORY_URI_INVERSE (in _iri varchar)
		returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/component_archive_type/%s#this' ).


create iri class opl:ComponentCategory using
	function oplweb2.oplweb.COMPONENT_CATEGORY_URI (in _id integer not null)
		returns varchar,
	function oplweb2.oplweb.COMPONENT_CATEGORY_URI_INVERSE (in _iri varchar)
		returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/component_category/%s#this' ).

create iri class opl:ComponentMode using
	function oplweb2.oplweb.COMPONENT_MODE_URI (in _id integer not null)
		returns varchar,
	function oplweb2.oplweb.COMPONENT_MODE_URI_INVERSE (in _iri varchar)
		returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/component_mode/%s#this' ).

create iri class opl:ComponentType using
	function oplweb2.oplweb.COMPONENT_TYPE_URI (in _id integer not null)
		returns varchar,
	function oplweb2.oplweb.COMPONENT_TYPE_URI_INVERSE (in _iri varchar)
		returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/component_type/%s#this' ).

create iri class opl:DbmsFamily using
	function oplweb2.oplweb.DBMS_FAMILY_URI (in _family_id integer not null)
		returns varchar,
	function oplweb2.oplweb.DBMS_FAMILY_URI_INVERSE (in _iri varchar)
		returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/dbms_family/%s#this' ).

create iri class opl:DbmsEngine "http://data.openlinksw.com/oplweb/dbms_engine/%s#this"
	(in dbms_name varchar not null) .

create iri class opl:DownloadLocation using
	function oplweb2.oplweb.DOWNLOAD_LOCATION_URI (in uri varchar not null)
		returns varchar,
	function oplweb2.oplweb.DOWNLOAD_LOCATION_URI_INVERSE (in dl_iri varchar)
		returns varchar
	option (bijection, returns 'http://data.openlinksw.com/oplweb/download_location/%s#this' ).

create iri class opl:DownloadProtocol "http://data.openlinksw.com/oplweb/download_protocol/%s#this"
	(in protocol_name varchar not null) .

create iri class opl:DownloadPartner "http://data.openlinksw.com/oplweb/download_partner/%s/%s#this"
	(
	  in host_name varchar not null,
	  in domain_name varchar not null
	) .

create iri class opl:FeatureBenefit using
  function oplweb2.oplweb.FEATURE_BENEFIT_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.FEATURE_BENEFIT_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/feature_benefit/%s#this' ).

create iri class opl:Opsys "http://data.openlinksw.com/oplweb/opsys/%s#this"
	(in opsys_name varchar not null) .

create iri class opl:OpsysFamily 	using
  function oplweb2.oplweb.OPSYS_FAMILY_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.OPSYS_FAMILY_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/opsys_family/%s#this' ).

create iri class opl:OpsysType 			using
  function oplweb2.oplweb.OPSYS_TYPE_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.OPSYS_TYPE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/opsys_type/%s#this' ).

create iri class opl:Processor "http://data.openlinksw.com/oplweb/processor/%s/%d#this"
	(in processor_name varchar not null, in processor_mode_id integer not null) .

create iri class opl:ProcessorFamily 	using
  function oplweb2.oplweb.PROCESSOR_FAMILY_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PROCESSOR_FAMILY_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/processor_family/%s#this' ).

create iri class opl:ProcessorMode 			using
  function oplweb2.oplweb.PROCESSOR_MODE_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PROCESSOR_MODE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/processor_mode/%s#this' ).

create iri class opl:Product "http://data.openlinksw.com/oplweb/product/%s#this"
	(in product_id varchar not null) .

create iri class opl:ProductCategory "http://data.openlinksw.com/oplweb/product_category/%s#this"
	(in product_cat_code varchar not null) .

create iri class opl:ProductCategoryFeature 	using
  function oplweb2.oplweb.PRODUCT_CATEGORY_FEATURE_URI (in _id integer not null) returns varchar,
		function oplweb2.oplweb.PRODUCT_CATEGORY_FEATURE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_category_feature/%s#this' ).

create iri class opl:ProductPortfolio "http://data.openlinksw.com/oplweb/portfolio/%s#this"
	(in x varchar not null) .

create iri class opl:ProductFamily "http://data.openlinksw.com/oplweb/product_family/%s#this"
	(in product_family_code varchar not null) .

create iri class opl:ProductFamilyFeature 	using
  function oplweb2.oplweb.PRODUCT_FAMILY_FEATURE_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PRODUCT_FAMILY_FEATURE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_family_feature/%s#this' ).

create iri class opl:ProductFeatureCategory 			using
  function oplweb2.oplweb.PRODUCT_FEATURE_CATEGORY_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PRODUCT_FEATURE_CATEGORY_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_feature_category/%s#this' ).

create iri class opl:ProductFeature 					using
  function oplweb2.oplweb.PRODUCT_FEATURE_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PRODUCT_FEATURE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_feature/%s#this' ).

create iri class opl:ProductFormat "http://data.openlinksw.com/oplweb/product_format/%s#this"
	(in product_format_code varchar not null) .

create iri class opl:ProductFormatCategory "http://data.openlinksw.com/oplweb/product_format_category/%s/%s#this"
	(in product_format_code varchar not null, in product_cat_code varchar not null) .

create iri class opl:ProductFormatFeature 	using
  function oplweb2.oplweb.PRODUCT_FORMAT_FEATURE_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PRODUCT_FORMAT_FEATURE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_format_feature/%s#this' ).

create iri class opl:ProductReleaseFeature 			using
  function oplweb2.oplweb.PRODUCT_RELEASE_FEATURE_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PRODUCT_RELEASE_FEATURE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_release_feature/%s#this' ).

create iri class opl:ProductBenefit 					using
  function oplweb2.oplweb.PRODUCT_BENEFIT_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PRODUCT_BENEFIT_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_benefit/%s#this' ).

create iri class opl:ProductBenefitCategory 							using
  function oplweb2.oplweb.PRODUCT_BENEFIT_CATEGORY_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.PRODUCT_BENEFIT_CATEGORY_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/product_benefit_category/%s#this' ).

create iri class opl:ProductRelease "http://data.openlinksw.com/oplweb/product_release/%s/%s/%s/%s#this"
	(
	 in product_id varchar not null,
	 in product_release_id varchar not null,
	 in opsys_name varchar not null,
	 in dbms_name varchar not null
	) .

create iri class opl:Vendor 	using
  function oplweb2.oplweb.VENDOR_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.VENDOR_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/vendor/%s#this' ).

create iri class opl:VendorCategory 			using
  function oplweb2.oplweb.VENDOR_CATEGORY_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.VENDOR_CATEGORY_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/vendor_category/%s#this' ).

create iri class opl:VendorCategoryFamily 					using
  function oplweb2.oplweb.VENDOR_CATEGORY_FAMILY_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.VENDOR_CATEGORY_FAMILY_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/vendor_category_family/%s#this' ).

create iri class opl:PriceType "http://data.openlinksw.com/oplweb/price_type/%d#this"
    (in product_price_type_id integer not null) .

create iri class opl:LicenseType using
  function oplweb2.oplweb.LICENSE_MODEL_TYPE_URI (in _id integer not null) returns varchar,
  function oplweb2.oplweb.LICENSE_MODEL_TYPE_URI_INVERSE (in _iri varchar) returns integer
	option (bijection, returns 'http://data.openlinksw.com/oplweb/license_type/%s#this' ).

create iri class opl:PriceUnitType "http://data.openlinksw.com/oplweb/price_unit_type/%s_%s_%d_%d_%d_%s#this"
    (
    in product_release_id varchar not null,
    in product_id varchar not null,
    in opsys_family_id integer not null,
    in dbms_family_id integer not null,
    in product_price_type_id integer not null,
	in product_price_unit_type_id varchar not null) .

create iri class opl:PriceUnitIncrementalDiscount "http://data.openlinksw.com/oplweb/price_unit_discount/%s_%s_%d_%d_%d_%s#this"
    (
    in product_release_id varchar not null,
    in product_id varchar not null,
    in opsys_family_id integer not null,
    in dbms_family_id integer not null,
    in product_price_type_id integer not null,
	in product_price_unit_type_id varchar not null) .

create iri class opl:ProductPrice "http://data.openlinksw.com/oplweb/product_price/%d#this"
    (in product_price_id integer not null) .


create iri class opl:LicenseModel "http://data.openlinksw.com/oplweb/license_model/%s_%s_%d_%d_%d#this"
    (
      in product_release_id varchar not null,
      in product_id varchar not null,
      in opsys_family_id integer not null,
      in dbms_family_id integer not null,
	  in product_price_type_id integer not null
    ) .

create iri class opl:Discount "http://data.openlinksw.com/oplweb/discount/%s/%d/%s/%d/%d/%d#this"
    (
      in product_release_id varchar not null,
      in opsys_type_id integer not null,
      in product_id varchar not null,
      in opsys_family_id integer not null,
      in dbms_family_id integer not null,
      in product_price_type_id integer not null
    ) .

create iri class opl:wwwsitefamily "http://%s.openlinksw.com/"
    (
      in product_family_code varchar not null
    ) .

create iri class opl:wwwsitecategory "http://%s.openlinksw.com/%s/"
    (
      in product_family_code varchar not null,
      in product_category_code varchar not null
    ) .

create iri class opl:wwwsiteformat "http://%s.openlinksw.com/%s/%s/"
    (
      in product_family_code varchar not null,
      in product_category_code varchar not null,
      in product_format_code varchar not null
    ) .

create iri class opl:Uri "%s"
    ( in uri varchar not null
		) .

create literal class opl:lit_product_release_label using
	function oplweb2.oplweb.LIT_PRODUCT_RELEASE_LABEL(
		in _product_id varchar, in _id integer, in _opsys_name varchar, in _dbms_name varchar
		)
	returns varchar .

create literal class opl:lit_format_cat_label using
	function oplweb2.oplweb.LIT_FORMAT_CAT_LABEL(
		in _format integer, in _cat integer
		)
	returns varchar .

create iri class opl:lit_openlink_logo using
  function oplweb2.oplweb.LITRDF_openlink_logo(
    in _code varchar
  )
	returns varchar .

create iri class opl:lit_homepage using
  function oplweb2.oplweb.LITRDF_homepage(
    in _code varchar
  )
	returns varchar .

create iri class opl:lit_opsys_icon using
  function oplweb2.oplweb.LITRDF_opsys_icon(
    in _id integer
  )
	returns varchar .

create iri class opl:lit_to_shop using
  function oplweb2.oplweb.LITRDF_to_shop(
	in release_id varchar,
	in product_id varchar,
	in opsys varchar,
	in dbms varchar
  )
  returns varchar .

create literal class opl:lit_license_model_type using
	function oplweb2.oplweb.LITRDF_license_model_type (
		in _product_price_type_id integer
	)
	returns varchar .

create literal class opl:lit_license_model_explain using
	function oplweb2.oplweb.LITRDF_license_model_explain (
		in _product_price_type_id integer
	)
	returns varchar .

create literal class opl:lit_shop_sample using
	function oplweb2.oplweb.LITRDF_shop_sample (
	  in release_id varchar,
	  in product_id varchar,
	  in opsys varchar,
  	  in dbms varchar
	)
	returns varchar .

create iri class opl:lit_wikipedia_to_dbpedia using
	function oplweb2.oplweb.LITRDF_wikipedia_to_dbpedia (
	  in wikipedia_url varchar
	)
	returns varchar .

create literal class opl:lit_to_string using
	function oplweb2.oplweb.LITRDF_to_string (
	  in _s varchar
	)
	returns varchar .

create iri class opl:wwwsiteproduct using
  function oplweb2.oplweb.wwwsiteproduct_URI (in _id varchar not null) returns varchar,
  function oplweb2.oplweb.wwwsiteproduct_URI_INVERSE (in _iri varchar) returns varchar
  .


make opl:ProductCategory 	subclass of opl:ProductFamily .
make opl:Product 			subclass of opl:ProductCategory .
make opl:Product 			subclass of opl:ProductFormat .
make opl:ProductRelease		subclass of opl:Product .
make opl:Opsys		 		subclass of opl:OpsysFamily .
make opl:DbmsEngine		 	subclass of opl:DbmsFamily .

;



DB.DBA.RDF_AUDIT_METADATA (1, '*');


SPARQL
prefix opl: <http://www.openlinksw.com/schemas/oplweb#>
prefix dc: <http://purl.org/dc/terms#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix oplds: <http://www.openlinksw.com/dataspace/organization/openlink#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix umbel: <http://umbel.org/umbel/sc/>
prefix gr: <http://purl.org/goodrelations/v1#>

alter quad storage virtrdf:DefaultQuadStorage
FROM oplweb2.oplweb.component_archive as component_archive_tbl
FROM oplweb2.oplweb.component_archive_type as component_archive_type_tbl
FROM oplweb2.oplweb.component_category as component_category_tbl text literal component_category_long_description
FROM oplweb2.oplweb.component_mode as component_mode_tbl
FROM oplweb2.oplweb.component_type as component_type_tbl
FROM oplweb2.oplweb.components_for_rdfs as components_tbl
FROM oplweb2.oplweb.dbms_engine as dbms_engine_tbl
FROM oplweb2.oplweb.dbms_family as dbms_family_tbl
FROM oplweb2.oplweb.download_location as download_location_tbl
FROM oplweb2.oplweb.download_protocol as download_protocol_tbl
FROM oplweb2.oplweb.download_partner as download_partner_tbl
FROM oplweb2.oplweb.opsys as opsys_tbl
FROM oplweb2.oplweb.opsys_family as opsys_family_tbl
FROM oplweb2.oplweb.opsys_type as opsys_type_tbl
FROM oplweb2.oplweb.processor_family as processor_family_tbl
FROM oplweb2.oplweb.processor_mode as processor_mode_tbl
FROM oplweb2.oplweb.processors as processors_tbl
FROM oplweb2.oplweb.product as product_tbl text literal long_description
FROM oplweb2.oplweb.product_benefits as product_benefits_tbl text literal product_benefit_explanation
FROM oplweb2.oplweb.product_benefits_category as product_benefits_category_tbl
FROM oplweb2.oplweb.product_category as product_category_tbl
FROM oplweb2.oplweb.product_category_features_with_code as product_category_features_tbl text literal long_description
FROM oplweb2.oplweb.product_family as product_family_tbl
FROM oplweb2.oplweb.product_family as product_family_tbl_2
FROM oplweb2.oplweb.product_family_features_with_code as product_family_features_tbl text literal long_description
FROM oplweb2.oplweb.product_features as product_features_tbl text literal long_description
FROM oplweb2.oplweb.product_feature_category as product_feature_category_tbl text literal description
FROM oplweb2.oplweb.product_format_features_with_code as product_format_features_tbl text literal long_description
FROM oplweb2.oplweb.product_release_features as product_release_features_tbl text literal long_description
FROM oplweb2.oplweb.product_release_with_family as product_release_tbl
FROM oplweb2.oplweb.vendor_category as vendor_category_tbl
FROM oplweb2.oplweb.vendor_category_family as vendor_category_family_tbl
FROM oplweb2.oplweb.vendors as vendors_tbl
FROM oplweb2.oplweb.product_formats_categories as product_formats_categories
FROM oplweb2.oplweb.product_with_code as product_with_code
FROM oplweb2.oplweb.product_category_with_code as product_category_with_code
FROM oplweb2.oplweb.product_format as product_format_with_code
FROM oplweb2.oplweb.product_price as pp
FROM oplweb2.oplweb.product_price_type as pt
FROM oplweb2.DBA.license_model_unit_type as put
FROM oplweb2.DBA.license_model_unit_type as put2
FROM oplweb2.DBA.license_model as lm
FROM oplweb2.DBA.license_model as lm2
FROM oplweb2.DBA.license_model_type as license_model_type_tbl
FROM oplweb2.DBA.product_price_varchar as ppv
FROM oplweb2.DBA.product_general_discount_vc as gd
FROM oplweb2.oplweb.archive_coverage_osdb as ac1
{
	create virtrdf:product_portfolio as
		graph <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
	{
  opl:ProductPortfolio(product_family_tbl.product_family_code)
    a opl:ProductPortfolio
    as virtrdf:OplProductPortfolio .

  opl:ProductPortfolio(product_family_tbl.product_family_code) opl:hasProductFamilies
    opl:ProductFamily(product_family_tbl.product_family_code)
	as virtrdf:OplProductPortfolioProductFamily .

	  opl:ProductFamily(product_family_tbl.product_family_code)
	    a opl:ProductFamily
	    as virtrdf:OplProductFamily ;
	  rdfs:label product_family_tbl.product_family_description
	    as virtrdf:rdfsOplProductFamilyDescription ;
	  foaf:name 	product_family_tbl.product_family_description
		    as virtrdf:nameOplProductFamilyDescription ;
	  foaf:logo  opl:lit_openlink_logo(product_family_tbl.product_family_code)
	        as virtrdf:logoOpenLinkSoftware ;
	  foaf:homepage opl:lit_homepage(product_family_tbl.product_family_code)
	        as virtrdf:homepageProductFamily ;
	  foaf:homepage opl:wwwsitefamily(product_family_tbl.product_family_code)
#	    where (
#			^{product_family_tbl.}^.product_family_code = 'uda'
#		)
	        as virtrdf:homepageProductFamilyUda ;
	  foaf:maker oplds:this
	        as virtrdf:OplDataspaceOpenLinkUri ;
  	  owl:sameAs product_family_tbl.dbpedia_uri
        as virtrdf:OplFamilyOwlSameAsDBPediaUri ;
	  opl:ProductFamilyCode product_family_tbl.product_family_code
	    as virtrdf:OplProductFamilyCode ;
	  opl:ProductFamilyDescription product_family_tbl.product_family_description
	    as virtrdf:OplProductFamilyDescription ;
	  dc:description opl:lit_to_string(product_family_tbl.long_description)
	    as virtrdf:OplProductFamilyLongDescription 		;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy owl: ;
      rdfs:isDefinedBy rdfs:
		.

	  opl:ProductCategory(product_category_with_code.product_cat_code)
	    a opl:ProductCategory
	    as virtrdf:OplProductCategory ;
	    a opl:ProductFamily
	    as virtrdf:OplProductCategorySubClassOfProductFamily ;
	  rdfs:label product_category_with_code.product_category_description
	    as virtrdf:rdfsOplProductCategoryDescription ;
	  foaf:homepage opl:wwwsitecategory(product_category_with_code.product_family_code, product_category_with_code.product_cat_code)
#	    where (
#			^{product_category_with_code.}^.product_family_code = 'uda'
#		)
	        as virtrdf:homepageProductFamilyCategoryUda ;
	  opl:ProductCategoryCode product_category_with_code.product_cat_code
	    as virtrdf:OplProductCategoryCode ;
  	  owl:sameAs product_category_with_code.dbpedia_uri
        as virtrdf:OplCategoryOwlSameAsDBPediaUri ;
	  opl:hasFamily opl:ProductFamily(product_category_with_code.product_family_code)
	    as virtrdf:OplProductCategoryIsOfFamily ;
	  opl:ProductCategoryDescription product_category_with_code.product_category_description
	    as virtrdf:OplProductCategoryDescription ;
	  dc:description opl:lit_to_string(product_category_with_code.long_description)
	    as virtrdf:OplProductCategoryLongDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy owl:
		.

	  opl:ProductFormat(product_format_with_code.product_format_code)
	    a opl:ProductFormat
	    as virtrdf:OplProductFormat ;
	  opl:ProductFormatCode product_format_with_code.product_format_code
	    as virtrdf:OplProductFormatCode ;
	  rdfs:label product_format_with_code.product_format_description
	    as virtrdf:rdfsOplProductFormatDescription ;
	  dc:description product_format_with_code.product_format_description
	    as virtrdf:OplProductFormatDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs: ;
      rdfs:isDefinedBy dc:
		.

	  opl:ProductFormatCategory(product_formats_categories.product_format_code, product_formats_categories.product_cat_code)
	    a opl:ProductFormatCategory
	    as virtrdf:OplProductFormatCategory ;
	    a opl:ProductFormat
	    as virtrdf:OplProductFormatCategoryProductFormat ;
	    a opl:ProductCategory
	    as virtrdf:OplProductFormatCategoryProductCategory ;
	  foaf:homepage opl:wwwsiteformat(product_category_with_code.product_family_code, product_formats_categories.product_cat_code, product_formats_categories.product_format_code)
	    where (
			^{product_category_with_code.}^.product_cat_code = ^{product_formats_categories.}^.product_cat_code
#			and
#			^{product_category_with_code.}^.product_family_code = 'uda'
		)
	        as virtrdf:homepageProductFamilyCategoryFormatUda ;
	  opl:ProductFormatCode product_formats_categories.product_format_code
	    as virtrdf:OplProductFormatCategoryFormatCode ;
	  opl:ProductCategoryCode product_formats_categories.product_cat_code
	    as virtrdf:OplProductFormatCategoryCategoryCode ;
      opl:isProductCategory opl:ProductCategory(product_formats_categories.product_cat_code)
        as virtrdf:OplProductFormatCategoryisCategory ;
      opl:isProductFormat opl:ProductFormat(product_formats_categories.product_format_code)
        as virtrdf:OplProductFormatCategoryisFormat ;
	  rdfs:label opl:lit_format_cat_label(product_formats_categories.product_format_id, product_formats_categories.product_cat_id)
	    as virtrdf:rdfsOplProductFormatCategoryDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy rdfs:
		.


	  opl:ProductCategory(product_category_with_code.product_cat_code) opl:hasProduct
	    opl:Product(product_with_code.product_id)
	      where (^{product_with_code.}^.product_cat_id = ^{product_category_with_code.}^.product_cat_id)
	    as virtrdf:OplProductCategoryIsCategoryOfProduct .

	  opl:ProductFormat(product_format_with_code.product_format_code) opl:hasProduct
	    opl:Product(product_with_code.product_id)
	      where (^{product_with_code.}^.product_format_id = ^{product_format_with_code.}^.product_format_id)
	    as virtrdf:OplProductFormatIsFormatOfProduct .

	  opl:ProductFamily(product_family_tbl.product_family_code) opl:hasCategory
	    opl:ProductCategory(product_category_with_code.product_cat_code)
	      where (^{product_family_tbl.}^.product_family_id = ^{product_category_with_code.}^.product_family_id)
	    as virtrdf:OplProductFamilyIsFamilyOfProductCategory .

	  opl:ProductFamily(product_family_tbl.product_family_code) opl:hasFormat
	    opl:ProductFormat(product_formats_categories.product_format_code)
	      where (
		    ^{product_family_tbl.}^.product_family_id = ^{product_formats_categories.}^.product_family_id
		  )
	    as virtrdf:OplProductFamilyIsFamilyOfProductFormats .

	  opl:ProductFamily(product_family_tbl.product_family_code) opl:otherProductFamilies
	    opl:ProductFamily(product_family_tbl_2.product_family_code)
	      where (
		    ^{product_family_tbl.}^.product_family_id <> ^{product_family_tbl_2.}^.product_family_id
		  )
	    as virtrdf:OplProductFamilyHasOtherProductFamilies .

	  opl:ProductFormat(product_format_with_code.product_format_code) opl:hasCategory
	    opl:ProductFormatCategory(product_formats_categories.product_format_code, product_formats_categories.product_cat_code)
	      where (^{product_formats_categories.}^.product_format_id = ^{product_format_with_code.}^.product_format_id)
	    as virtrdf:OplProductFormatIsFormatOfProductFormatCategories .

	  opl:ProductFormatCategory(product_formats_categories.product_format_code, product_formats_categories.product_cat_code)
	    opl:hasProduct
	    opl:Product(product_with_code.product_id)
	      where (
		    ^{product_with_code.}^.product_cat_id = ^{product_formats_categories.}^.product_cat_id
		    and
		    ^{product_with_code.}^.product_format_id = ^{product_formats_categories.}^.product_format_id
		  )
	    as virtrdf:OplProductFormatCategoryIsFormatCategoryOfProduct .



	  opl:VendorCategoryFamily(vendor_category_family_tbl.vendor_category_family_id)
	    a opl:VendorCategoryFamily
	    as virtrdf:OplVendorCategoryFamily ;
	  opl:VendorCategoryFamilyDescription vendor_category_family_tbl.vendor_category_family_desc
	    as virtrdf:OplVendorCategoryFamilyDesc .


	  opl:VendorCategory(vendor_category_tbl.vendor_category_id)
	    a opl:VendorCategory
	    as virtrdf:OplVendorCategory ;
	    a opl:VendorCategoryFamily
	    as virtrdf:OplVendorCategorySubClassOfVendorCategoryFamily ;
	  rdfs:label vendor_category_tbl.vendor_category_description
	    as virtrdf:rdfsOplVendorCategoryDescription ;
	  opl:VendorCategoryDescription vendor_category_tbl.vendor_category_description
	    as virtrdf:OplVendorCategoryDescription ;
	  opl:isVendorCategoryOf opl:VendorCategoryFamily(vendor_category_tbl.vendor_category_family_id)
	    as virtrdf:OplVendorCategoryIsOfCategoryFamily ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	  opl:Vendor(vendors_tbl.vendor_id)
	    a opl:Vendor
	    as virtrdf:OplVendor ;
	    a opl:VendorCategory
	    as virtrdf:OplVendorSubClassOfVendorCategory ;
	  rdfs:label vendors_tbl.vendor_name
	    as virtrdf:rdfsOplVendorsName ;
	  opl:VendorName vendors_tbl.vendor_name
	    as virtrdf:OplVendorsName ;
	  opl:WikipediaPage opl:Uri(vendors_tbl.wikipedia_url)
	    as virtrdf:OplVendorsWikipediaUrl ;
	  owl:sameAs opl:lit_wikipedia_to_dbpedia(vendors_tbl.wikipedia_url)
	    as virtrdf:OplVendorsWikipediaUrlOwlSameAs ;
	  foaf:homepage opl:Uri(vendors_tbl.vendor_homepage)
	    as virtrdf:OplFoafVendorHomepage ;
	  opl:isOfVendorCategory opl:VendorCategory(vendors_tbl.vendor_category_id)
	    as virtrdf:OplVendorIsOfVendorCategory ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy owl:
		.

	  opl:VendorCategoryFamily(vendor_category_family_tbl.vendor_category_family_id)
	    opl:hasVendorCategory
	    opl:VendorCategory(vendor_category_tbl.vendor_category_id)
	      where (
		    ^{vendor_category_family_tbl.}^.vendor_category_family_id = ^{vendor_category_tbl.}^.vendor_category_family_id
		  )
	    as virtrdf:OplVendorCategoryFamilyHasVendorCategory .

      opl:VendorCategory(vendor_category_tbl.vendor_category_id)
	    opl:hasVendorCategory
  	    opl:Vendor(vendors_tbl.vendor_id)
	      where (
		    ^{vendor_category_tbl.}^.vendor_category_id = ^{vendors_tbl.}^.vendor_category_id
		  )
	    as virtrdf:OplVendorCategoryHasVendors .

  	opl:OpsysFamily(opsys_family_tbl.opsys_family_id)
	    a opl:OpsysFamily
	    as virtrdf:OplOpsysFamily ;
	  rdfs:label opsys_family_tbl.opsys_family_name
  	  as virtrdf:rdfsOplOpsysFamilyName ;
	  opl:OpsysFamilyName opsys_family_tbl.opsys_family_name
  	  as virtrdf:OplOpsysFamilyName ;
  	opl:OpsysFamilyLicenseCode opsys_family_tbl.opsys_license_code
	    as virtrdf:OplOpsysFamilyLicenseCode ;
	  opl:OpsysFamilyVendor opl:Vendor(opsys_family_tbl.vendor_id)
  	  as virtrdf:OplOpsysFamilyVendor ;
  	opl:OpsysFamilyRating opsys_family_tbl.rating
	    as virtrdf:OplOpsysFamilyRating ;
	foaf:logo opl:lit_opsys_icon(opsys_family_tbl.opsys_family_id)
	  as virtrdf:OplLogoOpsysFamily ;
	foaf:homepage opl:Uri(opsys_family_tbl.wikipedia_url)
	  as virtrdf:FoafHomepageOpsysFamilyWikipediaUrl ;
	owl:sameAs opl:lit_wikipedia_to_dbpedia(opsys_family_tbl.wikipedia_url)
	  as virtrdf:FoafHomepageOpsysFamilyPediaUrlOwlSameAs ;
	opl:WikipediaPage opl:Uri(opsys_family_tbl.wikipedia_url)
	  as virtrdf:OplOpsysFamilyWikipediaUrl ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy owl:
		.

	  opl:OpsysFamily(opsys_family_tbl.opsys_family_id) opl:hasOpsys
	    opl:Opsys(opsys_tbl.opsys_name)
	    where (^{opsys_tbl.}^.opsys_family_id = ^{opsys_family_tbl.}^.opsys_family_id)
	    as virtrdf:OplOpsysFamilyIsOpsysFamilyOfOpsys .


	  opl:DbmsFamily(dbms_family_tbl.dbms_family_id)
  	  a opl:DbmsFamily
	    as virtrdf:OplDbmsFamily ;
	  rdfs:label dbms_family_tbl.dbms_family_name
  	  as virtrdf:rdfsOplDbmsFamilyName ;
	  opl:DbmsFamilyName dbms_family_tbl.dbms_family_name
  	  as virtrdf:OplDbmsFamilyName ;
  	opl:DbmsFamilyVendor opl:Vendor(dbms_family_tbl.vendor_id)
      as virtrdf:OplDbmsFamilyVendor ;
	foaf:homepage opl:Uri(dbms_family_tbl.wikipedia_url)
 	  as virtrdf:FoafHomepageDbmsFamilyWikipediaUrl ;
	owl:sameAs opl:lit_wikipedia_to_dbpedia(dbms_family_tbl.wikipedia_url)
 	  as virtrdf:OwnSameAsDbmsFamilyPediaUrl ;
	opl:WikipediaPage opl:Uri(dbms_family_tbl.wikipedia_url)
	  as virtrdf:OplDbmsFamilyWikipediaUrl ;
	  opl:DbmsFamilyRating dbms_family_tbl.rating
  	  as virtrdf:OplDbmsFamilyRating ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy owl:
		.

	  opl:DbmsEngine(dbms_engine_tbl.dbms_name)
  	  a opl:DbmsEngine
	    as virtrdf:OplDbmsEngine ;
  	  a opl:DbmsFamily
	    as virtrdf:DbmsEngineSubClassOfDbmsFamily ;
	    a umbel:RelationalDatabaseServerProgram
	    as virtrdf:DbmEngineSubClassOfUmbel ;
	  opl:isOfDbmsFamily opl:DbmsFamily(dbms_engine_tbl.dbms_family_id)
  	  as virtrdf:OplDbmsEngineisOfDbmsFamily ;
	  rdfs:label dbms_engine_tbl.dbms_name
  	  as virtrdf:rdfsOplLabelDbmsName ;
  	opl:DbmsEngineVersion dbms_engine_tbl.dbms_version
	    as virtrdf:OplDbmsEngineVersion ;
	  opl:DbmsEngineUpwardCompatible dbms_engine_tbl.upward_compatible
  	  as virtrdf:OplDbmsEngineUpwardCompatible ;
  	opl:DbmsEngineDownwardCompatible dbms_engine_tbl.downward_compatible
	    as virtrdf:OplDbmsEngineDownwardCompatible ;
	  opl:DbmsEngineRating dbms_engine_tbl.rating
  	  as virtrdf:OplDbmsEngineRating ;
  	opl:DbmsEngineOldArchiveCode dbms_engine_tbl.old_archive_code
	    as virtrdf:OplDbmsEngineOldArchiveCode ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.


  opl:DbmsFamily(dbms_family_tbl.dbms_family_id)
    opl:hasDatabaseVersions
    opl:DbmsEngine(dbms_engine_tbl.dbms_name)
    where (
        ^{dbms_family_tbl.}^.dbms_family_id = ^{dbms_engine_tbl.}^.dbms_family_id
    )
    as virtrdf:OplDbmsFamilyToDbms .


	  opl:OpsysType(opsys_type_tbl.opsys_type_id)
   	  a opl:OpsysType
	    as virtrdf:OplOpsysType ;
	  rdfs:label opsys_type_tbl.opsys_type_description
  	  as virtrdf:rdfsOplOpsysTypeDescription ;
	  opl:OpsysTypeDescription opsys_type_tbl.opsys_type_description
  	  as virtrdf:OplOpsysTypeDescription ;
  	opl:OpsysTypeShortDescription opsys_type_tbl.short_description
	    as virtrdf:OplOpsysTypeShortDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.


	  opl:OpsysType(opsys_type_tbl.opsys_type_id) opl:hasOpsys
	    opl:Opsys(opsys_tbl.opsys_name)
	    where (^{opsys_tbl.}^.opsys_type_id = ^{opsys_type_tbl.}^.opsys_type_id)
	    as virtrdf:OplOpsysTypeIsOpsysTypeOfOpsys .


	  opl:ProcessorMode(processor_mode_tbl.processor_mode_id)
  	  a opl:ProcessorMode
	    as virtrdf:OplProcessorMode ;
	  opl:ProcessorModeName processor_mode_tbl.processor_mode_name
  	  as virtrdf:OplProcessorModeName .

  	opl:Processor(processors_tbl.processor_name, processors_tbl.processor_mode_id)
	    a opl:Processor
	    as virtrdf:OplProcessor ;
	  opl:ProcessorName processors_tbl.processor_name
  	  as virtrdf:OplProcessorName ;
  	opl:ProcessorVersion processors_tbl.processor_version
	    as virtrdf:OplProcessorVersion ;
	  rdfs:label processors_tbl.processor_description
  	  as virtrdf:rdfsOplProcessorDescription ;
	  opl:ProcessorDescription processors_tbl.processor_description
  	  as virtrdf:OplProcessorDescription ;
  	opl:ProcessorMode opl:ProcessorMode(processors_tbl.processor_mode_id)
	    as virtrdf:OplProcessorProcessorMode ;
	  opl:isOfProcessorFamily opl:ProcessorFamily(processors_tbl.processor_family_id)
  	  as virtrdf:OplProcessorIsOfProcessorFamily ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	opl:ProcessorFamily(processor_family_tbl.processor_family_id)
  	  a opl:ProcessorFamily
	    as virtrdf:OplProcessorFamily ;
    opl:ProcessorFamilyName processor_family_tbl.processor_family_name
  	  as virtrdf:OplProcessorFamilyName ;
    opl:ProcessorFamilyVendor opl:Vendor(processor_family_tbl.vendor_id)
	  as virtrdf:OplProcessorFamilyVendor ;
	foaf:homepage opl:Uri(processor_family_tbl.wikipedia_url)
	  as virtrdf:FoafHomepageProcessorFamilyWikipediaUrl ;
	owl:sameAs opl:lit_wikipedia_to_dbpedia(processor_family_tbl.wikipedia_url)
	  as virtrdf:OwlSameAsProcessorFamilyPediaUrl ;
    opl:WikipediaPage opl:Uri(processor_family_tbl.wikipedia_url)
	  as virtrdf:OplProcessorFamilyWikipediaUrl ;
	rdfs:label processor_family_tbl.processor_family_description
  	  as virtrdf:rdfsOplProcessorFamilyDescription ;
	opl:ProcessorFamilyDescription processor_family_tbl.processor_family_description
  	  as virtrdf:OplProcessorFamilyDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy owl: ;
      rdfs:isDefinedBy rdfs:
		.

	  opl:Opsys(opsys_tbl.opsys_name)
  	  a opl:Opsys
	    as virtrdf:OplOpsys ;
  	  a opl:OpsysFamily
	    as virtrdf:OpsysSubClassOfOplOpsysFamily ;
  	  a umbel:OperatingSystem
	    as virtrdf:OpsysSubClassOfUmbelOpsys ;
	  opl:OpsysVersion opsys_tbl.opsys_version
  	  as virtrdf:OplOpsysVersion ;
  	opl:OpsysUpwardCompatible opsys_tbl.upward_compatible
	    as virtrdf:OplOpsysUpwardCompatible ;
	  opl:OpsysDownwardCompatible opsys_tbl.downward_compatible
  	  as virtrdf:OplOpsysDownwardCompatible ;
  	opl:OpsysSupported opsys_tbl.supported
	    as virtrdf:OplOpsysSupported ;
	  opl:OpsysLicenseCode opsys_tbl.opsys_license_code
  	  as virtrdf:OplOpsysLicenseCode ;
  	rdfs:label opsys_tbl.commercial_name
	    as virtrdf:rdfsOplOpsysCommercialName ;
  	opl:OpsysCommercialName opsys_tbl.commercial_name
	    as virtrdf:OplOpsysCommercialName ;
	  opl:OpsysEmulationMode opl:ProcessorMode(opsys_tbl.emulation_mode_id)
  	  as virtrdf:OplOpsysEmulationMode ;
  	opl:OpsysProcessor opl:Processor(opsys_tbl.processor_name, opsys_tbl.processor_mode_id)
	    as virtrdf:OplOpsysProcessor ;
	  opl:isOfOpsysFamily opl:OpsysFamily(opsys_tbl.opsys_family_id)
  	  as virtrdf:OplOpsysIsOfOpsysFamily ;
  	opl:isOfOpsysType opl:OpsysType(opsys_tbl.opsys_type_id)
	    as virtrdf:OplOpsysIsOfOpsysType ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.


	  opl:Product(product_with_code.product_id)
	    a opl:Product
	    as virtrdf:OplProduct ;
	    a opl:ProductFormat
	    as virtrdf:ProductSubClassOfProductFormat ;
	    a opl:ProductCategory
	    as virtrdf:ProductSubClassOfProductCategory ;
	    a opl:ProductFormatCategory
	    as virtrdf:OplProductProductFormatCategory ;
	  rdfs:label product_with_code.poduct_description
	    as virtrdf:rdfsOplProductDescription ;
	  foaf:homepage opl:wwwsiteproduct(product_with_code.product_id)
        as virtrdf:homepageProductFamilyCategoryFormatProductUda ;
	  opl:ProductDescription product_with_code.poduct_description
	    as virtrdf:OplProductDescription ;
	  dc:description opl:lit_to_string(product_with_code.long_description)
	    as virtrdf:OplProductLongDescription ;
	  opl:isOfCategory opl:ProductCategory(product_with_code.product_cat_code)
	    as virtrdf:OplProductIsOfCategory ;
	  opl:isOfFormat opl:ProductFormat(product_with_code.product_format_code)
	    as virtrdf:OplProductIsOfFormat ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy foaf: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy rdfs:
		.


	  opl:Product(product_with_code.product_id) opl:hasProductRelease
	    opl:ProductRelease(
	      product_release_tbl.product_id,
	      product_release_tbl.product_release_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
	      )
	      where (^{product_with_code.}^.product_id = ^{product_release_tbl.}^.product_id)
	    as virtrdf:OplProductIsProductOfProductRelease .



	  opl:ProductRelease(
	      product_release_tbl.product_id,
	      product_release_tbl.product_release_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
	      )
	    a opl:ProductRelease
	    as virtrdf:OplProductRelease ;
	    a opl:Product
	    as virtrdf:OplProductReleaseSubClassProduct ;
		a gr:ProductOrService
		as virtrdf:OplProductReleaseAgrProductOrService ;
	  rdfs:label opl:lit_product_release_label(
	      product_release_tbl.product_id,
	      product_release_tbl.product_release_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
	  )
	    as virtrdf:rdfsOplProductReleaseProductReleaseId ;
	  opl:ProductReleaseProductReleaseId product_release_tbl.product_release_id
	    as virtrdf:OplProductReleaseProductReleaseId ;
	  opl:isOfProduct opl:Product(product_release_tbl.product_id)
	    as virtrdf:OplProductReleaseIsOfProduct ;
	  opl:isForOpsys opl:Opsys(product_release_tbl.opsys_name)
	    as virtrdf:OplProductReleaseIsForOpsys ;
	  opl:isForDbmsEngine opl:DbmsEngine(product_release_tbl.dbms_name)
	    as virtrdf:OplProductReleaseIsForDbmsEngine ;
  	  opl:UpwardCompatible product_release_tbl.upward_compatible
	    as virtrdf:OplProductReleaseUpwardCompatible ;
	  opl:DownwardCompatible product_release_tbl.downward_compatible
  	    as virtrdf:OplProductReleaseDownwardCompatible ;
      opl:PurchaseInShop opl:lit_to_shop (
	      product_release_tbl.product_release_id,
	      product_release_tbl.product_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
	 	)
   		as virtrdf:OplProductReleaseToShop ;
	  gr:hasBusinessFunction gr:Sell as virtrdf:grbusinessfunctionsell;
  	  opl:Supported product_release_tbl.supported
	    as virtrdf:OplProductReleaseSupported ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy gr:
		.

	  opl:ProductRelease(
	      product_release_tbl.product_id,
	      product_release_tbl.product_release_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
	      ) opl:hasComponentArchive
	  opl:ComponentArchive(component_archive_tbl.component_archive_name)
			where (
					^{product_release_tbl.}^.product_id = ^{component_archive_tbl.}^.product_id and
					^{product_release_tbl.}^.product_release_id = ^{component_archive_tbl.}^.product_release_id and
					^{product_release_tbl.}^.opsys_name = ^{component_archive_tbl.}^.opsys_name and
					^{product_release_tbl.}^.dbms_name = ^{component_archive_tbl.}^.dbms_name
			)
	    as virtrdf:OplProductReleaseIsProductReleaseOfComponentArchive .


	  opl:Component(components_tbl.component_name)
	    a opl:Component
	    as virtrdf:OplComponent ;
	  opl:isOfComponentCategory opl:ComponentCategory(components_tbl.component_category_id)
	    as virtrdf:OplComponentIsOfComponentCategory ;
	  opl:isOfComponentType opl:ComponentType(components_tbl.component_type_id)
	    as virtrdf:OplComponentIsOfComponentType ;
	  opl:isOfComponentMode opl:ComponentMode(components_tbl.component_mode_id)
	    as virtrdf:OplComponentIsOfComponentMode ;
	  opl:isForOpsys opl:Opsys(components_tbl.opsys_name)
	    as virtrdf:OplComponentIsForOpsys ;
	  opl:isForDbmsEngine opl:DbmsEngine(components_tbl.dbms_name)
	    as virtrdf:OplComponentIsForDbmsEngine ;
	  opl:ComponentCvsid components_tbl.component_cvsid
	    as virtrdf:OplComponentComponentCvsId ;
	  opl:ComponentBuildDate components_tbl.component_build_date
	    as virtrdf:OplComponentComponentBuildDate ;
	  opl:Notes components_tbl.notes
	    as virtrdf:OplComponentNotes ;
	  opl:BuildComments components_tbl.build_comments
	    as virtrdf:OplComponentBuildComments ;
	  opl:Filesize components_tbl.str_filesize
	    as virtrdf:OplComponentFilesize ;
      rdfs:isDefinedBy opl:
		.

    opl:DbmsEngine (dbms_engine_tbl.dbms_name) opl:hasComponents
      opl:Component(components_tbl.component_name)
      where (^{components_tbl.}^.dbms_name = ^{dbms_engine_tbl.}^.dbms_name)
      as virtrdf:OplDbmsEngineForComponents .

    opl:Opsys (opsys_tbl.opsys_name) opl:hasComponents
      opl:Component(components_tbl.component_name)
      where (^{components_tbl.}^.opsys_name = ^{opsys_tbl.}^.opsys_name)
      as virtrdf:OplOpsysForComponents .


	  opl:ComponentMode(component_mode_tbl.component_mode_id)
	    a opl:ComponentMode
	    as virtrdf:OplComponentMode ;
	  rdfs:label component_mode_tbl.component_mode_description
	    as virtrdf:rdfsOplComponentModeDescription ;
	  opl:ComponentModeDescription component_mode_tbl.component_mode_description
	    as virtrdf:OplComponentModeDescription ;
	  opl:ComponentModeShortDescription component_mode_tbl.short_description
	    as virtrdf:OplComponentModeShortDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	  opl:ComponentType(component_type_tbl.component_type_id)
	    a opl:ComponentType
	    as virtrdf:OplComponentType ;
	  rdfs:label component_type_tbl.component_type_description
	    as virtrdf:rdfsOplComponentTypeDescription ;
	  opl:ComponentTypeDescription component_type_tbl.component_type_description
	    as virtrdf:OplComponentTypeDescription ;
	  opl:ComponentTypeShortDescription component_type_tbl.short_description
	    as virtrdf:OplComponentTypeShortDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	  opl:ComponentCategory(component_category_tbl.component_category_id)
	    a opl:ComponentCategory
	    as virtrdf:OplComponentCategory ;
	  rdfs:label component_category_tbl.component_category_description
	    as virtrdf:rdfsOplComponentCategoryDescription ;
	  opl:ComponentCategoryDescription component_category_tbl.component_category_description
	    as virtrdf:OplComponentCategoryDescription ;
	  opl:ComponentCategoryShortDescription component_category_tbl.short_description
	    as virtrdf:OplComponentCategoryShortDescription ;
	  dc:description opl:lit_to_string(component_category_tbl.component_category_long_description)
	    as virtrdf:OplComponentCategoryLongDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	  opl:ComponentArchive(component_archive_tbl.component_archive_name)
	    a opl:ComponentArchive
	    as virtrdf:OplComponentArchive ;
	    a opl:Component
	    as virtrdf:ComponentArchiveSubClassOfComponent ;
	  opl:ComponentArchiveName component_archive_tbl.component_archive_name
	    as virtrdf:OplComponentArchiveComponentArchiveName ;
	  rdfs:label component_archive_tbl.component_archive_name
	    as virtrdf:rdfsComponentArchiveComponentArchiveName ;
  	opl:ComponentArchiveType opl:ComponentArchiveType(component_archive_tbl.component_archive_type_id)
	  	as virtrdf:ComponentArchiveComponentArchiveType ;
	  opl:isOfComponent opl:Component(component_archive_tbl.component_name)
	    as virtrdf:OplComponentArchiveIsOfComponent ;
	  opl:isOfProductRelease opl:ProductRelease(
	      component_archive_tbl.product_id,
	      component_archive_tbl.product_release_id,
	      component_archive_tbl.opsys_name,
	      component_archive_tbl.dbms_name
	      )
	    as virtrdf:OplComponentArchiveIsOfProductRelease ;
  	opl:AssemblyDate component_archive_tbl.assembly_date
	  	as virtrdf:OplComponentArchiveAssemblyDate ;
	  opl:FileUri component_archive_tbl.file_uri
  		as virtrdf:OplComponentArchiveFileUri ;
  	opl:LicenseCode component_archive_tbl.license_code
		  as virtrdf:OplComponentArchiveLicenseCode ;
	  opl:ResFullPath component_archive_tbl.res_full_path
  		as virtrdf:OplComponentArchiveResFullPath ;
  	opl:ResName component_archive_tbl.res_name
		  as virtrdf:OplComponentArchiveResName ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.


	opl:ComponentArchiveType(component_archive_type_tbl.component_archive_type_id)
	  a opl:ComponentArchiveType
		as virtrdf:OplComponentArchiveType ;
	opl:ComponentArchiveShortName component_archive_type_tbl.component_archive_short_name
		as virtrdf:OplComponentArchiveTypeComponentArchiveShortName ;
	rdfs:label component_archive_type_tbl.component_archive_type_name
		as virtrdf:rdfsOplComponentArchiveTypeComponentArchiveTypeName ;
	opl:ComponentArchiveTypeName component_archive_type_tbl.component_archive_type_name
		as virtrdf:OplComponentArchiveTypeComponentArchiveTypeName ;
	opl:Extension component_archive_type_tbl.extension
		as virtrdf:OplComponentArchiveTypeExtension ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.


	opl:DownloadLocation(download_location_tbl.uri)
	  a opl:DownloadLocation
		as virtrdf:OplDownloadLocation ;
	opl:isOfComponentArchive opl:ComponentArchive(download_location_tbl.component_archive_name)
		as virtrdf:OplDownloadLocationIsOfComponentArchive ;
	opl:hasDownloadProtocol opl:DownloadProtocol(download_location_tbl.protocol_name)
		as virtrdf:DownloadLocationHasProtocolName ;
	rdfs:label download_location_tbl.uri_old
		as virtrdf:rdfsOplDownloadLocationLabel ;
	opl:isOfProductRelease opl:ProductRelease(
		download_location_tbl.product_id,
		download_location_tbl.product_release_id,
		download_location_tbl.opsys_name,
		download_location_tbl.dbms_name
		)
		as virtrdf:OplDownloadLocationIsOfProductRelease ;
	opl:Uri download_location_tbl.uri
		as virtrdf:OplDownloadLocationUri ;
	opl:UriOld download_location_tbl.uri_old
		as virtrdf:OplDownloadLocationUriOld ;
    opl:hasDownloadPartner opl:DownloadPartner(
        download_location_tbl.host_name,
        download_location_tbl.domain_name
      )
        as virtrdf:OplDownloadLocationHasDownloadPartner ;
	opl:DomainName download_location_tbl.domain_name
		as virtrdf:OplDownloadLocationDomainName ;
	opl:HostName download_location_tbl.host_name
		as virtrdf:OplDownloadLocationHostName ;
	opl:ResName download_location_tbl.res_name
		as virtrdf:OplDownloadLocationResName ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	opl:DownloadProtocol(download_protocol_tbl.protocol_name)
	  a opl:DownloadProtocol
		as virtrdf:OplDownloadProtocolProtocolName ;
	opl:ProtocolDescription download_protocol_tbl.protocol_description
		as virtrdf:OplDownloadProtocolProtocolDescription .

	opl:DownloadPartner(
	  download_partner_tbl.host_name,
	  download_partner_tbl.domain_name
	  )
	  a opl:DownloadPartner
	  as virtrdf:OplDownloadPartner;
	rdfs:label download_partner_tbl.partner_name
	  as virtrdf:rdfsOplDownloadPartnerPartnerNamelabel ;
	opl:DownloadPartner download_partner_tbl.partner_name
	  as virtrdf:OplDownloadPartnerPartnerName ;
	opl:PortNumber download_partner_tbl.port_number
	  as virtrdf:OplDownloadPartnerPortNumber ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

    opl:ComponentArchive(component_archive_tbl.component_archive_name)
      opl:hasDownloadLocation
      opl:DownloadLocation(download_location_tbl.uri)
		where (
				^{component_archive_tbl.}^.component_archive_name = ^{download_location_tbl.}^.component_archive_name
		)
      as virtrdf:OplComponentArchiveIsComponentArchiveOfDownloadLocation .

    opl:DownloadLocation(download_location_tbl.uri)
      opl:isDownloadLocationOf
      opl:ComponentArchive(component_archive_tbl.component_archive_name)
		where (
				 ^{download_location_tbl.}^.component_archive_name = ^{component_archive_tbl.}^.component_archive_name
		)
      as virtrdf:OplDownloadLocationIsDownloadLocationOfComponentArchive .


#
# Extra Peripheral family/cat/format/etc... to/from... dbfamily/opsysfamily/....
# ==================================================================================


# ---------------------> product_family

#  opl:ProductFamily(product_family_tbl.product_family_code)
#    opl:OperatingSystems
#    opl:Opsys(ac1.opsys_name)
#    where (
#        ^{product_family_tbl.}^.product_family_code = ^{ac1.}^.product_family_code
#    )
#    as virtrdf:OplProductFamilyToOpsys .

  opl:ProductFamily(product_family_tbl.product_family_code)
    opl:OperatingSystemsFamilies
    opl:OpsysFamily(ac1.opsys_family_id)
    where (
        ^{product_family_tbl.}^.product_family_code = ^{ac1.}^.product_family_code
    )
    as virtrdf:OplProductFamilyToOpsysFamily .

#  opl:ProductFamily(product_family_tbl.product_family_code)
#    opl:Databases
#    opl:DbmsEngine(ac1.dbms_name)
#    where (
#        ^{product_family_tbl.}^.product_family_code = ^{ac1.}^.product_family_code
#    )
#    as virtrdf:OplProductFamilyToDbms .

  opl:ProductFamily(product_family_tbl.product_family_code)
    opl:DatabaseFamilies
    opl:DbmsFamily(ac1.dbms_family_id)
    where (
        ^{product_family_tbl.}^.product_family_code = ^{ac1.}^.product_family_code
    )
    as virtrdf:OplProductFamilyToDbmsFamily .

#  opl:ProductFamily(product_family_tbl.product_family_code)
#    opl:Processors
#  	opl:Processor(ac1.processor_name, ac1.processor_mode_id)
#    where (
#        ^{product_family_tbl.}^.product_family_code = ^{ac1.}^.product_family_code
#    )
#    as virtrdf:OplProductFamilyToProcessor .

  opl:ProductFamily(product_family_tbl.product_family_code)
    opl:ProcessorFamilies
	opl:ProcessorFamily(ac1.processor_family_id)
    where (
        ^{product_family_tbl.}^.product_family_code = ^{ac1.}^.product_family_code
    )
    as virtrdf:OplProductFamilyToProcessorFamily .



# ---------------------> product_format

#  opl:ProductFormat(product_format_with_code.product_format_code)
#    opl:OperatingSystems
#    opl:Opsys(ac1.opsys_name)
#    where (
#        ^{product_format_with_code.}^.product_format_code = ^{ac1.}^.product_format_code
#    )
#    as virtrdf:OplProductFormatToOpsys .

  opl:ProductFormat(product_format_with_code.product_format_code)
    opl:OperatingSystemsFamilies
    opl:OpsysFamily(ac1.opsys_family_id)
    where (
        ^{product_format_with_code.}^.product_format_code = ^{ac1.}^.product_format_code
    )
    as virtrdf:OplProductFormatToOpsysFamily .

#  opl:ProductFormat(product_format_with_code.product_format_code)
#    opl:Databases
#    opl:DbmsEngine(ac1.dbms_name)
#    where (
#        ^{product_format_with_code.}^.product_format_code = ^{ac1.}^.product_format_code
#    )
#    as virtrdf:OplProductFormatToDbms .

  opl:ProductFormat(product_format_with_code.product_format_code)
    opl:DatabaseFamilies
    opl:DbmsFamily(ac1.dbms_family_id)
    where (
        ^{product_format_with_code.}^.product_format_code = ^{ac1.}^.product_format_code
    )
    as virtrdf:OplProductFormatToDbmsFamily .

  opl:ProductFormat(product_format_with_code.product_format_code)
    opl:Processors
  	opl:Processor(ac1.processor_name, ac1.processor_mode_id)
    where (
        ^{product_format_with_code.}^.product_format_code = ^{ac1.}^.product_format_code
    )
    as virtrdf:OplProductFormatToProcessor .

  opl:ProductFormat(product_format_with_code.product_format_code)
    opl:ProcessorFamilies
	opl:ProcessorFamily(ac1.processor_family_id)
    where (
        ^{product_format_with_code.}^.product_format_code = ^{ac1.}^.product_format_code
    )
    as virtrdf:OplProductFormatToProcessorFamily .



# ---------------------> product_category

#  opl:ProductCategory(product_category_with_code.product_cat_code)
#    opl:OperatingSystems
#    opl:Opsys(ac1.opsys_name)
#    where (
#        ^{product_category_with_code.}^.product_cat_code = ^{ac1.}^.product_cat_code
#    )
#    as virtrdf:OplProductCatToOpsys .

  opl:ProductCategory(product_category_with_code.product_cat_code)
    opl:OperatingSystemsFamilies
    opl:OpsysFamily(ac1.opsys_family_id)
    where (
        ^{product_category_with_code.}^.product_cat_code = ^{ac1.}^.product_cat_code
    )
    as virtrdf:OplProductCatToOpsysFamily .

#  opl:ProductCategory(product_category_with_code.product_cat_code)
#    opl:Databases
#    opl:DbmsEngine(ac1.dbms_name)
#    where (
#        ^{product_category_with_code.}^.product_cat_code = ^{ac1.}^.product_cat_code
#    )
#    as virtrdf:OplProductCatToDbms .

  opl:ProductCategory(product_category_with_code.product_cat_code)
    opl:DatabaseFamilies
    opl:DbmsFamily(ac1.dbms_family_id)
    where (
        ^{product_category_with_code.}^.product_cat_code = ^{ac1.}^.product_cat_code
    )
    as virtrdf:OplProductCatToDbmsFamily .

#  opl:ProductCategory(product_category_with_code.product_cat_code)
#    opl:Processors
#  	opl:Processor(ac1.processor_name, ac1.processor_mode_id)
#    where (
#        ^{product_category_with_code.}^.product_cat_code = ^{ac1.}^.product_cat_code
#    )
#    as virtrdf:OplProductCatToProcessor .

  opl:ProductCategory(product_category_with_code.product_cat_code)
    opl:ProcessorFamilies
	opl:ProcessorFamily(ac1.processor_family_id)
    where (
        ^{product_category_with_code.}^.product_cat_code = ^{ac1.}^.product_cat_code
    )
    as virtrdf:OplProductCatToProcessorFamily .




# ---------------------> product

  opl:Product(product_with_code.product_id)
    opl:OperatingSystems
    opl:Opsys(ac1.opsys_name)
    where (
        ^{product_with_code.}^.product_id = ^{ac1.}^.product_id
    )
    as virtrdf:OplProductToOpsys .

  opl:Product(product_with_code.product_id)
    opl:OperatingSystemsFamilies
    opl:OpsysFamily(ac1.opsys_family_id)
    where (
        ^{product_with_code.}^.product_id = ^{ac1.}^.product_id
    )
    as virtrdf:OplProductToOpsysFamily .

  opl:Product(product_with_code.product_id)
    opl:Databases
    opl:DbmsEngine(ac1.dbms_name)
    where (
        ^{product_with_code.}^.product_id = ^{ac1.}^.product_id
    )
    as virtrdf:OplProductToDbms .

  opl:Product(product_with_code.product_id)
    opl:DatabaseFamilies
    opl:DbmsFamily(ac1.dbms_family_id)
    where (
        ^{product_with_code.}^.product_id = ^{ac1.}^.product_id
    )
    as virtrdf:OplProductToDbmsFamily .

  opl:Product(product_with_code.product_id)
    opl:Processors
  	opl:Processor(ac1.processor_name, ac1.processor_mode_id)
    where (
        ^{product_with_code.}^.product_id = ^{ac1.}^.product_id
    )
    as virtrdf:OplProductToProcessor .

  opl:Product(product_with_code.product_id)
    opl:ProcessorFamilies
	opl:ProcessorFamily(ac1.processor_family_id)
    where (
        ^{product_with_code.}^.product_id = ^{ac1.}^.product_id
    )
    as virtrdf:OplProductToProcessorFamily .




# ---------------------> to product

  opl:Opsys(opsys_tbl.opsys_name)
    opl:hasProducts
    opl:Product(ac1.product_id)
    where (
        ^{opsys_tbl.}^.opsys_name = ^{ac1.}^.opsys_name
    )
    as virtrdf:OplOpsysToProduct .

  opl:OpsysFamily(opsys_family_tbl.opsys_family_id)
    opl:hasProducts
    opl:Product(ac1.product_id)
    where (
        ^{opsys_family_tbl.}^.opsys_family_id = ^{ac1.}^.opsys_family_id
    )
    as virtrdf:OplOpsysFamilyToProduct .

  opl:DbmsEngine(dbms_engine_tbl.dbms_name)
    opl:hasProducts
    opl:Product(ac1.product_id)
    where (
        ^{dbms_engine_tbl.}^.dbms_name = ^{ac1.}^.dbms_name
    )
    as virtrdf:OplDbmsToProduct .

  opl:DbmsFamily(dbms_family_tbl.dbms_family_id)
    opl:hasProducts
    opl:Product(ac1.product_id)
    where (
        ^{dbms_family_tbl.}^.dbms_family_id = ^{ac1.}^.dbms_family_id
    )
    as virtrdf:OplDbmsFamilyToProduct .

  opl:Processor(processors_tbl.processor_name, processors_tbl.processor_mode_id)
    opl:hasProducts
    opl:Product(ac1.product_id)
    where (
        ^{processors_tbl.}^.processor_name = ^{ac1.}^.processor_name
        and
        ^{processors_tbl.}^.processor_mode_id = ^{ac1.}^.processor_mode_id
    )
    as virtrdf:OplProcessorToProduct .

  opl:ProcessorFamily(processor_family_tbl.processor_family_id)
    opl:hasProducts
    opl:Product(ac1.product_id)
    where (
        ^{processor_family_tbl.}^.processor_family_id = ^{ac1.}^.processor_family_id
    )
    as virtrdf:OplProcessorFamilyProduct .




# ---------------------> to product_cat

#  opl:Opsys(opsys_tbl.opsys_name)
#    opl:hasProductCategory
#    opl:ProductCategory(ac1.product_cat_code)
#    where (
#        ^{opsys_tbl.}^.opsys_name = ^{ac1.}^.opsys_name
#    )
#    as virtrdf:OplOpsysToProductCategory .

  opl:OpsysFamily(opsys_family_tbl.opsys_family_id)
    opl:hasProductCategory
    opl:ProductCategory(ac1.product_cat_code)
    where (
        ^{opsys_family_tbl.}^.opsys_family_id = ^{ac1.}^.opsys_family_id
    )
    as virtrdf:OplOpsysFamilyToProductCategory .

#  opl:DbmsEngine(dbms_engine_tbl.dbms_name)
#    opl:hasProductCategory
#    opl:ProductCategory(ac1.product_cat_code)
#    where (
#        ^{dbms_engine_tbl.}^.dbms_name = ^{ac1.}^.dbms_name
#    )
#    as virtrdf:OplDbmsToProductCategory .

  opl:DbmsFamily(dbms_family_tbl.dbms_family_id)
    opl:hasProductCategory
    opl:ProductCategory(ac1.product_cat_code)
    where (
        ^{dbms_family_tbl.}^.dbms_family_id = ^{ac1.}^.dbms_family_id
    )
    as virtrdf:OplDbmsFamilyToProductCategory .

#  opl:Processor(processors_tbl.processor_name, processors_tbl.processor_mode_id)
#    opl:hasProductCategory
#    opl:ProductCategory(ac1.product_cat_code)
#    where (
#        ^{processors_tbl.}^.processor_name = ^{ac1.}^.processor_name
#        and
#        ^{processors_tbl.}^.processor_mode_id = ^{ac1.}^.processor_mode_id
#    )
#    as virtrdf:OplProcessorToProductCategory .

  opl:ProcessorFamily(processor_family_tbl.processor_family_id)
    opl:hasProductCategory
    opl:ProductCategory(ac1.product_cat_code)
    where (
        ^{processor_family_tbl.}^.processor_family_id = ^{ac1.}^.processor_family_id
    )
    as virtrdf:OplProcessorFamilyProductCategory .




# ---------------------> to product_format

#  opl:Opsys(opsys_tbl.opsys_name)
#    opl:hasProductFormat
#    opl:ProductFormat(ac1.product_format_code)
#    where (
#        ^{opsys_tbl.}^.opsys_name = ^{ac1.}^.opsys_name
#    )
#    as virtrdf:OplOpsysToProductFormat .

  opl:OpsysFamily(opsys_family_tbl.opsys_family_id)
    opl:hasProductFormat
    opl:ProductFormat(ac1.product_format_code)
    where (
        ^{opsys_family_tbl.}^.opsys_family_id = ^{ac1.}^.opsys_family_id
    )
    as virtrdf:OplOpsysFamilyToProductFormat .

#  opl:DbmsEngine(dbms_engine_tbl.dbms_name)
#    opl:hasProductFormat
#    opl:ProductFormat(ac1.product_format_code)
#    where (
#        ^{dbms_engine_tbl.}^.dbms_name = ^{ac1.}^.dbms_name
#    )
#    as virtrdf:OplDbmsToProductFormat .

  opl:DbmsFamily(dbms_family_tbl.dbms_family_id)
    opl:hasProductFormat
    opl:ProductFormat(ac1.product_format_code)
    where (
        ^{dbms_family_tbl.}^.dbms_family_id = ^{ac1.}^.dbms_family_id
    )
    as virtrdf:OplDbmsFamilyToProductFormat .

#  opl:Processor(processors_tbl.processor_name, processors_tbl.processor_mode_id)
#    opl:hasProductFormat
#    opl:ProductFormat(ac1.product_format_code)
#    where (
#        ^{processors_tbl.}^.processor_name = ^{ac1.}^.processor_name
#        and
#        ^{processors_tbl.}^.processor_mode_id = ^{ac1.}^.processor_mode_id
#    )
#    as virtrdf:OplProcessorToProductFormat .

  opl:ProcessorFamily(processor_family_tbl.processor_family_id)
    opl:hasProductFormat
    opl:ProductFormat(ac1.product_format_code)
    where (
        ^{processor_family_tbl.}^.processor_family_id = ^{ac1.}^.processor_family_id
    )
    as virtrdf:OplProcessorFamilyProductFormat .




# ---------------------> to product_family

#  opl:Opsys(opsys_tbl.opsys_name)
#    opl:hasProductFamily
#    opl:ProductFamily(ac1.product_family_code)
#    where (
#        ^{opsys_tbl.}^.opsys_name = ^{ac1.}^.opsys_name
#    )
#    as virtrdf:OplOpsysToProductFamily .

  opl:OpsysFamily(opsys_family_tbl.opsys_family_id)
    opl:hasProductFamily
    opl:ProductFamily(ac1.product_family_code)
    where (
        ^{opsys_family_tbl.}^.opsys_family_id = ^{ac1.}^.opsys_family_id
    )
    as virtrdf:OplOpsysFamilyToProductFamily .

#  opl:DbmsEngine(dbms_engine_tbl.dbms_name)
#    opl:hasProductFamily
#    opl:ProductFamily(ac1.product_family_code)
#    where (
#        ^{dbms_engine_tbl.}^.dbms_name = ^{ac1.}^.dbms_name
#    )
#    as virtrdf:OplDbmsToProductFamily .

  opl:DbmsFamily(dbms_family_tbl.dbms_family_id)
    opl:hasProductFamily
    opl:ProductFamily(ac1.product_family_code)
    where (
        ^{dbms_family_tbl.}^.dbms_family_id = ^{ac1.}^.dbms_family_id
    )
    as virtrdf:OplDbmsFamilyToProductFamily .

#  opl:Processor(processors_tbl.processor_name, processors_tbl.processor_mode_id)
#    opl:hasProductFamily
#    opl:ProductFamily(ac1.product_family_code)
#    where (
#        ^{processors_tbl.}^.processor_name = ^{ac1.}^.processor_name
#        and
#        ^{processors_tbl.}^.processor_mode_id = ^{ac1.}^.processor_mode_id
#    )
#    as virtrdf:OplProcessorToProductFamily .

  opl:ProcessorFamily(processor_family_tbl.processor_family_id)
    opl:hasProductFamily
    opl:ProductFamily(ac1.product_family_code)
    where (
        ^{processor_family_tbl.}^.processor_family_id = ^{ac1.}^.processor_family_id
    )
    as virtrdf:OplProcessorFamilyProductFamily .


#
# Product Benefits and things
# =========================================

	opl:ProductBenefit(product_benefits_tbl.product_benefit_id)
	  a opl:ProductBenefit
	  as virtrdf:OplProductBenefit ;
	rdfs:label product_benefits_tbl.product_benefit_desc
	  as virtrdf:rdfsLabelProductBenefitDescription ;
	opl:isOfProductBenefitCategory opl:ProductBenefitCategory(product_benefits_tbl.product_benefit_category_id)
	  as virtrdf:OplProductBenefitIsOfProductBenefitCategory ;
	opl:Description product_benefits_tbl.product_benefit_desc
	  as virtrdf:OplProductBenefitDescription ;
	opl:Acronym product_benefits_tbl.product_benefit_acronym
	  as virtrdf:OplProductBenefitAcronym ;
  opl:Explanation product_benefits_tbl.product_benefit_explanation
    as virtrdf:OplProductBenefitExplanation ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	opl:ProductBenefitCategory(product_benefits_category_tbl.product_benefit_category_id)
	  a opl:ProductBenefitCategory
	  as virtrdf:OplProductBenefitCategory ;
	rdfs:label product_benefits_category_tbl.description
	  as virtrdf:rdfsLabelProductBenefitCategoryDescription ;
	opl:Description product_benefits_category_tbl.description
	  as virtrdf:OplProductBenefitCategoryDescription ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	opl:ProductFeatureCategory(product_feature_category_tbl.product_feature_category_id)
	  a opl:ProductFeatureCategory
	  as virtrdf:OplProductFeatureCategory ;
	rdfs:label product_feature_category_tbl.short_desc
	  as virtrdf:rdfsLabelProductFeatureCategoryShortDescription ;
	opl:ShortDescription product_feature_category_tbl.short_desc
	  as virtrdf:OplProductFeatureCategoryShortDescription ;
	opl:Description product_feature_category_tbl.description
	  as virtrdf:OplProductFeatureCategoryDescription ;
	opl:StandardsId product_feature_category_tbl.standards_id
	  as virtrdf:OplProductFeatureCategoryStandardsId ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.

	opl:ProductFeature(product_features_tbl.product_feature_id)
	  a opl:ProductFeature
	  as virtrdf:OplProductFeature ;
	rdfs:label product_features_tbl.short_description
		as virtrdf:rdfsLabelProductFeaturesShortDescription ;
	opl:Description product_features_tbl.short_description
		as virtrdf:OplProductFeaturesShortDescription ;
	dc:description opl:lit_to_string(product_features_tbl.long_description)
		as virtrdf:OplProductFeaturesLongDescription ;
	opl:isOfProductBenefit opl:ProductBenefit(product_features_tbl.product_feature_benefit_id)
		as virtrdf:ProductFeaturesIsOfProductBenefit ;
	opl:isOfProductFeatureCategory opl:ProductFeatureCategory(product_features_tbl.product_feature_category_id)
		as virtrdf:ProductFeaturesIsOfProductFeatureCategory ;
	opl:isOfProduct opl:Product(product_features_tbl.product_id)
		as virtrdf:ProductFeaturesIsOfProduct ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy rdfs:
		.

    opl:Product(product_with_code.product_id)
      opl:hasFeature
      opl:ProductFeature(product_features_tbl.product_feature_id)
      where (
	    ^{product_with_code.}^.product_id = ^{product_features_tbl.}^.product_id
	)
	as virtrdf:OplProductHasProductFeaturesProductFeatures .

    opl:ProductFeature(product_features_tbl.product_feature_id)
      opl:isFeatureOf
      opl:Product(product_with_code.product_id)
      where (
        ^{product_with_code.}^.product_id = ^{product_features_tbl.}^.product_id
    )
    as virtrdf:OplProductFeaturesAreProductFeaturesProduct .


	opl:ProductFamilyFeature(product_family_features_tbl.product_family_feature_id)
	  a opl:ProductFamilyFeature
		as virtrdf:OplProductFamilyFeature ;
	rdfs:label product_family_features_tbl.short_description
		as virtrdf:rdfsLabelProductFamilyFeaturesShortDescription ;
	opl:Description product_family_features_tbl.short_description
		as virtrdf:OplProductFamilyFeaturesShortDescription ;
	dc:description opl:lit_to_string(product_family_features_tbl.long_description)
		as virtrdf:OplProductFamilyFeaturesLongDescription ;
	opl:isOfProductBenefit opl:ProductBenefit(product_family_features_tbl.product_family_feature_benefit_id)
		as virtrdf:ProductFamilyFeaturesIsOfProductBenefit ;
	opl:isOfProductFeatureCategory opl:ProductFeatureCategory(product_family_features_tbl.product_family_feature_cat_id)
		as virtrdf:ProductFamilyFeaturesIsOfProductFeatureCategory ;
	opl:isOfProductFamily opl:ProductFamily(product_family_features_tbl.product_family_code)
		as virtrdf:ProductFamilyFeaturesIsOfProductFamily ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy rdfs:
		.

    opl:ProductFamily(product_family_tbl.product_family_code)
      opl:hasFeature
      opl:ProductFamilyFeature(product_family_features_tbl.product_family_feature_id)
      where (
	    ^{product_family_tbl.}^.product_family_id = ^{product_family_features_tbl.}^.product_family_id
	)
	as virtrdf:OplProductFamilyHasProductFamilyFeaturesProductFamilyFeatures .

    opl:ProductFamilyFeature(product_family_features_tbl.product_family_feature_id)
      opl:isFeatureOf
      opl:Product(product_family_tbl.product_family_code)
      where (
        ^{product_family_tbl.}^.product_family_id = ^{product_family_features_tbl.}^.product_family_id
    )
    as virtrdf:OplProductFamilyFeaturesAreProductFamilyFeaturesProductFamily .


	opl:ProductFormatFeature(product_format_features_tbl.product_format_feature_id)
	  a opl:ProductFormatFeature
	  as virtrdf:OplProductFormatFeature ;
	rdfs:label product_format_features_tbl.short_description
		as virtrdf:rdfsLabelProductFormatFeaturesShortDescription ;
	opl:Description product_format_features_tbl.short_description
		as virtrdf:OplProductFormatFeaturesShortDescription ;
	dc:description opl:lit_to_string(product_format_features_tbl.long_description)
		as virtrdf:OplProductFormatFeaturesLongDescription ;
	opl:isOfProductBenefit opl:ProductBenefit(product_format_features_tbl.product_format_feature_benefit_id)
		as virtrdf:ProductFormatFeaturesIsOfProductBenefit ;
	opl:isOfProductFeatureCategory opl:ProductFeatureCategory(product_format_features_tbl.product_format_feature_cat_id)
		as virtrdf:ProductFormatFeaturesIsOfProductFeatureCategory ;
	opl:isOfProductFormat opl:ProductFormat(product_format_features_tbl.product_format_code)
		as virtrdf:ProductFormatFeaturesIsOfProductFormat ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy rdfs:
		.

    opl:ProductFormat(product_format_with_code.product_format_code)
      opl:hasFeature
      opl:ProductFormatFeature(product_format_features_tbl.product_format_feature_id)
      where (
	    ^{product_format_with_code.}^.product_format_id = ^{product_format_features_tbl.}^.product_format_id
	)
	as virtrdf:OplProductFormatHasProductFormatFeaturesProductFormatFeatures .

    opl:ProductFormatFeature(product_format_features_tbl.product_format_feature_id)
      opl:isFeatureOf
      opl:ProductFormat(product_format_with_code.product_format_code)
      where (
        ^{product_format_with_code.}^.product_format_id = ^{product_format_features_tbl.}^.product_format_id
    )
    as virtrdf:OplProductFormatFeaturesAreProductFormatFeaturesProductFormat .



	opl:ProductCategoryFeature(product_category_features_tbl.product_category_feature_id)
	  a opl:ProductCategoryFeature
	  as virtrdf:OplProductCategoryFeature ;
	rdfs:label product_category_features_tbl.short_description
		as virtrdf:rdfsLabelProductCategoryFeaturesShortDescription ;
	opl:Description product_category_features_tbl.short_description
		as virtrdf:OplProductCategoryFeaturesShortDescription ;
	dc:description opl:lit_to_string(product_category_features_tbl.long_description)
		as virtrdf:OplProductCategoryFeaturesLongDescription ;
	opl:isOfProductBenefit opl:ProductBenefit(product_category_features_tbl.product_category_feature_benefit_id)
		as virtrdf:ProductCategoryFeaturesIsOfProductBenefit ;
	opl:isOfProductFeatureCategory opl:ProductFeatureCategory(product_category_features_tbl.product_category_feature_category_id)
		as virtrdf:ProductCategoryFeaturesIsOfProductFeatureCategory ;
	opl:isOfProductCategory opl:ProductCategory(product_category_features_tbl.product_cat_code)
		as virtrdf:ProductCategoryFeaturesIsOfProductCategory ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy rdfs:
		.

    opl:ProductCategory(product_category_with_code.product_cat_code)
      opl:hasFeature
      opl:ProductCategoryFeature(product_category_features_tbl.product_category_feature_id)
      where (
	    ^{product_category_with_code.}^.product_cat_id = ^{product_category_features_tbl.}^.product_cat_id
	)
	as virtrdf:OplProductCategoryHasProductCategoryFeaturesProductCategoryFeatures .

    opl:ProductCategoryFeature(product_category_features_tbl.product_category_feature_id)
      opl:isFeatureOf
      opl:ProductCategory(product_category_with_code.product_cat_code)
      where (
        ^{product_category_with_code.}^.product_cat_id = ^{product_category_features_tbl.}^.product_cat_id
    )
    as virtrdf:OplProductCategoryFeaturesAreProductCategoryFeaturesProductCategory .


	opl:ProductReleaseFeature(product_release_features_tbl.product_release_feature_id)
	  a opl:ProductReleaseFeature
	  as virtrdf:OplProductReleaseFeature ;
	rdfs:label product_release_features_tbl.short_description
		as virtrdf:rdfsLabelProductReleaseFeaturesShortDescription ;
	opl:Description product_release_features_tbl.short_description
		as virtrdf:OplProductReleaseFeaturesShortDescription ;
	dc:description opl:lit_to_string(product_release_features_tbl.long_description)
		as virtrdf:OplProductReleaseFeaturesLongDescription ;
	opl:isOfProductBenefit opl:ProductBenefit(product_release_features_tbl.product_release_feature_benefit_id)
		as virtrdf:ProductReleaseFeaturesIsOfProductBenefit ;
	opl:isOfProductFeatureCategory opl:ProductFeatureCategory(product_release_features_tbl.product_release_feature_cat_id)
		as virtrdf:ProductReleaseFeaturesIsOfProductFeatureCategory ;
	opl:isOfProduct opl:Product(product_release_features_tbl.product_id)
		as virtrdf:ProductReleaseFeaturesIsOfProduct ;
	opl:ProductReleaseId product_release_features_tbl.product_release_id
		as virtrdf:ProductReleaseFeaturesProductRelease ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy rdfs:
	.


	} .
} .
;




DB.DBA.RDF_AUDIT_METADATA (1, '*');


SPARQL
prefix opl: <http://www.openlinksw.com/schemas/oplweb#>
prefix dc: <http://purl.org/dc/terms#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix oplds: <http://www.openlinksw.com/dataspace/organization/openlink#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix umbel: <http://umbel.org/umbel/sc/>
prefix gr: <http://purl.org/goodrelations/v1#>

alter quad storage virtrdf:DefaultQuadStorage
FROM oplweb2.oplweb.component_archive as component_archive_tbl
FROM oplweb2.oplweb.component_archive_type as component_archive_type_tbl
FROM oplweb2.oplweb.component_category as component_category_tbl text literal component_category_long_description
FROM oplweb2.oplweb.component_mode as component_mode_tbl
FROM oplweb2.oplweb.component_type as component_type_tbl
FROM oplweb2.oplweb.components_for_rdfs as components_tbl
FROM oplweb2.oplweb.dbms_engine as dbms_engine_tbl
FROM oplweb2.oplweb.dbms_family as dbms_family_tbl
FROM oplweb2.oplweb.download_location as download_location_tbl
FROM oplweb2.oplweb.download_protocol as download_protocol_tbl
FROM oplweb2.oplweb.download_partner as download_partner_tbl
FROM oplweb2.oplweb.opsys as opsys_tbl
FROM oplweb2.oplweb.opsys_family as opsys_family_tbl
FROM oplweb2.oplweb.opsys_type as opsys_type_tbl
FROM oplweb2.oplweb.processor_family as processor_family_tbl
FROM oplweb2.oplweb.processor_mode as processor_mode_tbl
FROM oplweb2.oplweb.processors as processors_tbl
FROM oplweb2.oplweb.product as product_tbl text literal long_description
FROM oplweb2.oplweb.product_benefits as product_benefits_tbl text literal product_benefit_explanation
FROM oplweb2.oplweb.product_benefits_category as product_benefits_category_tbl
FROM oplweb2.oplweb.product_category as product_category_tbl
FROM oplweb2.oplweb.product_category_features_with_code as product_category_features_tbl text literal long_description
FROM oplweb2.oplweb.product_family as product_family_tbl
FROM oplweb2.oplweb.product_family as product_family_tbl_2
FROM oplweb2.oplweb.product_family_features_with_code as product_family_features_tbl text literal long_description
FROM oplweb2.oplweb.product_features as product_features_tbl text literal long_description
FROM oplweb2.oplweb.product_feature_category as product_feature_category_tbl text literal description
FROM oplweb2.oplweb.product_format_features_with_code as product_format_features_tbl text literal long_description
FROM oplweb2.oplweb.product_release_features as product_release_features_tbl text literal long_description
FROM oplweb2.oplweb.product_release_with_family as product_release_tbl
FROM oplweb2.oplweb.vendor_category as vendor_category_tbl
FROM oplweb2.oplweb.vendor_category_family as vendor_category_family_tbl
FROM oplweb2.oplweb.vendors as vendors_tbl
FROM oplweb2.oplweb.product_formats_categories as product_formats_categories
FROM oplweb2.oplweb.product_with_code as product_with_code
FROM oplweb2.oplweb.product_category_with_code as product_category_with_code
FROM oplweb2.oplweb.product_format as product_format_with_code
FROM oplweb2.oplweb.product_price as pp
FROM oplweb2.oplweb.product_price_type as pt
FROM oplweb2.DBA.license_model_unit_type as put
FROM oplweb2.DBA.license_model_unit_type as put2
FROM oplweb2.DBA.license_model as lm
FROM oplweb2.DBA.license_model as lm2
FROM oplweb2.DBA.license_model_type as license_model_type_tbl
FROM oplweb2.DBA.product_price_varchar as ppv
FROM oplweb2.DBA.product_general_discount_vc as gd
FROM oplweb2.oplweb.archive_coverage_osdb as ac1
{
	create virtrdf:product_portfolio2 as
		graph <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
	  option (exclusive)
	{

  opl:ProcessorFamily(processor_family_tbl.processor_family_id)
    opl:hasProcessors
    opl:Processor(processors_tbl.processor_name, processors_tbl.processor_mode_id)
    where (
        ^{processor_family_tbl.}^.processor_family_id = ^{processors_tbl.}^.processor_family_id
    )
    as virtrdf:OplProcessorFamilyHasProcessors .


  opl:Processor(processors_tbl.processor_name, processors_tbl.processor_mode_id)
    opl:hasProductFamily
    opl:ProductFamily(ac1.product_family_code)
    where (
        ^{processors_tbl.}^.processor_name = ^{ac1.}^.processor_name
        and
        ^{processors_tbl.}^.processor_mode_id = ^{ac1.}^.processor_mode_id
    )
    as virtrdf:OplProcessorToProductFamily .



#
# Product Licensing and Shop stuff
# =========================================


	  opl:ProductRelease(
	      product_release_tbl.product_id,
	      product_release_tbl.product_release_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
	      )
      opl:hasLicenseModel
      opl:LicenseModel(
        lm.product_release_id,
        lm.product_id,
        lm.opsys_family_id,
        lm.dbms_family_id,
        lm.product_price_type_id
	  )
      where (
        ^{lm.}^.product_id = ^{product_release_tbl.}^.product_id and
        ^{lm.}^.product_release_id = ^{product_release_tbl.}^.product_release_id and
        ^{lm.}^.opsys_family_id = ^{product_release_tbl.}^.opsys_family_id and
        ^{lm.}^.dbms_family_id = ^{product_release_tbl.}^.dbms_family_id
    )
    as virtrdf:OplProductReleaseHasLicenseModel .

	  opl:ProductRelease(
	      product_release_tbl.product_id,
	      product_release_tbl.product_release_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
	      )
      opl:hasPriceSample
	  opl:lit_shop_sample (
	      product_release_tbl.product_release_id,
	      product_release_tbl.product_id,
	      product_release_tbl.opsys_name,
	      product_release_tbl.dbms_name
      	)
      as virtrdf:OplPriceSamples .


	opl:LicenseModel(
	    lm.product_release_id,
        lm.product_id,
        lm.opsys_family_id,
        lm.dbms_family_id,
		lm.product_price_type_id)
	a opl:LicenseModel
	as virtrdf:OplLicenseModel;
	a gr:Sell
	as virtrdf:OplLicenseModelAgrSell ;
	a gr:ActualProductOrServiceInstance
	as virtrdf:OplLicenseModelAgrProductOrServiceInstance ;
	rdfs:label opl:lit_license_model_type(
		lm.product_price_type_id
	) as virtrdf:OplLabelLicenseModel ;
	rdfs:description opl:lit_license_model_explain (
		lm.product_price_type_id
	) as virtrdf:OplLicenseModelExplain ;
	opl:ProductReleaseId
	  lm.product_release_id
	  as virtrdf:lm_shop_price_product_release;
	opl:isOfFormat
	  opl:ProductFormat(lm.product_format_code)
	  as virtrdf:lm_shop_price_product_format;
	opl:isOfCategory
	  opl:ProductCategory(lm.product_cat_code)
	  as virtrdf:lm_shop_price_product_cat;
	opl:OpsysFamily
	  opl:OpsysFamily(lm.opsys_family_id)
	  as virtrdf:lm_shop_price_opsys_family_oplweb;
	opl:OpsysType
	  opl:OpsysType(lm.opsys_type_id)
	  as virtrdf:lm_shop_price_opsys_type;
	opl:DbmsFamily
	  opl:DbmsFamily(lm.dbms_family_id)
	  as virtrdf:lm_shop_price_dbms_family	;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs: ;
      rdfs:isDefinedBy gr:
		.


	opl:LicenseModel(
	    lm.product_release_id,
        lm.product_id,
        lm.opsys_family_id,
        lm.dbms_family_id,
		lm.product_price_type_id)
	opl:hasPriceUnitType
	opl:PriceUnitType(
	    lm2.product_release_id,
        lm2.product_id,
        lm2.opsys_family_id,
        lm2.dbms_family_id,
		lm2.product_price_type_id,
		lm2.product_price_unit_type_id)
      where (
        ^{lm.}^.product_release_id = ^{lm2.}^.product_release_id AND
        ^{lm.}^.product_id = ^{lm2.}^.product_id AND
        ^{lm.}^.opsys_family_id = ^{lm2.}^.opsys_family_id AND
        ^{lm.}^.opsys_type_id = ^{lm2.}^.opsys_type_id AND
        ^{lm.}^.product_price_type_id = ^{lm2.}^.product_price_type_id AND
		^{lm2.}^.product_price_unit_type_id <> 'db_sessions'
        and
        (
          ^{lm.}^.dbms_family_id = ^{lm2.}^.dbms_family_id
    	  OR
          ^{lm2.}^.dbms_family_id = 15
        )
    )
    as virtrdf:OplLicenseModelPriceUnitTypes .



	opl:LicenseModel(
	    lm.product_release_id,
        lm.product_id,
        lm.opsys_family_id,
        lm.dbms_family_id,
		lm.product_price_type_id)
	gr:hasPriceSpecification
	opl:PriceUnitType(
	    lm2.product_release_id,
        lm2.product_id,
        lm2.opsys_family_id,
        lm2.dbms_family_id,
		lm2.product_price_type_id,
		lm2.product_price_unit_type_id)
      where (
        ^{lm.}^.product_release_id = ^{lm2.}^.product_release_id AND
        ^{lm.}^.product_id = ^{lm2.}^.product_id AND
        ^{lm.}^.opsys_family_id = ^{lm2.}^.opsys_family_id AND
        ^{lm.}^.opsys_type_id = ^{lm2.}^.opsys_type_id AND
        ^{lm.}^.product_price_type_id = ^{lm2.}^.product_price_type_id AND
		^{lm2.}^.product_price_unit_type_id = 'db_sessions'
        and
        (
          ^{lm.}^.dbms_family_id = ^{lm2.}^.dbms_family_id
    	  OR
          ^{lm2.}^.dbms_family_id = 15
        )
    )
    as virtrdf:OplLicenseModelBasePriceUnitTypes .


	opl:Discount(
	    gd.product_release_id,
	    gd.opsys_type_id,
	    gd.product_id,
	    gd.opsys_family_id,
	    gd.dbms_family_id,
	    gd.product_price_type_id)
	a opl:Discount
	as virtrdf:product_discount;
	rdfs:label gd.product_discount_description as virtrdf:OplLabelDiscount ;
	rdfs:description gd.product_discount_description as virtrdf:OplDiscountExplain ;
	opl:discount_description
	  gd.product_discount_description
	  as virtrdf:gd_discount_description;
	opl:discount_start
	  gd.discount_start
	  as virtrdf:gd_discount_start;
	opl:discount_end
	  gd.discount_end
	  as virtrdf:gd_discount_end;
	opl:ProductPriceType
	  opl:PriceType(gd.product_price_type_id)
	  as virtrdf:gd_shop_price_type;
	gr:hasUnitOfMeasurement
	  opl:PriceType(gd.product_price_type_id)
	  as virtrdf:gd_shop_price_type_grUnitOfMeasurement;
	opl:ProductReleaseId
	  gd.product_release_id
	  as virtrdf:gd_shop_price_product_release;
	opl:ProductFormat
	  opl:ProductFormat(gd.product_format_code)
	  as virtrdf:gd_shop_price_product_format;
	opl:ProductCategory
	  opl:ProductCategory(gd.product_cat_code)
	  as virtrdf:gd_shop_price_product_cat;
	opl:OpsysFamily
	  opl:OpsysFamily(gd.opsys_family_id)
	  as virtrdf:gd_shop_price_opsys_family_oplweb;
	opl:OpsysType
	  opl:OpsysType(gd.opsys_type_id)
	  as virtrdf:gd_shop_price_opsys_type;
	opl:DbmsFamily
	  opl:DbmsFamily(gd.dbms_family_id)
	  as virtrdf:gd_shop_price_dbms_family;
	opl:discount_token
	  gd.discount_token
	  as virtrdf:gd_discount_token ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.




	opl:PriceType(pt.product_price_type_id)
	  a opl:PriceType
	  as virtrdf:shop_product_price_type;
	rdfs:label pt.product_price_type_description as virtrdf:OplLabelPriceType ;
	rdfs:description pt.product_price_type_description as virtrdf:OplPriceTypeExplain ;
	opl:PriceTypeDescription
	  pt.product_price_type_description
	  as virtrdf:shop_product_price_type_description;
	dc:description
	  pt.product_price_type_long_description
	  as virtrdf:shop_product_price_type_long_description ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy dc: ;
      rdfs:isDefinedBy rdfs:
		.

	opl:PriceUnitType(
		put.product_release_id,
        put.product_id,
        put.opsys_family_id,
        put.dbms_family_id,
		put.product_price_type_id,
		put.product_price_unit_type_id)
	  a opl:PriceUnitType
	  as virtrdf:shop_product_price_unit_type;
	rdfs:label put.product_price_unit_description as virtrdf:OplLabelproductpriceunitdescription ;
	rdfs:description put.product_price_unit_description as virtrdf:OplproductpriceunitdescriptionExplain ;
	gr:hasUnitOfMeasurement
	  opl:PriceType(put.product_price_type_id)
	  as virtrdf:put_shop_price_type_grUnitOfMeasurement;
	opl:unitValue
	  put.unit_price
	  as virtrdf:unit_type_unit_price;
	gr:hasValue
	  put.unit_price
	  as virtrdf:unit_type_unit_price_grHasValue;
	opl:graceUnits
	  put.unit_grace
	  as virtrdf:unit_type_unit_grace;
	opl:minUnits
	  put.unit_low
	  as virtrdf:unit_type_unit_low;
	opl:maxUnits
	  put.unit_cap
	  as virtrdf:unit_type_unit_cap;
	opl:unit_type_description
	  put.product_price_unit_description
	  as virtrdf:unit_type_description ;
      rdfs:isDefinedBy opl: ;
      rdfs:isDefinedBy rdfs:
		.


    opl:PriceUnitType(
		put.product_release_id,
        put.product_id,
        put.opsys_family_id,
        put.dbms_family_id,
		put.product_price_type_id,
		put.product_price_unit_type_id
	  )
      opl:hasIncrementalDiscount
      opl:PriceUnitIncrementalDiscount(
		put2.product_release_id,
        put2.product_id,
        put2.opsys_family_id,
        put2.dbms_family_id,
		put2.product_price_type_id,
		put2.product_price_unit_type_id
	  )
      where (
		^{put.}^.product_release_id = ^{put2.}^.product_release_id and
        ^{put.}^.product_id = ^{put2.}^.product_id and
        ^{put.}^.opsys_family_id = ^{put2.}^.opsys_family_id and
        ^{put.}^.dbms_family_id = ^{put2.}^.dbms_family_id and
		^{put.}^.product_price_type_id = ^{put2.}^.product_price_type_id and
		^{put.}^.product_price_unit_type_id = ^{put2.}^.product_price_unit_type_id
    )
    as virtrdf:OplLicenseModelUnitsIncrementalDiscounts .


	opl:PriceUnitIncrementalDiscount(
		put.product_release_id,
        put.product_id,
        put.opsys_family_id,
        put.dbms_family_id,
		put.product_price_type_id,
		put.product_price_unit_type_id)
	  a opl:PriceUnitIncrementalDiscount
	  as virtrdf:shop_product_price_unit_type_incremental_discount;
	rdfs:label put.product_price_unit_description as virtrdf:OplLabelproductpriceunitIncDisdescription ;
	rdfs:description put.product_price_unit_description as virtrdf:OplproductpriceunitIncDisdescriptionExplain ;
	opl:percentageOfBase
	  put.unit_discount
	  as virtrdf:unit_type_unit_discount;
	opl:triggerPoint
	  put.quantity
	  as virtrdf:unit_type_unit_discount_quantity
	.


      opl:LicenseModel(
        lm.product_release_id,
        lm.product_id,
        lm.opsys_family_id,
        lm.dbms_family_id,
        lm.product_price_type_id
	  )
      opl:hasGeneralDiscounts
      opl:Discount(
	    gd.product_release_id,
	    gd.opsys_type_id,
	    gd.product_id,
	    gd.opsys_family_id,
	    gd.dbms_family_id,
	    gd.product_price_type_id
	  )
      where (
        ^{lm.}^.product_release_id = ^{gd.}^.product_release_id AND
        ^{lm.}^.product_id = ^{gd.}^.product_id AND
        ^{lm.}^.opsys_family_id = ^{gd.}^.opsys_family_id AND
        ^{lm.}^.dbms_family_id = ^{gd.}^.dbms_family_id AND
        ^{lm.}^.opsys_type_id = ^{gd.}^.opsys_type_id AND
        ^{lm.}^.product_price_type_id = ^{gd.}^.product_price_type_id
    )
    as virtrdf:OplLicenseModelGeneralDiscounts .



	} .
} .
;


DB.DBA.XML_SET_NS_DECL ('OpenLink', 'http://www.openlinksw.com/schemas/oplweb#', 2);
DB.DBA.XML_SET_NS_DECL ('OplProductCategory', 'http://data.openlinksw.com/oplweb/product_category/', 2);
DB.DBA.XML_SET_NS_DECL ('OplProductFamily', 'http://data.openlinksw.com/oplweb/product_family/', 2);
DB.DBA.XML_SET_NS_DECL ('OplProductFormat', 'http://data.openlinksw.com/oplweb/product_format/', 2);
DB.DBA.XML_SET_NS_DECL ('OplProduct', 'http://data.openlinksw.com/oplweb/product/', 2);
DB.DBA.XML_SET_NS_DECL ('OplProductRelease', 'http://data.openlinksw.com/oplweb/product_release/', 2);


DB.DBA.RDF_AUDIT_METADATA (1, '*');


commit work;
-- Clear the 'cache' for immediate effects
SELECT hs_local_iri, exec ('SPARQL clear graph <'||hs_local_iri||'>')
  FROM sys_http_sponge
  WHERE hs_local_iri like '%oplweb%';

SELECT id_to_iri(G), exec ('SPARQL clear graph <'||id_to_iri(G)||'>')
  FROM rdf_quad
  WHERE id_to_iri(G) like '%oplweb%';

SPARQL CLEAR GRAPH <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>;
commit work;


SPARQL CONSTRUCT { <http://data.openlinksw.com/oplweb/product_family/uda#this> ?p ?o }
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { <http://data.openlinksw.com/oplweb/product_family/uda#this> ?p ?o }
;

SPARQL SELECT *
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { <http://data.openlinksw.com/oplweb/product_category/odbc#this> ?p ?o }
  limit 100
;

SPARQL define get:soft "soft" SELECT *
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { <http://data.openlinksw.com/oplweb/product_category/odbc#this> ?p ?o }
  limit 100
;

SPARQL CONSTRUCT { <http://data.openlinksw.com/oplweb/product_category/jdbc#this> ?p ?o }
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { <http://data.openlinksw.com/oplweb/product_category/jdbc#this> ?p ?o }
  limit 100
;

SPARQL CONSTRUCT { <http://data.openlinksw.com/oplweb/product_format/mt#this> ?p ?o }
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { <http://data.openlinksw.com/oplweb/product_format/mt#this> ?p ?o }
  limit 1
;


SPARQL SELECT  ?p ?o
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { <http://data.openlinksw.com/oplweb/product_family/uda#this> ?p ?o }
  limit 1
;

SPARQL
prefix opl: <http://www.openlinksw.com/schemas/oplweb#>
SELECT  ?s ?o
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { ?s opl:hasProcessors ?o }
  limit 1
;

SPARQL
prefix opl: <http://www.openlinksw.com/schemas/oplweb#>
SELECT distinct ?o
  FROM <http://www.openlinksw.com/dataspace/organization/openlink/oplweb/>
  WHERE { <http://data.openlinksw.com/oplweb/processor/i686_1#this> opl:hasProductFamily ?o }
  limit 10
;

-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/price_unit_type/6.1_odbc-sqlserver-st_1_2_1_db_sessions#this"
-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/price_unit_type/6.1_odbc-sqlserver-st_1_2_1_cpu#this"

--SELECT top 10 * FROM oplweb2.DBA.license_model_unit_type WHERE product_release_id = '6.1' and product_id = 'odbc-sqlserver-st'
--  and opsys_family_id = 1 and dbms_family_id = 15 and product_price_type_id = 1 and product_price_unit_type_id = 'cpu';

-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/rdfbrowser/index.html?uri=http%3A//data.openlinksw.com/oplweb/component_archive/6.1-odbc-oracle-st-i686-generic-win-32-ora10-odbclt-clnt-only_mv.msi"
-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/product_family/uda"
-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/product_category/odbc"
-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/dbms_family/MySQL"
-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/product_release/odbc-oracle-mt_6.1_i686-generic-win-32_ora9"
-- curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/license_model/6.1_odbc-sqlserver-st_1_2_1"




curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/rdfbrowser/index.html?uri=http%3A//data.openlinksw.com/oplweb/component_archive/6.1-odbc-oracle-st-i686-generic-win-32-ora10-odbclt-clnt-only_mv.msi"
curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/product_family/uda"
curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/product_release/odbc-oracle-mt_6.1_i686-generic-win-32_ora9"
curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/license_model/6.1_odbc-sqlserver-st_1_2_1"

--
-- XXX: note , the below would work only if www.openlinksw.com has the GRAPH <http://data.openlinksw.com/oplweb/>
-- if experimenting on other box, then www.openlinksw.com should be replaced with [URIQA] DefaultHost INI value
--



DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oplweb2_rule2',
    1,
    '/oplweb(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//data.openlinksw.com/oplweb%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//www.openlinksw.com/dataspace/organization/openlink/oplweb/%%3E+WHERE+{+%%3Chttp%%3A//data.openlinksw.com/oplweb%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oplweb2_rule1',
    1,
    '(/oplweb/[^#]*)',
    vector('path'),
    1,
    '/rdfbrowser/index.html?uri=http%%3A//data.openlinksw.com%U%',
--    '/DAV/RDF/rdfqry.vsp?uri=http%%3A//data.openlinksw.com%U%%23this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oplweb2_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%s',
    vector('path'),
    null,
    null,
    0,
    null
    );



create procedure DB.DBA.REDO_OPLWEB2_RDF_DET()
{
  declare colid int;
  colid := DAV_SEARCH_ID('/DAV/RDF/oplweb2/', 'C');
  if (colid < 0)
    return;
  update WS.WS.SYS_DAV_COL set COL_DET=null where COL_ID = colid;
}
;

DB.DBA.REDO_OPLWEB2_RDF_DET();

drop procedure DB.DBA.REDO_OPLWEB2_RDF_DET;

DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/RDF/oplweb2/', 'http://data.openlinksw.com/oplweb', NULL);
VHOST_REMOVE (lpath=>'/oplweb/data/rdf');
DB.DBA.VHOST_DEFINE (lpath=>'/oplweb/data/rdf', ppath=>'/DAV/RDF/oplweb2/All/', is_dav=>1, vsp_user=>'dba');

-- procedure to convert path to DET resource name
create procedure DB.DBA.OPLWEB2_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  iri := 'http://data.openlinksw.com/oplweb' || val;
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('oplweb2_rdf', 1,
    '/oplweb/(.*)', vector('path'), 1,
    '/oplweb/data/rdf/%U', vector('path'),
    'DB.DBA.OPLWEB2_DET_REF',
    'application/rdf.xml',
    2,
    303);


DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oplweb2_rule_list1',
    1,
    vector (
                'oplweb2_rule1',
                'oplweb2_rule2',
                'oplweb2_rule3',
                'oplweb2_rdf'
          ));


VHOST_REMOVE (vhost=>'data.openlinksw.com:80', lpath=>'/oplweb');
DB.DBA.VHOST_DEFINE (vhost=>'data.openlinksw.com:80', lpath=>'/oplweb', ppath=>'/DAV/RDF/oplweb2/',
  vsp_user=>'dba', is_dav=>1, def_page=>'sfront.vspx', is_brws=>0, opts=>vector ('url_rewrite', 'oplweb2_rule_list1'));


/*

DB.DBA.VHOST_DEFINE (vhost=>'data.openlinksw.com:80', lhost=>':80', lpath=>'/rdf_net', ppath=>'/rdf_net');
DB.DBA.VHOST_DEFINE (vhost=>'data.openlinksw.com:80', lhost=>':80', lpath=>'/sparql/',
  ppath => '/!sparql/', is_dav => 1, vsp_user => 'dba', opts => vector('noinherit', 1));

VHOST_REMOVE (vhost=>'data.openlinksw.com', lpath=>'/proxy');
DB.DBA.VHOST_DEFINE (vhost=>'data.openlinksw.com', lhost=>':80', lpath=>'/proxy',
  ppath=>'/SOAP/Http/ext_http_proxy', soap_user=>'PROXY');

DB.DBA.VHOST_DEFINE (vhost=>'data.openlinksw.com:80', lhost=>':80', lpath=>'/xml_a',
  ppath=>'/SOAP/',soap_user=>'XML_A');
DB.DBA.VHOST_DEFINE (vhost=>'data.openlinksw.com:80', lhost=>':80', lpath=>'/XMLA',
  ppath=>'/SOAP/', soap_user=>'XMLA', soap_opts => vector ('ServiceName', 'XMLAnalysis', 'elementFormDefault', 'qualified'))

GRANT EXECUTE ON DB.DBA.RDF_SPONGE_UP TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.TTLP_EV_NEW_GRAPH TO "SPARQL", "SPARQL_UPDATE";
grant SPARQL_UPDATE to "SPARQL";

curl -H "Accept: application/rdf+xml" "http://data.openlinksw.com/oplweb/product_family/uda#this"

SELECT hs_local_iri, exec ('sparql clear graph <'||hs_local_iri||'>') from sys_http_sponge;

*/



OWL based Ontology

--sparql construct { ?x ?y ?z } from --<http://www.openlinksw.com/dataspace/organization/openlink#this>
--	where { ?x ?y ?z }

DB.DBA.RDF_LOAD_RDFXML_MT (
'<?xml version="1.0"?>
<rdf:RDF
    xmlns="http://www.openlinksw.com/dataspace/organization/openlink/oplweb#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:virtrdf="http://www.openlinksw.com/schemas/virtrdf#"
    xml:base="http://www.openlinksw.com/schemas/oplweb#">
  <owl:Ontology rdf:about="http://www.openlinksw.com/schemas/oplweb#">
        <rdfs:label>ProductPortfolio</rdfs:label>
        <rdfs:comment>OpenLink Product Portfolio</rdfs:comment>
        <virtrdf:catName>oplweb</virtrdf:catName>
        <virtrdf:version>1.00</virtrdf:version>
  </owl:Ontology>

	<!-- Family / Category / Format -->

	<rdfs:Class rdf:ID="ProductFamily">
		<rdfs:label>Product Family</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Family
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductCategory">
		<rdfs:label>Product Category</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Category
		</rdfs:comment>
    <rdfs:subPropertyOf rdf:resource="#ProductFamily"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductFormat">
		<rdfs:label>Product Format</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Format
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductFormatCategory">
		<rdfs:label>Product Format Category</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Format Category
		</rdfs:comment>
	</rdfs:Class>

	<rdf:Property rdf:ID="ProductFamilyDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:label>Product Family Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductFamilyLongDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:label>Product Family Long Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductFamilyCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:label>Product Family Long Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductFormatDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:label>Product Format Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductFormatLongDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:label>Product Format Long Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductFormatCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#ProductFormatCategory"/>
    <rdfs:label>Product Format Long Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductCategoryDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:label>Product Category Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductCategoryLongDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:label>Product Category Long Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductCategoryCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#ProductFormatCategory"/>
    <rdfs:label>Product Category Long Description</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="hasProduct">
    <rdfs:range rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#ProductFormatCategory"/>
    <rdfs:label>Product</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="hasCategory">
    <rdfs:range rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:label>Product</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="hasFormat">
    <rdfs:range rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:label>Product</rdfs:label>
  </rdf:Property>


	<!-- Vendor -->

	<rdfs:Class rdf:ID="VendorCategoryFamily">
		<rdfs:label>vendor_category_family</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			vendor_category_family
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="VendorCategory">
		<rdfs:label>vendor_category</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			vendor_category
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="VendorCategoryFamily"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="Vendors">
		<rdfs:label>vendors</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			vendors
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="VendorCategory"/>
	</rdfs:Class>

	<rdf:Property rdf:ID="VendorName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Vendors"/>
    <rdfs:label>vendor name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="VendorCategoryFamilyDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#VendorCategoryFamily"/>
    <rdfs:label>vendor_category_family_description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="VendorCategoryDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#VendorCategory"/>
    <rdfs:label>vendor_category_description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="isOfVendorCategory">
    <rdfs:range rdf:resource="#VendorCategory"/>
    <rdfs:domain rdf:resource="#Vendors"/>
    <rdfs:label>vendor_category_description</rdfs:label>
  </rdf:Property>

	<!-- Opsys / DBMS -->

	<rdfs:Class rdf:ID="OpsysFamily">
		<rdfs:label>Opsys Family</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Opsys Family
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="DbmsFamily">
		<rdfs:label>Dbms Family</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Dbms Family
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="DbmsEngine">
		<rdfs:label>Dbms Engine</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Dbms Engine
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="DbmsFamily"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="OpsysType">
		<rdfs:label>Opsys Type</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Opsys Type
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProcessorMode">
		<rdfs:label>Processor Mode</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Processor Mode
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="Processor">
		<rdfs:label>Processor</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Processor
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="ProcessorFamily"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProcessorFamily">
		<rdfs:label>Processor Family</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Processor Family
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="Opsys">
		<rdfs:label>Dbms Engine</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			opsys
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="OpsysFamily"/>
    <rdfs:subClassOf rdf:resource="OpsysType"/>
	</rdfs:Class>

	<rdf:Property rdf:ID="OpsysFamilyName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#OpsysFamily"/>
    <rdfs:label>Opsys Family Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysFamilyRating">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#OpsysFamily"/>
    <rdfs:label>Opsys Family Rating</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysFamilyLicenseCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#OpsysFamily"/>
    <rdfs:label>Opsys Family License Code</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysFamilyVendor">
    <rdfs:range rdf:resource="#Vendors"/>
    <rdfs:domain rdf:resource="#OpsysFamily"/>
    <rdfs:label>Opsys Family Vendor</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsFamilyName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DbmsFamily"/>
    <rdfs:label>DBMS Family Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsFamilyVendor">
    <rdfs:range rdf:resource="#Vendors"/>
    <rdfs:domain rdf:resource="#DbmsFamily"/>
    <rdfs:label>DBMS Family Vendor</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DbmsEngine"/>
    <rdfs:label>DBMS Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsVersion">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DbmsEngine"/>
    <rdfs:label>DBMS Version</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsEngineRating">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DbmsEngine"/>
    <rdfs:label>DBMS Engine Rating</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsEngineOldArchiveCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DbmsEngine"/>
    <rdfs:label>DBMS Engine old Archive Code</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsUpwardCompatible">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DbmsEngine"/>
    <rdfs:label>DBMS Upward Compatible</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="DbmsDownwardCompatible">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DbmsEngine"/>
    <rdfs:label>DBMS Downward Compatible</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysTypeDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#OpsysType"/>
    <rdfs:label>Opsys Type Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysTypeShortDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#OpsysType"/>
    <rdfs:label>Opsys Type Short Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysVersion">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys Version</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysUpwardCompatible">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys Compatible</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysDownwardCompatible">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys Downward Compatible</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysLicenseCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys License Code</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysCommercialName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys Commercial Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysProcessor">
    <rdfs:range rdf:resource="#Processor"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys Processor</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="OpsysEmulation">
    <rdfs:range rdf:resource="#ProcessorMode"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:label>Opsys Emulation Mode</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProcessorModeName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProcessorMode"/>
    <rdfs:label>Processor Mode Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProcessorName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Processor"/>
    <rdfs:label>Processor Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProcessorProcessorMode">
    <rdfs:range rdf:resource="#ProcessorMode"/>
    <rdfs:domain rdf:resource="#Processor"/>
    <rdfs:label>Processor Mode</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProcessorDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Processor"/>
    <rdfs:label>Processor Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProcessorFamilyName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProcessorFamily"/>
    <rdfs:label>Processor Family Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProcessorFamilyDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProcessorFamily"/>
    <rdfs:label>Processor Family Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProcessorFamilyVendor">
    <rdfs:range rdf:resource="#Vendors"/>
    <rdfs:domain rdf:resource="#ProcessorFamily"/>
    <rdfs:label>Processor Family Vendor</rdfs:label>
  </rdf:Property>


	<!-- Product / Product Release -->

	<rdfs:Class rdf:ID="Product">
		<rdfs:label>Product</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product
		</rdfs:comment>
    <rdfs:subPropertyOf rdf:resource="#ProductFormat"/>
    <rdfs:subPropertyOf rdf:resource="#ProductCategory"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductRelease">
		<rdfs:label>Product Release</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Release
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#Product"/>
	</rdfs:Class>

	<rdf:Property rdf:ID="ProductId">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:label>Product ID</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="isOfCategory">
    <rdfs:range rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:label>Product Category</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="isOfFormat">
    <rdfs:range rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:label>Product Category</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductDescription">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:label>Product Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductLongDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:label>Product Long Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductReleaseId">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Product Release ID</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductReleaseOpsys">
    <rdfs:range rdf:resource="#Opsys"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Product Release Opsys</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductReleaseDbms">
    <rdfs:range rdf:resource="#DbmsEngine"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Product Release DBMS</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductReleaseUpwardCompatible">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Product Release upward compatible</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductReleaseDownwardCompatible">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Product Release downward compatible</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ProductReleaseSupported">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Product Release Supported</rdfs:label>
  </rdf:Property>

	<!-- Components -->

	<rdfs:Class rdf:ID="Component">
		<rdfs:label>Components</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Components
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ComponentMode">
		<rdfs:label>Component Mode</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Component
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ComponentType">
		<rdfs:label>Component</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Component Type
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ComponentCategory">
		<rdfs:label>Component Category</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Component
		</rdfs:comment>
	</rdfs:Class>

	<rdf:Property rdf:ID="ComponentModeDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentMode"/>
    <rdfs:label>Component Mode Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ComponentModeShortDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentMode"/>
    <rdfs:label>Component Mode Short Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ComponentTypeDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentType"/>
    <rdfs:label>Component Type Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ComponentTypeShortDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentType"/>
    <rdfs:label>Component Type Short Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ComponentCategoryDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentCategory"/>
    <rdfs:label>Component Category Description</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ComponentCategoryLongDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentCategory"/>
    <rdfs:label>Component Category Long Description</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentCategoryShortDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentCategory"/>
    <rdfs:label>Component Category Short Description</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentCvsid">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components CVSID</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentBuildDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Build Date</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="Notes">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Notes</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="BuildComments">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Build Comments</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="Filesize">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Name</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ComponentComponentCategory">
    <rdfs:range rdf:resource="#ComponentCategory"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Component Category</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentComponentType">
    <rdfs:range rdf:resource="#ComponentType"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Component Type</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentComponentMode">
    <rdfs:range rdf:resource="#ComponentMode"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Component Mode</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentOpsys">
    <rdfs:range rdf:resource="#Opsys"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components Opsys</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentDbmsEngine">
    <rdfs:range rdf:resource="#DbmsEngine"/>
    <rdfs:domain rdf:resource="#Component"/>
    <rdfs:label>Components DBMS</rdfs:label>
  </rdf:Property>

	<!-- Component Archives -->

	<rdfs:Class rdf:ID="ComponentArchive">
		<rdfs:label>Component Archive</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Component Archives
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ProductRelease"/>
    <rdfs:subClassOf rdf:resource="#Component"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ComponentArchiveType">
		<rdfs:label>Component Archive Type</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Component Archives Type
		</rdfs:comment>
	</rdfs:Class>

  <rdf:Property rdf:ID="ComponentArchiveTypeName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchiveType"/>
    <rdfs:label>Component Archive Type Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveTypeShortName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchiveType"/>
    <rdfs:label>Component Archive Type Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveTypeExtension">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchiveType"/>
    <rdfs:label>Component Archive Type Extension</rdfs:label>
  </rdf:Property>

	<rdf:Property rdf:ID="ComponentArchiveComponentArchiveType">
    <rdfs:range rdf:resource="#ComponentArchiveType"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive Component Archive Type</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveName">
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveAssemblyDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive Assembly Date</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveFileUri">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive File URI</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveLicenseCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive License Code</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveResName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive DAV Resource Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveResFullPath">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive DAV Full Path</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ComponentArchiveResFileSize">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:label>Component Archive File Size in DAV</rdfs:label>
  </rdf:Property>

	<!-- Download locations -->

	<rdfs:Class rdf:ID="DownloadLocation">
		<rdfs:label>Download Location</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Download Location
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ComponentArchive"/>
    <rdfs:subClassOf rdf:resource="#DownloadPartner"/>
    <rdfs:subClassOf rdf:resource="#DownloadProtocol"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="DownloadProtocol">
		<rdfs:label>Download Protocol</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Download Protocol
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="DownloadPartner">
		<rdfs:label>Download Partner</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Download Partner
		</rdfs:comment>
	</rdfs:Class>

  <rdf:Property rdf:ID="ProtocolName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadProtocol"/>
    <rdfs:label>Protocol Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ProtocolDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadProtocol"/>
    <rdfs:label>Protocol Description</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ProtocolActive">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadProtocol"/>
    <rdfs:label>Protocol Active</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="PartnerName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadPartner"/>
    <rdfs:label>Download Partner Partner Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="HostName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadPartner"/>
    <rdfs:label>Download Partner Hostname</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="DomainName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadPartner"/>
    <rdfs:label>Download Partner Domain Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="PortNumber">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadPartner"/>
    <rdfs:label>Download Partner Port Number</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="Uri">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadLocation"/>
    <rdfs:label>Download Location URI</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="UriOld">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#DownloadLocation"/>
    <rdfs:label>Download Location URI Old</rdfs:label>
  </rdf:Property>

	<!-- Features and Benefits -->

	<rdfs:Class rdf:ID="ProductBenefit">
		<rdfs:label>Product Benefit</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Benefit
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ProductBenefitCategory"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductBenefitCategory">
		<rdfs:label>Product Benefit</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Benefit
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductFeatureCategory">
		<rdfs:label>Product Feature Category</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Feature Category
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductFeature">
		<rdfs:label>Product Features</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Features
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ProductFeatureCategory"/>
    <rdfs:subClassOf rdf:resource="#ProductBenefit"/>
    <rdfs:subClassOf rdf:resource="#Product"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductFamilyFeature">
		<rdfs:label>Product Family Features</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Family Features
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ProductFeatureCategory"/>
    <rdfs:subClassOf rdf:resource="#ProductBenefit"/>
    <rdfs:subClassOf rdf:resource="#ProductFamily"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductFormatFeature">
		<rdfs:label>Product Format Features</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Format Features
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ProductFeatureCategory"/>
    <rdfs:subClassOf rdf:resource="#ProductBenefit"/>
    <rdfs:subClassOf rdf:resource="#ProductFormat"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductCategoryFeature">
		<rdfs:label>Product Category Features</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Category Features
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ProductFeatureCategory"/>
    <rdfs:subClassOf rdf:resource="#ProductBenefit"/>
    <rdfs:subClassOf rdf:resource="#ProductCategory"/>
	</rdfs:Class>

	<rdfs:Class rdf:ID="ProductReleaseFeature">
		<rdfs:label>Product Benefit</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Product Benefit
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#ProductFeatureCategory"/>
    <rdfs:subClassOf rdf:resource="#ProductBenefit"/>
    <rdfs:subClassOf rdf:resource="#ProductRelease"/>
	</rdfs:Class>

  <rdf:Property rdf:ID="ProductBenefitsCategoryDescription">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductBenefitsCategory"/>
    <rdfs:label>product Benefits Category</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="Description">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductBenefit"/>
    <rdfs:domain rdf:resource="#ProductBenefitCategory"/>
    <rdfs:domain rdf:resource="#ProductFeatureCategory"/>
    <rdfs:domain rdf:resource="#ProductFeature"/>
    <rdfs:domain rdf:resource="#ProductFamilyFeature"/>
    <rdfs:domain rdf:resource="#ProductFormatFeature"/>
    <rdfs:domain rdf:resource="#ProductCategoryFeature"/>
    <rdfs:domain rdf:resource="#ProductReleaseFeature"/>
    <rdfs:label>Product Benefits Description</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="Details">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductFeature"/>
    <rdfs:domain rdf:resource="#ProductFamilyFeature"/>
    <rdfs:domain rdf:resource="#ProductFormatFeature"/>
    <rdfs:domain rdf:resource="#ProductCategoryFeature"/>
    <rdfs:domain rdf:resource="#ProductReleaseFeature"/>
    <rdfs:label>Product Benefits Description Details</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ProductBenefitsAcronym">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductBenefit"/>
    <rdfs:label>Product Benefits Acronym</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="ProductBenefitsExplanation">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductBenefit"/>
    <rdfs:label>Product Benefits Explanation</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="DemoUrl">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductCategoryFeature"/>
    <rdfs:domain rdf:resource="#ProductFormatFeature"/>
    <rdfs:domain rdf:resource="#ProductFamilyFeature"/>
    <rdfs:domain rdf:resource="#ProductReleaseFeature"/>
    <rdfs:label>The Features Demo URL</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="HypesPerSecond">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#ProductCategoryFeature"/>
    <rdfs:domain rdf:resource="#ProductFormatFeature"/>
    <rdfs:domain rdf:resource="#ProductFamilyFeature"/>
    <rdfs:domain rdf:resource="#ProductreleaseFeature"/>
    <rdfs:label>The Features Number of Hypes per second</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="Implemented">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#ProductCategoryFeature"/>
    <rdfs:domain rdf:resource="#ProductFormatFeature"/>
    <rdfs:domain rdf:resource="#ProductFamilyFeature"/>
    <rdfs:domain rdf:resource="#ProductReleaseFeature"/>
    <rdfs:label>The Features Short Description</rdfs:label>
  </rdf:Property>

<!-- shop / pricing stuff -->

	<rdfs:Class rdf:ID="LicenseType">
		<rdfs:label>License Type</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			License Type
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="UnitType">
		<rdfs:label>Unit Type</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Unit Type
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="GeneralDiscount">
		<rdfs:label>General Discount</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			General Discount
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="IncrementalDiscount">
		<rdfs:label>Incremental Discount</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			Incremental Discount
		</rdfs:comment>
	</rdfs:Class>

	<rdfs:Class rdf:ID="License">
		<rdfs:label>License</rdfs:label>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
			License
		</rdfs:comment>
    <rdfs:subClassOf rdf:resource="#LicenseType"/>
    <rdfs:subClassOf rdf:resource="#ProductRelease"/>
	</rdfs:Class>

  <rdf:Property rdf:ID="BaseCostUnit">
    <rdfs:range rdf:resource="#UnitType"/>
    <rdfs:domain rdf:resource="#License"/>
    <rdfs:label>Base Unit Cost</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="PriceUnit">
    <rdfs:range rdf:resource="#UnitType"/>
    <rdfs:domain rdf:resource="#License"/>
    <rdfs:label>Price Unit Cost</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="hasDiscount">
    <rdfs:range rdf:resource="#IncrementalDiscount"/>
    <rdfs:domain rdf:resource="#UnitType"/>
    <rdfs:label>Base Unit Cost</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="hasGeneralDiscount">
    <rdfs:range rdf:resource="#GeneralDiscount"/>
    <rdfs:domain rdf:resource="#License"/>
    <rdfs:label>General Discount</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="unitValue">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#UnitType"/>
    <rdfs:label>Unit Value</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="graceUnit">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#UnitType"/>
    <rdfs:label>Grace Unit</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="minUnits">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#UnitType"/>
    <rdfs:label>Minimum Units</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="maxUnits">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#UnitType"/>
    <rdfs:label>Maximum Units</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="codeWord">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#GeneralDiscount"/>
    <rdfs:label>Code Word needed to activate this discount</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="startDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#GeneralDiscount"/>
    <rdfs:label>Discount Start Date</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="endDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#GeneralDiscount"/>
    <rdfs:label>Discount End Date</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="percentageOfCost">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#GeneralDiscount"/>
    <rdfs:label>Percentage of cost attributing as discount</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="triggerPoint">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#IncrementalDiscount"/>
    <rdfs:label>Discount Trigger Point</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="percentageOfBase">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#IncrementalDiscount"/>
    <rdfs:label>Percentage of base cost attributing as discount</rdfs:label>
  </rdf:Property>

<!-- common properties -->

  <rdf:Property rdf:ID="label">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://www.w3.org/2001/XMLSchema#label"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:domain rdf:resource="#VendorCategory"/>
    <rdfs:domain rdf:resource="#Vendor"/>
    <rdfs:domain rdf:resource="#OpsysFamily"/>
    <rdfs:domain rdf:resource="#DbmsFamily"/>
    <rdfs:domain rdf:resource="#DbmsEngine"/>
    <rdfs:domain rdf:resource="#OpsysType"/>
    <rdfs:domain rdf:resource="#Processor"/>
    <rdfs:domain rdf:resource="#ProcessorFamily"/>
    <rdfs:domain rdf:resource="#Opsys"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#ComponentMode"/>
    <rdfs:domain rdf:resource="#ComponentType"/>
    <rdfs:domain rdf:resource="#ComponentCategory"/>
    <rdfs:domain rdf:resource="#ComponentArchive"/>
    <rdfs:domain rdf:resource="#ComponentArchiveType"/>
    <rdfs:domain rdf:resource="#DownloadLocation"/>
    <rdfs:domain rdf:resource="#ProductBenefit"/>
    <rdfs:domain rdf:resource="#ProductBenefitCategory"/>
    <rdfs:domain rdf:resource="#ProductFeatureCategory"/>
    <rdfs:domain rdf:resource="#ProductFeature"/>
    <rdfs:domain rdf:resource="#ProductFamilyFeature"/>
    <rdfs:domain rdf:resource="#ProductFormatFeature"/>
    <rdfs:domain rdf:resource="#ProductCategoryFeature"/>
    <rdfs:domain rdf:resource="#ProductReleaseFeature"/>
    <rdfs:domain rdf:resource="#LicenseModel"/>
    <rdfs:domain rdf:resource="#Discount"/>
    <rdfs:domain rdf:resource="#PriceType"/>
    <rdfs:domain rdf:resource="#PriceUnitType"/>
    <rdfs:label>Label</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="name">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Name</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="logo">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/logo"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:label>logo</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="homepage">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/homepage"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:domain rdf:resource="#ProcessorFamily"/>
    <rdfs:domain rdf:resource="#OpsysFamily"/>
    <rdfs:domain rdf:resource="#DbmsFamily"/>
    <rdfs:label>homepage</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="maker">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/maker"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:label>Maker</rdfs:label>
  </rdf:Property>

  <rdf:Property rdf:ID="sameAs">
    <rdfs:range rdf:resource="owl#sameAs"/>
    <rdfs:domain rdf:resource="#ProductCategory"/>
    <rdfs:domain rdf:resource="#ProductFormat"/>
    <rdfs:domain rdf:resource="#ProductFamily"/>
    <rdfs:domain rdf:resource="#ProductRelease"/>
    <rdfs:domain rdf:resource="#ProductFormatCategory"/>
    <rdfs:label>Name</rdfs:label>
  </rdf:Property>

</rdf:RDF>

',
'http://www.openlinksw.com/schemas/oplweb#',
'http://www.openlinksw.com/schemas/oplweb#')
--'http://www.openlinksw.com/dataspace/organization/openlink/ProductPortfolioOntology/1.0/')
;

rdfs_rule_set ('oplweb2_owlset', 'http://www.openlinksw.com/schemas/oplweb#', 1);

DB.DBA.XML_SET_NS_DECL ('opl', 'http://www.openlinksw.com/schemas/oplweb#', 2);
]]></programlisting>
</sect2>
  <sect2 id="rdfviewsenterprsyb">
      <title>Sybase using demonstration 'pubs2' database</title>
<programlisting><![CDATA[
-- Setup script for RDF views of Sybase 15 PUBS2 Sample Database --

DB..vd_remote_data_source ('syb15ma-pubs2', '', '<uid>','<pwd>');

ATTACH TABLE  "pubs2.dbo.au_pix"  PRIMARY KEY ("au_id")                  AS "pubs2"."syb"."au_pix"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.authors"  PRIMARY KEY ("au_id")                  AS "pubs2"."syb"."authors"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.discounts"  PRIMARY KEY ("stor_id")                  AS "pubs2"."syb"."discounts"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.publishers"  PRIMARY KEY ("pub_id")                  AS "pubs2"."syb"."publishers"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.roysched"  PRIMARY KEY ("title_id")                  AS "pubs2"."syb"."roysched"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.sales"  PRIMARY KEY ("stor_id", "ord_num")                  AS "pubs2"."syb"."sales"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.salesdetail"  PRIMARY KEY ("stor_id", "ord_num", "title_id")                   AS "pubs2"."syb"."salesdetail"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.stores"  PRIMARY KEY ("stor_id")                  AS "pubs2"."syb"."stores"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.titleauthor"  PRIMARY KEY ("au_id", "title_id")                  AS "pubs2"."syb"."titleauthor"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.titles"  PRIMARY KEY ("title_id", "pub_id")                  AS "pubs2"."syb"."titles"  FROM 'syb15ma-pubs2';

COMMIT WORK;

GRANT SELECT ON pubs2.syb.au_pix TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.authors TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.discounts TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.publishers TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.roysched TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.sales TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.salesdetail TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.stores TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.titleauthor TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.titles TO "SPARQL", "SPARQL_UPDATE";

-------------------------------------------------------------------

-------- Create rdfs:Class definitions ----------------------------

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix syb: <http://localhost:8890/schemas/sybasepubs2/> .

syb:titles a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "titles" ;
	rdfs:comment "Sybase Pubs2 titles table" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "title id" .

syb:title a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "title" .

syb:type a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "type" .

syb:pub_id a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range syb:publishers ;
	rdfs:label "pub_id" .

syb:advance a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:decimal ;
	rdfs:label "advance" .

syb:price a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:decimal ;
	rdfs:label "price" .

syb:total_sales a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:integer ;
	rdfs:label "total_sales" .

syb:notes a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "notes" .

syb:contract a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:integer ;
	rdfs:label "contract" .

syb:pubdate a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:dateTime ;
	rdfs:label "publish date" .

syb:authors a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "authors" ;
	rdfs:comment "Sybase Pubs2 authors table" .

syb:au_id a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "author id" .

syb:au_lname a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "author last name" .

syb:au_fname a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "author first name" .

syb:phone a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "phone number" .

syb:address a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "address" .

syb:city a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "city" .

syb:state a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "state" .

syb:country a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "country" .

syb:postalcode a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "postalcode" .

syb:stores a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "stores" ;
	rdfs:comment "Sybase Pubs2 stores table" .

syb:stor_id a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "store id" .

syb:stor_name a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "store name" .

syb:stor_address a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "store address" .

syb:city a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "city" .

syb:state a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "state" .

syb:country a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "country" .

syb:postalcode a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "postal code" .

syb:payterms a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "payment terms" .

syb:au_pix a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "authors pictures" ;
	rdfs:comment "Sybase Pubs2 au_pix table" .

syb:au_id a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range syb:authors ;
	rdfs:label "author id" .

syb:format_type a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:string ;
	rdfs:label "format type" .

syb:bytesize a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:integer ;
	rdfs:label "byte size" .

syb:pixwidth_hor a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:string ;
	rdfs:label "picture horizontal width" .

syb:pixwidth_vert a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:string ;
	rdfs:label "picture vertical width" .

syb:discounts a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "discounts" ;
	rdfs:comment "Sybase Pubs2 discount table" .

syb:discounttype a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:string ;
	rdfs:label "discounttype" .

syb:stor_id a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range syb:stores ;
	rdfs:label "store id" .

syb:lowqty a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:integer ;
	rdfs:label "min quantity" .

syb:highqty a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:integer ;
	rdfs:label "max quantity" .

syb:discount a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:decimal ;
	rdfs:label "min quantity" .

syb:salesdetail a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "sales details" ;
	rdfs:comment "Sybase Pubs2 sales detail table" .

syb:store_id a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range syb:stores ;
	rdfs:label "store id" .

syb:ord_num a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range syb:sales ;
	rdfs:label "order number" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range syb:titles ;
	rdfs:label "title id" .

syb:qty a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range xsd:integer ;
	rdfs:label "quantity" .

syb:discount a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range xsd:decimal ;
	rdfs:label "discount" .

syb:publishers a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "Publishers" ;
	rdfs:comment "Sybase Pubs2 publishers table" .

syb:pub_id a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "publisher id" .

syb:pub_name a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "publisher name" .

syb:city a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "city" .

syb:state a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "state" .

syb:titleauthor a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "title author" ;
	rdfs:comment "Sybase Pubs2 titleauthor table" .

syb:au_id a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range syb:authors ;
	rdfs:label "author id" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range syb:titles ;
	rdfs:label "title id" .

syb:au_ord a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range xsd:integer ;
	rdfs:label "author order" .

syb:royaltyper a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range xsd:integer ;
	rdfs:label "royalty per book" .

syb:roysched a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "Royalty Schedule" ;
	rdfs:comment "Sybase Pubs2 roysched table" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range syb:titles ;
	rdfs:label "title id" .

syb:lorange a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range xsd:integer ;
	rdfs:label "low range" .

syb:hirange a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range xsd:integer ;
	rdfs:label "high range" .

syb:royalty a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range xsd:integer ;
	rdfs:label "royalty" .

syb:sales a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "Sales" ;
	rdfs:comment "Sybase Pubs2 sales table" .

syb:stor_id a rdf:Property ;
	rdfs:domain syb:sales ;
	rdfs:range xsd:string ;
	rdfs:label "store id" .

syb:ord_num a rdf:Property ;
	rdfs:domain syb:sales ;
	rdfs:range xsd:string ;
	rdfs:label "order number" .

syb:date a rdf:Property ;
	rdfs:domain syb:sales ;
	rdfs:range xsd:dateTime ;
	rdfs:label "date" .
', '', 'http://localhost:8890/schemas/sybasepubs2', 0);

---------------------------------------------------------------

----------- Create IRI Classes -------------

SPARQL

	create iri class <http://localhost:8890/schemas/sybasepubs2/titles_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/titles/%s_%s#this"
    	(in title_id varchar not null, in title varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/authors_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/authors/%s#this"
    	(in au_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/stores_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/stores/%s#this"
    	(in stor_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/au_pix_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/au_pix/%s#this"
    	(in au_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/discounts_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/discounts/%s#this"
    	(in discounttype varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/salesdetail_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/salesdetail/%s_%s_%s#this"
    	(in stor_id varchar not null, in ord_num varchar not null, in title_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/publishers_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/publishers/%s#this"
    	(in pub_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/titleauthor_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/titleauthor/%s_%s#this"
    	(in au_id varchar not null, in title_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/roysched_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/roysched/%s#this"
    	(in title_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/sales_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/sales/%s_%s#this"
    	(in stor_id varchar not null, in ord_num varchar not null) .

;

--------------------------------------------------------------------

------------- Create Quad Store ------------------------------------

SPARQL

prefix syb: <http://localhost:8890/schemas/sybasepubs2/>

alter quad storage virtrdf:DefaultQuadStorage
  from pubs2.syb.au_pix as au_pix_tbl
  from pubs2.syb.authors as authors_tbl
  from pubs2.syb.discounts as discounts_tbl
  from pubs2.syb.publishers as publishers_tbl
  from pubs2.syb.roysched as roysched_tbl
  from pubs2.syb.sales as sales_tbl
  from pubs2.syb.salesdetail as salesdetail_tbl
  from pubs2.syb.stores as stores_tbl
  from pubs2.syb.titleauthor as titleauthor_tbl
  from pubs2.syb.titles as titles_tbl
{
  create virtrdf:sybasepubs2 as
      graph <http://localhost:8890/sybasepubs2>
  {
	syb:au_pix_iri (au_pix_tbl.au_id) a syb:au_pix as virtrdf:au_pix_id;
	syb:au_id au_pix_tbl.au_id as virtrdf:au_pix_au_id;
	syb:format_type au_pix_tbl.format_type as virtrdf:au_pix_format_type;
	syb:bytesize au_pix_tbl.bytesize as virtrdf:au_pix_bytesize;
	syb:pixwidth_hor au_pix_tbl.pixwidth_hor as virtrdf:au_pix_pixwidth_hor;
	syb:pixwidth_vert au_pix_tbl.pixwidth_vert as virtrdf:au_pix_pixwidth_vert ;
       	syb:has_author syb:authors_iri(authors_tbl.au_id) where (^{authors_tbl.}^.au_id = ^{au_pix_tbl.}^.au_id) as virtrdf:au_pix_has_author .

        syb:authors_iri (authors_tbl.au_id) a syb:authors as virtrdf:authors_pk ;
	syb:au_id authors_tbl.au_id as virtrdf:authors_au_id;
       	syb:au_lname authors_tbl.au_lname as virtrdf:authors_au_lname;
       	syb:au_fname authors_tbl.au_fname as virtrdf:authors_au_fname;
       	syb:phone authors_tbl.phone  as virtrdf:authors_phone;
       	syb:address authors_tbl.address  as virtrdf:authors_address;
       	syb:city authors_tbl.city as virtrdf:authors_city;
       	syb:state authors_tbl.state  as virtrdf:authors_state;
       	syb:country authors_tbl.country as virtrdf:authors_country;
       	syb:postalcode authors_tbl.postalcode as virtrdf:authors_postalcode;
      	syb:has_title syb:titleauthor_iri(titleauthor_tbl.au_id, titleauthor_tbl.title_id) where (^{titleauthor_tbl.}^.au_id = ^{authors_tbl.}^.au_id) as virtrdf:authors_has_title;
      	syb:has_pix syb:au_pix_iri(au_pix_tbl.au_id) where (^{au_pix_tbl.}^.au_id = ^{authors_tbl.}^.au_id) as virtrdf:authors_has_pix .

	syb:discounts_iri (discounts_tbl.stor_id) a syb:discounts as virtrdf:discounts_pk;
	syb:discounttype discounts_tbl.discounttype as virtrdf:discounts_discounttype;
	syb:stor_id syb:stores_iri(stores_tbl.stor_id) where (^{stores_tbl.}^.stor_id = ^{stores_tbl.}^.stor_id) as virtrdf:discounts_stor_id;
	syb:lowqty discounts_tbl.lowqty as virtrdf:discounts_lowqty;
	syb:highqty discounts_tbl.highqty as virtrdf:discounts_highqty;
	syb:discount discounts_tbl.discount as virtrdf:discounts_discount .

	syb:publishers_iri (publishers_tbl.pub_id) a syb:publishers as virtrdf:publishers_pk;
	syb:pub_id syb:titles_iri(titles_tbl.title_id, titles_tbl.pub_id) where (^{titles_tbl.}^.pub_id = ^{titles_tbl.}^.pub_id) as virtrdf:publisherss_pub_id;
	syb:pub_name publishers_tbl.pub_name as virtrdf:publisherss_pub_name;
	syb:city publishers_tbl.city as virtrdf:publisherss_city;
	syb:state publishers_tbl.state as virtrdf:publisherss_state .

	syb:roysched_iri (roysched_tbl.title_id) a syb:roysched as virtrdf:roysched_pk;
       	syb:title_id syb:titleauthor_iri(titleauthor_tbl.au_id, titleauthor_tbl.title_id) where (^{titleauthor_tbl.}^.title_id = ^{roysched_tbl.}^.title_id) as virtrdf:roysched_title_id;
	syb:lorange roysched_tbl.lorange as virtrdf:roysched_lorange;
	syb:hirange roysched_tbl.hirange as virtrdf:roysched_hirange;
	syb:royalty roysched_tbl.royalty as virtrdf:roysched_royalty .

	syb:sales_iri (sales_tbl.stor_id, sales_tbl.ord_num) a syb:sales as virtrdf:sales_pk;
	syb:stor_id sales_tbl.stor_id as virtrdf:sales_stor_id;
	syb:ord_num sales_tbl.ord_num as virtrdf:sales_ord_num;
	syb:date sales_tbl.date as virtrdf:sales_date;
       	syb:has_salesdetail syb:salesdetail_iri(salesdetail_tbl.stor_id, salesdetail_tbl.ord_num, salesdetail_tbl.title_id) where (^{salesdetail_tbl.}^.stor_id = ^{sales_tbl.}^.stor_id and ^{salesdetail_tbl.}^.ord_num = ^{sales_tbl.}^.ord_num)  as virtrdf:sales_has_salesdetail;
       	syb:has_stores syb:stores_iri(stores_tbl.stor_id) where (^{stores_tbl.}^.stor_id = ^{sales_tbl.}^.stor_id)  as virtrdf:sales_has_stores .

	syb:salesdetail_iri (salesdetail_tbl.stor_id, salesdetail_tbl.ord_num, salesdetail_tbl.title_id) a syb:salesdetail as virtrdf:salesdetail_pk;
	syb:stor_id salesdetail_tbl.stor_id as virtrdf:salesdetail_stor_id;
	syb:ord_num salesdetail_tbl.ord_num as virtrdf:salesdetail_ord_num;
	syb:title_id salesdetail_tbl.title_id as virtrdf:salesdetail_title_id;
	syb:qty salesdetail_tbl.qty as virtrdf:salesdeail_qty;
	syb:discount salesdetail_tbl.discount as virtrdf:salesdetail_discount;
	syb:has_title  syb:titles_iri (titles_tbl.title_id, titles_tbl.pub_id) where (^{titles_tbl.}^.title_id = ^{salesdetail_tbl.}^.title_id) as virtrdf:salesdetail_has_title;
       	syb:has_sales syb:sales_iri(sales_tbl.stor_id, sales_tbl.ord_num) where (^{salesdetail_tbl.}^.stor_id = ^{sales_tbl.}^.stor_id and ^{salesdetail_tbl.}^.ord_num = ^{sales_tbl.}^.ord_num ) as virtrdf:salesdetail_has_sales .

	syb:stores_iri (stores_tbl.stor_id) a syb:stores as virtrdf:stores_pk;
       	syb:stor_id stores_tbl.stor_id as virtrdf:stores_stor_id;
	syb:stor_name stores_tbl.stor_name as virtrdf:stores_stor_name;
	syb:stor_address stores_tbl.stor_address as virtrdf:stores_stor_address;
	syb:city stores_tbl.city as virtrdf:stores_city;
	syb:state stores_tbl.state as virtrdf:stores_state;
	syb:country stores_tbl.country as virtrdf:stores_country;
	syb:postalcode stores_tbl.postalcode as virtrdf:stores_postalcode;
	syb:payterms stores_tbl.payterms as virtrdf:stores_payterms;
       	syb:has_sales syb:sales_iri(sales_tbl.stor_id, sales_tbl.ord_num) where (^{sales_tbl.}^.stor_id = ^{stores_tbl.}^.stor_id) as virtrdf:stores_has_sales .

	syb:titleauthor_iri (titleauthor_tbl.au_id, titleauthor_tbl.title_id) a syb:titleauthor as virtrdf:titleauthor_pk;
	syb:au_id titleauthor_tbl.au_id as virtrdf:titleauthor_au_id;
	syb:title_id titleauthor_tbl.title_id as virtrdf:titleauthor_title_id;
	syb:au_ord titleauthor_tbl.au_ord as virtrdf:titleauthor_au_ord;
	syb:royaltyper titleauthor_tbl.royaltyper as virtrdf:titleauthor_royaltyper;
	syb:has_author syb:authors_iri(authors_tbl.au_id) where (^{authors_tbl.}^.au_id = ^{titleauthor_tbl.}^.au_id) as virtrdf:titleauthor_has_author;
	syb:has_titles syb:titles_iri(titles_tbl.title_id, titles_tbl.pub_id) where (^{titles_tbl.}^.title_id = ^{titleauthor_tbl.}^.title_id) as virtrdf:titleauthor_has_titles .

	syb:titles_iri (titles_tbl.title_id, titles_tbl.pub_id) a syb:titles as virtrdf:titles_pk;
	syb:title_id titles_tbl.title_id as virtrdf:titles_title_idd;
	syb:title titles_tbl.title as virtrdf:titles_title;
	syb:type titles_tbl.type as virtrdf:titles_type;
	syb:pub_id titles_tbl.pub_id as virtrdf:titles_pub_id;
	syb:price titles_tbl.price as virtrdf:titles_price;
	syb:advance titles_tbl.advance as virtrdf:titles_advance;
	syb:total_sales titles_tbl.total_sales as virtrdf:titles_total_sales;
	syb:notes titles_tbl.notes as virtrdf:titles_notes;
	syb:pubdate titles_tbl.pubdate as virtrdf:titles_pubdate;
	syb:contract titles_tbl.contract as virtrdf:titles_contract;
       	syb:has_titleauthor syb:titleauthor_iri(titleauthor_tbl.au_id, titleauthor_tbl.title_id) where (^{titleauthor_tbl.}^.title_id = ^{titles_tbl.}^.title_id) as virtrdf:titles_has_titleauthor;
       	syb:has_salesdetail syb:salesdetail_iri (salesdetail_tbl.stor_id, salesdetail_tbl.ord_num, salesdetail_tbl.title_id) where (^{salesdetail_tbl.}^.title_id = ^{titles_tbl.}^.title_id) as virtrdf:titles_has_salesdetail .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'sybasepubs2_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'sybasepubs2_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'sybasepubs2_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'sybasepubs2_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/sybasepubs2%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'sybasepubs2_rule_list1',
    1,
    vector (
  	 	'sybasepubs2_rule1',
  	 	'sybasepubs2_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/sybasepubs2');

VHOST_DEFINE (
	lpath=>'/sybasepubs2',
	ppath=>'/DAV/sybasepubs2/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'sybasepubs2_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'sybase_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'sybase_schemas_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'sybase_schemas_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'sybase_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/sybasepubs2%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'sybase_schemas_rule_list1',
    1,
    vector (
  	 	'sybase_schemas_rule1',
  	 	'sybase_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/sybasepubs2');

VHOST_DEFINE (
	lpath=>'/schemas/sybasepubs2',
	ppath=>'/DAV/schemas/sybasepubs2/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'sybase_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('hr', 'http://^{URIQADefaultHost}^/schemas/sybasepubs2', 2);
]]></programlisting>
  </sect2>
  <sect2 id="rdfviewsenterprtn">
      <title>Virtuoso's Northwind based Demo Database (Tutorials variant) to RDF </title>
<programlisting><![CDATA[
use DB;

DB.DBA.exec_no_error('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/CAT%\'')
;

DB.DBA.exec_no_error('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/EMP%\'')
;

GRANT SELECT ON "Demo"."demo"."Products" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Suppliers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Shippers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Categories" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Customers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Employees" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Orders" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Order_Details" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Countries" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Provinces" TO "SPARQL";

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
drop quad map graph iri("http://^{URIQADefaultHost}^/tutorial/Northwind") .
;

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
drop quad map virtrdf:TutorialNorthwindDemo .
;

create function DB.DBA.TUT_NORTHWIND_ID_TO_IRI(in _prefix varchar,in _id varchar)
{
  declare iri, uriqa_host any;
  uriqa_host := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  iri := 'http://' || uriqa_host || '/tutorial/Northwind/' || _prefix || '/' || _id || '#this';
  return sprintf ('http://%s/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/All/iid%%20(%d).rdf', uriqa_host, iri_id_num (iri_to_id (iri)));
}
;

create function DB.DBA.TUT_NORTHWIND_IRI_TO_ID(in _iri varchar)
{
    declare parts any;
    parts := sprintf_inverse (_iri, 'http://%s/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/All/iid (%d).rdf', 1 );
    if (parts is not null)
    {
        declare uriqa_host, iri any;
        uriqa_host := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
        if (parts[0] = uriqa_host)
        {
            iri := id_to_iri(iri_id_from_num(parts[1]));
            parts := sprintf_inverse (iri, 'http://%s/tutorial/Northwind/%s/%s#this', 1 );
            if (parts[0] = uriqa_host)
            {
                return parts[2];
            }
        }
    }
    return NULL;
}
;

create function DB.DBA.TUT_CATEGORY_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Category', cast(_id as varchar));
}
;

create function DB.DBA.TUT_CATEGORY_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_SHIPPER_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Shipper', cast(_id as varchar));
}
;

create function DB.DBA.TUT_SHIPPER_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_SUPPLIER_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Supplier', cast(_id as varchar));
}
;

create function DB.DBA.TUT_SUPPLIER_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_PRODUCT_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Product', cast(_id as varchar));
}
;

create function DB.DBA.TUT_PRODUCT_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_CUSTOMER_IRI (in _id varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Customer', _id);
}
;

create function DB.DBA.TUT_CUSTOMER_IRI_INVERSE (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_EMPLOYEE_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Employee', cast(_id as varchar));
}
;

create function DB.DBA.TUT_EMPLOYEE_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_ORDER_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Order', cast(_id as varchar));
}
;

create function DB.DBA.TUT_ORDER_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_CUSTOMERCONTACT_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('CustomerContact', cast(_id as varchar));
}
;

create function DB.DBA.TUT_CUSTOMERCONTACT_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_ORDERLINE_IRI (in _id1 integer, in _id2 integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('OrderLine', sprintf('%d/%d', _id1, _id2));
}
;

create function DB.DBA.TUT_ORDERLINE_IRI_INV_1 (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_ORDERLINE_IRI_INV_2 (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};


create function DB.DBA.TUT_PROVINCE_IRI (in _id1 varchar, in _id2 varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Province', sprintf('%s/%s', _id1, _id2));
}
;

create function DB.DBA.TUT_PROVINCE_IRI_INV_1 (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_PROVINCE_IRI_INV_2 (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_COUNTRY_IRI (in _id varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Country', _id);
}
;

create function DB.DBA.TUT_COUNTRY_IRI_INVERSE (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_FLAG_IRI (in _id varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Flag', _id);
}
;

create function DB.DBA.TUT_FLAG_IRI_INVERSE (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_EMPLOYEEPHOTO_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('EmployeePhoto', cast(_id as varchar));
}
;

create function DB.DBA.TUT_EMPLOYEEPHOTO_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_CATEGORYPHOTO_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('CategoryPhoto', cast(_id as varchar));
}
;

create function DB.DBA.TUT_CATEGORYPHOTO_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

grant execute on DB.DBA.TUT_CATEGORY_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CATEGORY_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_SHIPPER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_SHIPPER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_SUPPLIER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_SUPPLIER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_PRODUCT_IRI to "SPARQL";
grant execute on DB.DBA.TUT_PRODUCT_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEE_IRI to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEE_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_ORDER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_ORDER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMERCONTACT_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMERCONTACT_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_ORDERLINE_IRI to "SPARQL";
grant execute on DB.DBA.TUT_ORDERLINE_IRI_INV_1 to "SPARQL";
grant execute on DB.DBA.TUT_ORDERLINE_IRI_INV_2 to "SPARQL";
grant execute on DB.DBA.TUT_PROVINCE_IRI to "SPARQL";
grant execute on DB.DBA.TUT_PROVINCE_IRI_INV_1 to "SPARQL";
grant execute on DB.DBA.TUT_PROVINCE_IRI_INV_2 to "SPARQL";
grant execute on DB.DBA.TUT_COUNTRY_IRI to "SPARQL";
grant execute on DB.DBA.TUT_COUNTRY_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_FLAG_IRI to "SPARQL";
grant execute on DB.DBA.TUT_FLAG_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEEPHOTO_IRI to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEEPHOTO_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_CATEGORYPHOTO_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CATEGORYPHOTO_IRI_INVERSE to "SPARQL";

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
create iri class tut_northwind:Category "http://^{URIQADefaultHost}^/tutorial/Northwind/Category/%d#this" (in category_id integer not null) .
create iri class tut_northwind:Shipper "http://^{URIQADefaultHost}^/tutorial/Northwind/Shipper/%d#this" (in shipper_id integer not null) .
create iri class tut_northwind:Supplier "http://^{URIQADefaultHost}^/tutorial/Northwind/Supplier/%d#this" (in supplier_id integer not null) .
create iri class tut_northwind:Product   "http://^{URIQADefaultHost}^/tutorial/Northwind/Product/%d#this" (in product_id integer not null) .
create iri class tut_northwind:Customer "http://^{URIQADefaultHost}^/tutorial/Northwind/Customer/%U#this" (in customer_id varchar not null) .
create iri class tut_northwind:Employee "http://^{URIQADefaultHost}^/tutorial/Northwind/Employee/%U%U%d#this" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class tut_northwind:Order "http://^{URIQADefaultHost}^/tutorial/Northwind/Order/%d#this" (in order_id integer not null) .
create iri class tut_northwind:CustomerContact "http://^{URIQADefaultHost}^/tutorial/Northwind/CustomerContact/%U#this" (in customer_id varchar not null) .
create iri class tut_northwind:OrderLine "http://^{URIQADefaultHost}^/tutorial/Northwind/OrderLine/%d/%d#this" (in order_id integer not null, in product_id integer not null) .
create iri class tut_northwind:Province "http://^{URIQADefaultHost}^/tutorial/Northwind/Province/%U/%U#this" (in country_name varchar not null, in province_name varchar not null) .
create iri class tut_northwind:Country "http://^{URIQADefaultHost}^/tutorial/Northwind/Country/%U#this" (in country_name varchar not null) .
create iri class tut_northwind:Flag "http://^{URIQADefaultHost}^%U#this" (in flag_path varchar not null) .
create iri class tut_northwind:dbpedia_iri "http://dbpedia.org/resource/%U" (in uname varchar not null) .
create iri class tut_northwind:EmployeePhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/EMP%d#this" (in emp_id varchar not null) .
create iri class tut_northwind:CategoryPhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/CAT%d#this" (in category_id varchar not null) .
;

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
create iri class tut_northwind:customercontact_iri using
    function DB.DBA.TUT_CUSTOMERCONTACT_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_CUSTOMERCONTACT_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:category_iri using
    function DB.DBA.TUT_CATEGORY_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_CATEGORY_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:shipper_iri using
    function DB.DBA.TUT_SHIPPER_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_SHIPPER_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:supplier_iri using
    function DB.DBA.TUT_SUPPLIER_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_SUPPLIER_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:product_iri using
    function DB.DBA.TUT_PRODUCT_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_PRODUCT_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:customer_iri using
    function DB.DBA.TUT_CUSTOMER_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_CUSTOMER_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:employee_iri using
    function DB.DBA.TUT_EMPLOYEE_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_EMPLOYEE_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:order_iri using
    function DB.DBA.TUT_ORDER_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_ORDER_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:orderline_iri using
    function DB.DBA.TUT_ORDERLINE_IRI (in customer_id integer, in customer_id2 integer) returns varchar,
    function DB.DBA.TUT_ORDERLINE_IRI_INV_1 (in customer_iri varchar) returns integer,
    function DB.DBA.TUT_ORDERLINE_IRI_INV_2 (in customer_iri varchar) returns integer.
create iri class tut_northwind:province_iri using
    function DB.DBA.TUT_PROVINCE_IRI (in customer_id varchar, in customer_id2 varchar) returns varchar,
    function DB.DBA.TUT_PROVINCE_IRI_INV_1 (in customer_iri varchar) returns varchar,
    function DB.DBA.TUT_PROVINCE_IRI_INV_2 (in customer_iri varchar) returns varchar.
create iri class tut_northwind:country_iri using
    function DB.DBA.TUT_COUNTRY_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_COUNTRY_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:employeephoto_iri using
    function DB.DBA.TUT_EMPLOYEEPHOTO_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_EMPLOYEEPHOTO_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:categoryphoto_iri using
    function DB.DBA.TUT_CATEGORYPHOTO_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_CATEGORYPHOTO_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:flag_iri using
    function DB.DBA.TUT_FLAG_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_FLAG_IRI_INVERSE (in customer_iri varchar) returns varchar.
;

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
alter quad storage virtrdf:DefaultQuadStorage
from Demo.demo.Products as products
from Demo.demo.Suppliers as suppliers
from Demo.demo.Shippers as shippers
from Demo.demo.Categories as categories
from Demo.demo.Customers as customers
from Demo.demo.Employees as employees
from Demo.demo.Orders as orders
from Demo.demo.Order_Details as order_lines
from Demo.demo.Countries as countries
from Demo.demo.Provinces as provinces
where (^{suppliers.}^.Country = ^{countries.}^.Name)
where (^{customers.}^.Country = ^{countries.}^.Name)
where (^{employees.}^.Country = ^{countries.}^.Name)
where (^{orders.}^.ShipCountry = ^{countries.}^.Name)
{
        create virtrdf:TutorialNorthwindDemo as graph iri ("http://^{URIQADefaultHost}^/tutorial/Northwind") option (exclusive)
        {
                tut_northwind:CustomerContact (customers.CustomerID)
                        a foaf:Person
                                as virtrdf:tutCustomerContact-foaf_Person .

                tut_northwind:CustomerContact (customers.CustomerID)
                        a tut_northwind:CustomerContact
                                as virtrdf:tutCustomerContact-CustomerContact;
                        foaf:name customers.ContactName
                                as virtrdf:tutCustomerContact-contact_name ;
                        foaf:phone customers.Phone
                                as virtrdf:tutCustomerContact-foaf_phone ;
                        tut_northwind:is_contact_at tut_northwind:Customer (customers.CustomerID)
                                as virtrdf:tutCustomerContact-is_contact_at ;
                        tut_northwind:country tut_northwind:Country (customers.Country)
                                as virtrdf:tutCustomerContact-country ;
                        rdfs:isDefinedBy tut_northwind:customercontact_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy tut_northwind:CustomerContact (customers.CustomerID) .

                tut_northwind:Country (customers.Country)
                        tut_northwind:is_country_of
                tut_northwind:CustomerContact (customers.CustomerID) as virtrdf:tutCustomerContact-is_country_of .

                tut_northwind:Product (products.ProductID)
                        a tut_northwind:Product
                                as virtrdf:tutProduct-ProductID ;
                        tut_northwind:has_category tut_northwind:Category (products.CategoryID)
                                as virtrdf:tutProduct-product_has_category ;
                        tut_northwind:has_supplier tut_northwind:Supplier (products.SupplierID)
                                as virtrdf:tutProduct-product_has_supplier ;
                        tut_northwind:productName products.ProductName
                                as virtrdf:tutProduct-name_of_product ;
                        tut_northwind:quantityPerUnit products.QuantityPerUnit
                                as virtrdf:tutProduct-quantity_per_unit ;
                        tut_northwind:unitPrice products.UnitPrice
                                as virtrdf:tutProduct-unit_price ;
                        tut_northwind:unitsInStock products.UnitsInStock
                                as virtrdf:tutProduct-units_in_stock ;
                        tut_northwind:unitsOnOrder products.UnitsOnOrder
                                as virtrdf:tutProduct-units_on_order ;
                        tut_northwind:reorderLevel products.ReorderLevel
                                as virtrdf:tutProduct-reorder_level ;
                        tut_northwind:discontinued products.Discontinued
                                as virtrdf:tutProduct-discontinued ;
                        rdfs:isDefinedBy tut_northwind:product_iri (products.ProductID) ;
                        rdfs:isDefinedBy tut_northwind:Product (products.ProductID).

                tut_northwind:Category (products.CategoryID)
                        tut_northwind:category_of tut_northwind:Product (products.ProductID) as virtrdf:tutProduct-category_of .

                tut_northwind:Supplier (products.SupplierID)
                        tut_northwind:supplier_of tut_northwind:Product (products.ProductID) as virtrdf:tutProduct-supplier_of .

                tut_northwind:Supplier (suppliers.SupplierID)
                        a tut_northwind:Supplier
                                as virtrdf:tutSupplier-SupplierID ;
                        tut_northwind:companyName suppliers.CompanyName
                                as virtrdf:tutSupplier-company_name ;
                        tut_northwind:contactName suppliers.ContactName
                                as virtrdf:tutSupplier-contact_name ;
                        tut_northwind:contactTitle suppliers.ContactTitle
                                as virtrdf:tutSupplier-contact_title ;
                        tut_northwind:address suppliers.Address
                                as virtrdf:tutSupplier-address ;
                        tut_northwind:city suppliers.City
                                as virtrdf:tutSupplier-city ;
                        tut_northwind:dbpedia_city tut_northwind:dbpedia_iri(suppliers.City)
                                as virtrdf:tutSupplier-dbpedia_city ;
                        tut_northwind:region suppliers.Region
                                as virtrdf:tutSupplier-region ;
                        tut_northwind:postalCode suppliers.PostalCode
                                as virtrdf:tutSupplier-postal_code ;
                        tut_northwind:country tut_northwind:Country(suppliers.Country)
                                as virtrdf:tutSupplier-country ;
                        tut_northwind:phone suppliers.Phone
                                as virtrdf:tutSupplier-phone ;
                        tut_northwind:fax suppliers.Fax
                                as virtrdf:tutSupplier-fax ;
                        tut_northwind:homePage suppliers.HomePage
                                as virtrdf:tutSupplier-home_page ;
                        rdfs:isDefinedBy tut_northwind:supplier_iri (suppliers.SupplierID) ;
                        rdfs:isDefinedBy tut_northwind:Supplier (suppliers.SupplierID).

                tut_northwind:Country (suppliers.Country)
                        tut_northwind:is_country_of
                tut_northwind:Supplier (suppliers.SupplierID) as virtrdf:tutSupplier-is_country_of .

                tut_northwind:Category (categories.CategoryID)
                        a tut_northwind:Category
                                as virtrdf:tutCategory-CategoryID ;
                        tut_northwind:categoryName categories.CategoryName
                                as virtrdf:tutCategory-home_page ;
                        tut_northwind:description categories.Description
                                as virtrdf:tutCategory-description ;
                        foaf:img tut_northwind:CategoryPhoto(categories.CategoryID)
                                as virtrdf:tutCategory-categories.CategoryPhoto ;
                        rdfs:isDefinedBy tut_northwind:category_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy tut_northwind:Category (categories.CategoryID).

                tut_northwind:CategoryPhoto(categories.CategoryID)
                        a tut_northwind:CategoryPhoto
                                as virtrdf:tutCategory-categories.CategoryPhotoID ;
                        rdfs:isDefinedBy tut_northwind:categoryphoto_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy tut_northwind:CategoryPhoto(categories.CategoryID).

                tut_northwind:Shipper (shippers.ShipperID)
                        a tut_northwind:Shipper
                                as virtrdf:tutShipper-ShipperID ;
                        tut_northwind:companyName shippers.CompanyName
                                as virtrdf:tutShipper-company_name ;
                        tut_northwind:phone shippers.Phone
                                as virtrdf:tutShipper-phone ;
                        rdfs:isDefinedBy tut_northwind:shipper_iri (shippers.ShipperID) ;
                        rdfs:isDefinedBy tut_northwind:Shipper (shippers.ShipperID).

                tut_northwind:Customer (customers.CustomerID)
                        a  tut_northwind:Customer
                                as virtrdf:tutCustomer-CustomerID2 ;
                        a  foaf:Organization
                                as virtrdf:tutCustomer-CustomerID ;
                        foaf:name customers.CompanyName
                                as virtrdf:tutCustomer-foaf_name ;
                        tut_northwind:companyName customers.CompanyName
                                as virtrdf:tutCustomer-company_name ;
                        tut_northwind:has_contact tut_northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:tutCustomer-contact ;
                        tut_northwind:country tut_northwind:Country (customers.Country)
                                as virtrdf:tutCustomer-country ;
                        tut_northwind:contactName customers.ContactName
                                as virtrdf:tutCustomer-contact_name ;
                        tut_northwind:contactTitle customers.ContactTitle
                                as virtrdf:tutCustomer-contact_title ;
                        tut_northwind:address customers.Address
                                as virtrdf:tutCustomer-address ;
                        tut_northwind:city customers.City
                                as virtrdf:tutCustomer-city ;
                        tut_northwind:dbpedia_city tut_northwind:dbpedia_iri(customers.City)
                                as virtrdf:tutCustomer-dbpedia_city ;
                        tut_northwind:region customers.Region
                                as virtrdf:tutCustomer-region ;
                        tut_northwind:PostalCode customers.PostalCode
                                as virtrdf:tutCustomer-postal_code ;
                        foaf:phone customers.Phone
                                as virtrdf:tutCustomer-foaf_phone ;
                        tut_northwind:phone customers.Phone
                                as virtrdf:tutCustomer-phone ;
                        tut_northwind:fax customers.Fax
                                as virtrdf:tutCustomer-fax ;
                        rdfs:isDefinedBy tut_northwind:customer_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy tut_northwind:Customer (customers.CustomerID).

                tut_northwind:Country (customers.Country)
                        tut_northwind:is_country_of
                tut_northwind:Customer (customers.CustomerID) as virtrdf:tutCustomer-is_country_of .

                tut_northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a tut_northwind:Employee
                                as virtrdf:tutEmployee-EmployeeID2 ;
                        a foaf:Person
                                as virtrdf:tutEmployee-EmployeeID ;
                        foaf:surname employees.LastName
                                as virtrdf:tutEmployee-foaf_last_name ;
                        tut_northwind:lastName employees.LastName
                                as virtrdf:tutEmployee-last_name ;
                        foaf:firstName employees.FirstName
                                as virtrdf:tutEmployee-foaf_first_name ;
                        tut_northwind:firstName employees.FirstName
                                as virtrdf:tutEmployee-first_name ;
                        foaf:title employees.Title
                                as virtrdf:tutEmployee-title ;
                        tut_northwind:titleOfCourtesy employees.TitleOfCourtesy
                                as virtrdf:tutEmployee-title_of_courtesy ;
                        foaf:birthday employees.BirthDate
                                as virtrdf:tutEmployee-foaf_birth_date ;
                        tut_northwind:birthday employees.BirthDate
                                as virtrdf:tutEmployee-birth_date ;
                        tut_northwind:hireDate employees.HireDate
                                as virtrdf:tutEmployee-hire_date ;
                        tut_northwind:address employees.Address
                                as virtrdf:tutEmployee-address ;
                        tut_northwind:city employees.City
                                as virtrdf:tutEmployee-city ;
                        tut_northwind:dbpedia_city tut_northwind:dbpedia_iri(employees.City)
                                as virtrdf:tutEmployee-dbpedia_city ;
                        tut_northwind:region employees.Region
                                as virtrdf:tutEmployee-region ;
                        tut_northwind:postalCode employees.PostalCode
                                as virtrdf:tutEmployee-postal_code ;
                        tut_northwind:country tut_northwind:Country (employees.Country)
                                as virtrdf:tutEmployee-country ;
                        foaf:phone employees.HomePhone
                                as virtrdf:tutEmployee-home_phone ;
                        tut_northwind:extension employees.Extension
                                as virtrdf:tutEmployee-extension ;
                        tut_northwind:notes employees.Notes
                                as virtrdf:tutEmployee-notes ;
                        tut_northwind:reportsTo tut_northwind:Employee(employees.FirstName, employees.LastName, employees.ReportsTo) where (^{employees.}^.ReportsTo = ^{employees.}^.EmployeeID)
                                as virtrdf:tutEmployee-reports_to ;
                        foaf:img tut_northwind:EmployeePhoto(employees.EmployeeID)
                                as virtrdf:tutEmployee-employees.EmployeePhoto ;
                        rdfs:isDefinedBy tut_northwind:employee_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy tut_northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID).

                tut_northwind:EmployeePhoto(employees.EmployeeID)
                        a tut_northwind:EmployeePhoto
                                as virtrdf:tut_Employee-employees.EmployeePhotoId ;
                        rdfs:isDefinedBy tut_northwind:employeephoto_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy tut_northwind:EmployeePhoto (employees.EmployeeID).

                tut_northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID)
                        tut_northwind:is_salesrep_of
                tut_northwind:Order (orders.OrderID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID) as virtrdf:tutOrder-is_salesrep_of .

                tut_northwind:Country (employees.Country)
                        tut_northwind:is_country_of
                tut_northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) as virtrdf:tutEmployee-is_country_of .

                tut_northwind:Order (orders.OrderID)
                        a tut_northwind:Order
                                as virtrdf:tutOrder-Order ;
                        tut_northwind:has_customer tut_northwind:Customer (orders.CustomerID)
                                as virtrdf:tutOrder-order_has_customer ;
                        tut_northwind:has_salesrep tut_northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:tutCustomer-has_salesrep ;
                        tut_northwind:has_employee tut_northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:tutOrder-order_has_employee ;
                        tut_northwind:orderDate orders.OrderDate
                                as virtrdf:tutOrder-order_date ;
                        tut_northwind:requiredDate orders.RequiredDate
                                as virtrdf:tutOrder-required_date ;
                        tut_northwind:shippedDate orders.ShippedDate
                                as virtrdf:tutOrder-shipped_date ;
                        tut_northwind:order_ship_via tut_northwind:Shipper (orders.ShipVia)
                                as virtrdf:tutOrder-order_ship_via ;
                        tut_northwind:freight orders.Freight
                                as virtrdf:tutOrder-freight ;
                        tut_northwind:shipName orders.ShipName
                                as virtrdf:tutOrder-ship_name ;
                        tut_northwind:shipAddress orders.ShipAddress
                                as virtrdf:tutOrder-ship_address ;
                        tut_northwind:shipCity orders.ShipCity
                                as virtrdf:tutOrder-ship_city ;
                        tut_northwind:dbpedia_shipCity tut_northwind:dbpedia_iri(orders.ShipCity)
                                as virtrdf:tutOrder-ship_dbpedia_city ;
                        tut_northwind:shipRegion orders.ShipRegion
                                as virtrdf:tutOrder-ship_region ;
                        tut_northwind:shipPostal_code orders.ShipPostalCode
                                as virtrdf:tutOrder-ship_postal_code ;
                        tut_northwind:shipCountry tut_northwind:Country(orders.ShipCountry)
                                as virtrdf:tutship_country ;
                        rdfs:isDefinedBy tut_northwind:order_iri (orders.OrderID) ;
                        rdfs:isDefinedBy tut_northwind:Order (orders.OrderID).

                tut_northwind:Country (orders.ShipCountry)
                        tut_northwind:is_ship_country_of
                tut_northwind:Order (orders.OrderID) as virtrdf:tutOrder-is_country_of .

                tut_northwind:Customer (orders.CustomerID)
                        tut_northwind:has_order tut_northwind:Order (orders.OrderID) as virtrdf:tutOrder-has_order .

                tut_northwind:Shipper (orders.ShipVia)
                        tut_northwind:ship_order tut_northwind:Order (orders.OrderID) as virtrdf:tutOrder-ship_order .

                tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                        a tut_northwind:OrderLine
                                as virtrdf:tutOrderLine-OrderLines ;
                        tut_northwind:has_order_id tut_northwind:Order (order_lines.OrderID)
                                as virtrdf:tutorder_lines_has_order_id ;
                        tut_northwind:has_product_id tut_northwind:Product (order_lines.ProductID)
                                as virtrdf:tutorder_lines_has_product_id ;
                        tut_northwind:unitPrice order_lines.UnitPrice
                                as virtrdf:tutOrderLine-unit_price ;
                        tut_northwind:quantity order_lines.Quantity
                                as virtrdf:tutOrderLine-quantity ;
                        tut_northwind:discount order_lines.Discount
                                as virtrdf:tutOrderLine-discount ;
                        rdfs:isDefinedBy tut_northwind:orderline_iri (order_lines.OrderID, order_lines.ProductID) ;
                        rdfs:isDefinedBy tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID).

                tut_northwind:Order (orders.OrderID)
                        tut_northwind:is_order_of
                tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{orders.}^.OrderID = ^{order_lines.}^.OrderID) as virtrdf:tutOrder-is_order_of .

                tut_northwind:Product (products.ProductID)
                        tut_northwind:is_product_of
                tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{products.}^.ProductID = ^{order_lines.}^.ProductID) as virtrdf:tutProduct-is_product_of .

                tut_northwind:Country (countries.Name)
                        a tut_northwind:Country
                                as virtrdf:tutCountry-Type2 ;
                        a wgs:SpatialThing
                                as virtrdf:tutCountry-Type ;
                        owl:sameAs tut_northwind:dbpedia_iri (countries.Name) ;
                        tut_northwind:name countries.Name
                                as virtrdf:tutCountry-Name ;
                        tut_northwind:code countries.Code
                                as virtrdf:tutCountry-Code ;
                        tut_northwind:smallFlagDAVResourceName countries.SmallFlagDAVResourceName
                                as virtrdf:tutCountry-SmallFlagDAVResourceName ;
                        tut_northwind:largeFlagDAVResourceName countries.LargeFlagDAVResourceName
                                as virtrdf:tutCountry-LargeFlagDAVResourceName ;
                        tut_northwind:smallFlagDAVResourceURI tut_northwind:Flag(countries.SmallFlagDAVResourceURI)
                                as virtrdf:tutCountry-SmallFlagDAVResourceURI ;
                        tut_northwind:largeFlagDAVResourceURI tut_northwind:Flag(countries.LargeFlagDAVResourceURI)
                                as virtrdf:tutCountry-LargeFlagDAVResourceURI ;
                        wgs:lat countries.Lat
                                as virtrdf:tutCountry-Lat ;
                        wgs:long countries.Lng
                                as virtrdf:tutCountry-Lng ;
                        rdfs:isDefinedBy tut_northwind:country_iri (countries.Name) ;
                        rdfs:isDefinedBy tut_northwind:Country (countries.Name).

                tut_northwind:Country (countries.Name)
                        tut_northwind:has_province
                tut_northwind:Province (provinces.CountryCode, provinces.Province) where (^{provinces.}^.CountryCode = ^{countries.}^.Code) as virtrdf:tutCountry-has_province .

                tut_northwind:Province (provinces.CountryCode, provinces.Province)
                        a tut_northwind:Province
                                as virtrdf:tutProvince-Provinces ;
                        tut_northwind:has_country_code provinces.CountryCode
                                as virtrdf:tuthas_country_code ;
                        tut_northwind:provinceName provinces.Province
                                as virtrdf:tutProvince-ProvinceName ;
                        rdfs:isDefinedBy tut_northwind:province_iri (provinces.CountryCode, provinces.Province) ;
                        rdfs:isDefinedBy tut_northwind:Province (provinces.CountryCode, provinces.Province).

                tut_northwind:Province (provinces.CountryCode, provinces.Province)
                        tut_northwind:is_province_of
                tut_northwind:Country (countries.Name) where  (^{countries.}^.Code = ^{provinces.}^.CountryCode) as virtrdf:tutProvince-country_of .
        } .
} .
;

DELETE FROM db.dba.url_rewrite_rule_list where urrl_list like 'tut_nw%';
DELETE FROM db.dba.url_rewrite_rule where urr_rule like 'tut_nw%';

create procedure DB.DBA.install_run ()
{
        declare file_text, uriqa varchar;
        uriqa := registry_get('URIQADefaultHost');
        file_text := (SELECT blob_to_string (RES_CONTENT) FROM WS.WS.SYS_DAV_RES where RES_FULL_PATH='/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.isparql');
        file_text := replace(file_text, 'URIQA_MACRO', concat('http://', uriqa, '/tutorial/Northwind'));
        update WS.WS.SYS_DAV_RES set RES_CONTENT=file_text where RES_FULL_PATH='/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.isparql';
}
;

DB.DBA.install_run()
;

drop procedure DB.DBA.install_run
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_nw_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/tutorial/Northwind%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_nw_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/rdfbrowser/index.html?uri=http%%3A//^{URIQADefaultHost}^%U%%23this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_nw_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%s',
    vector('path'),
    null,
    null,
    0,
    null
    );

create procedure DB.DBA.REMOVE_TUT_DEMO_RDF_DET()
{
  declare colid int;
  colid := DAV_SEARCH_ID('/DAV/VAD/tutorial/rdfview/rd_v_1/', 'C');
  if (colid < 0)
    return;
  update WS.WS.SYS_DAV_COL set COL_DET=null where COL_ID = colid;
}
;

DB.DBA.REMOVE_TUT_DEMO_RDF_DET();

drop procedure DB.DBA.REMOVE_TUT_DEMO_RDF_DET;

create procedure DB.DBA.TUT_NORTHWIND_MAKE_RDF_DET()
{
    declare uriqa_str varchar;
    uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
    uriqa_str := 'http://' || uriqa_str || '/tutorial/Northwind';
    DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/', uriqa_str, NULL);
    VHOST_REMOVE (lpath=>'/tutorial/Northwind/data/rdf');
    DB.DBA.VHOST_DEFINE (lpath=>'/tutorial/Northwind/data/rdf', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/All/', is_dav=>1, vsp_user=>'dba');
}
;

DB.DBA.TUT_NORTHWIND_MAKE_RDF_DET();

drop procedure DB.DBA.TUT_NORTHWIND_MAKE_RDF_DET;

-- procedure to convert path to DET resource name
create procedure DB.DBA.TUT_NORTHWIND_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  declare uriqa_str varchar;
  uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  uriqa_str := 'http://' || uriqa_str || '/tutorial/Northwind';
  iri := uriqa_str || val;
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tut_nw_rdf', 1,
    '/tutorial/Northwind/(.*)', vector('path'), 1,
    '/tutorial/Northwind/data/rdf/%U', vector('path'),
    'DB.DBA.TUT_NORTHWIND_DET_REF',
    'application/rdf.xml',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tut_nw_rule_list1',
    1,
    vector (
                'tut_nw_rule1',
                'tut_nw_rule2',
                'tut_nw_rule3',
                'tut_nw_rdf'
          ));


VHOST_REMOVE (lpath=>'/tutorial/Northwind');
DB.DBA.VHOST_DEFINE (lpath=>'/tutorial/Northwind', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/', vsp_user=>'dba', is_dav=>1, def_page=>'sfront.vspx',
          is_brws=>0, opts=>vector ('url_rewrite', 'tut_nw_rule_list1'));

create procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV()
{
  declare content, urihost varchar;
  whenever not found goto endpoint;
  SELECT cast (RES_CONTENT as varchar) into content FROM WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl';
  if (content is null or content = '')
    goto endpoint;
  DB.DBA.RDF_LOAD_RDFXML (content, 'http://demo.openlinksw.com/schemas/tutorial/northwind#', 'http://demo.openlinksw.com/schemas/TutorialNorthwindOntology/1.0/');
  if (urihost = 'demo.openlinksw.com')
  {
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial/northwind#');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial/northwind#', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial/northwind');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial/northwind', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
  }
  endpoint:
  ;
}
;

DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV()
;

drop procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV
;

create procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV2()
{
  declare urihost varchar;
  sparql base <http://demo.openlinksw.com/schemas/tutorial/northwind#> load bif:concat ("http://", bif:registry_get("URIQADefaultHost"), "/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl")
   into graph <http://demo.openlinksw.com/schemas/TutorialNorthwindOntology/1.0/>;
  urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  if (urihost = 'demo.openlinksw.com')
  {
    DB.DBA.VHOST_REMOVE (lpath=>'/tutorial/northwind#');
    DB.DBA.VHOST_DEFINE (lpath=>'/tutorial/northwind#', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
  }
}
;

--DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV2();

drop procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV2
;

DB.DBA.XML_SET_NS_DECL ('tut_northwind', 'http://demo.openlinksw.com/schemas/tutorial/northwind#', 2);
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterprsn">
      <title>SQL Server's Northwind Demo Database</title>
<programlisting><![CDATA[
use DB;

DB.DBA.exec_stmt ('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/CAT%\'', 0)
;

DB.DBA.exec_stmt ('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/EMP%\'', 0)
;

GRANT SELECT ON "Demo"."demo"."Products" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Suppliers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Shippers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Categories" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Customers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Employees" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Orders" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Order_Details" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Countries" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Provinces" TO "SPARQL";


SPARQL drop quad map graph iri("http://^{URIQADefaultHost}^/Northwind") .
;

SPARQL drop quad map virtrdf:NorthwindDemo .
;

SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>
drop iri class northwind:Category .
drop iri class northwind:CategoryDoc .
drop iri class northwind:Shipper .
drop iri class northwind:ShipperDoc .
drop iri class northwind:Supplier .
drop iri class northwind:SupplierDoc .
drop iri class northwind:Product .
drop iri class northwind:ProductDoc .
drop iri class northwind:Customer .
drop iri class northwind:CustomerDoc .
drop iri class northwind:Employee .
drop iri class northwind:EmployeeDoc .
drop iri class northwind:Order .
drop iri class northwind:OrderDoc .
drop iri class northwind:CustomerContact .
drop iri class northwind:CustomerContactDoc .
drop iri class northwind:OrderLine .
drop iri class northwind:OrderLineDoc .
drop iri class northwind:Province .
drop iri class northwind:ProvinceDoc .
drop iri class northwind:Country .
drop iri class northwind:CountryDoc .
drop iri class northwind:Flag .
drop iri class northwind:FlagDoc .
drop iri class northwind:dbpedia_iri2 .
drop iri class northwind:EmployeePhoto .
drop iri class northwind:CategoryPhoto .

drop iri class northwind:category_iri .
drop iri class northwind:categorydoc_iri .
drop iri class northwind:shipper_iri .
drop iri class northwind:shipperdoc_iri .
drop iri class northwind:supplier_iri .
drop iri class northwind:supplierdoc_iri .
drop iri class northwind:product_iri .
drop iri class northwind:productdoc_iri .
drop iri class northwind:customer_iri .
drop iri class northwind:customerdoc_iri .
drop iri class northwind:employee_iri .
drop iri class northwind:employeedoc_iri .
drop iri class northwind:order_iri .
drop iri class northwind:orderdoc_iri .
drop iri class northwind:customercontact_iri .
drop iri class northwind:customercontactdoc_iri .
drop iri class northwind:orderline_iri .
drop iri class northwind:orderlinedoc_iri .
drop iri class northwind:province_iri .
drop iri class northwind:provincedoc_iri .
drop iri class northwind:country_iri .
drop iri class northwind:countrydoc_iri .
drop iri class northwind:employeephoto_iri .
drop iri class northwind:categoryphoto_iri .
drop iri class northwind:flag_iri .
drop iri class northwind:flagdoc_iri .
;

SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>

create iri class northwind:Category "http://^{URIQADefaultHost}^/Northwind/Category/%d#this" (in category_id integer not null) .
create iri class northwind:CategoryDoc "http://^{URIQADefaultHost}^/Northwind/Category/%d" (in category_id integer not null) .
create iri class northwind:Shipper "http://^{URIQADefaultHost}^/Northwind/Shipper/%d#this" (in shipper_id integer not null) .
create iri class northwind:ShipperDoc "http://^{URIQADefaultHost}^/Northwind/Shipper/%d" (in shipper_id integer not null) .
create iri class northwind:Supplier "http://^{URIQADefaultHost}^/Northwind/Supplier/%d#this" (in supplier_id integer not null) .
create iri class northwind:SupplierDoc "http://^{URIQADefaultHost}^/Northwind/Supplier/%d" (in supplier_id integer not null) .
create iri class northwind:Product   "http://^{URIQADefaultHost}^/Northwind/Product/%d#this" (in product_id integer not null) .
create iri class northwind:ProductDoc   "http://^{URIQADefaultHost}^/Northwind/Product/%d" (in product_id integer not null) .
create iri class northwind:Customer "http://^{URIQADefaultHost}^/Northwind/Customer/%U#this" (in customer_id varchar not null) .
create iri class northwind:CustomerDoc "http://^{URIQADefaultHost}^/Northwind/Customer/%U" (in customer_id varchar not null) .
create iri class northwind:Employee "http://^{URIQADefaultHost}^/Northwind/Employee/%U_%U_%d#this" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class northwind:EmployeeDoc "http://^{URIQADefaultHost}^/Northwind/Employee/%U_%U_%d" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class northwind:Order "http://^{URIQADefaultHost}^/Northwind/Order/%d#this" (in order_id integer not null) .
create iri class northwind:OrderDoc "http://^{URIQADefaultHost}^/Northwind/Order/%d" (in order_id integer not null) .
create iri class northwind:CustomerContact "http://^{URIQADefaultHost}^/Northwind/CustomerContact/%U#this" (in customer_id varchar not null) .
create iri class northwind:CustomerContactDoc "http://^{URIQADefaultHost}^/Northwind/CustomerContact/%U" (in customer_id varchar not null) .
create iri class northwind:OrderLine "http://^{URIQADefaultHost}^/Northwind/OrderLine/%d/%d#this" (in order_id integer not null, in product_id integer not null) .
create iri class northwind:OrderLineDoc "http://^{URIQADefaultHost}^/Northwind/OrderLine/%d/%d" (in order_id integer not null, in product_id integer not null) .
create iri class northwind:Province "http://^{URIQADefaultHost}^/Northwind/Province/%U/%U#this" (in country_name varchar not null, in province_name varchar not null) .
create iri class northwind:ProvinceDoc "http://^{URIQADefaultHost}^/Northwind/Province/%U/%U" (in country_name varchar not null, in province_name varchar not null) .
create iri class northwind:Country "http://^{URIQADefaultHost}^/Northwind/Country/%U#this" (in country_name varchar not null) .
create iri class northwind:CountryDoc "http://^{URIQADefaultHost}^/Northwind/Country/%U" (in country_name varchar not null) .
create iri class northwind:Flag "http://^{URIQADefaultHost}^%U#this" (in flag_path varchar not null) .
create iri class northwind:FlagDoc "http://^{URIQADefaultHost}^%U" (in flag_path varchar not null) .
create iri class northwind:dbpedia_iri2 "http://dbpedia.org/resource/%U" (in uname varchar not null) .
create iri class northwind:EmployeePhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/EMP%d#this" (in emp_id varchar not null) .
create iri class northwind:CategoryPhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/CAT%d#this" (in category_id varchar not null) .
create iri class northwind:Phone "tel:%s" (in phone_number varchar) .
create iri class northwind:Fax "fax:%s" (in fax_number varchar) .
;

SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>

alter quad storage virtrdf:DefaultQuadStorage
FROM Demo.demo.Products as products
FROM Demo.demo.Suppliers as suppliers
FROM Demo.demo.Shippers as shippers
FROM Demo.demo.Categories as categories
FROM Demo.demo.Customers as customers
FROM Demo.demo.Employees as employees
FROM Demo.demo.Orders as orders
FROM Demo.demo.Order_Details as order_lines
FROM Demo.demo.Countries as countries
FROM Demo.demo.Provinces as provinces
where (^{suppliers.}^.Country = ^{countries.}^.Name)
where (^{customers.}^.Country = ^{countries.}^.Name)
where (^{employees.}^.Country = ^{countries.}^.Name)
where (^{orders.}^.ShipCountry = ^{countries.}^.Name)
{
        create virtrdf:NorthwindDemo as graph iri ("http://^{URIQADefaultHost}^/Northwind") option (exclusive)
        {
                northwind:CustomerContact (customers.CustomerID)
                        a foaf:Person
                                as virtrdf:CustomerContact-foaf_Person .

                northwind:CustomerContact (customers.CustomerID)
                        a northwind:CustomerContact
                                as virtrdf:CustomerContact-CustomerContact;
                        foaf:name customers.ContactName
                                as virtrdf:CustomerContact-contact_name ;
                        foaf:phone northwind:Phone (customers.Phone)
                                as virtrdf:CustomerContact-foaf_phone ;
                        northwind:is_contact_at northwind:Customer (customers.CustomerID)
                                as virtrdf:CustomerContact-is_contact_at ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:CustomerContact-country ;
                        rdfs:isDefinedBy northwind: .

                northwind:CustomerContactDoc (customers.CustomerID)
                        a northwind:CustomerContactDoc
                                as virtrdf:CustomerContactDoc-CustomerID ;
                        a foaf:Document
                                as virtrdf:CustomerContactDoc-foaf_DocCustomerID ;
                        foaf:primaryTopic northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:CustomerContactDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:CustomerContact (customers.CustomerID) as virtrdf:CustomerContact-is_country_of .

                northwind:Product (products.ProductID)
                        a northwind:Product
                                as virtrdf:Product-ProductID ;
                        northwind:has_category northwind:Category (products.CategoryID)
                                as virtrdf:Product-product_has_category ;
                        northwind:has_supplier northwind:Supplier (products.SupplierID)
                                as virtrdf:Product-product_has_supplier ;
                        northwind:productName products.ProductName
                                as virtrdf:Product-name_of_product ;
                        northwind:quantityPerUnit products.QuantityPerUnit
                                as virtrdf:Product-quantity_per_unit ;
                        northwind:unitPrice products.UnitPrice
                                as virtrdf:Product-unit_price ;
                        northwind:unitsInStock products.UnitsInStock
                                as virtrdf:Product-units_in_stock ;
                        northwind:unitsOnOrder products.UnitsOnOrder
                                as virtrdf:Product-units_on_order ;
                        northwind:reorderLevel products.ReorderLevel
                                as virtrdf:Product-reorder_level ;
                        northwind:discontinued products.Discontinued
                                as virtrdf:Product-discontinued ;
                        rdfs:isDefinedBy northwind: .

                northwind:ProductDoc (products.ProductID)
                        a northwind:ProductDoc
                                as virtrdf:ProductDoc-ProductID ;
                        a foaf:Document
                                as virtrdf:ProductDoc-foaf_DocProductID ;
                        foaf:primaryTopic northwind:Product (products.ProductID)
                                as virtrdf:ProductDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Category (products.CategoryID)
                        northwind:category_of northwind:Product (products.ProductID) as virtrdf:Product-category_of .

                northwind:Supplier (products.SupplierID)
                        northwind:supplier_of northwind:Product (products.ProductID) as virtrdf:Product-supplier_of .

                northwind:Supplier (suppliers.SupplierID)
                        a northwind:Supplier
                                as virtrdf:Supplier-SupplierID ;
                        northwind:companyName suppliers.CompanyName
                                as virtrdf:Supplier-company_name ;
                        northwind:contactName suppliers.ContactName
                                as virtrdf:Supplier-contact_name ;
                        northwind:contactTitle suppliers.ContactTitle
                                as virtrdf:Supplier-contact_title ;
                        northwind:address suppliers.Address
                                as virtrdf:Supplier-address ;
                        northwind:city northwind:dbpedia_iri2(suppliers.City)
                                as virtrdf:Supplier-dbpediacity ;
                        northwind:region suppliers.Region
                                as virtrdf:Supplier-region ;
                        northwind:postalCode suppliers.PostalCode
                                as virtrdf:Supplier-postal_code ;
                        northwind:country northwind:Country(suppliers.Country)
                                as virtrdf:Supplier-country ;
                        northwind:phone northwind:Phone (suppliers.Phone)
                                as virtrdf:Supplier-phone ;
                        northwind:fax northwind:Fax (suppliers.Fax)
                                as virtrdf:Supplier-fax ;
                        northwind:homePage suppliers.HomePage
                                as virtrdf:Supplier-home_page ;
                        rdfs:isDefinedBy northwind: .

                northwind:SupplierDoc (suppliers.SupplierID)
                        a northwind:SupplierDoc
                                as virtrdf:SupplierDoc-SupplierID ;
                        a foaf:Document
                                as virtrdf:SupplierDoc-foaf_DocSupplierID ;
                        foaf:primaryTopic northwind:Supplier (suppliers.SupplierID)
                                as virtrdf:SupplierDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (suppliers.Country)
                        northwind:is_country_of
                northwind:Supplier (suppliers.SupplierID) as virtrdf:Supplier-is_country_of .

                northwind:Category (categories.CategoryID)
                        a northwind:Category
                                as virtrdf:Category-CategoryID ;
                        northwind:categoryName categories.CategoryName
                                as virtrdf:Category-home_page ;
                        northwind:description categories.Description
                                as virtrdf:Category-description ;
                        foaf:img northwind:CategoryPhoto(categories.CategoryID)
                                as virtrdf:Category-categories.CategoryPhoto ;
                        rdfs:isDefinedBy northwind: .

                northwind:CategoryDoc (categories.CategoryID)
                        a northwind:CategoryDoc
                                as virtrdf:CategoryDoc-CategoryID ;
                        a foaf:Document
                                as virtrdf:CategoryDoc-foaf_DocCategoryID ;
                        foaf:primaryTopic northwind:Category (categories.CategoryID)
                                as virtrdf:CategoryDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:CategoryPhoto(categories.CategoryID)
                        a northwind:CategoryPhoto
                                as virtrdf:Category-categories.CategoryPhotoID ;
                        rdfs:isDefinedBy northwind: .

                northwind:Shipper (shippers.ShipperID)
                        a northwind:Shipper
                                as virtrdf:Shipper-ShipperID ;
                        northwind:companyName shippers.CompanyName
                                as virtrdf:Shipper-company_name ;
                        northwind:phone northwind:Phone (shippers.Phone)
                                as virtrdf:Shipper-phone ;
                        rdfs:isDefinedBy northwind: .

                northwind:ShipperDoc (shippers.ShipperID)
                        a northwind:ShipperDoc
                                as virtrdf:ShipperDoc-ShipperID ;
                        a foaf:Document
                                as virtrdf:ShipperDoc-foaf_DocShipperID ;
                        foaf:primaryTopic northwind:Shipper (shippers.ShipperID)
                                as virtrdf:ShipperDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Customer (customers.CustomerID)
                        a  northwind:Customer
                                as virtrdf:Customer-CustomerID2 ;
                        a  foaf:Organization
                                as virtrdf:Customer-CustomerID ;
                        foaf:name customers.CompanyName
                                as virtrdf:Customer-foaf_name ;
                        northwind:companyName customers.CompanyName
                                as virtrdf:Customer-company_name ;
                        northwind:has_contact northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:Customer-contact ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:Customer-country ;
                        northwind:contactName customers.ContactName
                                as virtrdf:Customer-contact_name ;
                        northwind:contactTitle customers.ContactTitle
                                as virtrdf:Customer-contact_title ;
                        northwind:address customers.Address
                                as virtrdf:Customer-address ;
                        northwind:city northwind:dbpedia_iri2(customers.City)
                                as virtrdf:Customer-dbpediacity ;
                        northwind:region customers.Region
                                as virtrdf:Customer-region ;
                        northwind:PostalCode customers.PostalCode
                                as virtrdf:Customer-postal_code ;
                        foaf:phone northwind:Phone (customers.Phone)
                                as virtrdf:Customer-foaf_phone ;
                        northwind:phone northwind:Phone (customers.Phone)
                                as virtrdf:Customer-phone ;
                        northwind:fax northwind:Fax (customers.Fax)
                                as virtrdf:Customer-fax ;
                        rdfs:isDefinedBy northwind: .

                northwind:CustomerDoc (customers.CustomerID)
                        a  northwind:CustomerDoc
                                as virtrdf:CustomerDoc-CustomerID2 ;
                        a  foaf:Document
                                as virtrdf:CustomerDoc-CustomerID3 ;
                        foaf:primaryTopic northwind:Customer (customers.CustomerID)
                                as virtrdf:CustomerDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:Customer (customers.CustomerID) as virtrdf:Customer-is_country_of .

                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a northwind:Employee
                                as virtrdf:Employee-EmployeeID2 ;
                        a foaf:Person
                                as virtrdf:Employee-EmployeeID ;
                        foaf:surname employees.LastName
                                as virtrdf:Employee-foaf_last_name ;
                        northwind:lastName employees.LastName
                                as virtrdf:Employee-last_name ;
                        foaf:firstName employees.FirstName
                                as virtrdf:Employee-foaf_first_name ;
                        northwind:firstName employees.FirstName
                                as virtrdf:Employee-first_name ;
                        foaf:title employees.Title
                                as virtrdf:Employee-title ;
                        northwind:titleOfCourtesy employees.TitleOfCourtesy
                                as virtrdf:Employee-title_of_courtesy ;
                        foaf:birthday employees.BirthDate
                                as virtrdf:Employee-foaf_birth_date ;
                        northwind:birthday employees.BirthDate
                                as virtrdf:Employee-birth_date ;
                        northwind:hireDate employees.HireDate
                                as virtrdf:Employee-hire_date ;
                        northwind:address employees.Address
                                as virtrdf:Employee-address ;
                        northwind:city northwind:dbpedia_iri2(employees.City)
                                as virtrdf:Employee-dbpediacity ;
                        northwind:region employees.Region
                                as virtrdf:Employee-region ;
                        northwind:postalCode employees.PostalCode
                                as virtrdf:Employee-postal_code ;
                        northwind:country northwind:Country(employees.Country)
                                as virtrdf:Employee-country ;
                        foaf:phone employees.HomePhone
                                as virtrdf:Employee-home_phone ;
                        northwind:extension employees.Extension
                                as virtrdf:Employee-extension ;
                        northwind:notes employees.Notes
                                as virtrdf:Employee-notes ;
                        northwind:reportsTo northwind:Employee(employees.FirstName, employees.LastName, employees.ReportsTo) where (^{employees.}^.ReportsTo = ^{employees.}^.EmployeeID)
                                as virtrdf:Employee-reports_to ;
                        foaf:img northwind:EmployeePhoto(employees.EmployeeID)
                                as virtrdf:Employee-employees.EmployeePhoto ;
                        rdfs:isDefinedBy northwind: .

                northwind:EmployeeDoc (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a  northwind:EmployeeDoc
                                as virtrdf:EmployeeDoc-EmployeeID2 ;
                        a  foaf:Document
                                as virtrdf:EmployeeDoc-EmployeeID3 ;
                        foaf:primaryTopic northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                                as virtrdf:EmployeeDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:EmployeePhoto(employees.EmployeeID)
                        a northwind:EmployeePhoto
                                as virtrdf:Employee-employees.EmployeePhotoId ;
                        rdfs:isDefinedBy northwind: .

                northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID)
                        northwind:is_salesrep_of
                northwind:Order (orders.OrderID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID) as virtrdf:Order-is_salesrep_of .

                northwind:Country (employees.Country)
                        northwind:is_country_of
                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) as virtrdf:Employee-is_country_of .

                northwind:Order (orders.OrderID)
                        a northwind:Order
                                as virtrdf:Order-Order ;
                        northwind:has_customer northwind:Customer (orders.CustomerID)
                                as virtrdf:Order-order_has_customer ;
                        northwind:has_salesrep northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Customer-has_salesrep ;
                        northwind:has_employee northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Order-order_has_employee ;
                        northwind:orderDate orders.OrderDate
                                as virtrdf:Order-order_date ;
                        northwind:requiredDate orders.RequiredDate
                                as virtrdf:Order-required_date ;
                        northwind:shippedDate orders.ShippedDate
                                as virtrdf:Order-shipped_date ;
                        northwind:order_ship_via northwind:Shipper (orders.ShipVia)
                                as virtrdf:Order-order_ship_via ;
                        northwind:freight orders.Freight
                                as virtrdf:Order-freight ;
                        northwind:shipName orders.ShipName
                                as virtrdf:Order-ship_name ;
                        northwind:shipAddress orders.ShipAddress
                                as virtrdf:Order-ship_address ;
                        northwind:shipCity northwind:dbpedia_iri2(orders.ShipCity)
                                as virtrdf:Order-dbpediaship_city ;
                        northwind:shipRegion orders.ShipRegion
                                as virtrdf:Order-ship_region ;
                        northwind:shipPostal_code orders.ShipPostalCode
                                as virtrdf:Order-ship_postal_code ;
                        northwind:shipCountry northwind:Country(orders.ShipCountry)
                                as virtrdf:ship_country ;
                        rdfs:isDefinedBy northwind: .

                northwind:OrderDoc (orders.OrderID)
                        a  northwind:OrderDoc
                                as virtrdf:OrderDoc-OrderID2 ;
                        a  foaf:Document
                                as virtrdf:OrderDoc-OrderID3 ;
                        foaf:primaryTopic northwind:Order (orders.OrderID)
                                as virtrdf:OrderDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (orders.ShipCountry)
                        northwind:is_ship_country_of
                northwind:Order (orders.OrderID) as virtrdf:Order-is_country_of .

                northwind:Customer (orders.CustomerID)
                        northwind:has_order northwind:Order (orders.OrderID) as virtrdf:Order-has_order .

                northwind:Shipper (orders.ShipVia)
                        northwind:ship_order northwind:Order (orders.OrderID) as virtrdf:Order-ship_order .

                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                        a northwind:OrderLine
                                as virtrdf:OrderLine-OrderLines ;
                        northwind:has_order_id northwind:Order (order_lines.OrderID)
                                as virtrdf:order_lines_has_order_id ;
                        northwind:has_product_id northwind:Product (order_lines.ProductID)
                                as virtrdf:order_lines_has_product_id ;
                        northwind:unitPrice order_lines.UnitPrice
                                as virtrdf:OrderLine-unit_price ;
                        northwind:quantity order_lines.Quantity
                                as virtrdf:OrderLine-quantity ;
                        northwind:discount order_lines.Discount
                                as virtrdf:OrderLine-discount ;
                        rdfs:isDefinedBy northwind: .

                northwind:OrderLineDoc (order_lines.OrderID, order_lines.ProductID)
                        a  northwind:OrderLineDoc
                                as virtrdf:OrderLineDoc-OrderLineID2 ;
                        a  foaf:Document
                                as virtrdf:OrderLineDoc-OrderLineID3 ;
                        foaf:primaryTopic northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                                as virtrdf:OrderLineDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Order (orders.OrderID)
                        northwind:is_order_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{orders.}^.OrderID = ^{order_lines.}^.OrderID) as virtrdf:Order-is_order_of .

                northwind:Product (products.ProductID)
                        northwind:is_product_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{products.}^.ProductID = ^{order_lines.}^.ProductID) as virtrdf:Product-is_product_of .

                northwind:Country (countries.Name)
                        a northwind:Country
                                as virtrdf:Country-Type2 ;
                        a wgs:SpatialThing
                                as virtrdf:Country-Type ;
                        owl:sameAs northwind:dbpedia_iri2 (countries.Name) ;
                        northwind:name countries.Name
                                as virtrdf:Country-Name ;
                        northwind:code countries.Code
                                as virtrdf:Country-Code ;
                        northwind:smallFlagDAVResourceName countries.SmallFlagDAVResourceName
                                as virtrdf:Country-SmallFlagDAVResourceName ;
                        northwind:largeFlagDAVResourceName countries.LargeFlagDAVResourceName
                                as virtrdf:Country-LargeFlagDAVResourceName ;
                        northwind:smallFlagDAVResourceURI northwind:Flag(countries.SmallFlagDAVResourceURI)
                                as virtrdf:Country-SmallFlagDAVResourceURI ;
                        northwind:largeFlagDAVResourceURI northwind:Flag(countries.LargeFlagDAVResourceURI)
                                as virtrdf:Country-LargeFlagDAVResourceURI ;
                        wgs:lat countries.Lat
                                as virtrdf:Country-Lat ;
                        wgs:long countries.Lng
                                as virtrdf:Country-Lng ;
                        rdfs:isDefinedBy northwind: .

                northwind:CountryDoc (countries.Name)
                        a  northwind:CountryDoc
                                as virtrdf:CountryDoc-CountryID2 ;
                        a  foaf:Document
                                as virtrdf:CountryDoc-CountryID3 ;
                        foaf:primaryTopic northwind:Country (countries.Name)
                                as virtrdf:CountryDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (countries.Name)
                        northwind:has_province
                northwind:Province (provinces.CountryCode, provinces.Province) where (^{provinces.}^.CountryCode = ^{countries.}^.Code) as virtrdf:Country-has_province .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        a northwind:Province
                                as virtrdf:Province-Provinces ;
                        owl:sameAs northwind:dbpedia_iri2 (provinces.Province) ;
                        northwind:has_country_code provinces.CountryCode
                                as virtrdf:has_country_code ;
                        northwind:provinceName provinces.Province
                                as virtrdf:Province-ProvinceName ;
                        rdfs:isDefinedBy northwind: .

                northwind:ProvinceDoc (provinces.CountryCode, provinces.Province)
                        a  northwind:ProvinceDoc
                                as virtrdf:ProvinceDoc-ProvinceID2 ;
                        a  foaf:Document
                                as virtrdf:ProvinceDoc-ProvinceID3 ;
                        foaf:primaryTopic northwind:Province (provinces.CountryCode, provinces.Province)
                                as virtrdf:ProvinceDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        northwind:is_province_of
                northwind:Country (countries.Name) where  (^{countries.}^.Code = ^{provinces.}^.CountryCode) as virtrdf:Province-country_of .
        }.
}.
;

delete FROM DB.DBA.URL_REWRITE_RULE_LIST where urrl_list like 'demo_nw%';
delete FROM DB.DBA.URL_REWRITE_RULE where urr_rule like 'demo_nw%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'demo_nw_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%3E+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/Northwind%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'demo_nw_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'demo_nw_rule_list1',
    1,
    vector (
                'demo_nw_rule1',
                'demo_nw_rule2'
          ));


VHOST_REMOVE (lpath=>'/Northwind');
DB.DBA.VHOST_DEFINE (lpath=>'/Northwind', ppath=>'/DAV/home/demo/', vsp_user=>'dba', is_dav=>1,
          is_brws=>0, opts=>vector ('url_rewrite', 'demo_nw_rule_list1'));

create procedure DB.DBA.LOAD_NW_ONTOLOGY_FROM_DAV()
{
  declare content1, urihost varchar;
  SELECT cast (RES_CONTENT as varchar) into content1 FROM WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/VAD/demo/sql/nw.owl';
  DB.DBA.RDF_LOAD_RDFXML (content1, 'http://demo.openlinksw.com/schemas/northwind#', 'http://demo.openlinksw.com/schemas/NorthwindOntology/1.0/');
  urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  if (urihost = 'demo.openlinksw.com')
  {
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/northwind');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/northwind', ppath=>'/DAV/VAD/demo/sql/nw.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/northwind#');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/northwind#', ppath=>'/DAV/VAD/demo/sql/nw.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
  }
};

DB.DBA.LOAD_NW_ONTOLOGY_FROM_DAV();
drop procedure DB.DBA.LOAD_NW_ONTOLOGY_FROM_DAV;

DB.DBA.XML_SET_NS_DECL ('northwind', 'http://demo.openlinksw.com/schemas/northwind#', 2);
]]></programlisting>
    <para><emphasis>Basic Northwind Ontology</emphasis></para>
<programlisting><![CDATA[
<?xml version="1.0" encoding="utf-8"?>
<!--
 -
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2007 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<rdf:RDF xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:owl ="http://www.w3.org/2002/07/owl#"
         xmlns:virtrdf="http://www.openlinksw.com/schemas/virtrdf#"
         xml:base="http://demo.openlinksw.com/schemas/northwind#">
  <owl:Ontology rdf:about="http://demo.openlinksw.com/schemas/northwind#">
        <rdfs:label>Northwind</rdfs:label>
        <rdfs:comment>Northwind database classes and properties</rdfs:comment>
        <virtrdf:catName>Northwind</virtrdf:catName>
        <virtrdf:version>1.00</virtrdf:version>
  </owl:Ontology>

  <rdfs:Class rdf:ID="Product">
    <rdfs:label>Product</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_category">
    <rdfs:range rdf:resource="#Category"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Category</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="has_supplier">
    <rdfs:range rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Supplier</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ProductName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ProductName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="QuantityPerUnit">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>QuantityPerUnit</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="UnitPrice">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>UnitPrice</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="UnitsInStock">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>UnitsInStock</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="UnitsOnOrder">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>UnitsOnOrder</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ReorderLevel">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ReorderLevel</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Discontinued">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Discontinued</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Supplier">
    <rdfs:label>Supplier</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="CompanyName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Shipper"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>CompanyName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ContactName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#CustomerContact"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ContactName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ContactTitle">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/title"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ContactTitle</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Address">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Address</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="City">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>City</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Region">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Region</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="PostalCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>PostalCode</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="CountryName">
    <rdfs:range rdf:resource="#Country"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#CustomerContact"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Country</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Phone">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/phone"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Shipper"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#CustomerContact"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Phone</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Fax">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Fax</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="HomePage">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>HomePage</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Category">
    <rdfs:label>Category</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="CategoryName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Category"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>CategoryName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Description">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Category"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Description</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Shipper">
    <rdfs:label>Shipper</rdfs:label>
  </rdfs:Class>

  <rdfs:Class rdf:ID="CustomerContact">
    <rdfs:label>CustomerContact</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
  </rdfs:Class>

  <rdfs:Class rdf:ID="Customer">
    <rdfs:label>Customer</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Organization"/>
  </rdfs:Class>

  <rdfs:Class rdf:ID="Employee">
    <rdfs:label>Employee</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
  </rdfs:Class>
  <rdf:Property rdf:ID="LastName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/surname"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>LastName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="FirstName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/firstName"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>FirstName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Title">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/title"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Title</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="TitleOfCourtesy">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>TitleOfCourtesy</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="BirthDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/birthday"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>BirthDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="HireDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>HireDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Extension">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Extension</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Notes">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Notes</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ReportsTo">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ReportsTo</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Order">
    <rdfs:label>Order</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_customer">
    <rdfs:range rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Customer</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="has_employee">
    <rdfs:range rdf:resource="#Employee"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Employee</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="OrderDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>OrderDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="RequiredDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>RequiredDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShippedDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShippedDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="order_ship_via">
    <rdfs:range rdf:resource="#Shipper"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Shipper</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Freight">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Freight</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipAddress">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipAddress</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipCity">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipCity</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipRegion">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipRegion</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipPostalCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipPostalCode</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipCountry">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipCountry</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="OrderLine">
    <rdfs:label>OrderLine</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_order_id">
    <rdfs:range rdf:resource="#Order"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Order</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="has_product_id">
    <rdfs:range rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Product</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Quantity">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Quantity</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Discount">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Discount</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Country">
    <rdfs:label>Country</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing"/>
  </rdfs:Class>
  <rdf:Property rdf:ID="Name">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Name</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Code">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Code</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="SmallFlagDAVResourceName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>SmallFlagDAVResourceName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="LargeFlagDAVResourceName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>LargeFlagDAVResourceName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="SmallFlagDAVResourceURI">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>SmallFlagDAVResourceURI</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="LargeFlagDAVResourceURI">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>LargeFlagDAVResourceURI</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Lat">
    <rdfs:range rdf:resource="ttp://www.w3.org/2003/01/geo/wgs84_pos#lat"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Lat</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Lng">
    <rdfs:range rdf:resource="ttp://www.w3.org/2003/01/geo/wgs84_pos#lng"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Lng</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Province">
    <rdfs:label>Province</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_country_code">
    <rdfs:range rdf:resource="#Country"/>
    <rdfs:domain rdf:resource="#Provinces"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Country Code</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ProvinceName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Province"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ProvinceName</rdfs:label>
  </rdf:Property>

</rdf:RDF>
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterohr">
      <title>Oracle Demonstration 'HR' Database </title>
<para><emphasis>Live links to a sample instance</emphasis></para>
<itemizedlist mark="bullet">
<listitem><ulink url="http://demo.openlinksw.com/sparql?default-graph-uri=&amp;should-sponge=&amp;query=%20prefix%20hr%3A%20%3Chttp%3A%2F%2Fdemo.openlinksw.com%2Fschemas%2Foraclehr%2F%3E%20select%20*%20from%20%3Chttp%3A%2F%2Fdemo.openlinksw.com%2Foraclehr%3E%20WHERE%20%7B%3Fs%20a%20hr%3Aemployees%7D&amp;format=text%2Fhtml&amp;debug=on">list all employee URIs</ulink></listitem>
<listitem><ulink url="http://demo.openlinksw.com/about/html/http/demo.openlinksw.com/oraclehr/employees/105">description of employee 105</ulink></listitem>
</itemizedlist>
<para><emphasis>Script to set up your own instance</emphasis></para>
<programlisting><![CDATA[
-- Setup script for RDF views of Oracle 10 Human Resources Sample Database --

GRANT SELECT ON HR.orama.COUNTRIES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.REGIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.DEPARTMENTS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.LOCATIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.EMPLOYEES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOBS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";

-------------------------------------------------------------------

-------- Create rdfs:Class definitions ----------------------------

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix hr: <http://localhost:8890/schemas/oraclehr/> .

hr:countries a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "COUNTRIES" ;
	rdfs:comment "Oracle HR COUNTRIES table" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY ID" .

hr:country_name a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY NAME" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range hr:regions ;
	rdfs:label "REGION ID" .

hr:regions a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "REGIONS" ;
	rdfs:comment "Oracle HR REGIONS table" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:integer ;
        rdfs:label "REGION ID" .

hr:region_name a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:string ;
	rdfs:label "REGION NAME" .

hr:departments a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "DEPARTMENTS" ;
	rdfs:comment "Oracle HR DEPARTMENT table" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range xsd:integer ;
	rdfs:label "DEPARTMENT ID" .

hr:department_name a rdf:Property ;
   	rdfs:domain hr:departments ;
	rdfs:range xsd:string ;
	rdfs:comment "DEPARTMENT NAME" .

hr:manager_id a rdf:Property ;
 	rdfs:domain hr:departments ;
	rdfs:range hr:employees ;
	rdfs:comment "MANAGER ID" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range hr:locations ;
	rdfs:comment "LOCATION ID" .

hr:employees a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "employees" ;
	rdfs:comment "Oracle HR EMPLOYEES table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:integer ;
	rdfs:label "EMPLOYEE ID" .

hr:first_name a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "FIRST NAME" .

hr:last_name a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "LAST NAME" .

hr:email a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "EMAIL" .

hr:phone_number a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "PHONE NUMBER" .

hr:hire_date a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:date ;
	rdfs:label "HIRE DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:salary a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "SALARY" .

hr:commission_pct a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "COMMISSION PCT" .

hr:manager_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "MANAGER ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:jobs a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOBS" ;
	rdfs:comment "Oracle HR JOBS table" .

hr:job_id a rdf:Property ;

	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB ID" .

hr:job_title a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB TITLE" .

hr:min_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MIN SALARY" .

hr:max_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MAXSALARY" .

hr:job_history a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOB HISTORY" ;
	rdfs:comment "Oracle HR JOB HISTORY table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:employees ;
	rdfs:label "EMPLOYEE ID" .

hr:start_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "START DATE" .

hr:end_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "END DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:locations a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "LOCATIONS" ;
	rdfs:comment "Oracle HR JOB LOCATIONS table" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:number ;
	rdfs:label "LOCATION ID" .

hr:street_address a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STREET ADDRESS" .

hr:postal_code a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "POSTAL CODE" .

hr:city a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "CITY" .

hr:state_province a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STATE PROVINCE" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range hr:countries ;
	rdfs:label "COUNTRY" .
', '', 'http://localhost:8890/schemas/oraclehr', 0);

---------------------------------------------------------------

----------- Create IRI Classes -------------

create function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer, in
START_DATE date) returns varchar
{
  return sprintf_or_null
('http://localhost:8890/oraclehr/job_history/%d_%s#this',
  EMPLOYEE_ID, cast (START_DATE as varchar) );
}
;

create function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer
{
  return sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[0];
}
;

create function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  return cast (sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[1] as date);
}
;


GRANT EXECUTE ON DB.DBA.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_1 TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_2 TO "SPARQL", "SPARQL_UPDATE";

SPARQL


	create iri class <http://localhost:8890/schemas/oraclehr/countries_iri>
	"http://^{URIQADefaultHost}^/oraclehr/countries/%s#this"
    	(in COUNTRY_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/regions_iri>
	"http://^{URIQADefaultHost}^/oraclehr/regions/%d#this"
	    (in REGION_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/departments_iri>
	"http://^{URIQADefaultHost}^/oraclehr/departments/%d#this"
	    (in DEPARTMENT_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/employees_iri>
	"http://^{URIQADefaultHost}^/oraclehr/employees/%d#this"
		(in EMPLOYEE_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/jobs_iri>
	"http://^{URIQADefaultHost}^/oraclehr/jobs/%s#this"
	    (in JOB_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/job_history_iri>
		using function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer not null, in
		START_DATE date not null) returns varchar not null,
		function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer,
		function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
		option (bijection, returns
		"http://localhost:8890/oraclehr/job_history/%d_%s#this") .

	create iri class <http://localhost:8890/schemas/oraclehr/locations_iri>
	"http://^{URIQADefaultHost}^/oraclehr/locations/%d#this"
	    (in LOCATION_ID integer not null) .
;

--------------------------------------------------------------------

------------- Create Quad Store ------------------------------------

SPARQL

prefix hr: <http://localhost:8890/schemas/oraclehr/>

alter quad storage virtrdf:DefaultQuadStorage
  FROM HR.orama.COUNTRIES as countries_tbl
  FROM HR.orama.REGIONS as regions_tbl
  FROM HR.orama.DEPARTMENTS as departments_tbl
  FROM HR.orama.EMPLOYEES as employees_tbl
  FROM HR.orama.EMPLOYEES as employees_tbl_1		### alias required to represent recursive FK relationship (hr: has_manager ) below.
  FROM HR.orama.JOBS as jobs_tbl
  FROM HR.orama.JOB_HISTORY as job_history_tbl
  FROM HR.orama.LOCATIONS as locations_tbl
{
  create virtrdf:oraclehr as
      graph <http://localhost:8890/oraclehr>
  {
        hr:countries_iri(countries_tbl.COUNTRY_ID) a hr:countries  as virtrdf:countires_country_id ;
        hr:country_name countries_tbl.COUNTRY_NAME  as virtrdf:countries_country_name ;
        hr:region_id hr:regions_iri(regions_tbl.REGION_ID) where (^{countries_tbl.}^.REGION_ID = ^{regions_tbl.}^.REGION_ID)  as virtrdf:countries_region_id .

	hr:regions_iri(regions_tbl.REGION_ID) a hr:regions as virtrdf:regions_region_id ;
	hr:region_name regions_tbl.REGION_NAME  as virtrdf:regions_region_name .

	hr:departments_iri(departments_tbl.DEPARTMENT_ID) a hr:departments as virtrdf:departments_department_id ;
	hr:department_name departments_tbl.DEPARTMENT_NAME as virtrdf:departments_department_name ;
	hr:location_id hr:locations_iri(locations_tbl.LOCATION_ID) where (^{departments_tbl.}^.LOCATION_ID = ^{locations_tbl.}^.LOCATION_ID) as virtrdf:departments_location_id ;
	hr:manager_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{departments_tbl.}^.MANAGER_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:departments_manager_id .

	hr:employees_iri(employees_tbl.EMPLOYEE_ID) a hr:employees as virtrdf:employees_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{employees_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:employees_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{employees_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:employees_job_id ;
	hr:manager_id employees_tbl.MANAGER_ID as virtrdf:employees_manager_id ;
	hr:commissin_pct employees_tbl.COMMISSION_PCT as virtrdf:employees_commission_pct ;
	hr:email employees_tbl.EMAIL as virtrdf:employees_email ;
	hr:first_name employees_tbl.FIRST_NAME as virtrdf:employees_first_name ;
	hr:hire_date employees_tbl.HIRE_DATE as virtrdf:employees_hire_date ;
	hr:last_name employees_tbl.LAST_NAME as virtrdf:employees_last_name ;
	hr:phone_number employees_tbl.PHONE_NUMBER as virtrdf:employees_phone_number ;
	hr:salary employees_tbl.SALARY as virtrdf:employees_salary ;
	hr:has_job_history hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) where (^{employees_tbl.}^.EMPLOYEE_ID = ^{job_history_tbl.}^.EMPLOYEE_ID) as virtrdf:employees_has_job_history;
	hr:has_manager hr:employees_iri(employees_tbl_1.EMPLOYEE_ID) where (^{employees_tbl.}^.MANAGER_ID = ^{employees_tbl_1.}^.EMPLOYEE_ID) as virtrdf:employees_has_manager.

	hr:locations_iri(locations_tbl.LOCATION_ID) a hr:locations as virtrdf:locations_location_id ;
	hr:country_id hr:countries_iri(countries_tbl.COUNTRY_ID) where (^{locations_tbl.}^.COUNTRY_ID = ^{countries_tbl.}^.COUNTRY_ID) as virtrdf:locations_country_id ;
	hr:city locations_tbl.CITY as virtrdf:locations_city ;
	hr:postal_code locations_tbl.POSTAL_CODE as virtrdf:locations_postal_code ;
	hr:state_province locations_tbl.STATE_PROVINCE as virtrdf:locations_state_province ;
	hr:street_address locations_tbl.STREET_ADDRESS as virtrdf:locations_street_address .

	hr:jobs_iri(jobs_tbl.JOB_ID) a hr:jobs as virtrdf:jobs_job_id ;
	hr:job_title jobs_tbl.JOB_TITLE as virtrdf:jobs_job_title ;
	hr:max_salary jobs_tbl.MAX_SALARY as virtrdf:jobs_max_salary ;
	hr:min_salary jobs_tbl.MIN_SALARY as virtrdf:jobs_min_salary .

	hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) a hr:job_history as virtrdf:job_history_pk ;
	hr:employee_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{job_history_tbl.}^.EMPLOYEE_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:job_history_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{job_history_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:job_history_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{job_history_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:job_history_job_id ;
	hr:start_date job_history_tbl.START_DATE as virtrdf:job_history_start_date ;
	hr:end_date job_history_tbl.END_DATE as virtrdf:job_history_end_date .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oraclehr_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oraclehr_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oraclehr_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oraclehr_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/oraclehr%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oraclehr_rule_list1',
    1,
    vector (
  	 	'oraclehr_rule1',
  	 	'oraclehr_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/oraclehr');

VHOST_DEFINE (
	lpath=>'/oraclehr',
	ppath=>'/DAV/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oraclehr_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oracle_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oracle_schemas_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oracle_schemas_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oracle_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/oraclehr%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oracle_schemas_rule_list1',
    1,
    vector (
  	 	'oracle_schemas_rule1',
  	 	'oracle_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/oraclehr');

VHOST_DEFINE (
	lpath=>'/schemas/oraclehr',
	ppath=>'/DAV/schemas/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oracle_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('hr', 'http://^{URIQADefaultHost}^/schemas/oraclehr/', 2);
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterprohd">
      <title>Oracle using the demonstration 'Human Resources' database</title>
<para><emphasis>Live links to a sample instance</emphasis></para>
<itemizedlist mark="bullet">
<listitem><ulink url="http://demo.openlinksw.com/sparql?default-graph-uri=&amp;should-sponge=&amp;query=%20prefix%20hr%3A%20%3Chttp%3A%2F%2Fdemo.openlinksw.com%2Fschemas%2Foraclehr%2F%3E%20select%20*%20from%20%3Chttp%3A%2F%2Fdemo.openlinksw.com%2Foraclehr%3E%20WHERE%20%7B%3Fs%20a%20hr%3Aemployees%7D&amp;format=text%2Fhtml&amp;debug=on">list all employee URIs</ulink></listitem>
<listitem><ulink url="http://demo.openlinksw.com/about/html/http/demo.openlinksw.com/oraclehr/employees/105">description of employee 105</ulink></listitem>
</itemizedlist>
<para><emphasis>Script to set up your own instance</emphasis></para>
<programlisting><![CDATA[
-- Setup script for RDF views of Oracle 10 Human Resources Sample Database --

GRANT SELECT ON HR.orama.COUNTRIES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.REGIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.DEPARTMENTS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.LOCATIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.EMPLOYEES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOBS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";

-------------------------------------------------------------------

-------- Create rdfs:Class definitions ----------------------------

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix hr: <http://localhost:8890/schemas/oraclehr/> .

hr:countries a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "COUNTRIES" ;
	rdfs:comment "Oracle HR COUNTRIES table" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY ID" .

hr:country_name a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY NAME" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range hr:regions ;
	rdfs:label "REGION ID" .

hr:regions a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "REGIONS" ;
	rdfs:comment "Oracle HR REGIONS table" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:integer ;
        rdfs:label "REGION ID" .

hr:region_name a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:string ;
	rdfs:label "REGION NAME" .

hr:departments a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "DEPARTMENTS" ;
	rdfs:comment "Oracle HR DEPARTMENT table" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range xsd:integer ;
	rdfs:label "DEPARTMENT ID" .

hr:department_name a rdf:Property ;
   	rdfs:domain hr:departments ;
	rdfs:range xsd:string ;
	rdfs:comment "DEPARTMENT NAME" .

hr:manager_id a rdf:Property ;
 	rdfs:domain hr:departments ;
	rdfs:range hr:employees ;
	rdfs:comment "MANAGER ID" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range hr:locations ;
	rdfs:comment "LOCATION ID" .

hr:employees a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "employees" ;
	rdfs:comment "Oracle HR EMPLOYEES table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:integer ;
	rdfs:label "EMPLOYEE ID" .

hr:first_name a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "FIRST NAME" .

hr:last_name a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "LAST NAME" .

hr:email a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "EMAIL" .

hr:phone_number a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "PHONE NUMBER" .

hr:hire_date a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:date ;
	rdfs:label "HIRE DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:salary a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "SALARY" .

hr:commission_pct a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "COMMISSION PCT" .

hr:manager_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "MANAGER ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:jobs a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOBS" ;
	rdfs:comment "Oracle HR JOBS table" .

hr:job_id a rdf:Property ;

	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB ID" .

hr:job_title a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB TITLE" .

hr:min_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MIN SALARY" .

hr:max_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MAXSALARY" .

hr:job_history a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOB HISTORY" ;
	rdfs:comment "Oracle HR JOB HISTORY table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:employees ;
	rdfs:label "EMPLOYEE ID" .

hr:start_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "START DATE" .

hr:end_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "END DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:locations a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "LOCATIONS" ;
	rdfs:comment "Oracle HR JOB LOCATIONS table" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:number ;
	rdfs:label "LOCATION ID" .

hr:street_address a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STREET ADDRESS" .

hr:postal_code a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "POSTAL CODE" .

hr:city a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "CITY" .

hr:state_province a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STATE PROVINCE" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range hr:countries ;
	rdfs:label "COUNTRY" .
', '', 'http://localhost:8890/schemas/oraclehr', 0);

---------------------------------------------------------------

----------- Create IRI Classes -------------

create function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer, in
START_DATE date) returns varchar
{
  return sprintf_or_null
('http://localhost:8890/oraclehr/job_history/%d_%s#this',
  EMPLOYEE_ID, cast (START_DATE as varchar) );
}
;

create function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer
{
  return sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[0];
}
;

create function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  return cast (sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[1] as date);
}
;


GRANT EXECUTE ON DB.DBA.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_1 TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_2 TO "SPARQL", "SPARQL_UPDATE";

SPARQL


	create iri class <http://localhost:8890/schemas/oraclehr/countries_iri>
	"http://^{URIQADefaultHost}^/oraclehr/countries/%s#this"
    	(in COUNTRY_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/regions_iri>
	"http://^{URIQADefaultHost}^/oraclehr/regions/%d#this"
	    (in REGION_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/departments_iri>
	"http://^{URIQADefaultHost}^/oraclehr/departments/%d#this"
	    (in DEPARTMENT_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/employees_iri>
	"http://^{URIQADefaultHost}^/oraclehr/employees/%d#this"
		(in EMPLOYEE_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/jobs_iri>
	"http://^{URIQADefaultHost}^/oraclehr/jobs/%s#this"
	    (in JOB_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/job_history_iri>
		using function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer not null, in
		START_DATE date not null) returns varchar not null,
		function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer,
		function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
		option (bijection, returns
		"http://localhost:8890/oraclehr/job_history/%d_%s#this") .

	create iri class <http://localhost:8890/schemas/oraclehr/locations_iri>
	"http://^{URIQADefaultHost}^/oraclehr/locations/%d#this"
	    (in LOCATION_ID integer not null) .
;

--------------------------------------------------------------------

------------- Create Quad Store ------------------------------------

SPARQL

prefix hr: <http://localhost:8890/schemas/oraclehr/>

alter quad storage virtrdf:DefaultQuadStorage
  from HR.orama.COUNTRIES as countries_tbl
  from HR.orama.REGIONS as regions_tbl
  from HR.orama.DEPARTMENTS as departments_tbl
  from HR.orama.EMPLOYEES as employees_tbl
  from HR.orama.EMPLOYEES as employees_tbl_1		### alias required to represent recursive FK relationship (hr: has_manager ) below.
  from HR.orama.JOBS as jobs_tbl
  from HR.orama.JOB_HISTORY as job_history_tbl
  from HR.orama.LOCATIONS as locations_tbl
{
  create virtrdf:oraclehr as
      graph <http://localhost:8890/oraclehr>
  {
        hr:countries_iri(countries_tbl.COUNTRY_ID) a hr:countries  as virtrdf:countires_country_id ;
        hr:country_name countries_tbl.COUNTRY_NAME  as virtrdf:countries_country_name ;
        hr:region_id hr:regions_iri(regions_tbl.REGION_ID) where (^{countries_tbl.}^.REGION_ID = ^{regions_tbl.}^.REGION_ID)  as virtrdf:countries_region_id .

	hr:regions_iri(regions_tbl.REGION_ID) a hr:regions as virtrdf:regions_region_id ;
	hr:region_name regions_tbl.REGION_NAME  as virtrdf:regions_region_name .

	hr:departments_iri(departments_tbl.DEPARTMENT_ID) a hr:departments as virtrdf:departments_department_id ;
	hr:department_name departments_tbl.DEPARTMENT_NAME as virtrdf:departments_department_name ;
	hr:location_id hr:locations_iri(locations_tbl.LOCATION_ID) where (^{departments_tbl.}^.LOCATION_ID = ^{locations_tbl.}^.LOCATION_ID) as virtrdf:departments_location_id ;
	hr:manager_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{departments_tbl.}^.MANAGER_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:departments_manager_id .

	hr:employees_iri(employees_tbl.EMPLOYEE_ID) a hr:employees as virtrdf:employees_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{employees_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:employees_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{employees_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:employees_job_id ;
	hr:manager_id employees_tbl.MANAGER_ID as virtrdf:employees_manager_id ;
	hr:commissin_pct employees_tbl.COMMISSION_PCT as virtrdf:employees_commission_pct ;
	hr:email employees_tbl.EMAIL as virtrdf:employees_email ;
	hr:first_name employees_tbl.FIRST_NAME as virtrdf:employees_first_name ;
	hr:hire_date employees_tbl.HIRE_DATE as virtrdf:employees_hire_date ;
	hr:last_name employees_tbl.LAST_NAME as virtrdf:employees_last_name ;
	hr:phone_number employees_tbl.PHONE_NUMBER as virtrdf:employees_phone_number ;
	hr:salary employees_tbl.SALARY as virtrdf:employees_salary ;
	hr:has_job_history hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) where (^{employees_tbl.}^.EMPLOYEE_ID = ^{job_history_tbl.}^.EMPLOYEE_ID) as virtrdf:employees_has_job_history;
	hr:has_manager hr:employees_iri(employees_tbl_1.EMPLOYEE_ID) where (^{employees_tbl.}^.MANAGER_ID = ^{employees_tbl_1.}^.EMPLOYEE_ID) as virtrdf:employees_has_manager.

	hr:locations_iri(locations_tbl.LOCATION_ID) a hr:locations as virtrdf:locations_location_id ;
	hr:country_id hr:countries_iri(countries_tbl.COUNTRY_ID) where (^{locations_tbl.}^.COUNTRY_ID = ^{countries_tbl.}^.COUNTRY_ID) as virtrdf:locations_country_id ;
	hr:city locations_tbl.CITY as virtrdf:locations_city ;
	hr:postal_code locations_tbl.POSTAL_CODE as virtrdf:locations_postal_code ;
	hr:state_province locations_tbl.STATE_PROVINCE as virtrdf:locations_state_province ;
	hr:street_address locations_tbl.STREET_ADDRESS as virtrdf:locations_street_address .

	hr:jobs_iri(jobs_tbl.JOB_ID) a hr:jobs as virtrdf:jobs_job_id ;
	hr:job_title jobs_tbl.JOB_TITLE as virtrdf:jobs_job_title ;
	hr:max_salary jobs_tbl.MAX_SALARY as virtrdf:jobs_max_salary ;
	hr:min_salary jobs_tbl.MIN_SALARY as virtrdf:jobs_min_salary .

	hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) a hr:job_history as virtrdf:job_history_pk ;
	hr:employee_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{job_history_tbl.}^.EMPLOYEE_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:job_history_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{job_history_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:job_history_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{job_history_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:job_history_job_id ;
	hr:start_date job_history_tbl.START_DATE as virtrdf:job_history_start_date ;
	hr:end_date job_history_tbl.END_DATE as virtrdf:job_history_end_date .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oraclehr_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oraclehr_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oraclehr_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oraclehr_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/oraclehr%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oraclehr_rule_list1',
    1,
    vector (
  	 	'oraclehr_rule1',
  	 	'oraclehr_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/oraclehr');

VHOST_DEFINE (
	lpath=>'/oraclehr',
	ppath=>'/DAV/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oraclehr_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oracle_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oracle_schemas_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oracle_schemas_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'oracle_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/oraclehr%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oracle_schemas_rule_list1',
    1,
    vector (
  	 	'oracle_schemas_rule1',
  	 	'oracle_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/oraclehr');

VHOST_DEFINE (
	lpath=>'/schemas/oraclehr',
	ppath=>'/DAV/schemas/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oracle_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('hr', 'http://^{URIQADefaultHost}^/schemas/oraclehr/', 2);
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterprdb">
      <title>DB2 using the demonstration 'Sample' database</title>
<para><emphasis>Version defined using explicit host - localhost:8890</emphasis></para>
<programlisting><![CDATA[
-- $Id: rdfviewssamples.xml,v 1.1.2.2 2011/09/09 14:09:19 source Exp $
-- Setup script for RDF view of portions of DB2 SAMPLE database included
-- in DB2 Express Edition v9.5
--
-- The script assumes external DB2 tables are linked into Virtuoso using
-- local schema name db2sample.

DB..vd_remote_data_source ('db2ma-smpl', '', '<uid>','<pwd>);

ATTACH TABLE  "DB2ADMIN"."ACT"      PRIMARY KEY ("ACTNO")              AS "DB"."db2sample"."ACT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."DEPARTMENT"      PRIMARY KEY ("DEPTNO")              AS "DB"."db2sample"."DEPARTMENT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."EMPLOYEE"      PRIMARY KEY ("EMPNO")              AS "DB"."db2sample"."EMPLOYEE"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."EMPPROJACT"      PRIMARY KEY ("EMPNO", "PROJNO", "ACTNO", "EMSTDATE")              AS "DB"."db2sample"."EMPPROJACT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."EMP_RESUME"      PRIMARY KEY ("EMPNO", "RESUME_FORMAT)              AS "DB"."db2sample"."EMP_RESUME"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."PROJACT"      PRIMARY KEY ("PROJNO", "ACTNO", "ACSTDATE")              AS "DB"."db2sample"."PROJACT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."PROJECT"      PRIMARY KEY ("PROJNO")              AS "DB"."db2sample"."PROJECT"      FROM 'db2ma-smpl';

COMMIT WORK;

GRANT SELECT ON DB.db2sample.ACT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.DEPARTMENT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.EMPLOYEE TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.EMPPROJACT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.EMP_RESUME TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.PROJACT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.PROJECT TO "SPARQL", "SPARQL_UPDATE";

create function DB.DBA.PROJ_ACT_IRI (
  in proj_no varchar,
  in act_no integer,
  in ac_st_date date
  ) returns varchar
{
  declare _act_no, _datetime, _date any;
  _act_no := cast(act_no as varchar);
  _datetime := cast(ac_st_date as varchar);
  _date := left(_datetime, 10);
  return sprintf('http://localhost:8890/db2sample/proj_act/%s_%s_%s#this',
    proj_no, _act_no, _date);
};

create function
DB.DBA.PROJ_ACT_IRI_INV_1 (in proj_act_iri varchar) returns varchar
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (proj_act_iri,
   'http://localhost:8890/db2sample/proj_act/%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return parts[0];
  }
  return NULL;
};

create function
DB.DBA.PROJ_ACT_IRI_INV_2 (in proj_act_iri varchar) returns integer
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (proj_act_iri,
   'http://localhost:8890/db2sample/proj_act/%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[1] as integer);
  }
  return NULL;
};

create function
DB.DBA.PROJ_ACT_IRI_INV_3 (in proj_act_iri varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (proj_act_iri,
   'http://localhost:8890/db2sample/proj_act/%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[2] as date);
  }
  return NULL;
};

create function DB.DBA.EMP_PROJ_ACT_IRI (
  in emp_no varchar,
  in proj_no varchar,
  in act_no integer,
  in emp_start_date date
  ) returns varchar
{
  declare _act_no, _datetime, _date any;
  _act_no := cast(act_no as varchar);
  _datetime := cast(emp_start_date as varchar);
  _date := left(_datetime, 10);
  return sprintf(
      'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this',
    emp_no, proj_no, _act_no, _date);
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_1 (in emp_proj_act_iri varchar) returns varchar
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return parts[0];
  }
  return NULL;
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_2 (in emp_proj_act_iri varchar) returns varchar
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return parts[1];
  }
  return NULL;
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_3 (in emp_proj_act_iri varchar) returns integer
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[2] as integer);
  }
  return NULL;
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_4 (in emp_proj_act_iri varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[3] as date);
  }
  return NULL;
};

grant execute on DB.DBA.PROJ_ACT_IRI to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.PROJ_ACT_IRI_INV_1 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.PROJ_ACT_IRI_INV_2 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.PROJ_ACT_IRI_INV_3 to "SPARQL", "SPARQL_UPDATE";

grant execute on DB.DBA.EMP_PROJ_ACT_IRI to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_1 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_2 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_3 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_4 to "SPARQL", "SPARQL_UPDATE";

SPARQL drop graph <http://localhost:8890/schemas/db2sample> ;
SPARQL drop graph <http://localhost:8890/db2sample> ;

SPARQL drop quad map virtrdf:db2sample ;

--------------------------
-- RDFS class definitions
ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix opl: <http://localhost:8890/schemas/db2sample/> .

opl:Act a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Act" ;
	rdfs:comment "Activity" .

# ACTNO SMALLINT PRIMARY KEY
opl:act_no a rdf:Property ;
	rdfs:domain opl:Act ;
	rdfs:range xsd:integer ;
	rdfs:label "Activity number" .

# ACTKWD VARCHAR(6)
opl:act_kwd a rdf:Property ;
	rdfs:domain opl:Act ;
	rdfs:range xsd:string ;
	rdfs:label "Activity keyword" .

# ACTDESC VARCHAR(20)
opl:act_desc a rdf:Property ;
	rdfs:domain opl:Act ;
	rdfs:range xsd:string ;
	rdfs:label "Activity description" .

#####
opl:Department a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Department" ;
	rdfs:comment "Department" .

# DEPTNO VARCHAR(3) PRIMARY KEY
opl:dept_no a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:string ;
	rdfs:label "Department number" .

# DEPTNAME VARCHAR(36)
opl:dept_name a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:string ;
	rdfs:label "Department name" .

# MGRNO CHAR(6)
opl:dept_manager a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:Employee ;
	rdfs:label "Department manager" .

# ADMRDEPT CHAR(3)
opl:supervising_dept a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range opl:Department ;
	rdfs:label "Department reported to" .

# LOCATION CHAR(6)
opl:location a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:string ;
	rdfs:label "Location" .

opl:employee_collection a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range opl:Employee ;
	rdfs:label "Department employees" .

opl:dept_project_collection a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range opl:Project ;
	rdfs:label "Department projects" .

#####
opl:Employee a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Employee" ;
	rdfs:comment "Employee" .

# EMPNO VARCHAR(6) PRIMARY KEY
opl:emp_no a rdf:Property ;
	rdfs:domain opl:Employee;
	rdfs:range xsd:string ;
	rdfs:label "Employee number" .

# FIRSTNME VARCHAR(12)
opl:first_name a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "First name" .

# MIDINIT VARCHAR(1)
opl:middle_initial a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Middle initial" .

# LASTNAME VARCHAR(15)
opl:last_name a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Last name" .

# WORKDEPT VARCHAR(3)
opl:work_dept a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:Department ;
	rdfs:label "Work department" .

# PHONENO VARCHAR(4)
opl:phone_no a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Phone number" .

# HIREDATE DATE
opl:hire_date a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:date;
	rdfs:label "Hire date" .

# JOB VARCHAR(8)
opl:job a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Job" .

# EDLEVEL SMALLINT
opl:education_level a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:integer ;
	rdfs:label "Education level" .

# SEX VARCHAR(1)
opl:gender a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Gender" .

# BIRTHDATE DATE
opl:date_of_birth a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:date ;
	rdfs:label "Date of birth" .

# SALARY DECIMAL(9,2)
opl:salary a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:decimal ;
	rdfs:label "Salary" .

# BONUS DECIMAL(9,2)
opl:bonus a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:decimal ;
	rdfs:label "Bonus" .

# COMM DECIMAL(9,2)
opl:commission a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:decimal ;
	rdfs:label "Commission" .

opl:resume_collection a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:EmployeeResume ;
	rdfs:label "Employee resumes" .

opl:projects_responsible_for_collection a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:Project ;
	rdfs:label "responsible for project" .

opl:activity_collection a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:EmpProjAct ;
	rdfs:label "project activities" .

#####
opl:EmpProjAct a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "EmpProjAct" ;
	rdfs:comment "Employee project activity" .

# EMPNO VARCHAR(6) PRIMARY KEY
opl:epa_emp_no a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Employee number" .

# PROJNO VARCHAR(6) PRIMARY KEY
opl:epa_proj_no a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Project number" .

# ACTNO SMALLINT PRIMARY KEY
opl:epa_act_no a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Activity number" .

# EMSTDATE DATE PRIMARY KEY
opl:emp_start_date a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Employee activity start date" .

# EMPTIME DECIMAL(5,2)
opl:emp_time a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:decimal ;
	rdfs:label "Employee time" .

# EMENDATE DATE PRIMARY KEY
opl:emp_end_date a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Employee activity end date" .

opl:assigned_to a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range opl:Employee ;
	rdfs:label "Assigned to" .

opl:project_activity a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range opl:ProjAct ;
	rdfs:label "Project activity" .

#####
opl:EmployeeResume a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "EmployeeResume" ;
	rdfs:comment "Employee resume" .

# EMPNO VARCHAR(6) PRIMARY KEY
opl:er_emp_no a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range xsd:string ;
	rdfs:label "Employee number" .

# RESUME_FORMAT VARCHAR(10) PRIMARY KEY
opl:resume_format a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range xsd:string ;
	rdfs:label "Resume format" .

# RESUME VARCHAR(5120)
opl:resume a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range xsd:string ;
	rdfs:label "Resume" .

opl:resume_of a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range opl:Employee ;
	rdfs:label "Resume subject" .

#####
opl:ProjAct a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "ProjAct" ;
	rdfs:comment "Project activity" .

# PROJNO VARCHAR(6) PRIMARY KEY
opl:pa_proj_no a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Project number" .

# ACTNO SMALLINT PRIMARY KEY
opl:pa_act_no a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Activity number" .

# ACSTDATE DATE PRIMARY KEY
opl:ac_st_date a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Activity start date" .

# ACSTAFF DECIMAL(5,2)
opl:ac_staff a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:decimal ;
	rdfs:label "Acstaff" .

# ACENDATE DATE
opl:ac_en_date a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Activity end date" .

opl:project a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range opl:Project ;
	rdfs:label "Project" .

opl:activity a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range opl:Act ;
	rdfs:label "Activity" .

opl:employee_activity_collection a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range opl:EmpProjAct ;
	rdfs:label "Employee activity collection" .

#####
opl:Project a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Project" ;
	rdfs:comment "Project" .

# PROJNO VARCHAR(6) PRIMARY KEY
opl:proj_no a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:string ;
	rdfs:label "Project number" .

# PROJNAME VARCHAR(24)
opl:proj_name a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:string ;
	rdfs:label "Project name" .

# DEPTNO CHAR(3)
opl:is_project_of_department a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range opl:Department ;
	rdfs:label "is project of department" .

# RESPEMP VARCHAR(6)
opl:resp_emp a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range opl:Employee ;
	rdfs:label "Employee responsible" .

# PRSTAFF DECIMAL(5,2)
opl:pr_staff a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:decimal ;
	rdfs:label "PrStaff" .

# PRSTDATE DATE
opl:pr_st_date a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:date ;
	rdfs:label "Project start date" .

# PRENDATE DATE
opl:pr_en_date a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:date ;
	rdfs:label "Project end date" .

# MAJPROJ VARCHAR(6)
opl:maj_proj a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:string ;
	rdfs:label "MajProj" .

opl:proj_activity_collection a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range opl:ProjAct ;
	rdfs:label "Project activities" .

', '', 'http://localhost:8890/schemas/db2sample', 0);

--------------------------

SPARQL
prefix opl: <http://localhost:8890/schemas/db2sample/>

create iri class
<http://localhost:8890/schemas/db2sample/act_iri>
	"http://localhost:8890/db2sample/act/%d#this"
	(
	 in act_no integer not null
	) .

create iri class
<http://localhost:8890/schemas/db2sample/department_iri>
	"http://localhost:8890/db2sample/department/%s#this"
	(
	 in dept_no varchar not null
	) .

create iri class
<http://localhost:8890/schemas/db2sample/employee_iri>
	"http://localhost:8890/db2sample/employee/%s#this"
	(
	 in emp_no varchar not null
	) .

create iri class opl:emp_proj_act_iri using
	function DB.DBA.EMP_PROJ_ACT_IRI (
	 	in emp_no varchar,
	 	in proj_no varchar,
	 	in act_no integer,
	 	in emp_start_date date
		) returns varchar,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_1 (in emp_proj_act_iri varchar)
		returns varchar ,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_2 (in emp_proj_act_iri varchar)
		returns varchar ,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_3 (in emp_proj_act_iri varchar)
		returns integer ,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_4 (in emp_proj_act_iri varchar)
		returns date
	option (bijection, returns
	  "http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this")
	.


create iri class
<http://localhost:8890/schemas/db2sample/employee_resume_iri>
	"http://localhost:8890/db2sample/employee_resume/%s_%s#this"
	(
	 in emp_no varchar not null,
	 in resume_format varchar not null
	) .

create iri class opl:proj_act_iri using
	function DB.DBA.PROJ_ACT_IRI (
		in proj_no varchar,
		in act_no integer,
		in ac_st_date date
		) returns varchar,
	function DB.DBA.PROJ_ACT_IRI_INV_1 (in proj_act_iri varchar)
		returns varchar ,
	function DB.DBA.PROJ_ACT_IRI_INV_2 (in proj_act_iri varchar)
		returns integer ,
	function DB.DBA.PROJ_ACT_IRI_INV_3 (in proj_act_iri varchar)
		returns date
	option (bijection, returns
		"http://localhost:8890/db2sample/proj_act/%s_%s_%s#this")
	.

create iri class
<http://localhost:8890/schemas/db2sample/project_iri>
	"http://localhost:8890/db2sample/project/%s#this"
	(
	 in proj_no varchar not null
	) .
;

SPARQL
prefix opl: <http://localhost:8890/schemas/db2sample/>

alter quad storage virtrdf:DefaultQuadStorage
from DB.db2sample.ACT as act_tbl
from DB.db2sample.DEPARTMENT as dept_tbl
from DB.db2sample.EMPLOYEE as emp_tbl
from DB.db2sample.EMPPROJACT as emp_proj_act_tbl
from DB.db2sample.EMP_RESUME as emp_resume_tbl
from DB.db2sample.PROJACT as proj_act_tbl
from DB.db2sample.PROJECT as project_tbl
{
	create virtrdf:db2sample as
		graph <http://localhost:8890/db2sample>
	{
	opl:act_iri(act_tbl.ACTNO) a opl:Act
		as virtrdf:act_id ;
	opl:act_no act_tbl.ACTNO
		as virtrdf:act_act_no ;
	opl:act_kwd act_tbl.ACTKWD
		as virtrdf:act_act_kwd ;
	opl:act_desc act_tbl.ACTDESC
		as virtrdf:act_act_desc .

	opl:department_iri(dept_tbl.DEPTNO) a opl:Department
		as virtrdf:dept_id ;
	opl:dept_no dept_tbl.DEPTNO
		as virtrdf:dept_dept_no ;
	opl:dept_name dept_tbl.DEPTNAME
		as virtrdf:dept_dept_name ;
	opl:dept_manager opl:employee_iri(dept_tbl.MGRNO)
		as virtrdf:dept_mgr_no ;
	opl:supervising_dept opl:department_iri(dept_tbl.ADMRDEPT)
		as virtrdf:dept_supervising_dept ;
	opl:location dept_tbl.LOCATION
		as virtrdf:dept_location ;
	opl:employee_collection opl:employee_iri(emp_tbl.EMPNO)
		where (^{emp_tbl.}^.WORKDEPT = ^{dept_tbl.}^.DEPTNO)
		as virtrdf:dept_employee_collection ;
	opl:dept_project_collection opl:project_iri(project_tbl.PROJNO)
		where (^{project_tbl.}^.DEPTNO = ^{dept_tbl.}^.DEPTNO)
		as virtrdf:dept_project_collection .

	opl:employee_iri(emp_tbl.EMPNO) a opl:Employee
		as virtrdf:employee_id ;
	opl:emp_no emp_tbl.EMPNO
		as virtrdf:employee_emp_no ;
	opl:first_name emp_tbl.FIRSTNME
		as virtrdf:employee_first_name ;
	opl:middle_initial emp_tbl.MIDINIT
		as virtrdf:employee_middle_initial ;
	opl:last_name emp_tbl.LASTNAME
		as virtrdf:employee_last_name ;
	opl:work_dept opl:department_iri(emp_tbl.WORKDEPT)
		as virtrdf:employee_work_dept ;
	opl:phone_no emp_tbl.PHONENO
		as virtrdf:employee_phone_no ;
	opl:hire_date emp_tbl.HIREDATE
		as virtrdf:employee_hire_date ;
	opl:job emp_tbl.JOB
		as virtrdf:employee_job ;
	opl:education_level emp_tbl.EDLEVEL
		as virtrdf:employee_education_level ;
	opl:gender emp_tbl.SEX
		as virtrdf:employee_gender ;
	opl:date_of_birth emp_tbl.BIRTHDATE
		as virtrdf:employee_date_of_birth ;
	opl:salary emp_tbl.SALARY
		as virtrdf:employee_salary ;
	opl:bonus emp_tbl.BONUS
		as virtrdf:employee_bonus ;
	opl:commission emp_tbl.COMM
		as virtrdf:employee_commission ;
	opl:resume_collection opl:employee_resume_iri(
		emp_resume_tbl.EMPNO,
		emp_resume_tbl.RESUME_FORMAT
		)
		where (^{emp_tbl.}^.EMPNO = ^{emp_resume_tbl.}^.EMPNO)
		as virtrdf:employee_resume_collection ;
	opl:projects_responsible_for_collection
 		opl:project_iri(project_tbl.PROJNO)
		where (^{project_tbl.}^.RESPEMP = ^{emp_tbl.}^.EMPNO)
		as virtrdf:employee_projects_responsible_for_collection ;
	opl:activity_collection opl:emp_proj_act_iri(
		emp_proj_act_tbl.EMPNO,
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		)
		where (^{emp_tbl.}^.EMPNO = ^{emp_proj_act_tbl.}^.EMPNO)
		as virtrdf:employee_activity_collection .

	opl:emp_proj_act_iri(
		emp_proj_act_tbl.EMPNO,
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		) a opl:EmpProjAct
		as virtrdf:empprojact_id ;
	opl:epa_emp_no emp_proj_act_tbl.EMPNO
		as virtrdf:empprojact_emp_no ;
	opl:epa_proj_no emp_proj_act_tbl.PROJNO
		as virtrdf:empprojact_proj_no ;
	opl:epa_act_no emp_proj_act_tbl.ACTNO
		as virtrdf:empprojact_act_no ;
	opl:emp_start_date emp_proj_act_tbl.EMSTDATE
		as virtrdf:empprojact_emp_start_date ;
	opl:emp_time emp_proj_act_tbl.EMPTIME
		as virtrdf:empprojact_emp_time ;
	opl:emp_end_date emp_proj_act_tbl.EMENDATE
		as virtrdf:empprojact_emp_end_date ;
	opl:assigned_to opl:employee_iri(emp_proj_act_tbl.EMPNO)
		as virtrdf:empprojact_assigned_to ;
	opl:project_activity opl:proj_act_iri(
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		)
		as virtrdf:empprojact_project_activity .

	opl:employee_resume_iri(
		emp_resume_tbl.EMPNO,
		emp_resume_tbl.RESUME_FORMAT
		) a opl:EmployeeResume
		as virtrdf:employee_resume_id ;
	opl:er_emp_no emp_resume_tbl.EMPNO
		as virtrdf:employee_resume_emp_no ;
	opl:resume_format emp_resume_tbl.RESUME_FORMAT
		as virtrdf:employee_resume_resume_format ;
	opl:resume emp_resume_tbl.RESUME
		as virtrdf:employee_resume_resume ;
	opl:resume_of opl:employee_iri(emp_resume_tbl.EMPNO)
		as virtrdf:employee_resume_resume_of .

	opl:proj_act_iri(
		proj_act_tbl.PROJNO,
		proj_act_tbl.ACTNO,
		proj_act_tbl.ACSTDATE
		) a opl:ProjAct
		as virtrdf:projact_id;
	opl:pa_proj_no proj_act_tbl.PROJNO
		as virtrdf:projact_proj_no ;
	opl:pa_act_no proj_act_tbl.ACTNO
		as virtrdf:projact_act_no ;
	opl:ac_st_date proj_act_tbl.ACSTDATE
		as virtrdf:projact_ac_st_date ;
	opl:ac_staff proj_act_tbl.ACSTAFF
		as virtrdf:projact_ac_staff ;
	opl:ac_en_date proj_act_tbl.ACENDATE
		as virtrdf:projact_ac_en_date ;
	opl:project opl:project_iri(proj_act_tbl.PROJNO)
		as virtrdf:projact_project ;
	opl:activity opl:act_iri(proj_act_tbl.ACTNO)
		as virtrdf:projact_activity ;
	opl:employee_activity_collection opl:emp_proj_act_iri(
		emp_proj_act_tbl.EMPNO,
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		)
		where (
		^{proj_act_tbl.}^.PROJNO = ^{emp_proj_act_tbl.}^.PROJNO AND
	        ^{proj_act_tbl.}^.ACTNO = ^{emp_proj_act_tbl.}^.ACTNO AND
	        ^{proj_act_tbl.}^.ACSTDATE = ^{emp_proj_act_tbl.}^.EMSTDATE
	        )
		as virtrdf:project_employee_activity_collection .

	opl:project_iri(project_tbl.PROJNO) a opl:Project
		as virtrdf:project_id ;
	opl:proj_no project_tbl.PROJNO
		as virtrdf:project_proj_no ;
	opl:proj_name project_tbl.PROJNAME
		as virtrdf:project_proj_name ;
	opl:is_project_of_department opl:department_iri(project_tbl.DEPTNO)
		as virtrdf:project_is_project_of_department ;
	opl:resp_emp opl:employee_iri(project_tbl.RESPEMP)
		as virtrdf:project_resp_emp ;
	opl:pr_staff project_tbl.PRSTAFF
		as virtrdf:project_pr_staff ;
	opl:pr_st_date project_tbl.PRSTDATE
		as virtrdf:project_pr_st_date ;
	opl:pr_en_date project_tbl.PRENDATE
		as virtrdf:project_pr_en_date ;
	opl:maj_proj project_tbl.MAJPROJ
		as virtrdf:project_maj_proj ;
	opl:proj_activity_collection opl:proj_act_iri(
		proj_act_tbl.PROJNO,
		proj_act_tbl.ACTNO,
		proj_act_tbl.ACSTDATE
		)
		where (^{project_tbl.}^.PROJNO = ^{proj_act_tbl.}^.PROJNO)
		as virtrdf:project_activity_collection .
	} .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'db2sample_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'db2sample_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'db2sample_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/localhost:8890%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'db2sample_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/db2sample%%3E&format=%U',

    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'db2sample_rule_list1',
    1,
    vector (
  	 	'db2sample_rule1',
  	 	'db2sample_rule2'
	  ));


-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/db2sample');

VHOST_DEFINE (
	lpath=>'/db2sample',
	ppath=>'/DAV/db2sample/',
	vsp_user=>'dba',
    	is_dav=>1,
	is_brws=>0,
	opts=>vector ('url_rewrite', 'db2sample_rule_list1')
	);
delete from db.dba.url_rewrite_rule_list where urrl_list like 'db2sample_schema_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'db2sample_schema_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'db2sample_schema_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/localhost:8890%U',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'db2sample_schema_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/db2sample%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'db2sample_schema_rule_list1',
    1,
    vector (
  	 	'db2sample_schema_rule1',
  	 	'db2sample_schema_rule2'
	  ));


-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/db2sample');

VHOST_DEFINE (
	lpath=>'/schemas/db2sample',
	ppath=>'/DAV/schemas_db2sample/',
	vsp_user=>'dba',
    	is_dav=>1,
	is_brws=>0,
	opts=>vector ('url_rewrite', 'db2sample_schema_rule_list1')
	);
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterprinf">
      <title>Informix using demonstration 'Stores' database</title>
<programlisting><![CDATA[
DB..vd_remote_data_source ('inf10_stores_demo_rdf', '', '<uid>','<pwd>');

ATTACH TABLE  "informix"."call_type"  PRIMARY KEY ("call_code")                  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."call_type"  FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."catalog"    PRIMARY KEY ("catalog_num")                AS "stores_demo_rdf"."inf10_stores_demo_rdf"."catalog"    FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."cust_calls" PRIMARY KEY ("customer_num", "call_dtime") AS "stores_demo_rdf"."inf10_stores_demo_rdf"."cust_calls" FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."customer"   PRIMARY KEY ("customer_num")               AS "stores_demo_rdf"."inf10_stores_demo_rdf"."customer"   FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."items"      PRIMARY KEY ("item_num", "order_num")      AS "stores_demo_rdf"."inf10_stores_demo_rdf"."items"      FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."manufact"   PRIMARY KEY ("manu_code")                  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."manufact"   FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."msgs"       PRIMARY KEY ("lang", "number", "message")  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."msgs"       FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."orders"     PRIMARY KEY ("order_num")                  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."orders"     FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."state"      PRIMARY KEY ("code", "sname")              AS "stores_demo_rdf"."inf10_stores_demo_rdf"."state"      FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."stock"      PRIMARY KEY ("stock_num", "manu_code")     AS "stores_demo_rdf"."inf10_stores_demo_rdf"."stock"      FROM 'inf10_stores_demo_rdf';

COMMIT WORK;

GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.items      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.catalog    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.msgs       TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.state      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.orders     TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.stock      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.customer   TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.call_type  TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.manufact   TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.cust_calls TO "SPARQL", "SPARQL_UPDATE";
GRANT SPARQL_UPDATE to "SPARQL";


create function DB.DBA.CUST_CALLS_IRI (in customer_num integer, in call_dtime datetime) returns varchar
{
	declare _call_dtime any;
	_call_dtime := cast(call_dtime as varchar);
	return sprintf('http://localhost:8890/informix/stores_demo/cust_calls/%d_%U#this', customer_num, _call_dtime);
};

create function DB.DBA.CUST_CALLS_IRI_INV_1 (in cust_calls_iri varchar) returns integer
{
	declare parts any;
	parts := sprintf_inverse(cust_calls_iri, 'http://localhost:8890/informix/stores_demo/cust_calls/%d_%U#this', 1);
	if(parts is not null)
	{
		return parts[0];
	}
	return NULL;
};

create function DB.DBA.CUST_CALLS_IRI_INV_2 (in cust_calls_iri varchar) returns datetime
{
	declare parts any;
	parts := sprintf_inverse(cust_calls_iri, 'http://localhost:8890/informix/stores_demo/cust_calls/%d_%U#this', 1);
	if(parts is not null)
	{
		return parts[1];
	}
	return NULL;
};


grant execute on DB.DBA.CUST_CALLS_IRI to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.CUST_CALLS_IRI_INV_1 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.CUST_CALLS_IRI_INV_2 to "SPARQL", "SPARQL_UPDATE";


-------- Create rdfs:Class definitions ----------------------------

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix items:   <http://localhost:8890/schemas/informix/stores_demo/items/> .
@prefix catalog: <http://localhost:8890/schemas/informix/stores_demo/catalog/> .
@prefix stock:   <http://localhost:8890/schemas/informix/stores_demo/stock/> .
@prefix msgs:    <http://localhost:8890/schemas/informix/stores_demo/msgs/> .
@prefix state:   <http://localhost:8890/schemas/informix/stores_demo/state/> .
@prefix orders:  <http://localhost:8890/schemas/informix/stores_demo/orders/> .
@prefix manuf:   <http://localhost:8890/schemas/informix/stores_demo/manufact/> .
@prefix cust:    <http://localhost:8890/schemas/informix/stores_demo/customer/> .
@prefix callt:   <http://localhost:8890/schemas/informix/stores_demo/call_type/> .
@prefix custc:   <http://localhost:8890/schemas/informix/stores_demo/cust_calls/> .



items:Items a rdfs:Class ;
	rdfs:label "Items" ;
	rdfs:comment "Informix SD items table" .

items:item_num a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range xsd:integer ;
	rdfs:label "ITEM NUMBER" .

items:quantity a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range xsd:integer ;
	rdfs:label "QUANTITY" .

items:total_price a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range xsd:decimal ;
	rdfs:label "TOTAL PRICE" .

items:order_num_fk a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range orders:Orders ;
	rdfs:label "ORDER NUMBER" .

items:stock_num_fk a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range stock:Stock ;
	rdfs:label "STOCK NUMBER" .

items:manu_code_fk a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range stock:Stock ;
	rdfs:label "MANUAL CODE" .



catalog:Catalog a rdfs:Class ;
	rdfs:label "Catalog" ;
	rdfs:comment "Informix SD catalog table" .

catalog:manu_code a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:integer ;
	rdfs:label "MANUAL CODE" .

catalog:cat_descr a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:string ;
	rdfs:label "CATALOG DESCRIPTION" .

catalog:cat_picture a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:byte ;
	rdfs:label "CATALOG PICTURE" .

catalog:cat_advert a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:string ;
	rdfs:label "CATALOG ADVERT" .

catalog:catalog_num_fk a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range stock:Stock ;
	rdfs:label "CATALOG NUMBER" .

catalog:stock_num_fk a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range stock:Stock ;
	rdfs:label "STOCK NUMBER" .



msgs:Msgs a rdfs:Class ;
	rdfs:label "Msgs" ;
	rdfs:comment "Informix SD msgs table" .

msgs:lang a rdf:Property ;
	rdfs:domain msgs:Msgs ;
	rdfs:range xsd:string ;
	rdfs:label "LANGUAGE" .

msgs:number a rdf:Property ;
	rdfs:domain msgs:Msgs ;
	rdfs:range xsd:integer ;
	rdfs:label "NUMBER" .

msgs:message a rdf:Property ;
	rdfs:domain msgs:Msgs ;
	rdfs:range xsd:string ;
	rdfs:label "MESSAGE" .



state:State a rdfs:Class ;
	rdfs:label "State" ;
	rdfs:comment "Informix SD state table" .

state:code a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "STATE CODE" .

state:sname a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "STATE NAME" .



orders:Orders a rdfs:Class ;
	rdfs:label "Orders" ;
	rdfs:comment "Informix SD orders table" .

orders:order_num a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:integer ;
	rdfs:label "ORDER NUMBER" .

orders:order_date a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:date ;
	rdfs:label "ORDER DATE" .

orders:ship_instruct a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:string ;
	rdfs:label "SHIPPING INSTRUCTION" .

orders:backlog a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:string ;
	rdfs:label "BACKLOG" .

orders:po_num a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:string ;
	rdfs:label "PURCHASE ORDER NUMBER" .

orders:ship_date a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:date ;
	rdfs:label "SHIPPING DATE" .

orders:ship_weight a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:decimal ;
	rdfs:label "SHIPPING WEIGHT" .

orders:ship_charge a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:decimal ;
	rdfs:label "SHIPPING CHARGE" .

orders:paid_date a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:date ;
	rdfs:label "PAID DATE" .

orders:customer_num_fk a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range cust:Customer ;
	rdfs:label "CUSTOMER NUMBER" .



stock:Stock a rdfs:Class ;
	rdfs:label "Stock" ;
	rdfs:comment "Informix SD stock table" .

stock:stock_num a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:integer ;
	rdfs:label "STOCK NUMBER" .

stock:description a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:string ;
	rdfs:label "DESCRIPTION" .

stock:unit_price a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:decimal ;
	rdfs:label "UNIT PRICE" .

stock:unit a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:string ;
	rdfs:label "UNIT" .

stock:unit_descr a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:decimal ;
	rdfs:label "UNIT DESCRIPTION" .

stock:manu_code_fk a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range manuf:Manufact ;
	rdfs:label "MANUAL CODE" .



cust:Customer a rdfs:Class ;
	rdfs:label "Customer" ;
	rdfs:comment "Informix SD customer table" .

cust:customer_num a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "CUSTOMER NUMBER" .

cust:fname a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "FIRST NAME" .

cust:lname a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "LAST NAME" .

cust:company a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "COMPANY" .

cust:address1 a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "ADDRESS1" .

cust:address2 a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "ADDRESS2" .

cust:city a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "CITY" .

cust:state a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "STATE" .

cust:zipcode a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "ZIP CODE" .

cust:phone a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "PHONE NUMBER" .



callt:Call_type a rdfs:Class ;
	rdfs:label "Call_type" ;
	rdfs:comment "Informix SD call_type table" .

callt:call_code a rdf:Property ;
	rdfs:domain callt:Call_type ;
	rdfs:range xsd:string ;
	rdfs:label "CALL CODE" .

callt:code_descr a rdf:Property ;
	rdfs:domain callt:Call_type ;
	rdfs:range xsd:string ;
	rdfs:label "CODE DESCRIPTION" .



manuf:Manufact a rdfs:Class ;
	rdfs:label "Manufact" ;
	rdfs:comment "Informix SD manufact table" .

manuf:manu_code a rdf:Property ;
	rdfs:domain manuf:Manufact ;
	rdfs:range xsd:string ;
	rdfs:label "MANUFACTURE CODE" .

manuf:manu_name a rdf:Property ;
	rdfs:domain manuf:Manufact ;
	rdfs:range xsd:string ;
	rdfs:label "MANUFACTURE NAME" .

manuf:lead_time a rdf:Property ;
	rdfs:domain manuf:Manufact ;
	rdfs:range xsd:integer ;
	rdfs:label "LEAD TIME" .



custc:Cust_calls a rdfs:Class ;
	rdfs:label "Cust_calls" ;
	rdfs:comment "Informix SD cust_calls table" .

custc:call_dtime a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:datetime ;
	rdfs:label "CALL TIME" .

custc:user_id a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:string ;
	rdfs:label "USER ID" .

custc:call_descr a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:string ;
	rdfs:label "CALL DESCRIPTION" .

custc:res_dtime a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:datetime ;
	rdfs:label "RES TIME" .

custc:res_descr a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:string ;
	rdfs:label "RES DESCRIPTION" .

custc:customer_num_fk a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range cust:Customer ;
	rdfs:label "CUSTOMER NUM" .

custc:call_code_fk a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range callt:Call_type ;
	rdfs:label "CALL CODE" .


', '', 'http://localhost:8890/schemas/informix/stores_demo', 0);



----------- Create IRI Classes -------------




SPARQL

prefix items:   <http://localhost:8890/schemas/informix/stores_demo/items/>
prefix catalog: <http://localhost:8890/schemas/informix/stores_demo/catalog/>
prefix stock:   <http://localhost:8890/schemas/informix/stores_demo/stock/>
prefix msgs:    <http://localhost:8890/schemas/informix/stores_demo/msgs/>
prefix state:   <http://localhost:8890/schemas/informix/stores_demo/state/>
prefix orders:  <http://localhost:8890/schemas/informix/stores_demo/orders/>
prefix manuf:   <http://localhost:8890/schemas/informix/stores_demo/manufact/>
prefix cust:    <http://localhost:8890/schemas/informix/stores_demo/customer/>
prefix callt:   <http://localhost:8890/schemas/informix/stores_demo/call_type/>
prefix custc:   <http://localhost:8890/schemas/informix/stores_demo/cust_calls/>

create iri class items:items_iri
	"http://localhost:8890/informix/stores_demo/items/%d_%d#this"
	(in item_num integer not null, in order_num integer not null) .

create iri class catalog:catalog_iri
	"http://localhost:8890/informix/stores_demo/catalog/%d#this"
    	(in catalog_num integer not null) .

create iri class msgs:msgs_iri
	"http://localhost:8890/informix/stores_demo/msgs/%U_%d_%U#this"
    	(in _lang varchar not null, in number integer not null, in message varchar not null) .

create iri class state:state_iri
	"http://localhost:8890/informix/stores_demo/state/%U#this"
    	(in code varchar not null) .

create iri class orders:orders_iri
	"http://localhost:8890/informix/stores_demo/orders/%d#this"
    	(in order_num integer not null) .

create iri class stock:stock_iri
	"http://localhost:8890/informix/stores_demo/stock/%d_%U#this"
    	(in stock_num integer not null, in manu_code varchar not null) .

create iri class cust:customer_iri
	"http://localhost:8890/informix/stores_demo/customer/%d#this"
    	(in customer_num integer not null) .

create iri class callt:call_type_iri
	"http://localhost:8890/informix/stores_demo/call_type/%U#this"
    	(in call_code varchar not null) .

create iri class manuf:manufact_iri
	"http://localhost:8890/informix/stores_demo/manufact/%U#this"
    	(in manu_code varchar not null) .

create iri class custc:cust_calls_iri using
	function DB.DBA.CUST_CALLS_IRI (in customer_num integer, in call_dtime datetime) returns varchar,
	function DB.DBA.CUST_CALLS_IRI_INV_1 (in cust_calls_iri varchar) returns integer,
        function DB.DBA.CUST_CALLS_IRI_INV_2 (in cust_calls_iri varchar) returns datetime .
;







------------- Create Quad Store ------------------------------------

SPARQL

prefix items:   <http://localhost:8890/schemas/informix/stores_demo/items/>
prefix catalog: <http://localhost:8890/schemas/informix/stores_demo/catalog/>
prefix stock:   <http://localhost:8890/schemas/informix/stores_demo/stock/>
prefix msgs:    <http://localhost:8890/schemas/informix/stores_demo/msgs/>
prefix state:   <http://localhost:8890/schemas/informix/stores_demo/state/>
prefix orders:  <http://localhost:8890/schemas/informix/stores_demo/orders/>
prefix manuf:   <http://localhost:8890/schemas/informix/stores_demo/manufact/>
prefix cust:    <http://localhost:8890/schemas/informix/stores_demo/customer/>
prefix callt:   <http://localhost:8890/schemas/informix/stores_demo/call_type/>
prefix custc:   <http://localhost:8890/schemas/informix/stores_demo/cust_calls/>

alter quad storage virtrdf:DefaultQuadStorage
  from stores_demo_rdf.inf10_stores_demo_rdf.items      as items_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.catalog    as catalog_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.msgs       as msgs_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.state      as state_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.orders     as orders_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.stock      as stock_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.customer   as customer_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.call_type  as call_type_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.manufact   as manufact_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.cust_calls as cust_calls_tbl
{
  create virtrdf:informix_stores_demo as graph <http://localhost:8890/informix/stores_demo>
  {
    items:items_iri (items_tbl.item_num, items_tbl.order_num) a items:Items as virtrdf:items_pk ;
    items:item_num    items_tbl.item_num       as virtrdf:items_item_num ;
    items:order_num   items_tbl.order_num      as virtrdf:items_order_num ;
    items:stock_num   items_tbl.stock_num      as virtrdf:items_stock_num ;
    items:manu_code   items_tbl.manu_code      as virtrdf:items_manu_code ;
    items:quantity    items_tbl.quantity       as virtrdf:items_quantity ;
    items:total_price items_tbl.total_price    as virtrdf:items_total_price ;
    items:from_order  orders:orders_iri (orders_tbl.order_num) where (^{items_tbl.}^.order_num = ^{orders_tbl.}^.order_num) as virtrdf:Items-from_order ;
    items:has_stock   stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) where (^{items_tbl.}^.stock_num = ^{stock_tbl.}^.stock_num and ^{items_tbl.}^.manu_code = ^{stock_tbl.}^.manu_code)  as virtrdf:Item-has_stock .

    catalog:catalog_iri (catalog_tbl.catalog_num) a catalog:Catalog as virtrdf:catalog_num;
    catalog:stock_num   catalog_tbl.stock_num    as virtrdf:catalog_stock_num ;
    catalog:manu_code   catalog_tbl.manu_code    as virtrdf:catalog_manu_code ;
    catalog:cat_descr   catalog_tbl.cat_descr    as virtrdf:catalog_cat_descr ;
    catalog:cat_picture catalog_tbl.cat_picture  as virtrdf:catalog_cat_picture ;
    catalog:cat_advert  catalog_tbl.cat_advert   as virtrdf:catalog_cat_advert ;
    catalog:has_stock   stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) where (^{catalog_tbl.}^.stock_num = ^{stock_tbl.}^.stock_num and ^{catalog_tbl.}^.manu_code = ^{stock_tbl.}^.manu_code)  as virtrdf:Catalog-has_stock .

    msgs:msgs_iri (msgs_tbl.lang, msgs_tbl.number, msgs_tbl.message) a msgs:Msgs as virtrdf:msgs_pk ;
    msgs:lang     msgs_tbl.lang    as virtrdf:msgs_lang ;
    msgs:number   msgs_tbl.number  as virtrdf:msgs_number ;
    msgs:message  msgs_tbl.message as virtrdf:msgs_message .

    state:state_iri (state_tbl.code) a state:State as virtrdf:code ;
    state:code   state_tbl.code   as virtrdf:state_code ;
    state:sname  state_tbl.sname  as virtrdf:state_sname .

    orders:orders_iri (orders_tbl.order_num) a orders:Orders as virtrdf:order_num ;
    orders:order_num     orders_tbl.order_num     as virtrdf:orders_order_num ;
    orders:order_date    orders_tbl.order_date    as virtrdf:orders_order_date ;
    orders:customer_num  orders_tbl.customer_num  as virtrdf:orders_customer_num ;
    orders:ship_instruct orders_tbl.ship_instruct as virtrdf:orders_ship_instruct ;
    orders:backlog       orders_tbl.backlog       as virtrdf:orders_backlog ;
    orders:po_num        orders_tbl.po_num        as virtrdf:orders_po_num ;
    orders:ship_date     orders_tbl.ship_date     as virtrdf:orders_ship_date ;
    orders:ship_weight   orders_tbl.ship_weight   as virtrdf:orders_ship_weight ;
    orders:ship_charge   orders_tbl.ship_charge   as virtrdf:orders_ship_charge ;
    orders:paid_date     orders_tbl.paid_date     as virtrdf:orders_paid_date ;
    orders:has_customer cust:customer_iri (customer_tbl.customer_num) where (^{orders_tbl.}^.customer_num = ^{customer_tbl.}^.customer_num) as virtrdf:Orders-has_customer ;
    orders:has_item     items:items_iri (items_tbl.item_num, items_tbl.order_num) where (^{orders_tbl.}^.order_num = ^{items_tbl.}^.order_num) as virtrdf:Orders-has_item .

    stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) a stock:Stock as virtrdf:stock_pk ;
    stock:stock_num    stock_tbl.stock_num    as virtrdf:stock_stock_num ;
    stock:manu_code    stock_tbl.manu_code    as virtrdf:stock_manu_code ;
    stock:description  stock_tbl.description  as virtrdf:stock_description ;
    stock:unit_price   stock_tbl.unit_price   as virtrdf:stock_unit_price ;
    stock:unit         stock_tbl.unit         as virtrdf:stock_unit ;
    stock:unit_descr   stock_tbl.unit_descr   as virtrdf:stock_unit_descr ;
    stock:manufactured_by manuf:manufact_iri (manufact_tbl.manu_code) where (^{stock_tbl.}^.manu_code = ^{manufact_tbl.}^.manu_code) as virtrdf:Stock-manufactured_by ;
    stock:in_catalog  catalog:catalog_iri (catalog_tbl.catalog_num) where (^{stock_tbl.}^.stock_num = ^{catalog_tbl.}^.stock_num and ^{stock_tbl.}^.manu_code = ^{catalog_tbl.}^.manu_code) as virtrdf:Stock-in_catalog ;
    stock:in_item     items:items_iri (items_tbl.item_num, items_tbl.order_num) where (^{stock_tbl.}^.stock_num = ^{items_tbl.}^.stock_num and ^{stock_tbl.}^.manu_code = ^{items_tbl.}^.manu_code) as virtrdf:Stock-in_items .


    cust:customer_iri (customer_tbl.customer_num) a cust:Customer as virtrdf:customer_num ;
    cust:customer_num  customer_tbl.customer_num  as virtrdf:customer_customer_num ;
    cust:fname         customer_tbl.fname         as virtrdf:customer_fname ;
    cust:lname         customer_tbl.lname         as virtrdf:customer_lname ;
    cust:company       customer_tbl.company       as virtrdf:customer_company ;
    cust:address1      customer_tbl.address1      as virtrdf:customer_address1 ;
    cust:address2      customer_tbl.address2      as virtrdf:customer_address2 ;
    cust:city          customer_tbl.city          as virtrdf:customer_city ;
    cust:state         customer_tbl.state         as virtrdf:customer_state ;
    cust:zipcode       customer_tbl.zipcode       as virtrdf:customer_zipcode ;
    cust:phone         customer_tbl.phone         as virtrdf:customer_phone ;
    cust:placed_order orders:orders_iri (orders_tbl.order_num) where (^{customer_tbl.}^.customer_num = ^{orders_tbl.}^.customer_num) as virtrdf:Customer-placed_order ;
    cust:made_call    custc:cust_calls_iri (cust_calls_tbl.customer_num, cust_calls_tbl.call_dtime ) where (^{customer_tbl.}^.customer_num = ^{cust_calls_tbl.}^.customer_num) as virtrdf:Cust_calls-made_call .

    callt:call_type_iri (call_type_tbl.call_code) a callt:Call_type as virtrdf:call_code ;
    callt:call_code   call_type_tbl.call_code as virtrdf:call_type_call_code ;
    callt:code_descr  call_type_tbl.code_descr as virtrdf:call_type_code_descr ;
    callt:call_is_type  custc:cust_calls_iri (cust_calls_tbl.customer_num, cust_calls_tbl.call_dtime) where (^{call_type_tbl.}^.call_code = ^{cust_calls_tbl.}^.call_code) as virtrdf:Call_type-call_is_type .

    manuf:manufact_iri (manufact_tbl.manu_code) a manuf:Manufact as virtrdf:manu_code ;
    manuf:manu_code     manufact_tbl.manu_code   as virtrdf:manufact_tbl_manu_code ;
    manuf:manu_name     manufact_tbl.manu_name   as virtrdf:manufact_tbl_manu_name ;
    manuf:lead_time     manufact_tbl.lead_time   as virtrdf:manufact_tbl_lead_time ;
    manuf:manufactures stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) where (^{manufact_tbl.}^.manu_code = ^{stock_tbl.}^.manu_code) as virtrdf:Manufact-manufactures .

    custc:cust_calls_iri  (cust_calls_tbl.customer_num, cust_calls_tbl.call_dtime) a custc:Cust_calls as virtrdf:cust_calls_pk ;
    custc:user_id    cust_calls_tbl.user_id      as virtrdf:cust_calls_user_id ;
    custc:call_code  cust_calls_tbl.call_code    as virtrdf:cust_calls_call_code ;
    custc:call_descr cust_calls_tbl.call_descr   as virtrdf:cust_calls_call_descr ;
    custc:res_dtime  cust_calls_tbl.res_dtime    as virtrdf:cust_calls_res_dtime ;
    custc:res_descr  cust_calls_tbl.res_descr    as virtrdf:cust_calls_res_descr ;
    custc:made_by_customer cust:customer_iri   (customer_tbl.customer_num) where (^{cust_calls_tbl.}^.customer_num = ^{customer_tbl.}^.customer_num) as virtrdf:Cust_calls-made_by_customer ;
    custc:is_call_type     callt:call_type_iri (call_type_tbl.call_code)   where (^{cust_calls_tbl.}^.call_code    = ^{call_type_tbl.}^.call_code)   as virtrdf:Cust_calls-is_call_type .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'informix_sd_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'informix_sd_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'informix_sd_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'informix_sd_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/informix/stores_demo%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'informix_sd_rule_list1',
    1,
    vector (
  	 	'informix_sd_rule1',
  	 	'informix_sd_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/informix/stores_demo');

VHOST_DEFINE (
	lpath=>'/informix/stores_demo',
	ppath=>'/DAV/informix/stores_demo/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'informix_sd_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'informix_sd_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'informix_sd_schemas_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'informix_sd_schemas_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'informix_sd_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/informix/stores_demo%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'informix_sd_schemas_rule_list1',
    1,
    vector (
  	 	'informix_sd_schemas_rule1',
  	 	'informix_sd_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/informix/stores_demo');

VHOST_DEFINE (
	lpath=>'/schemas/informix/stores_demo',
	ppath=>'/DAV/schemas/informix/stores_demo/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'informix_sd_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('items',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/items/', 2);
DB.DBA.XML_SET_NS_DECL ('catalog', 'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/catalog/', 2);
DB.DBA.XML_SET_NS_DECL ('stock',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/stock/', 2);
DB.DBA.XML_SET_NS_DECL ('msgs',    'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/msgs/', 2);
DB.DBA.XML_SET_NS_DECL ('state',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/state/', 2);
DB.DBA.XML_SET_NS_DECL ('orders',  'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/orders/', 2);
DB.DBA.XML_SET_NS_DECL ('manuf',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/manufact/', 2);
DB.DBA.XML_SET_NS_DECL ('cust',    'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/customer/', 2);
DB.DBA.XML_SET_NS_DECL ('callt',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/call_type/', 2);
DB.DBA.XML_SET_NS_DECL ('custc',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/cust_calls/', 2);
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterpringr">
      <title>Ingres using demonstration 'Tutorial' database</title>
<programlisting><![CDATA[
-- Setup script for RDF views of Ingres R3 Tutorial Sample Database --

DB..vd_remote_data_source ('ingiima-tut', '', '<uid>','<pwd>');

ATTACH TABLE  "ingres"."book_list"      PRIMARY KEY ("book_no")              AS "TUT"."ingiima"."book_list"      FROM 'ingiima-tut';
ATTACH TABLE  "ingres"."book_orders"      PRIMARY KEY ("order_no")              AS "TUT"."ingiima"."book_orders"      FROM 'ingiima-tut';
ATTACH TABLE  "ingres"."cust_info"      PRIMARY KEY ("cust_no")              AS "TUT"."ingiima"."cust_info"      FROM 'ingiima-tut';
ATTACH TABLE  "ingres"."cust_orders"      PRIMARY KEY ("order_no")              AS "TUT"."ingiima"."cust_orders"      FROM 'ingiima-tut';

COMMIT WORK;

GRANT SELECT ON TUT.ingiima.book_list TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON TUT.ingiima.book_orders TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON TUT.ingiima.cust_info TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON TUT.ingiima.cust_orders TO "SPARQL", "SPARQL_UPDATE";

-------------------------------------------------------------------

-------- Create rdfs:Class definitions ----------------------------

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix tut: <http://localhost:8890/schemas/ingrestut/> .

tut:book_list a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "book_list" ;
	rdfs:comment "Ingres Tutorial Database book_list table" .

tut:book_no a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:integer ;
	rdfs:label "Book No" .

tut:title a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label "Title" .

tut:author a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label "Author" .

tut:price a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:money;
	rdfs:label "Price" .

tut:category a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label "Category" .

tut:stock a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:integer ;
	rdfs:label "Stock" .

tut:dist_no a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:integer ;
	rdfs:label "Dist No" .

tut:book_orders a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "Book Orders" ;
	rdfs:comment "Ingres Tutorial Database book_orders table" .

tut:order_no a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:integer ;
         rdfs:label "Order No" .

tut:book_no_no a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range tut:book_list ;
         rdfs:label "Book No" .

tut:sale_price a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:money ;
         rdfs:label "Sale Price" .

tut:quantity a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:integer ;
         rdfs:label "Quantity" .

tut:extension a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:money ;
         rdfs:label "Extension" .

tut:cust_info a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "Customer Information" ;
	rdfs:comment "Ingres Tutorial Database cust_info table" .

tut:cust_no a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:integer ;
         rdfs:label "Customer No" .

tut:name a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string ;
         rdfs:label "Name" .

tut:company a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string ;
         rdfs:label "Company" .

tut:street a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "Street" .

tut:city a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "City" .

tut:state a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "State" .

tut:city a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "City" .

tut:state a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "State" .

tut:zip a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "Zip Code" .

tut:card_no a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "Card No" .

tut:exp_date a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:date;
         rdfs:label "Expire Date" .

tut:ship_to a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label "Ship To" .

tut:cust_orders a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "Customer Orders" ;
	rdfs:comment "Ingres Tutorial Database cust_orders table" .

tut:order_no a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range tut:book_orders ;
         rdfs:label "Order No" .

tut:book_no a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range tut:cust_info ;
         rdfs:label "Book No" .

tut:order_date a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range xsd:date ;
         rdfs:label "Order Date" .

tut:status a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range xsd:string ;
         rdfs:label "Status" .

tut:order_total a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range xsd:money ;
         rdfs:label "Order Total" .
', '', 'http://localhost:8890/schemas/ingrestut', 0);

---------------------------------------------------------------

----------- Create IRI Classes -------------

SPARQL

	create iri class <http://localhost:8890/schemas/ingrestut/book_list_iri>
	"http://^{URIQADefaultHost}^/ingrestut/book_list/%d#this"
    	(in book_no integer not null) .

	create iri class <http://localhost:8890/schemas/ingrestut/book_orders_iri>
	"http://^{URIQADefaultHost}^/ingrestut/book_orders/%d_%d#this"
	 (in order_no integer not null, in book_no integer not null ) .

	create iri class <http://localhost:8890/schemas/ingrestut/cust_info_iri>
	"http://^{URIQADefaultHost}^/ingrestut/cust_info/%d#this"
    	(in cust_no integer not null) .

	create iri class <http://localhost:8890/schemas/ingrestut/cust_orders_iri>
	"http://^{URIQADefaultHost}^/ingrestut/cust_orders/%d#this"
    	(in order_no integer not null) .

	;

--------------------------------------------------------------------

------------- Create Quad Store ------------------------------------

SPARQL

prefix tut:	<http://localhost:8890/schemas/ingrestut/>

alter quad storage virtrdf:DefaultQuadStorage
  from TUT.ingiima.book_list as book_list_tbl
  from TUT.ingiima.book_orders as book_orders_tbl
  from TUT.ingiima.cust_info as cust_info_tbl
  from TUT.ingiima.cust_orders as cust_orders_tbl
{
  create virtrdf:ingrestut as
      graph <http://localhost:8890/ingrestut>
  {
        tut:book_list_iri(book_list_tbl.book_no) a tut:book_list
               as virtrdf:book_list_book_no ;
        tut:title book_list_tbl.title
	     as virtrdf:book_list_title;
        tut:author book_list_tbl.author
              as virtrdf:book_list_author;
        tut:price book_list_tbl.price
              as virtrdf:book_list_price;
        tut:category book_list_tbl.category
              as virtrdf:book_list_category;
        tut:stock book_list_tbl.stock
              as virtrdf:book_list_stock;
        tut:dist_no book_list_tbl.dist_no
              as virtrdf:book_list_dist_no .

	tut:book_orders_iri(book_orders_tbl.order_no, book_orders_tbl.book_no) a tut:book_orders
		as virtrdf:book_orders_pk;
	tut:order_no book_orders_tbl.order_no
		as virtrdf:book_orders_order_no;
	tut:book_no tut:book_list_iri(book_list_tbl.book_no)
		where(^{book_orders_tbl.}^.book_no = ^{book_list_tbl.}^.book_no)
		as virtrdf:book_orders_book_no;
	tut:sale_price book_orders_tbl.sale_price
		as virtrdf:book_orders_sale_price;
	tut:quantity book_orders_tbl.quantity
		as virtrdf:book_orders_quantity;
	tut:extension book_orders_tbl.extension
		as virtrdf:book_orders_extension .

 	tut:cust_info_iri(cust_info_tbl.cust_no) a tut:cust_info
		as virtrdf:cust_info_cust_no;
	tut:name cust_info_tbl.name
		as virtrdf:cust_info_name;
	tut:company cust_info_tbl.company
		as virtrdf:cust_info_company;
	tut:street cust_info_tbl.street
		as virtrdf:cust_info_street;
	tut:city cust_info_tbl.city
		as virtrdf:cust_info_city;
	tut:state cust_info_tbl.state
		as virtrdf:cust_info_state;
	tut:zip cust_info_tbl.zip
		as virtrdf:cust_info_zip;
	tut:card_no cust_info_tbl.card_no
		as virtrdf:cust_info_card_no;
	tut:exp_date cust_info_tbl.exp_date
		as virtrdf:cust_info_exp_date;
	tut:ship_to cust_info_tbl.ship_to
		as virtrdf:cust_info_ship_to .

 	tut:cust_orders_iri(cust_orders_tbl.order_no) a tut:cust_orders
		as virtrdf:cust_orders_order_no;

	tut:cust_no tut:cust_info_iri(cust_info_tbl.cust_no)
		where (^{cust_orders_tbl.}^.cust_no = ^{cust_info_tbl.}^.cust_no)
		as virtrdf:cust_orders_cust_no;
	tut:order_date cust_orders_tbl.order_date
		as virtrdf:cust_orders_order_date;
	tut:status cust_orders_tbl.status
		as virtrdf:cust_orders_status;
	tut:order_total cust_orders_tbl.order_total
		as virtrdf:cust_orders_order_total   .
  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'ingrestut_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'ingrestut_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ingrestut_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ingrestut_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/ingrestut%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ingrestut_rule_list1',
    1,
    vector (
  	 	'ingrestut_rule1',
  	 	'ingrestut_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/ingrestut');

VHOST_DEFINE (
	lpath=>'/ingrestut',
	ppath=>'/DAV/ingrestut/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'ingrestut_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'ingres_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'ingres_schemas_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ingres_schemas_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ingres_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/ingrestut%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ingres_schemas_rule_list1',
    1,
    vector (
  	 	'ingres_schemas_rule1',
  	 	'ingres_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/ingrestut');

VHOST_DEFINE (
	lpath=>'/schemas/ingrestut',
	ppath=>'/DAV/schemas/ingrestut/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'ingres_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('tut', 'http://^{URIQADefaultHost}^/schemas/ingrestut/', 2);
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterprs89">
      <title>Progress (SQL-89) using demonstration 'iSports' database</title>
<programlisting><![CDATA[
ATTACH TABLE  "ISPORTS_RDF"."Customer" PRIMARY KEY ("Cust-Num")
AS "isports_rdf"."pro91_isports_rdf"."Customer"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Invoice" PRIMARY KEY ("Invoice-Num")
AS "isports_rdf"."pro91_isports_rdf"."Invoice"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Item" PRIMARY KEY ("Item-num")
AS "isports_rdf"."pro91_isports_rdf"."Item"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Local-Default" PRIMARY KEY ("Country")
AS "isports_rdf"."pro91_isports_rdf"."Local-Default"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Order" PRIMARY KEY ("Order-num")
AS "isports_rdf"."pro91_isports_rdf"."Order"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Order-Line"  PRIMARY KEY ("Order-num", "Line-num")
AS "isports_rdf"."pro91_isports_rdf"."Order-Line"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Ref-Call" PRIMARY KEY ("Call-Num")
AS "isports_rdf"."pro91_isports_rdf"."Ref-Call"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Salesrep" PRIMARY KEY ("Sales-Rep")
AS "isports_rdf"."pro91_isports_rdf"."Salesrep"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."State" PRIMARY KEY ("State")
AS "isports_rdf"."pro91_isports_rdf"."State"
FROM 'pro91_isports_rdf';

COMMIT WORK;

GRANT SELECT ON isports_rdf.pro91_isports_rdf.Customer        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Order"         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.Item            TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Order-Line"    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.Invoice         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Local-Default" TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Ref-Call"      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.Salesrep        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.State           TO "SPARQL", "SPARQL_UPDATE";

GRANT SPARQL_UPDATE to "SPARQL";

CREATE VIEW isports_rdf.pro91_isports_rdf.VCustomer      AS SELECT "Cust-Num" AS Cust_Num, Name, Address, Address2, City, State, Country, Phone, Contact, "Sales-Rep" AS Sales_Rep, Comments, "Credit-Limit" AS Credit_Limit, Balance, Terms, Discount, "Postal-Code" AS Postal_Code FROM "isports_rdf"."pro91_isports_rdf"."Customer";
CREATE VIEW isports_rdf.pro91_isports_rdf.VOrder         AS SELECT "Order-num" AS Order_num, "Cust-Num" AS Cust_Num, "Order-Date" AS Order_Date, "Ship-Date" AS Ship_Date, "Promise-Date" AS Promise_Date, Carrier, Instructions, PO, Terms, "Sales-Rep" AS Sales_Rep FROM isports_rdf.pro91_isports_rdf."Order";
CREATE VIEW isports_rdf.pro91_isports_rdf.VItem          AS SELECT "Item-num" AS Item_num, "Item-Name" AS Item_Name, "Cat-Page" AS Cat_Page, Price, "Cat-Description" AS Cat_Description, "On-hand" AS On_hand, Allocated, "Re-Order" AS Re_Order, "On-Order" AS On_Order FROM isports_rdf.pro91_isports_rdf.Item;
CREATE VIEW isports_rdf.pro91_isports_rdf.VOrder_Line    AS SELECT "Order-num" AS Order_num, "Line-num" AS Line_num, "Item-num" AS Item_num, Price, Qty, Discount, "Extended-Price" AS Extended_Price, Backorder FROM isports_rdf.pro91_isports_rdf."Order-Line";
CREATE VIEW isports_rdf.pro91_isports_rdf.VInvoice       AS SELECT "Invoice-Num" AS Invoice_Num, "Cust-Num" AS Cust_Num, "Invoice-Date" AS Invoice_Date, Amount, "Total-Paid" AS Total_Paid, Adjustment, "Order-Num" AS Order_Num, "Ship-Charge" AS Ship_Charge FROM isports_rdf.pro91_isports_rdf.Invoice;
CREATE VIEW isports_rdf.pro91_isports_rdf.VLocal_Default AS SELECT Country, "Region1-Label" AS Region1_Label, "Region2-Label" AS Region2_Label, "Postal-Label" AS Postal_Label, "Postal-Format" AS Postal_Format, "Tel-Format" AS Tel_Format, "Date-Format" AS Date_Format, "Currency-Symbol" AS Currency_Symbol FROM isports_rdf.pro91_isports_rdf."Local-Default";
CREATE VIEW isports_rdf.pro91_isports_rdf.VRef_Call      AS SELECT "Call-Num" AS Call_Num, "Cust-Num" AS Cust_Num, "Call-Date" AS Call_Date, "Sales-Rep" AS Sales_Rep, Parent, Txt FROM isports_rdf.pro91_isports_rdf."Ref-Call";
CREATE VIEW isports_rdf.pro91_isports_rdf.VSalesrep      AS SELECT "Rep-Name" AS Rep_Name, Region, "Sales-Rep" AS Sales_Rep, "Month-Quota@1" AS Month_Quota_1, "Month-Quota@2" AS Month_Quota_2, "Month-Quota@3" AS Month_Quota_3, "Month-Quota@4" AS Month_Quota_4, "Month-Quota@5" AS Month_Quota_5, "Month-Quota@6" AS Month_Quota_6, "Month-Quota@7" AS Month_Quota_7, "Month-Quota@8" AS Month_Quota_8, "Month-Quota@9" AS Month_Quota_9, "Month-Quota@10" AS Month_Quota_10, "Month-Quota@11" AS Month_Quota_11, "Month-Quota@12" AS Month_Quota_12 FROM isports_rdf.pro91_isports_rdf.Salesrep;
CREATE VIEW isports_rdf.pro91_isports_rdf.VState         AS SELECT State, "State-Name" AS State_Name, Region FROM isports_rdf.pro91_isports_rdf.State;

GRANT SELECT ON isports_rdf.pro91_isports_rdf.VCustomer      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VOrder         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VItem          TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VOrder_Line    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VInvoice       TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VLocal_Default TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VRef_Call      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VSalesrep      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VState         TO "SPARQL", "SPARQL_UPDATE";


-------- Create rdfs:Class definitions ----------------------------

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/> .
@prefix order:        <http://localhost:8890/schemas/progress/isports/order/> .
@prefix item:         <http://localhost:8890/schemas/progress/isports/item/> .
@prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/> .
@prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/> .
@prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/> .
@prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/> .
@prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/> .
@prefix state:        <http://localhost:8890/schemas/progress/isports/state/> .



customer:Customer a rdfs:Class ;
	rdfs:label "Customer" ;
	rdfs:comment "Progress isports Customer table" .

customer:Cust-Num a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

customer:Name a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Name" .

customer:Address a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address" .

customer:Address2 a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address2" .

customer:City a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "City" .

customer:State a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

customer:Country a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

customer:Phone a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Phone" .

customer:Contact a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Contact" .

customer:Sales-Rep a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

customer:Comments a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Comments" .

customer:Credit-Limit a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Credit-Limit" .

customer:Balance a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Balance" .

customer:Terms a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

customer:Discount a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

customer:Postal-Code a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Code" .



order:Order a rdfs:Class ;
	rdfs:label "Order" ;
	rdfs:comment "Progress isports Order table" .

order:Order-num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

order:Cust-Num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

order:Order-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Order-Date" .

order:Ship-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Ship-Date" .

order:Promise-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Promise-Date" .

order:Carrier a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Carrier" .

order:Instructions a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Instructions" .

order:PO a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "PO" .

order:Terms a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

order:Sales-Rep a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .



item:Item a rdfs:Class ;
	rdfs:label "Item" ;
	rdfs:comment "Progress isports Item table" .

item:Item-num a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

item:Item-Name a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Item-Name" .

item:Cat-Page a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Cat-Page" .

item:Price a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

item:Cat-Description a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Cat-Description" .

item:On-hand a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-hand" .

item:Allocated a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Allocated" .

item:Re-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Re-Order" .

item:On-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-Order" .



orderline:Order-Line a rdfs:Class ;
	rdfs:label "Order-Line" ;
	rdfs:comment "Progress isports Order-Line table" .

orderline:Order-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

orderline:Line-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Line-num" .

orderline:Item-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

orderline:Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

orderline:Qty a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Qty" .

orderline:Discount a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

orderline:Extended-Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Extended-Price" .

orderline:Backorder a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:byte ;
	rdfs:label "Backorder" .



invoice:Invoice a rdfs:Class ;
	rdfs:label "Invoice" ;
	rdfs:comment "Progress isports Invoice table" .

invoice:Invoice-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Invoice-Num" .

invoice:Cust-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

invoice:Invoice-Date a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:date ;
	rdfs:label "Invoice-Date" .

invoice:Amount a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Amount" .

invoice:Total-Paid a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Total-Paid" .

invoice:Adjustment a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Adjustment" .

invoice:Order-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-Num" .

invoice:Ship-Charge a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Ship-Charge" .



localdefault:Local-Default a rdfs:Class ;
	rdfs:label "Local-Default" ;
	rdfs:comment "Progress isports Local-Default table" .

localdefault:Country a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

localdefault:Region1-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region1-Label" .

localdefault:Region2-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region2-Label" .

localdefault:Postal-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Label" .

localdefault:Postal-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Format" .

localdefault:Tel-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Tel-Format" .

localdefault:Date-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Date-Format" .

localdefault:Currency-Symbol a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Currency-Symbol" .



refcall:Ref-Call a rdfs:Class ;
	rdfs:label "Ref-Call" ;
	rdfs:comment "Progress isports Ref-Call table" .

refcall:Call-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Call-Num" .

refcall:Cust-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

refcall:Call-Date a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:date ;
	rdfs:label "Call-Date" .

refcall:Sales-Rep a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

refcall:Parent a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Parent" .

refcall:Txt a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Txt" .



salesrep:Salesrep a rdfs:Class ;
	rdfs:label "Salesrep" ;
	rdfs:comment "Progress isports Salesrep table" .

salesrep:Sales-Rep a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

salesrep:Rep-Name a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Rep-Name" .

salesrep:Region a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

salesrep:Month-Quota-1 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@1" .

salesrep:Month-Quota-2 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@2" .

salesrep:Month-Quota-3 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@3" .

salesrep:Month-Quota-4 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@4" .

salesrep:Month-Quota-5 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@5" .

salesrep:Month-Quota-6 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@6" .

salesrep:Month-Quota-7 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@7" .

salesrep:Month-Quota-8 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@8" .

salesrep:Month-Quota-9 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@9" .

salesrep:Month-Quota-10 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@10" .

salesrep:Month-Quota-11 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@11" .

salesrep:Month-Quota-12 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@12" .



state:State a rdfs:Class ;
	rdfs:label "State" ;
	rdfs:comment "Progress isports State table" .

state:State_ a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

state:State-Name a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State-Name" .

state:Region a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

', '', 'http://localhost:8890/schemas/progress/isports', 0);



----------- Create IRI Classes -------------




SPARQL

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

create iri class customer:customer_iri
	"http://localhost:8890/progress/isports/customer/%d#this"
	(in Cust_Num integer not null) .

create iri class order:order_iri
	"http://localhost:8890/progress/isports/order/%d#this"
	(in Order_Num integer not null) .

create iri class item:item_iri
	"http://localhost:8890/progress/isports/item/%d#this"
	(in Item_num integer not null) .

create iri class orderline:order-line_iri
	"http://localhost:8890/progress/isports/order-line/%d_%d#this"
	(in Order_num integer not null, in Line_num integer not null) .

create iri class invoice:invoice_iri
	"http://localhost:8890/progress/isports/invoice/%d#this"
	(in Invoice_Num integer not null) .

create iri class localdefault:local-default_iri
	"http://localhost:8890/progress/isports/local-default/%U#this"
	(in Country varchar not null) .

create iri class refcall:ref-call_iri
	"http://localhost:8890/progress/isports/ref-call/%U#this"
	(in Call_Num varchar not null) .

create iri class salesrep:salesrep_iri
	"http://localhost:8890/progress/isports/salesrep/%U#this"
	(in Sales_Rep varchar not null) .

create iri class state:state_iri
	"http://localhost:8890/progress/isports/state/%U#this"
	(in State varchar not null) .

;







------------- Create Quad Store ------------------------------------

SPARQL

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

alter quad storage virtrdf:DefaultQuadStorage
  from isports_rdf.pro91_isports_rdf.VCustomer      as Customer_tbl
  from isports_rdf.pro91_isports_rdf.VOrder         as Order_tbl
  from isports_rdf.pro91_isports_rdf.VItem          as Item_tbl
  from isports_rdf.pro91_isports_rdf.VOrder_Line    as Order_Line_tbl
  from isports_rdf.pro91_isports_rdf.VInvoice       as Invoice_tbl
  from isports_rdf.pro91_isports_rdf.VRef_Call      as Ref_Call_tbl
  from isports_rdf.pro91_isports_rdf.VRef_Call      as Ref_Call_tbl_1
  from isports_rdf.pro91_isports_rdf.VLocal_Default as Local_Default_tbl
  from isports_rdf.pro91_isports_rdf.VSalesrep      as Salesrep_tbl
  from isports_rdf.pro91_isports_rdf.VState         as State_tbl
{
  create virtrdf:progress_isports as graph <http://localhost:8890/progress/isports>
  {
    customer:customer_iri (Customer_tbl.Cust_Num) a customer:Customer as virtrdf:customer_pk ;
    customer:Cust-Num     Customer_tbl.Cust_Num     as virtrdf:Customer_cust-num ;
    customer:Name         Customer_tbl.Name         as virtrdf:Customer_name ;
    customer:Address      Customer_tbl.Address      as virtrdf:Customer_address ;
    customer:Address2     Customer_tbl.Address2     as virtrdf:Customer_address2 ;
    customer:City         Customer_tbl.City         as virtrdf:Customer_city ;
    customer:State        Customer_tbl.State        as virtrdf:Customer_state ;
    customer:Country      Customer_tbl.Country      as virtrdf:Customer_country ;
    customer:Phone        Customer_tbl.Phone        as virtrdf:Customer_phone ;
    customer:Contact      Customer_tbl.Contact      as virtrdf:Customer_contact ;
    customer:Sales-Rep    Customer_tbl.Sales_Rep    as virtrdf:Customer_sales_rep ;
    customer:Comments     Customer_tbl.Comments     as virtrdf:Customer_comments ;
    customer:Credit-Limit Customer_tbl.Credit_Limit as virtrdf:Customer_credit-limit ;
    customer:Balance      Customer_tbl.Balance      as virtrdf:Customer_balance ;
    customer:Terms        Customer_tbl.Terms        as virtrdf:Customer_terms ;
    customer:Discount     Customer_tbl.Discount     as virtrdf:Customer_discount ;
    customer:Postal-Code  Customer_tbl.Postal_Code  as virtrdf:Customer_postal-code ;
    customer:from_state        state:state_iri (State_tbl.State)                           where ( ^{Customer_tbl.}^.State     = ^{State_tbl.}^.State )           as virtrdf:Customer_from_state ;
    customer:has_sales_rep     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)              where ( ^{Customer_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )    as virtrdf:Customer_has_sales_rep ;
    customer:has_local_default localdefault:local-default_iri (Local_Default_tbl.Country)  where ( ^{Customer_tbl.}^.Country   = ^{Local_Default_tbl.}^.Country ) as virtrdf:Customer_has_local_default ;
    customer:placed_order      order:order_iri (Order_tbl.Order_num)                       where ( ^{Customer_tbl.}^.Cust_Num  = ^{Order_tbl.}^.Cust_Num )        as virtrdf:Customer_placed_order ;
    customer:has_invoice       invoice:invoice_iri (Invoice_tbl.Invoice_Num)               where ( ^{Customer_tbl.}^.Cust_Num  = ^{Invoice_tbl.}^.Cust_Num )      as virtrdf:Customer_has_invoice ;
    customer:ref_call          refcall:ref-call_iri (Ref_Call_tbl.Call_Num)                where ( ^{Customer_tbl.}^.Cust_Num  = ^{Ref_Call_tbl.}^.Cust_Num )     as virtrdf:Customer_ref-call .

    order:order_iri (Order_tbl.Order_num) a order:Order as virtrdf:order_pk ;
    order:Order-num    Order_tbl.Order_num    as virtrdf:Order_order-num ;
    order:Cust-Num     Order_tbl.Cust_Num     as virtrdf:Order_cust_num ;
    order:Order-Date   Order_tbl.Order_Date   as virtrdf:Order_order-date ;
    order:Ship-Date    Order_tbl.Ship_Date    as virtrdf:Order_ship-date ;
    order:Promise-Date Order_tbl.Promise_Date as virtrdf:Order_promise-date ;
    order:Carrier      Order_tbl.Carrier      as virtrdf:Order_carrier ;
    order:Instructions Order_tbl.Instructions as virtrdf:Order_instructions ;
    order:PO           Order_tbl.PO           as virtrdf:Order_po ;
    order:Terms        Order_tbl.Terms        as virtrdf:Order_terms ;
    order:placed_by    customer:customer_iri (Customer_tbl.Cust_Num)                                 where ( ^{Order_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )    as virtrdf:Order_placed_by ;
    order:Sales-Rep    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)                                where ( ^{Order_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )   as virtrdf:Order_sales_rep ;
    order:invoiced_on  invoice:invoice_iri (Invoice_tbl.Invoice_Num)                                 where ( ^{Order_tbl.}^.Order_num = ^{Invoice_tbl.}^.Order_Num )    as virtrdf:Order_invoiced_on ;
    order:has_lines    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Order_tbl.}^.Order_num = ^{Order_Line_tbl.}^.Order_num ) as virtrdf:Order_has_lines .

    item:item_iri (Item_tbl.Item_num) a item:Item as virtrdf:item_pk ;
    item:Item-num        Item_tbl.Item_num        as virtrdf:item_item-num ;
    item:Item-Name       Item_tbl.Item_Name       as virtrdf:Item_item-Name ;
    item:Cat-Page        Item_tbl.Cat_Page        as virtrdf:Item_cat-page ;
    item:Price           Item_tbl.Price           as virtrdf:Item_price ;
    item:Cat-Description Item_tbl.Cat_Description as virtrdf:Item_cat-description ;
    item:On-hand         Item_tbl.On_hand         as virtrdf:Item_on-hand ;
    item:Allocated       Item_tbl.Allocated       as virtrdf:Item_allocated ;
    item:Re-Order        Item_tbl.Re_Order        as virtrdf:Item_re-order ;
    item:On-Order        Item_tbl.On_Order        as virtrdf:Item_on-order ;
    item:order_line  orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Item_tbl.}^.Item_num  = ^{Order_Line_tbl.}^.Item_num )   as virtrdf:Item_order_line .

    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num) a orderline:Order-Line as virtrdf:order-line_pk ;
    orderline:Line-num       Order_Line_tbl.Line_num       as virtrdf:Order-Line_line-num ;
    orderline:Price          Order_Line_tbl.Price          as virtrdf:Order-Line_price ;
    orderline:Qty            Order_Line_tbl.Qty            as virtrdf:Order-Line_qty ;
    orderline:Discount       Order_Line_tbl.Discount       as virtrdf:Order-Line_discount ;
    orderline:Extended-Price Order_Line_tbl.Extended_Price as virtrdf:Order-Line_extended-price ;
    orderline:Backorder      Order_Line_tbl.Backorder      as virtrdf:Order-Line_backorder ;
    orderline:Order-num  order:order_iri (Order_tbl.Order_num)  where ( ^{Order_Line_tbl.}^.Order_num = ^{Order_tbl.}^.Order_num ) as virtrdf:Order_Line_order_num ;
    orderline:Item-num   item:item_iri (Item_tbl.Item_num)      where ( ^{Order_Line_tbl.}^.Item_num  = ^{Item_tbl.}^.Item_num )   as virtrdf:Order_Line_item_num .

    invoice:invoice_iri (Invoice_tbl.Invoice_Num) a invoice:Invoice as virtrdf:invoice_pk ;
    invoice:Invoice-Num  Invoice_tbl.Invoice_Num  as virtrdf:Invoice_invoice-num ;
    invoice:Cust-Num     Invoice_tbl.Cust_Num    as virtrdf:Invoice_cust_num ;
    invoice:Invoice-Date Invoice_tbl.Invoice_Date as virtrdf:Invoice_invoice-date ;
    invoice:Amount       Invoice_tbl.Amount       as virtrdf:Invoice_amount ;
    invoice:Total-Paid   Invoice_tbl.Total_Paid   as virtrdf:Invoice_total-paid ;
    invoice:Adjustment   Invoice_tbl.Adjustment   as virtrdf:Invoice_adjustment ;
    invoice:Order-Num    Invoice_tbl.Order_Num    as virtrdf:Invoice_order-num ;
    invoice:Ship-Charge  Invoice_tbl.Ship_Charge  as virtrdf:Invoice_ship-charge ;
    invoice:invoiced_to  customer:customer_iri (Customer_tbl.Cust_Num)  where ( ^{Invoice_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num ) as virtrdf:Invoice_invoiced_to ;
    invoice:Order-Num    order:order_iri (Order_tbl.Order_num)          where ( ^{Invoice_tbl.}^.Order_Num = ^{Order_tbl.}^.Order_num )   as virtrdf:Invoice_order_num .

    localdefault:local-default_iri (Local_Default_tbl.Country) a localdefault:Local-Default as virtrdf:local-default_pk ;
    localdefault:Country         Local_Default_tbl.Country as virtrdf:local-default_country ;
    localdefault:Region1-Label   Local_Default_tbl.Region1_Label   as virtrdf:Local-Default_region1-label ;
    localdefault:Region2-Label   Local_Default_tbl.Region2_Label   as virtrdf:Local-Default_region2-label ;
    localdefault:Postal-Label    Local_Default_tbl.Postal_Label    as virtrdf:Local-Default_postal-label ;
    localdefault:Postal-Format   Local_Default_tbl.Postal_Format   as virtrdf:Local-Default_postal-format ;
    localdefault:Tel-Format      Local_Default_tbl.Tel_Format      as virtrdf:Local-Default_tel-format ;
    localdefault:Date-Format     Local_Default_tbl.Date_Format     as virtrdf:Local-Default_date-format ;
    localdefault:Currency-Symbol Local_Default_tbl.Currency_Symbol as virtrdf:Local-Default_currency-symbol ;
    localdefault:has_customer customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Local_Default_tbl.}^.Country = ^{Customer_tbl.}^.Country ) as virtrdf:Local-Default_has_customer .


    refcall:ref-call_iri (Ref_Call_tbl.Call_Num) a refcall:Ref-Call as virtrdf:ref-call_pk ;
    refcall:Call-Num   Ref_Call_tbl.Call_Num   as virtrdf:Ref-Call_call-num ;
    refcall:Cust-Num   Ref_Call_tbl.Cust_Num   as virtrdf:Ref-Call_cust-num ;
    refcall:Call-Date  Ref_Call_tbl.Call_Date  as virtrdf:Ref-Call_call-date ;
    refcall:Sales-Rep  Ref_Call_tbl.Sales_Rep  as virtrdf:Ref-sales-rep ;
    refcall:Parent     Ref_Call_tbl.Parent     as virtrdf:Ref-Call_parent ;
    refcall:Txt        Ref_Call_tbl.Txt        as virtrdf:Ref-Call_txt ;
    refcall:made_to     customer:customer_iri (Customer_tbl.Cust_Num)   where  ( ^{Ref_Call_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )   as virtrdf:Ref-Call_made_to ;
    refcall:made_by     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where  ( ^{Ref_Call_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )  as virtrdf:Ref-Call_made-by ;
    refcall:has_parent  refcall:ref-call_iri (Ref_Call_tbl_1.Call_Num)    where  ( ^{Ref_Call_tbl.}^.Parent    = ^{Ref_Call_tbl_1.}^.Call_Num )   as virtrdf:Ref-Call_has_parent .

    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep) a salesrep:Salesrep as virtrdf:salesrep_pk ;
    salesrep:Sales-Rep      Salesrep_tbl.Sales_Rep       as virtrdf:Salesrep_sales-rep ;
    salesrep:Region         Salesrep_tbl.Region          as virtrdf:Salesrep_region ;
    salesrep:Rep-Name       Salesrep_tbl.Rep_Name        as virtrdf:Salesrep_rep-name ;
    salesrep:Month-Quota-1  Salesrep_tbl.Month_Quota_1   as virtrdf:Salesrep_month-quota-1 ;
    salesrep:Month-Quota-2  Salesrep_tbl.Month_Quota_2   as virtrdf:Salesrep_month-quota-2 ;
    salesrep:Month-Quota-3  Salesrep_tbl.Month_Quota_3   as virtrdf:Salesrep_month-quota-3 ;
    salesrep:Month-Quota-4  Salesrep_tbl.Month_Quota_4   as virtrdf:Salesrep_month-quota-4 ;
    salesrep:Month-Quota-5  Salesrep_tbl.Month_Quota_5   as virtrdf:Salesrep_month-quota-5 ;
    salesrep:Month-Quota-6  Salesrep_tbl.Month_Quota_6   as virtrdf:Salesrep_month-quota-6 ;
    salesrep:Month-Quota-7  Salesrep_tbl.Month_Quota_7   as virtrdf:Salesrep_month-quota-7 ;
    salesrep:Month-Quota-8  Salesrep_tbl.Month_Quota_8   as virtrdf:Salesrep_month-quota-8 ;
    salesrep:Month-Quota-9  Salesrep_tbl.Month_Quota_9   as virtrdf:Salesrep_month-quota-9 ;
    salesrep:Month-Quota-10 Salesrep_tbl.Month_Quota_10  as virtrdf:Salesrep_month-quota-10 ;
    salesrep:Month-Quota-11 Salesrep_tbl.Month_Quota_11  as virtrdf:Salesrep_month-quota-11 ;
    salesrep:Month-Quota-12 Salesrep_tbl.Month_Quota_12  as virtrdf:Salesrep_month-quota-12 ;
    salesrep:is_sales_rep_for customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Customer_tbl.}^.Sales_Rep ) as virtrdf:Salesrep_is_sales_rep_for ;
    salesrep:has_order        order:order_iri (Order_tbl.Order_num)         where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Order_tbl.}^.Sales_Rep )    as virtrdf:Salesrep_has_order ;
    salesrep:manages_region   state:state_iri (State_tbl.State)             where ( ^{Salesrep_tbl.}^.Region    = ^{State_tbl.}^.Region )       as virtrdf:Salesrep_manages_region ;
    salesrep:made_call        refcall:ref-call_iri (Ref_Call_tbl.Call_Num)  where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Ref_Call_tbl.}^.Sales_Rep ) as virtrdf:Ref-Call_made_call .

    state:state_iri (State_tbl.State) a state:State as virtrdf:state_pk ;
    state:State_     State_tbl.State        as virtrdf:State_state ;
    state:State-Name State_tbl.State_Name   as virtrdf:State_state-name ;
    state:Region     State_tbl.Region       as virtrdf:State_region ;
    state:has_customer   customer:customer_iri (Customer_tbl.Cust_Num)   where ( ^{State_tbl.}^.State  = ^{Customer_tbl.}^.State )  as virtrdf:State_has_customer ;
    state:has_sales_rep  salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where ( ^{State_tbl.}^.Region = ^{Salesrep_tbl.}^.Region ) as virtrdf:State_has_sales_rep .


  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/progress/isports%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_rule_list1',
    1,
    vector (
  	 	'progress_isports_rule1',
  	 	'progress_isports_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/progress/isports');

VHOST_DEFINE (
	lpath=>'/progress/isports',
	ppath=>'/DAV/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_schemas_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_schemas_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/progress/isports%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_schemas_rule_list1',
    1,
    vector (
  	 	'progress_isports_schemas_rule1',
  	 	'progress_isports_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/progress/isports');

VHOST_DEFINE (
	lpath=>'/schemas/progress/isports',
	ppath=>'/DAV/schemas/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('customer',     'http://^{URIQADefaultHost}^/schemas/progress/isports/customer/', 2);
DB.DBA.XML_SET_NS_DECL ('order',        'http://^{URIQADefaultHost}^/schemas/progress/isports/order/', 2);
DB.DBA.XML_SET_NS_DECL ('item',         'http://^{URIQADefaultHost}^/schemas/progress/isports/item/', 2);
DB.DBA.XML_SET_NS_DECL ('orderline',    'http://^{URIQADefaultHost}^/schemas/progress/isports/order_line/', 2);
DB.DBA.XML_SET_NS_DECL ('invoice',      'http://^{URIQADefaultHost}^/schemas/progress/isports/invoice/', 2);
DB.DBA.XML_SET_NS_DECL ('localdefault', 'http://^{URIQADefaultHost}^/schemas/progress/isports/local_default/', 2);
DB.DBA.XML_SET_NS_DECL ('refcall',      'http://^{URIQADefaultHost}^/schemas/progress/isports/ref_call/', 2);
DB.DBA.XML_SET_NS_DECL ('salesrep',     'http://^{URIQADefaultHost}^/schemas/progress/isports/salesrep/', 2);
DB.DBA.XML_SET_NS_DECL ('state',        'http://^{URIQADefaultHost}^/schemas/progress/isports/state/', 2);
]]></programlisting>
    </sect2>
    <sect2 id="rdfviewsenterprs92">
      <title>Progress (SQL-92) using demonstration 'iSports' database</title>
<programlisting><![CDATA[
ATTACH TABLE  "PUB"."Customer"      PRIMARY KEY ("Cust-Num")              AS "isports_rdf"."prs10_isports_rdf"."Customer"      FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Invoice"       PRIMARY KEY ("Invoice-Num")           AS "isports_rdf"."prs10_isports_rdf"."Invoice"       FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Item"          PRIMARY KEY ("Item-num")              AS "isports_rdf"."prs10_isports_rdf"."Item"          FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Local-Default" PRIMARY KEY ("Country")               AS "isports_rdf"."prs10_isports_rdf"."Local-Default" FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Order"         PRIMARY KEY ("Order-num")             AS "isports_rdf"."prs10_isports_rdf"."Order"         FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Order-Line"    PRIMARY KEY ("Order-num", "Line-num") AS "isports_rdf"."prs10_isports_rdf"."Order-Line"    FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Ref-Call"      PRIMARY KEY ("Call-Num")              AS "isports_rdf"."prs10_isports_rdf"."Ref-Call"      FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Salesrep"      PRIMARY KEY ("Sales-Rep")             AS "isports_rdf"."prs10_isports_rdf"."Salesrep"      FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."State"         PRIMARY KEY ("State")                 AS "isports_rdf"."prs10_isports_rdf"."State"         FROM 'prs10_isports_rdf';

COMMIT WORK;

GRANT SELECT ON isports_rdf.prs10_isports_rdf.Customer        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Order"         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.Item            TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Order-Line"    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.Invoice         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Local-Default" TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Ref-Call"      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.Salesrep        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.State           TO "SPARQL", "SPARQL_UPDATE";

GRANT SPARQL_UPDATE to "SPARQL";


CREATE VIEW isports_rdf.prs10_isports_rdf.VCustomer      AS SELECT "Cust-Num" AS Cust_Num, Name, Address, Address2, City, State, Country, Phone, Contact, "Sales-Rep" AS Sales_Rep, Comments, "Credit-Limit" AS Credit_Limit, Balance, Terms, Discount, "Postal-Code" AS Postal_Code FROM isports_rdf.prs10_isports_rdf.Customer;
CREATE VIEW isports_rdf.prs10_isports_rdf.VOrder         AS SELECT "Order-num" AS Order_num, "Cust-Num" AS Cust_Num, "Order-Date" AS Order_Date, "Ship-Date" AS Ship_Date, "Promise-Date" AS Promise_Date, Carrier, Instructions, PO, Terms, "Sales-Rep" AS Sales_Rep FROM isports_rdf.prs10_isports_rdf."Order";
CREATE VIEW isports_rdf.prs10_isports_rdf.VItem          AS SELECT "Item-num" AS Item_num, "Item-Name" AS Item_Name, "Cat-Page" AS Cat_Page, Price, "Cat-Description" AS Cat_Description, "On-hand" AS On_hand, Allocated, "Re-Order" AS Re_Order, "On-Order" AS On_Order FROM isports_rdf.prs10_isports_rdf.Item;
CREATE VIEW isports_rdf.prs10_isports_rdf.VOrder_Line    AS SELECT "Order-num" AS Order_num, "Line-num" AS Line_num, "Item-num" AS Item_num, Price, Qty, Discount, "Extended-Price" AS Extended_Price, Backorder FROM isports_rdf.prs10_isports_rdf."Order-Line";
CREATE VIEW isports_rdf.prs10_isports_rdf.VInvoice       AS SELECT "Invoice-Num" AS Invoice_Num, "Cust-Num" AS Cust_Num, "Invoice-Date" AS Invoice_Date, Amount, "Total-Paid" AS Total_Paid, Adjustment, "Order-Num" AS Order_Num, "Ship-Charge" AS Ship_Charge FROM isports_rdf.prs10_isports_rdf.Invoice;
CREATE VIEW isports_rdf.prs10_isports_rdf.VLocal_Default AS SELECT Country, "Region1-Label" AS Region1_Label, "Region2-Label" AS Region2_Label, "Postal-Label" AS Postal_Label, "Postal-Format" AS Postal_Format, "Tel-Format" AS Tel_Format, "Date-Format" AS Date_Format, "Currency-Symbol" AS Currency_Symbol FROM isports_rdf.prs10_isports_rdf."Local-Default";
CREATE VIEW isports_rdf.prs10_isports_rdf.VRef_Call      AS SELECT "Call-Num" AS Call_Num, "Cust-Num" AS Cust_Num, "Call-Date" AS Call_Date, "Sales-Rep" AS Sales_Rep, Parent, Txt FROM isports_rdf.prs10_isports_rdf."Ref-Call";
CREATE VIEW isports_rdf.prs10_isports_rdf.VSalesrep      AS SELECT "Rep-Name" AS Rep_Name, Region, "Sales-Rep" AS Sales_Rep, "Month-Quota" AS Month_Quota FROM isports_rdf.prs10_isports_rdf.Salesrep;
CREATE VIEW isports_rdf.prs10_isports_rdf.VState         AS SELECT State, "State-Name" AS State_Name, Region FROM isports_rdf.prs10_isports_rdf.State;


GRANT SELECT ON isports_rdf.prs10_isports_rdf.VCustomer      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VOrder         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VItem          TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VOrder_Line    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VInvoice       TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VLocal_Default TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VRef_Call      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VSalesrep      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VState         TO "SPARQL", "SPARQL_UPDATE";


-------- Create rdfs:Class definitions ----------------------------

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/> .
@prefix order:        <http://localhost:8890/schemas/progress/isports/order/> .
@prefix item:         <http://localhost:8890/schemas/progress/isports/item/> .
@prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/> .
@prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/> .
@prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/> .
@prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/> .
@prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/> .
@prefix state:        <http://localhost:8890/schemas/progress/isports/state/> .



customer:Customer a rdfs:Class ;
	rdfs:label "Customer" ;
	rdfs:comment "Progress isports Customer table" .

customer:Cust-Num a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

customer:Name a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Name" .

customer:Address a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address" .

customer:Address2 a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address2" .

customer:City a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "City" .

customer:State a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

customer:Country a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

customer:Phone a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Phone" .

customer:Contact a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Contact" .

customer:Sales-Rep a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

customer:Comments a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Comments" .

customer:Credit-Limit a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Credit-Limit" .

customer:Balance a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Balance" .

customer:Terms a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

customer:Discount a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

customer:Postal-Code a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Code" .



order:Order a rdfs:Class ;
	rdfs:label "Order" ;
	rdfs:comment "Progress isports Order table" .

order:Order-num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

order:Cust-Num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

order:Order-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Order-Date" .

order:Ship-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Ship-Date" .

order:Promise-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Promise-Date" .

order:Carrier a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Carrier" .

order:Instructions a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Instructions" .

order:PO a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "PO" .

order:Terms a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

order:Sales-Rep a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .



item:Item a rdfs:Class ;
	rdfs:label "Item" ;
	rdfs:comment "Progress isports Item table" .

item:Item-num a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

item:Item-Name a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Item-Name" .

item:Cat-Page a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Cat-Page" .

item:Price a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

item:Cat-Description a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Cat-Description" .

item:On-hand a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-hand" .

item:Allocated a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Allocated" .

item:Re-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Re-Order" .

item:On-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-Order" .



orderline:Order-Line a rdfs:Class ;
	rdfs:label "Order-Line" ;
	rdfs:comment "Progress isports Order-Line table" .

orderline:Order-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

orderline:Line-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Line-num" .

orderline:Item-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

orderline:Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

orderline:Qty a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Qty" .

orderline:Discount a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

orderline:Extended-Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Extended-Price" .

orderline:Backorder a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:byte ;
	rdfs:label "Backorder" .



invoice:Invoice a rdfs:Class ;
	rdfs:label "Invoice" ;
	rdfs:comment "Progress isports Invoice table" .

invoice:Invoice-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Invoice-Num" .

invoice:Cust-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

invoice:Invoice-Date a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:date ;
	rdfs:label "Invoice-Date" .

invoice:Amount a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Amount" .

invoice:Total-Paid a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Total-Paid" .

invoice:Adjustment a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Adjustment" .

invoice:Order-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-Num" .

invoice:Ship-Charge a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Ship-Charge" .



localdefault:Local-Default a rdfs:Class ;
	rdfs:label "Local-Default" ;
	rdfs:comment "Progress isports Local-Default table" .

localdefault:Country a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

localdefault:Region1-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region1-Label" .

localdefault:Region2-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region2-Label" .

localdefault:Postal-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Label" .

localdefault:Postal-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Format" .

localdefault:Tel-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Tel-Format" .

localdefault:Date-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Date-Format" .

localdefault:Currency-Symbol a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Currency-Symbol" .



refcall:Ref-Call a rdfs:Class ;
	rdfs:label "Ref-Call" ;
	rdfs:comment "Progress isports Ref-Call table" .

refcall:Call-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Call-Num" .

refcall:Cust-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

refcall:Call-Date a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:date ;
	rdfs:label "Call-Date" .

refcall:Sales-Rep a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

refcall:Parent a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Parent" .

refcall:Txt a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Txt" .



salesrep:Salesrep a rdfs:Class ;
	rdfs:label "Salesrep" ;
	rdfs:comment "Progress isports Salesrep table" .

salesrep:Sales-Rep a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

salesrep:Rep-Name a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Rep-Name" .

salesrep:Region a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

salesrep:Month-Quota a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota" .



state:State a rdfs:Class ;
	rdfs:label "State" ;
	rdfs:comment "Progress isports State table" .

state:State_ a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

state:State-Name a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State-Name" .

state:Region a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

', '', 'http://localhost:8890/schemas/progress/isports', 0);



----------- Create IRI Classes -------------




SPARQL

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

create iri class customer:customer_iri
	"http://localhost:8890/progress/isports/customer/%d#this"
	(in Cust_Num integer not null) .

create iri class order:order_iri
	"http://localhost:8890/progress/isports/order/%d#this"
	(in Order_Num integer not null) .

create iri class item:item_iri
	"http://localhost:8890/progress/isports/item/%d#this"
	(in Item_num integer not null) .

create iri class orderline:order-line_iri
	"http://localhost:8890/progress/isports/order-line/%d_%d#this"
	(in Order_num integer not null, in Line_num integer not null) .

create iri class invoice:invoice_iri
	"http://localhost:8890/progress/isports/invoice/%d#this"
	(in Invoice_Num integer not null) .

create iri class localdefault:local-default_iri
	"http://localhost:8890/progress/isports/local-default/%U#this"
	(in Country varchar not null) .

create iri class refcall:ref-call_iri
	"http://localhost:8890/progress/isports/ref-call/%U#this"
	(in Call_Num varchar not null) .

create iri class salesrep:salesrep_iri
	"http://localhost:8890/progress/isports/salesrep/%U#this"
	(in Sales_Rep varchar not null) .

create iri class state:state_iri
	"http://localhost:8890/progress/isports/state/%U#this"
	(in State varchar not null) .

;







------------- Create Quad Store ------------------------------------

SPARQL

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

alter quad storage virtrdf:DefaultQuadStorage
  from isports_rdf.prs10_isports_rdf.VCustomer      as Customer_tbl
  from isports_rdf.prs10_isports_rdf.VOrder         as Order_tbl
  from isports_rdf.prs10_isports_rdf.VItem          as Item_tbl
  from isports_rdf.prs10_isports_rdf.VOrder_Line    as Order_Line_tbl
  from isports_rdf.prs10_isports_rdf.VInvoice       as Invoice_tbl
  from isports_rdf.prs10_isports_rdf.VRef_Call      as Ref_Call_tbl
  from isports_rdf.prs10_isports_rdf.VRef_Call      as Ref_Call_tbl_1  -- Additional Ref_Call_tbl_1 alias required to represent recursive FK relationship (refcall:has_parent) below.
  from isports_rdf.prs10_isports_rdf.VLocal_Default as Local_Default_tbl
  from isports_rdf.prs10_isports_rdf.VSalesrep      as Salesrep_tbl
  from isports_rdf.prs10_isports_rdf.VState         as State_tbl
{
  create virtrdf:progress_isports as graph <http://localhost:8890/progress/isports>
  {
    customer:customer_iri (Customer_tbl.Cust_Num) a customer:Customer as virtrdf:customer_pk ;
    customer:Cust-Num     Customer_tbl.Cust_Num     as virtrdf:Customer_cust-num ;
    customer:Name         Customer_tbl.Name         as virtrdf:Customer_name ;
    customer:Address      Customer_tbl.Address      as virtrdf:Customer_address ;
    customer:Address2     Customer_tbl.Address2     as virtrdf:Customer_address2 ;
    customer:City         Customer_tbl.City         as virtrdf:Customer_city ;
    customer:State        Customer_tbl.State        as virtrdf:Customer_state ;
    customer:Country      Customer_tbl.Country      as virtrdf:Customer_country ;
    customer:Phone        Customer_tbl.Phone        as virtrdf:Customer_phone ;
    customer:Contact      Customer_tbl.Contact      as virtrdf:Customer_contact ;
    customer:Sales-Rep    Customer_tbl.Sales_Rep    as virtrdf:Customer_sales_rep ;
    customer:Comments     Customer_tbl.Comments     as virtrdf:Customer_comments ;
    customer:Credit-Limit Customer_tbl.Credit_Limit as virtrdf:Customer_credit-limit ;
    customer:Balance      Customer_tbl.Balance      as virtrdf:Customer_balance ;
    customer:Terms        Customer_tbl.Terms        as virtrdf:Customer_terms ;
    customer:Discount     Customer_tbl.Discount     as virtrdf:Customer_discount ;
    customer:Postal-Code  Customer_tbl.Postal_Code  as virtrdf:Customer_postal-code ;
    customer:from_state        state:state_iri (State_tbl.State)                           where ( ^{Customer_tbl.}^.State     = ^{State_tbl.}^.State )           as virtrdf:Customer_from_state ;
    customer:has_sales_rep     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)              where ( ^{Customer_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )    as virtrdf:Customer_has_sales_rep ;
    customer:has_local_default localdefault:local-default_iri (Local_Default_tbl.Country)  where ( ^{Customer_tbl.}^.Country   = ^{Local_Default_tbl.}^.Country ) as virtrdf:Customer_has_local_default ;
    customer:placed_order      order:order_iri (Order_tbl.Order_num)                       where ( ^{Customer_tbl.}^.Cust_Num  = ^{Order_tbl.}^.Cust_Num )        as virtrdf:Customer_placed_order ;
    customer:has_invoice       invoice:invoice_iri (Invoice_tbl.Invoice_Num)               where ( ^{Customer_tbl.}^.Cust_Num  = ^{Invoice_tbl.}^.Cust_Num )      as virtrdf:Customer_has_invoice ;
    customer:ref_call          refcall:ref-call_iri (Ref_Call_tbl.Call_Num)                where ( ^{Customer_tbl.}^.Cust_Num  = ^{Ref_Call_tbl.}^.Cust_Num )     as virtrdf:Customer_ref-call .

    order:order_iri (Order_tbl.Order_num) a order:Order as virtrdf:order_pk ;
    order:Order-num    Order_tbl.Order_num    as virtrdf:Order_order-num ;
    order:Cust-Num     Order_tbl.Cust_Num     as virtrdf:Order_cust_num ;
    order:Order-Date   Order_tbl.Order_Date   as virtrdf:Order_order-date ;
    order:Ship-Date    Order_tbl.Ship_Date    as virtrdf:Order_ship-date ;
    order:Promise-Date Order_tbl.Promise_Date as virtrdf:Order_promise-date ;
    order:Carrier      Order_tbl.Carrier      as virtrdf:Order_carrier ;
    order:Instructions Order_tbl.Instructions as virtrdf:Order_instructions ;
    order:PO           Order_tbl.PO           as virtrdf:Order_po ;
    order:Terms        Order_tbl.Terms        as virtrdf:Order_terms ;
    order:placed_by    customer:customer_iri (Customer_tbl.Cust_Num)                                 where ( ^{Order_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )    as virtrdf:Order_placed_by ;
    order:Sales-Rep    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)                                where ( ^{Order_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )   as virtrdf:Order_sales_rep ;
    order:invoiced_on  invoice:invoice_iri (Invoice_tbl.Invoice_Num)                                 where ( ^{Order_tbl.}^.Order_num = ^{Invoice_tbl.}^.Order_Num )    as virtrdf:Order_invoiced_on ;
    order:has_lines    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Order_tbl.}^.Order_num = ^{Order_Line_tbl.}^.Order_num ) as virtrdf:Order_has_lines .

    item:item_iri (Item_tbl.Item_num) a item:Item as virtrdf:item_pk ;
    item:Item-num        Item_tbl.Item_num        as virtrdf:item_item-num ;
    item:Item-Name       Item_tbl.Item_Name       as virtrdf:Item_item-Name ;
    item:Cat-Page        Item_tbl.Cat_Page        as virtrdf:Item_cat-page ;
    item:Price           Item_tbl.Price           as virtrdf:Item_price ;
    item:Cat-Description Item_tbl.Cat_Description as virtrdf:Item_cat-description ;
    item:On-hand         Item_tbl.On_hand         as virtrdf:Item_on-hand ;
    item:Allocated       Item_tbl.Allocated       as virtrdf:Item_allocated ;
    item:Re-Order        Item_tbl.Re_Order        as virtrdf:Item_re-order ;
    item:On-Order        Item_tbl.On_Order        as virtrdf:Item_on-order ;
    item:order_line  orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Item_tbl.}^.Item_num  = ^{Order_Line_tbl.}^.Item_num )   as virtrdf:Item_order_line .

    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num) a orderline:Order-Line as virtrdf:order-line_pk ;
    orderline:Line-num       Order_Line_tbl.Line_num       as virtrdf:Order-Line_line-num ;
    orderline:Price          Order_Line_tbl.Price          as virtrdf:Order-Line_price ;
    orderline:Qty            Order_Line_tbl.Qty            as virtrdf:Order-Line_qty ;
    orderline:Discount       Order_Line_tbl.Discount       as virtrdf:Order-Line_discount ;
    orderline:Extended-Price Order_Line_tbl.Extended_Price as virtrdf:Order-Line_extended-price ;
    orderline:Backorder      Order_Line_tbl.Backorder      as virtrdf:Order-Line_backorder ;
    orderline:Order-num  order:order_iri (Order_tbl.Order_num)  where ( ^{Order_Line_tbl.}^.Order_num = ^{Order_tbl.}^.Order_num ) as virtrdf:Order_Line_order_num ;
    orderline:Item-num   item:item_iri (Item_tbl.Item_num)      where ( ^{Order_Line_tbl.}^.Item_num  = ^{Item_tbl.}^.Item_num )   as virtrdf:Order_Line_item_num .

    invoice:invoice_iri (Invoice_tbl.Invoice_Num) a invoice:Invoice as virtrdf:invoice_pk ;
    invoice:Invoice-Num  Invoice_tbl.Invoice_Num  as virtrdf:Invoice_invoice-num ;
    invoice:Cust-Num     Invoice_tbl.Cust_Num    as virtrdf:Invoice_cust_num ;
    invoice:Invoice-Date Invoice_tbl.Invoice_Date as virtrdf:Invoice_invoice-date ;
    invoice:Amount       Invoice_tbl.Amount       as virtrdf:Invoice_amount ;
    invoice:Total-Paid   Invoice_tbl.Total_Paid   as virtrdf:Invoice_total-paid ;
    invoice:Adjustment   Invoice_tbl.Adjustment   as virtrdf:Invoice_adjustment ;
    invoice:Order-Num    Invoice_tbl.Order_Num    as virtrdf:Invoice_order-num ;
    invoice:Ship-Charge  Invoice_tbl.Ship_Charge  as virtrdf:Invoice_ship-charge ;
    invoice:invoiced_to  customer:customer_iri (Customer_tbl.Cust_Num)  where ( ^{Invoice_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num ) as virtrdf:Invoice_invoiced_to ;
    invoice:Order-Num    order:order_iri (Order_tbl.Order_num)          where ( ^{Invoice_tbl.}^.Order_Num = ^{Order_tbl.}^.Order_num )   as virtrdf:Invoice_order_num .

    localdefault:local-default_iri (Local_Default_tbl.Country) a localdefault:Local-Default as virtrdf:local-default_pk ;
    localdefault:Country         Local_Default_tbl.Country as virtrdf:local-default_country ;
    localdefault:Region1-Label   Local_Default_tbl.Region1_Label   as virtrdf:Local-Default_region1-label ;
    localdefault:Region2-Label   Local_Default_tbl.Region2_Label   as virtrdf:Local-Default_region2-label ;
    localdefault:Postal-Label    Local_Default_tbl.Postal_Label    as virtrdf:Local-Default_postal-label ;
    localdefault:Postal-Format   Local_Default_tbl.Postal_Format   as virtrdf:Local-Default_postal-format ;
    localdefault:Tel-Format      Local_Default_tbl.Tel_Format      as virtrdf:Local-Default_tel-format ;
    localdefault:Date-Format     Local_Default_tbl.Date_Format     as virtrdf:Local-Default_date-format ;
    localdefault:Currency-Symbol Local_Default_tbl.Currency_Symbol as virtrdf:Local-Default_currency-symbol ;
    localdefault:has_customer customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Local_Default_tbl.}^.Country = ^{Customer_tbl.}^.Country ) as virtrdf:Local-Default_has_customer .

    refcall:ref-call_iri (Ref_Call_tbl.Call_Num) a refcall:Ref-Call as virtrdf:ref-call_pk ;
    refcall:Call-Num   Ref_Call_tbl.Call_Num   as virtrdf:Ref-Call_call-num ;
    refcall:Cust-Num   Ref_Call_tbl.Cust_Num   as virtrdf:Ref-Call_cust-num ;
    refcall:Call-Date  Ref_Call_tbl.Call_Date  as virtrdf:Ref-Call_call-date ;
    refcall:Sales-Rep  Ref_Call_tbl.Sales_Rep  as virtrdf:Ref-sales-rep ;
    refcall:Parent     Ref_Call_tbl.Parent     as virtrdf:Ref-Call_parent ;
    refcall:Txt        Ref_Call_tbl.Txt        as virtrdf:Ref-Call_txt ;
    refcall:made_to     customer:customer_iri (Customer_tbl.Cust_Num)   where  ( ^{Ref_Call_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )    as virtrdf:Ref-Call_made_to ;
    refcall:made_by     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where  ( ^{Ref_Call_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )   as virtrdf:Ref-Call_made-by ;
    refcall:has_parent  refcall:ref-call_iri (Ref_Call_tbl_1.Call_Num)  where  ( ^{Ref_Call_tbl.}^.Parent    = ^{Ref_Call_tbl_1.}^.Call_Num )  as virtrdf:Ref-Call_has_parent .

    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep) a salesrep:Salesrep as virtrdf:salesrep_pk ;
    salesrep:Sales-Rep   Salesrep_tbl.Sales_Rep   as virtrdf:Salesrep_sales-rep ;
    salesrep:Region      Salesrep_tbl.Region      as virtrdf:Salesrep_region ;
    salesrep:Rep-Name    Salesrep_tbl.Rep_Name    as virtrdf:Salesrep_rep-name ;
    salesrep:Month-Quota Salesrep_tbl.Month_Quota as virtrdf:Salesrep_month-quota ;
    salesrep:is_sales_rep_for customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Customer_tbl.}^.Sales_Rep ) as virtrdf:Salesrep_is_sales_rep_for ;
    salesrep:has_order        order:order_iri (Order_tbl.Order_num)         where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Order_tbl.}^.Sales_Rep )    as virtrdf:Salesrep_has_order ;
    salesrep:manages_region   state:state_iri (State_tbl.State)             where ( ^{Salesrep_tbl.}^.Region    = ^{State_tbl.}^.Region )       as virtrdf:Salesrep_manages_region ;
    salesrep:made_call        refcall:ref-call_iri (Ref_Call_tbl.Call_Num)  where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Ref_Call_tbl.}^.Sales_Rep ) as virtrdf:Ref-Call_made_call .

    state:state_iri (State_tbl.State) a state:State as virtrdf:state_pk ;
    state:State_     State_tbl.State        as virtrdf:State_state ;
    state:State-Name State_tbl.State_Name   as virtrdf:State_state-name ;
    state:Region     State_tbl.Region       as virtrdf:State_region ;
    state:has_customer   customer:customer_iri (Customer_tbl.Cust_Num)   where ( ^{State_tbl.}^.State  = ^{Customer_tbl.}^.State )  as virtrdf:State_has_customer ;
    state:has_sales_rep  salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where ( ^{State_tbl.}^.Region = ^{Salesrep_tbl.}^.Region ) as virtrdf:State_has_sales_rep .


  } .
} .
;


-- Setup re-write rules that enable de-referencing of RDF based descriptions of
-- iSports Entities

-- Cleanup old rules

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_rule%';

-- Create rules for handling HTML representation of Entity (resource) description requests

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

-- Create rules for handling RDF based representations (N3 or RDF/XML) of Entity (resource) descriptions

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/progress/isports%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_rule_list1',
    1,
    vector (
  	 	'progress_isports_rule1',
  	 	'progress_isports_rule2'
	  ));

-- Setup OWL ontology data space that describes iSports entities

-- Create Virtual Directory access point

VHOST_REMOVE (lpath=>'/progress/isports');

VHOST_DEFINE (
	lpath=>'/progress/isports',
	ppath=>'/DAV/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_schemas_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_schemas_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http/^{URIQADefaultHost}^%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'progress_isports_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/progress/isports%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_schemas_rule_list1',
    1,
    vector (
  	 	'progress_isports_schemas_rule1',
  	 	'progress_isports_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/progress/isports');

VHOST_DEFINE (
	lpath=>'/schemas/progress/isports',
	ppath=>'/DAV/schemas/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('customer',     'http://^{URIQADefaultHost}^/schemas/progress/isports/customer/', 2);
DB.DBA.XML_SET_NS_DECL ('order',        'http://^{URIQADefaultHost}^/schemas/progress/isports/order/', 2);
DB.DBA.XML_SET_NS_DECL ('item',         'http://^{URIQADefaultHost}^/schemas/progress/isports/item/', 2);
DB.DBA.XML_SET_NS_DECL ('orderline',    'http://^{URIQADefaultHost}^/schemas/progress/isports/order_line/', 2);
DB.DBA.XML_SET_NS_DECL ('invoice',      'http://^{URIQADefaultHost}^/schemas/progress/isports/invoice/', 2);
DB.DBA.XML_SET_NS_DECL ('localdefault', 'http://^{URIQADefaultHost}^/schemas/progress/isports/local_default/', 2);
DB.DBA.XML_SET_NS_DECL ('refcall',      'http://^{URIQADefaultHost}^/schemas/progress/isports/ref_call/', 2);
DB.DBA.XML_SET_NS_DECL ('salesrep',     'http://^{URIQADefaultHost}^/schemas/progress/isports/salesrep/', 2);
DB.DBA.XML_SET_NS_DECL ('state',        'http://^{URIQADefaultHost}^/schemas/progress/isports/state/', 2);
]]></programlisting>
    </sect2>
</sect1>