~juan457/+junk/zorba

« back to all changes in this revision

Viewing changes to test/rbkt/Queries/zorba/jsoniq/collection-and-index/foaf_module-with-index.xqlib

  • Committer: Markos Zaharioudakis
  • Date: 2012-07-11 15:38:39 UTC
  • mfrom: (10924 zorba)
  • mto: This revision was merged to the branch mainline in revision 10932.
  • Revision ID: markos_za@yahoo.com-20120711153839-0mkh15cg2ubknchd
work in progress

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
module namespace foaf = "http://www.w3.org/TestModules/foaf";
 
3
 
 
4
import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
 
5
import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
 
6
import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
 
7
import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
 
8
 
 
9
declare namespace ann = "http://www.zorba-xquery.com/annotations";
 
10
 
 
11
declare variable $foaf:network:= xs:QName("foaf:network");
 
12
declare variable $foaf:person:= xs:QName("foaf:person");
 
13
declare variable $foaf:age:= xs:QName("foaf:age");
 
14
declare variable $foaf:friends:= xs:QName("foaf:friends");
 
15
 
 
16
declare collection foaf:network as object()*;
 
17
 
 
18
 
 
19
(:
 
20
  The person index maps each person name with its information.
 
21
:)
 
22
 
 
23
declare %ann:unique %ann:automatic index foaf:person
 
24
on nodes dml:collection(xs:QName("foaf:network"))
 
25
by .("name") as xs:string;
 
26
 
 
27
 
 
28
(:
 
29
  The person index maps each person name with its information.
 
30
:)
 
31
 
 
32
declare %ann:value-range %ann:automatic index foaf:age
 
33
on nodes dml:collection(xs:QName("foaf:network"))
 
34
by xs:integer(.("age")) as xs:integer;
 
35
 
 
36
 
 
37
(:
 
38
  The person index maps each person name with its information.
 
39
:)
 
40
 
 
41
declare %ann:manual %ann:general-equality index foaf:friends
 
42
on nodes dml:collection(xs:QName("foaf:network"))
 
43
by jn:members(.("friends")) as xs:string*;
 
44
 
 
45
 
 
46
(:
 
47
  The person index maps each person with the person of which she is the best friend.
 
48
:)
 
49
 
 
50
declare %ann:manual %ann:general-range index foaf:age-range
 
51
on nodes dml:collection(xs:QName("foaf:network"))
 
52
by xs:integer(.("age")) as xs:integer;
 
53
 
 
54
 
 
55
(:
 
56
  Create and populate the collection, and then create the indexes
 
57
:)
 
58
 
 
59
declare %ann:sequential function foaf:create-db()
 
60
{
 
61
  ddl:create($foaf:network);
 
62
 
 
63
  dml:insert($foaf:network, (
 
64
    {
 
65
      "name" : "James T. Kirk",
 
66
      "age" : 30,
 
67
      "gender" : "male",
 
68
      "friends" : [ "Mister Spock", "Scotty", "Jean-Luc Picard"]
 
69
    },
 
70
    
 
71
    {
 
72
      "name" : "Jean-Luc Picard",
 
73
      "age" : 40,
 
74
      "gender" : "male",
 
75
      "friends" : [ "James T. Kirk", "Lieutenant Commander Data", "Beverly Crusher" ]
 
76
    },
 
77
    
 
78
    {
 
79
      "name" : "Beverly Crusher",
 
80
      "age" : 38,
 
81
      "gender" : "female",
 
82
      "friends" : [ "Jean-Luc Picard", "Ensign Crusher" ]
 
83
    },
 
84
    
 
85
    {
 
86
      "name" : "Lieutenant Commander Data",
 
87
      "age" : 100,
 
88
      "gender" : "positronic matrix",
 
89
      "friends" : [ "Geordi La Forge" ]
 
90
    }
 
91
  ));
 
92
 
 
93
  index_ddl:create($foaf:person);
 
94
  index_ddl:create($foaf:age);
 
95
  index_ddl:create($foaf:friends);
 
96
};
 
97
 
 
98
 
 
99
declare function foaf:probe-point-id($indexName as xs:QName, $id as xs:string)
 
100
{
 
101
  index_dml:probe-index-point-value($indexName, $id)
 
102
};
 
103
 
 
104
declare function foaf:probe-range-id($indexName as xs:QName, $lower as xs:integer, $upper as xs:integer)
 
105
{
 
106
  index_dml:probe-index-range-value($indexName, $lower, $upper, true(), true(), true(), true())
 
107
};
 
108
 
 
109
declare function foaf:probe-point-general-id($indexName as xs:QName, $names as xs:string*)
 
110
{
 
111
  index_dml:probe-index-point-general($indexName, $names)
 
112
};
 
113