rtm 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/DISCLAIMER +10 -33
- data/LICENSE +201 -0
- data/README +3 -3
- data/lib/rtm.rb +148 -74
- data/lib/rtm/axes.rb +295 -0
- data/lib/rtm/axes/association.rb +76 -0
- data/lib/rtm/axes/associations.rb +96 -0
- data/lib/rtm/axes/assocs_names_occs.rb +56 -0
- data/lib/rtm/axes/characteristic.rb +68 -0
- data/lib/rtm/axes/characteristics.rb +93 -0
- data/lib/rtm/axes/string.rb +76 -0
- data/lib/rtm/axes/strings.rb +87 -0
- data/lib/rtm/axes/topic.rb +233 -0
- data/lib/rtm/axes/topics.rb +280 -0
- data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
- data/lib/rtm/engine.rb +58 -0
- data/lib/rtm/extensions.rb +11 -1
- data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
- data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
- data/lib/rtm/helpers/uri.rb +13 -0
- data/lib/rtm/io.rb +18 -0
- data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
- data/lib/rtm/io/ontopia_io.rb +25 -0
- data/lib/rtm/io/tmapix.rb +234 -0
- data/lib/rtm/io/to_hash.rb +116 -0
- data/lib/rtm/io/to_jtm.rb +53 -103
- data/lib/rtm/io/to_rdf.rb +30 -0
- data/lib/rtm/io/to_string.rb +8 -6
- data/lib/rtm/io/to_xtm1.rb +6 -4
- data/lib/rtm/io/to_xtm2.rb +10 -8
- data/lib/rtm/io/to_yaml.rb +29 -98
- data/lib/rtm/navigation.rb +37 -0
- data/lib/rtm/navigation/association/players.rb +25 -0
- data/lib/rtm/navigation/name/atomify.rb +19 -0
- data/lib/rtm/navigation/name/characteristics.rb +33 -0
- data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
- data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/indicators.rb +31 -0
- data/lib/rtm/navigation/topic/items.rb +31 -0
- data/lib/rtm/navigation/topic/locators.rb +31 -0
- data/lib/rtm/navigation/topic/players.rb +27 -0
- data/lib/rtm/navigation/topic/supertypes.rb +162 -0
- data/lib/rtm/navigation/topic/traverse.rb +51 -0
- data/lib/rtm/navigation/topic/types.rb +107 -0
- data/lib/rtm/psi.rb +33 -2
- data/lib/rtm/sugar.rb +34 -0
- data/lib/rtm/sugar/association/hash_access.rb +46 -0
- data/lib/rtm/sugar/occurrence/dynamic_value.rb +75 -0
- data/lib/rtm/{pimp_my_api.rb → sugar/occurrence/externalize.rb} +3 -0
- data/lib/rtm/sugar/role/counterparts.rb +133 -46
- data/lib/rtm/sugar/topic/characteristics.rb +126 -12
- data/lib/rtm/sugar/topic/counterparts.rb +130 -7
- data/lib/rtm/sugar/topic/hash_access.rb +140 -30
- data/lib/rtm/sugar/topic/scoped.rb +65 -0
- data/lib/rtm/sugar/topic/topic_ref.rb +35 -0
- data/lib/rtm/sugar/topic/typed.rb +159 -0
- data/lib/rtm/sugar/typed/types.rb +38 -0
- data/lib/rtm/validation.rb +8 -5
- data/lib/rtm/version.rb +18 -0
- data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
- data/spec/rtm/axes/association_spec.rb +88 -0
- data/spec/rtm/axes/associations_spec.rb +60 -0
- data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
- data/spec/rtm/axes/characteristic_spec.rb +90 -0
- data/spec/rtm/axes/characteristics_spec.rb +85 -0
- data/spec/rtm/axes/string_spec.rb +145 -0
- data/spec/rtm/axes/strings_spec.rb +168 -0
- data/spec/rtm/axes/topic_spec.rb +124 -0
- data/spec/rtm/axes/topics_spec.rb +103 -0
- data/spec/rtm/base_spec.rb +32 -0
- data/spec/rtm/io/tmapix_spec.rb +85 -0
- data/spec/rtm/navigation/association/players_spec.rb +58 -0
- data/spec/rtm/navigation/association_spec.rb +52 -0
- data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/name_spec.rb +52 -0
- data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/occurrence_spec.rb +52 -0
- data/spec/rtm/navigation/string_spec.rb +51 -0
- data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
- data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
- data/spec/rtm/navigation/topic/items_spec.rb +44 -0
- data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
- data/spec/rtm/navigation/topic/players_spec.rb +48 -0
- data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
- data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
- data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
- data/spec/rtm/navigation/topic/types_spec.rb +195 -0
- data/spec/rtm/navigation/topic_spec.rb +153 -0
- data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
- data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +16 -0
- data/spec/rtm/sugar/role/counterparts_spec.rb +191 -0
- data/spec/rtm/sugar/topic/characteristics_spec.rb +318 -0
- data/spec/rtm/sugar/topic/counterparts_spec.rb +184 -0
- data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
- data/spec/rtm/sugar/topic/scoped_spec.rb +131 -0
- data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
- data/spec/rtm/sugar/topic/typed_spec.rb +155 -0
- data/spec/rtm/sugar/typed/types_spec.rb +24 -0
- data/spec/rtm/tmapi/core/association_spec.rb +169 -0
- data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
- data/spec/rtm/tmapi/core/name_spec.rb +85 -0
- data/spec/rtm/tmapi/core/occurrence_spec.rb +96 -0
- data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
- data/spec/rtm/tmapi/core/role_spec.rb +73 -0
- data/spec/rtm/tmapi/core/scoped_spec.rb +403 -0
- data/spec/rtm/tmapi/core/topic_map_spec.rb +648 -0
- data/spec/rtm/tmapi/core/topic_spec.rb +992 -0
- data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
- data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
- data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
- data/spec/rtm/tmapi_spec.rb +44 -0
- data/spec/rtm/utils/sparql_spec.rb +26 -0
- data/spec/rtm_spec.rb +94 -0
- data/spec/spec_helper.rb +23 -0
- data/test/base_unit_test.rb +161 -0
- data/test/{base_test.rb → base_unit_test_tmapi.rb} +46 -43
- metadata +122 -66
- data/COPYRIGHT +0 -4
- data/lib/Rakefile.rb +0 -42
- data/lib/activetopicmaps.rb +0 -278
- data/lib/rtm/backend/active_record.rb +0 -58
- data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
- data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
- data/lib/rtm/backend/active_record/locators.rb +0 -55
- data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
- data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
- data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
- data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
- data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
- data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
- data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
- data/lib/rtm/backend/active_record/tmdm.rb +0 -298
- data/lib/rtm/backend/active_record/topic.rb +0 -87
- data/lib/rtm/backend/active_record/topic_map.rb +0 -314
- data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
- data/lib/rtm/base.rb +0 -92
- data/lib/rtm/connect.rb +0 -92
- data/lib/rtm/core_ext.rb +0 -6
- data/lib/rtm/io/from_xtm2.rb +0 -263
- data/lib/rtm/merging/merging.rb +0 -307
- data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
- data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
- data/lib/run_main_project.rb +0 -16
@@ -0,0 +1,184 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
5
|
+
|
6
|
+
module Sugar::Topic::Counterparts
|
7
|
+
describe self do
|
8
|
+
before(:each) do
|
9
|
+
@tm = get_used_tm_sys_tm
|
10
|
+
@t1,@t2,@t3,@t4,@t5 = @tm.get!(["t1","t2","t3","t4","t5"])
|
11
|
+
@t_a1,@t_a2,@t_a3 = @tm.get!(["t_a1","t_a2","t_a3"])
|
12
|
+
@t_r1,@t_r2,@t_r3,@t_r4,@t_r5 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5"])
|
13
|
+
@a1 = @tm.create_association(@t_a1)
|
14
|
+
@a2 = @tm.create_association(@t_a2)
|
15
|
+
@a3 = @tm.create_association(@t_a1)
|
16
|
+
@a4 = @tm.create_association(@t_a3)
|
17
|
+
@a5 = @tm.create_association(@t_a1)
|
18
|
+
@r1 = @a1.create_role(@t_r1, @t1)
|
19
|
+
@r2 = @a1.create_role(@t_r2, @t2)
|
20
|
+
@r3 = @a1.create_role(@t_r1, @t4)
|
21
|
+
@r4 = @a2.create_role(@t_r1, @t1)
|
22
|
+
@r5 = @a2.create_role(@t_r3, @t3)
|
23
|
+
@r6 = @a3.create_role(@t_r4, @t1)
|
24
|
+
@r7 = @a3.create_role(@t_r5, @t5)
|
25
|
+
@r8 = @a4.create_role(@t_r4, @t4)
|
26
|
+
@r9 = @a4.create_role(@t_r5, @t4)
|
27
|
+
@r10= @a5.create_role(@t_r2, @t5)
|
28
|
+
@lonely_topic = @tm.get!("lonely")
|
29
|
+
end
|
30
|
+
after(:each) do
|
31
|
+
@tm.close
|
32
|
+
end
|
33
|
+
describe "#counterparts" do
|
34
|
+
it "should return an empty Array if this Topic playes no Roles" do
|
35
|
+
@lonely_topic.counterparts.should be_empty
|
36
|
+
end
|
37
|
+
it "should return all counterparts if no filter is given" do
|
38
|
+
@t1.counterparts.size.should == 4
|
39
|
+
@t1.counterparts.should include @r2, @r3, @r5, @r7
|
40
|
+
@t3.counterparts.first.should == @r4
|
41
|
+
end
|
42
|
+
it "should return some counterparts if the roletype is filtered" do
|
43
|
+
@t1.counterparts({:rtype => @t_r1}).size.should == 3
|
44
|
+
@t1.counterparts({:rtype => @t_r1}).should include @r2, @r3, @r5
|
45
|
+
@t3.counterparts({:rtype => @t_r1}).should be_empty
|
46
|
+
@t3.counterparts({:rtype => "test"}).should be_empty
|
47
|
+
end
|
48
|
+
it "should return some counterparts if the associationtype is filtered" do
|
49
|
+
@t1.counterparts({:atype => @t_a1}).size.should == 3
|
50
|
+
@t1.counterparts({:atype => @t_a1}).should include @r2, @r3, @r7
|
51
|
+
@t1.counterparts({:atype => @t_a3}).should be_empty
|
52
|
+
end
|
53
|
+
it "should return some counterparts if the other-roletype is filtered" do
|
54
|
+
@t1.counterparts({:otype => @t_r5}).size.should == 1
|
55
|
+
@t1.counterparts({:otype => @t_r5}).should include @r7
|
56
|
+
end
|
57
|
+
it "should return some counterparts if roletype, associationstype and other-roletype is filtered" do
|
58
|
+
@t1.counterparts({:rtype => @t_r1, :atype => @t_a1, :otype => @t_r2}).size.should == 1
|
59
|
+
@t1.counterparts({:rtype => @t_r1, :atype => @t_a1, :otype => @t_r1}).should include @r3
|
60
|
+
end
|
61
|
+
it "should handle circular associations" do
|
62
|
+
@t4.counterparts(:atype => @t_a3).size.should == 2
|
63
|
+
@t4.counterparts(:atype => @t_a3).should include @r8
|
64
|
+
end
|
65
|
+
end
|
66
|
+
describe "#counterplayers" do
|
67
|
+
it "should return an empty Array if this Topic playes no Roles" do
|
68
|
+
@lonely_topic.counterplayers.should be_empty
|
69
|
+
end
|
70
|
+
it "should return all counterplayers if no filter is given" do
|
71
|
+
@t1.counterplayers.size.should == 4
|
72
|
+
@t1.counterplayers.should include @t2, @t3, @t4, @t5
|
73
|
+
@t3.counterplayers.first.should == @t1
|
74
|
+
end
|
75
|
+
it "should return some counterplayers if the roletype is filtered" do
|
76
|
+
@t1.counterplayers({:rtype => @t_r1}).size.should == 3
|
77
|
+
@t1.counterplayers({:rtype => @t_r1}).should include @t2, @t3, @t4
|
78
|
+
@t3.counterplayers({:rtype => @t_r1}).should be_empty
|
79
|
+
@t3.counterplayers({:rtype => "test"}).should be_empty
|
80
|
+
end
|
81
|
+
it "should return some counterplayers if the associationtype is filtered" do
|
82
|
+
@t1.counterplayers(:atype => @t_a1).size.should == 3
|
83
|
+
@t1.counterplayers(:atype => @t_a1).should include @t2, @t4, @t5
|
84
|
+
@t1.counterplayers(:atype => @t_a3).should be_empty
|
85
|
+
end
|
86
|
+
it "should return some counterplayers if the other-roletype is filtered" do
|
87
|
+
@t1.counterplayers(:otype => @t_r5).size.should == 1
|
88
|
+
@t1.counterplayers(:otype => @t_r5).should include @t5
|
89
|
+
end
|
90
|
+
it "should return some counterplayers if roletype, associationstype and other-roletype is filtered" do
|
91
|
+
@t1.counterplayers(:rtype => @t_r1, :atype => @t_a1, :otype => @t_r2).size.should == 1
|
92
|
+
@t1.counterplayers(:rtype => @t_r1, :atype => @t_a1, :otype => @t_r1).should include @t4
|
93
|
+
end
|
94
|
+
it "should handle circular associations" do
|
95
|
+
@t4.counterplayers(:atype => @t_a3).size.should == 1
|
96
|
+
@t4.counterplayers(:atype => @t_a3).should include @t4
|
97
|
+
end
|
98
|
+
it "should return a unique Array" do
|
99
|
+
result = @t4.counterplayers
|
100
|
+
result.size.should == 3
|
101
|
+
result.should include @t1,@t2,@t4
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end #of describe self
|
105
|
+
|
106
|
+
describe self do
|
107
|
+
before(:all) do
|
108
|
+
@tm = get_used_tm_sys_tm
|
109
|
+
@t1,@t2,@t3,@t4,@t5,@t6,@t7,@t8 = @tm.get!(["t1","t2","t3","t4","t5","t6","t7","t8"])
|
110
|
+
@t_a1,@t_a2 = @tm.get!(["t_a1","t_a2"])
|
111
|
+
t_r1,t_r2,t_r3,t_r4,t_r5,t_r6 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5","t_r6"])
|
112
|
+
a1 = @tm.create_association(@t_a1)
|
113
|
+
a2 = @tm.create_association(@t_a1)
|
114
|
+
a3 = @tm.create_association(@t_a1)
|
115
|
+
a4 = @tm.create_association(@t_a1)
|
116
|
+
a5 = @tm.create_association(@t_a1)
|
117
|
+
a6 = @tm.create_association(@t_a2)
|
118
|
+
r1 = a1.create_role(t_r1, @t1)
|
119
|
+
r2 = a1.create_role(t_r3, @t2)
|
120
|
+
r4 = a2.create_role(t_r1, @t1)
|
121
|
+
r5 = a2.create_role(t_r3, @t3)
|
122
|
+
r6 = a3.create_role(t_r1, @t1)
|
123
|
+
r7 = a3.create_role(t_r5, @t5)
|
124
|
+
r3 = a4.create_role(t_r1, @t1)
|
125
|
+
r8 = a4.create_role(t_r3, @t4)
|
126
|
+
r9 = a4.create_role(t_r6, @t6)
|
127
|
+
r10 = a5.create_role(t_r4, @t1)
|
128
|
+
r11 = a5.create_role(t_r3, @t7)
|
129
|
+
r12 = a6.create_role(t_r4, @t1)
|
130
|
+
r13 = a6.create_role(t_r2, @t8)
|
131
|
+
end
|
132
|
+
after(:all) do
|
133
|
+
@tm.close
|
134
|
+
end
|
135
|
+
describe "#peers" do
|
136
|
+
it "should give back all peers if argument = :any" do
|
137
|
+
@t3.peers(:any).should == @t3.peers
|
138
|
+
end
|
139
|
+
it "should give back an empty Array if argument is not a Topic or Topic-Reference" do
|
140
|
+
@t3.peers("noTopic").should respond_to(:each)
|
141
|
+
@t3.peers("noTopic").should be_empty
|
142
|
+
end
|
143
|
+
it "should give back all peers" do
|
144
|
+
@t3.peers.size.should == 6 #loose
|
145
|
+
@t3.should have(6).peers
|
146
|
+
@t3.peers.should include @t2,@t4,@t5,@t6,@t7,@t8
|
147
|
+
end
|
148
|
+
it "should give back some peers if rtype is given" do
|
149
|
+
@t3.peers("t_r3").size.should == 3
|
150
|
+
@t3.peers("t_r3").should include @t2,@t4,@t7
|
151
|
+
end
|
152
|
+
it "should give back no peers if rtype is given but does not match" do
|
153
|
+
@t3.peers("t_r6").should respond_to(:each)
|
154
|
+
@t3.peers("t_r6").should be_empty
|
155
|
+
end
|
156
|
+
it "should give back some peers if atype is given" do
|
157
|
+
@t3.peers(@t_a1).size.should == 3
|
158
|
+
@t3.peers(@t_a1).should include @t2, @t4, @t7
|
159
|
+
end
|
160
|
+
it "should give back no peers if atype is given but does not match" do
|
161
|
+
@t3.peers(@t_a2).should respond_to(:each)
|
162
|
+
@t3.peers(@t_a2).should be_empty
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end #of describe self
|
166
|
+
|
167
|
+
describe self do
|
168
|
+
describe "#associations_played" do
|
169
|
+
before(:each) do
|
170
|
+
@tm = get_used_tm_sys_tm
|
171
|
+
@topic = @tm.get!("topic")
|
172
|
+
end
|
173
|
+
after(:each) do
|
174
|
+
@tm.close
|
175
|
+
end
|
176
|
+
it "should give back an empty Array if the topic plays in no association" do
|
177
|
+
@topic.associations_played.should be_empty
|
178
|
+
end
|
179
|
+
it "should be tested"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
5
|
+
|
6
|
+
module Sugar::Topic::HashAccess
|
7
|
+
|
8
|
+
describe self do
|
9
|
+
before(:each) do
|
10
|
+
@tm = get_used_tm_sys_tm
|
11
|
+
end
|
12
|
+
after(:each) do
|
13
|
+
@tm.close
|
14
|
+
end
|
15
|
+
describe "#[]" do
|
16
|
+
before(:each) do
|
17
|
+
@topic1 = @tm.get!("Hans")
|
18
|
+
@name1 = @topic1.create_name("Hans")
|
19
|
+
@name2 = @topic1.create_name("first","George",["en","always"])
|
20
|
+
@name3 = @topic1.create_name("last","Meyer",["underground"])
|
21
|
+
@occ1 = @topic1.create_occurrence("Heimat","Sachsen",:scope => ["de"])
|
22
|
+
@occ2 = @topic1.create_occurrence("Heimat","Germany",:scope => ["de","always"])
|
23
|
+
@occ3 = @topic1.create_occurrence("Birthyear","1969",:scope => ["always"])
|
24
|
+
@occ4 = @topic1.create_occurrence("parents","none")
|
25
|
+
end
|
26
|
+
it "should give back an Occurrence of the specified type, in an Array, if the argument is a Topic" do
|
27
|
+
@topic1[@tm.get("Something")].size.should == 0
|
28
|
+
@topic1[@tm.get("Heimat")].size.should == 2
|
29
|
+
@topic1[@tm.get("Heimat")].should include(@occ1)
|
30
|
+
@topic1[@tm.get("Heimat")].should include(@occ2)
|
31
|
+
end
|
32
|
+
it "should give back an empty Array if the argument is nil" do
|
33
|
+
@topic1[nil].should be_empty
|
34
|
+
@topic1.[](nil).should be_empty
|
35
|
+
end
|
36
|
+
it "should give back all occurrences of this Topic if no argument is given" do
|
37
|
+
@topic1[].size.should == 4
|
38
|
+
@topic1[].should include(@occ1)
|
39
|
+
@topic1[].should include(@occ2)
|
40
|
+
@topic1[].should include(@occ3)
|
41
|
+
@topic1[].should include(@occ4)
|
42
|
+
end
|
43
|
+
it "should return an array of names with default nametype if the argument equals '-'" do
|
44
|
+
@topic1["-"].size.should == 1
|
45
|
+
@topic1["-"].should include(@name1)
|
46
|
+
end
|
47
|
+
it "should give back all names that have the given name type if argument equals '-type'" do
|
48
|
+
@topic1["-first"].size.should == 1
|
49
|
+
@topic1["-first"].should include(@name2)
|
50
|
+
end
|
51
|
+
it "should give back all names that have the given name type and scope if argument equals '-type @scope" do
|
52
|
+
@topic1["-last @underground"].size.should == 1
|
53
|
+
@topic1["-last @underground"].should include(@name3)
|
54
|
+
end
|
55
|
+
it "should give back an empty Array if argument equals '-type' or '-type @scope' or '-type @scope1 scope2' but type or scope/1/2 does not exist" do
|
56
|
+
@topic1["-nothing"].should be_empty
|
57
|
+
@topic1["-first @nothing"].should be_empty
|
58
|
+
@topic1["-nothing @nothing"].should be_empty
|
59
|
+
@topic1["-first @en nothing"].should be_empty
|
60
|
+
@topic1["-first @nothing en"].should be_empty
|
61
|
+
@topic1["-nothing @nothing nothing"].should be_empty
|
62
|
+
end
|
63
|
+
it "should give back all names that have the given name type and scope if argument equals '-type @scope1 scope2" do
|
64
|
+
@topic1["-first @en always"].size.should == 1
|
65
|
+
@topic1["-first @en always"].should include(@name2)
|
66
|
+
@topic1["-first @en, always"].should == @topic1["-first @en always"]
|
67
|
+
end
|
68
|
+
it "should give back all occurrences that have the given occurrence type if argument equals 'type'" do
|
69
|
+
@topic1["Heimat"].size.should == 2
|
70
|
+
@topic1["Heimat"].should include(@occ1)
|
71
|
+
@topic1["Heimat"].should include(@occ2)
|
72
|
+
end
|
73
|
+
it "should give back all occurrences that have the given occurrence type and scope if argument equals 'type @scope'" do
|
74
|
+
@topic1["Heimat @de"].size.should == 2
|
75
|
+
@topic1["Heimat @de"].should include(@occ1)
|
76
|
+
@topic1["Heimat @de"].should include(@occ2)
|
77
|
+
end
|
78
|
+
it "should give back all occurrences that have the given occurrence type and scope if argument equals 'type @scope1 scope2'" do
|
79
|
+
@topic1["Heimat @de always"].size.should == 1
|
80
|
+
@topic1["Heimat @de always"].should include(@occ2)
|
81
|
+
@topic1["Heimat @de, always"].should == @topic1["Heimat @de always"]
|
82
|
+
end
|
83
|
+
it "should give back an empty Array if argument equals 'type' or 'type @scope' or 'type @scope1 scope2' but type or scope/1/2 does not exist" do
|
84
|
+
@topic1["nothing"].should be_empty
|
85
|
+
@topic1["first @nothing"].should be_empty
|
86
|
+
@topic1["nothing @nothing"].should be_empty
|
87
|
+
@topic1["parents @en nothing"].should be_empty
|
88
|
+
@topic1["parents @nothing en"].should be_empty
|
89
|
+
@topic1["nothing @nothing nothing"].should be_empty
|
90
|
+
end
|
91
|
+
it "should give back all name and occurrences of this Topic if argument equals '*'" do
|
92
|
+
@topic1["*"].size.should == 7
|
93
|
+
end
|
94
|
+
it "should give back all name and occurrences that have the given type if argument equals '*type'" do
|
95
|
+
name = @topic1.create_name("dummy_type","dummy_name")
|
96
|
+
occ = @topic1.create_occurrence("dummy_type","dummy_occ")
|
97
|
+
@topic1["*dummy_type"].size.should == 2
|
98
|
+
@topic1["*dummy_type"].should include(name)
|
99
|
+
@topic1["*dummy_type"].should include(occ)
|
100
|
+
@topic1["*first"].size.should == 1
|
101
|
+
@topic1["*first"].should include(@name2)
|
102
|
+
@topic1["*parents"].size.should == 1
|
103
|
+
@topic1["*parents"].should include(@occ4)
|
104
|
+
end
|
105
|
+
it "should give back all name and occurrences that have the given type and scope if argument equals '*type @scope'" do
|
106
|
+
name1 = @topic1.create_name("dummy_type","dummy_name1",["theme0"])
|
107
|
+
name2 = @topic1.create_name("dummy_type","dummy_name2",["theme1"])
|
108
|
+
occ1 = @topic1.create_occurrence("dummy_type","dummy_occ1", :scope => ["theme0","theme1"])
|
109
|
+
occ2 = @topic1.create_occurrence("dummy_type","dummy_occ2",:scope => ["theme1"])
|
110
|
+
@topic1["*dummy_type @theme0"].size.should == 2
|
111
|
+
@topic1["*dummy_type @theme0"].should include(occ1)
|
112
|
+
@topic1["*dummy_type @theme0"].should include(name1)
|
113
|
+
@topic1["*dummy_type @theme1"].size.should == 3
|
114
|
+
@topic1["*dummy_type @theme1"].should include(name2)
|
115
|
+
@topic1["*dummy_type @theme1"].should include(occ1)
|
116
|
+
@topic1["*dummy_type @theme1"].should include(occ2)
|
117
|
+
end
|
118
|
+
it "should give back all name and occurrences that have the given type and scope if argument equals '*type @scope1 scope2'" do
|
119
|
+
name1 = @topic1.create_name("dummy_type","dummy_name1",["theme0","theme1"])
|
120
|
+
name2 = @topic1.create_name("dummy_type","dummy_name2",["theme1"])
|
121
|
+
occ1 = @topic1.create_occurrence("dummy_type","dummy_occ1",:scope => ["theme0"])
|
122
|
+
occ2 = @topic1.create_occurrence("dummy_type","dummy_occ2",:scope => ["theme0","theme1"])
|
123
|
+
@topic1["*dummy_type @theme0 theme1"].size.should == 2
|
124
|
+
@topic1["*dummy_type @theme0 theme1"].should include(name1)
|
125
|
+
@topic1["*dummy_type @theme0 theme1"].should include(occ2)
|
126
|
+
end
|
127
|
+
it "should handle spaces if argument is a String" do
|
128
|
+
@topic1[" - "].should == @topic1["-"]
|
129
|
+
@topic1[" - first "].should == @topic1["-first"]
|
130
|
+
@topic1[" - last @ underground"].should == @topic1["-last @underground"]
|
131
|
+
@topic1[" - first @ en always"].should == @topic1["-first @en always"]
|
132
|
+
@topic1[" - first @ en, always"].should == @topic1["-first @en, always"]
|
133
|
+
@topic1[" Heimat "].should == @topic1["Heimat"]
|
134
|
+
@topic1[" Heimat @ de "].should == @topic1["Heimat @de"]
|
135
|
+
@topic1[" Heimat @ de always "].should == @topic1["Heimat @de always"]
|
136
|
+
@topic1[" * "].should == @topic1["*"]
|
137
|
+
end
|
138
|
+
it "should give back occurrences and names whose type have item identifier" do
|
139
|
+
topic = @tm.get!("name_ii_test")
|
140
|
+
name = topic.create_name("ii:firstname_ii_test","Hans")
|
141
|
+
@tm.get("^firstname_ii_test").should_not be_nil
|
142
|
+
occ = topic.create_occurrence("ii:age_ii_test","12")
|
143
|
+
@tm.get("^age_ii_test").should_not be_nil
|
144
|
+
topic["-ii:firstname_ii_test"].size.should == 1
|
145
|
+
topic["-ii:firstname_ii_test"].should include name
|
146
|
+
topic["ii:age_ii_test"].size.should == 1
|
147
|
+
topic["ii:age_ii_test"].should include occ
|
148
|
+
topic["-firstname_ii_test"].should be_empty
|
149
|
+
topic["age_ii_test"].should be_empty
|
150
|
+
topic["*"].size.should == 2
|
151
|
+
end
|
152
|
+
it "should give back occurrences and names whose type have subject locator"
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "#[]=" do
|
156
|
+
before(:each) do
|
157
|
+
@topic2 = @tm.get!("Peter")
|
158
|
+
end
|
159
|
+
it "should set a name with standard name type given '-'" do
|
160
|
+
@topic2["-"] = "Peter"
|
161
|
+
@topic2["Hausnummer"] = "1"
|
162
|
+
@topic2.names.size.should == 1
|
163
|
+
@topic2.names.first.type.should == @tm.get(RTM::PSI[:name_type])
|
164
|
+
@topic2.names.first.value.should == "Peter"
|
165
|
+
end
|
166
|
+
it "should set a name with standard name type and scope given '- @scope'" do
|
167
|
+
scope = RTM::PREFIX[:language] + "german"
|
168
|
+
@topic2["- @" + scope] = "Peter"
|
169
|
+
@topic2["Hausnummer"] = "1"
|
170
|
+
@topic2.names.size.should == 1
|
171
|
+
@topic2.names.first.type.should == @tm.get(RTM::PSI[:name_type])
|
172
|
+
@topic2.names.first.value.should == "Peter"
|
173
|
+
@topic2.names.first.scope.first.should == @tm.get(scope)
|
174
|
+
end
|
175
|
+
it "should set a name with standard name type and scope (which is a qname) given '-@qname'" do
|
176
|
+
@tm.add_prefix("lang",RTM::PREFIX[:language])
|
177
|
+
@topic2["- @lang:german"] = "Peter"
|
178
|
+
@topic2["Hausnummer"] = "1"
|
179
|
+
@topic2.names.size.should == 1
|
180
|
+
@topic2.names.first.type.should == @tm.get(RTM::PSI[:name_type])
|
181
|
+
@topic2.names.first.value.should == "Peter"
|
182
|
+
scope = RTM::PREFIX[:language] + "german"
|
183
|
+
@topic2.names.first.scope.first.should == @tm.get(scope)
|
184
|
+
end
|
185
|
+
it "should set a name and nametype type given '-nametype'" do
|
186
|
+
@topic2["-first"] = "Peter"
|
187
|
+
@topic2["Hausnummer"] = "1"
|
188
|
+
@topic2.names.size.should == 1
|
189
|
+
@topic2.names.first.type.should == @tm.get("first")
|
190
|
+
@topic2.names.first.value.should == "Peter"
|
191
|
+
end
|
192
|
+
it "should set an Occurrence and Occurrence type given 'occurrencetype'" do
|
193
|
+
@topic2["-first"] = "Peter"
|
194
|
+
@topic2["Hausnummer"] = "1"
|
195
|
+
@topic2.occurrences.size.should == 1
|
196
|
+
@topic2.occurrences.first.type.should == @tm.get("Hausnummer")
|
197
|
+
@topic2.occurrences.first.value.should == "1"
|
198
|
+
end
|
199
|
+
it "should set the Scope given [...@ scope] or [...@ scope1, scope2 scope3 ...]" do
|
200
|
+
@topic2["-first @deutsch"] = "Peter"
|
201
|
+
@topic2["Hausnummer @scope1, scope2 scope3"] = "1"
|
202
|
+
@topic2.names.first.type.should == @tm.get("first")
|
203
|
+
@topic2.names.first.value.should == "Peter"
|
204
|
+
@topic2.names.first.scope.first.should == @tm.get("deutsch")
|
205
|
+
@topic2.occurrences.first.type.should == @tm.get("Hausnummer")
|
206
|
+
@topic2.occurrences.first.value.should == "1"
|
207
|
+
@topic2.occurrences.first.scope.size.should == 3
|
208
|
+
@topic2.occurrences.first.scope.should include(@tm.get("scope1"))
|
209
|
+
@topic2.occurrences.first.scope.should include(@tm.get("scope2"))
|
210
|
+
@topic2.occurrences.first.scope.should include(@tm.get("scope3"))
|
211
|
+
end
|
212
|
+
it "should allow spaces before and after and between - and Nametype and @" do
|
213
|
+
@topic2[" - first @ scope1 scope2 scope3"] = "Peter"
|
214
|
+
@topic2.names.size.should == 1
|
215
|
+
@topic2.names.first.type.should == @tm.get("first")
|
216
|
+
@topic2.names.first.scope.size.should == 3
|
217
|
+
@topic2.names.first.scope.should include(@tm.get("scope1"))
|
218
|
+
@topic2.names.first.scope.should include(@tm.get("scope2"))
|
219
|
+
@topic2.names.first.scope.should include(@tm.get("scope3"))
|
220
|
+
end
|
221
|
+
it "should create names whose types have item identifier" do
|
222
|
+
@topic2["-ii:a_name"] = "Billy"
|
223
|
+
@tm.get("^a_name").should_not be_nil
|
224
|
+
@topic2.names.first.type.should == @tm.get("^a_name")
|
225
|
+
end
|
226
|
+
it "should create occurrences whose types have item identifier" do
|
227
|
+
@topic2["ii:an_occ"] = "42"
|
228
|
+
@tm.get("^an_occ").should_not be_nil
|
229
|
+
@topic2.occurrences.first.type.should == @tm.get("^an_occ")
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
5
|
+
|
6
|
+
module Sugar
|
7
|
+
module Topic
|
8
|
+
module Scoped
|
9
|
+
describe self do
|
10
|
+
before(:all) do
|
11
|
+
@tm = get_used_tm_sys_tm
|
12
|
+
@theme0 = @tm.get!("negative")
|
13
|
+
@theme1 = @tm.get!("german")
|
14
|
+
@theme2 = @tm.get!("english")
|
15
|
+
@theme3 = @tm.get!("2009")
|
16
|
+
@theme4 = @tm.get!("sorbian")
|
17
|
+
@test_theme = @tm.get!("dummy")
|
18
|
+
@leipzig = @tm.get!("leipzig")
|
19
|
+
@germany = @tm.get!("germany")
|
20
|
+
@name1 = @leipzig.create_name("Leipzig",[@theme1,@theme2])
|
21
|
+
@name2 = @germany.create_name("Germany",[@theme2,@test_theme])
|
22
|
+
@name3 = @germany.create_name("Deutschland",[@theme1])
|
23
|
+
@name4 = @leipzig.create_name("Leipzisch")
|
24
|
+
@name5 = @leipzig.create_name("Lipsk",[@theme4])
|
25
|
+
@occ1 = @leipzig.create_occurrence("inhabitants","500000", :scope => [@theme3])
|
26
|
+
@occ2 = @germany.create_occurrence("states","16", :scope => [@test_theme])
|
27
|
+
@occ3 = @leipzig.create_occurrence("state","Sachsen")
|
28
|
+
@tm.create_association("assoc_dummy")
|
29
|
+
@assoc = @tm.create_association("contained", [@test_theme])
|
30
|
+
@role1 = @assoc.create_role("containee",@leipzig)
|
31
|
+
@role2 = @assoc.create_role("container",@germany)
|
32
|
+
@variant = @name1.create_variant("LE",[@test_theme])
|
33
|
+
end
|
34
|
+
after(:all) do
|
35
|
+
@tm.close
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#scoped" do
|
39
|
+
it "should give back all constructs which have this Topic in their scope" do
|
40
|
+
@theme1.scoped.size.should == 3
|
41
|
+
@theme1.scoped.should include(@name1)
|
42
|
+
@theme1.scoped.should include(@name3)
|
43
|
+
@theme1.scoped.should include(@variant)
|
44
|
+
@theme2.scoped.size.should == 3
|
45
|
+
@theme2.scoped.should include(@name1)
|
46
|
+
@theme2.scoped.should include(@name2)
|
47
|
+
@theme2.scoped.should include(@variant)
|
48
|
+
@theme3.scoped.size.should == 1
|
49
|
+
@theme3.scoped.should include(@occ1)
|
50
|
+
@theme4.scoped.size.should == 1
|
51
|
+
@theme4.scoped.should include(@name5)
|
52
|
+
@test_theme.scoped.size.should == 4
|
53
|
+
@test_theme.scoped.should include(@name2)
|
54
|
+
@test_theme.scoped.should include(@occ2)
|
55
|
+
@test_theme.scoped.should include(@assoc)
|
56
|
+
@test_theme.scoped.should include(@variant)
|
57
|
+
end
|
58
|
+
it "should give back an empty Array if there are no Constructs which have this Topic in their scope" do
|
59
|
+
@theme0.scoped.should be_empty
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#scoped_associations" do
|
64
|
+
it "should give back all Associations which have this Topic in their scope" do
|
65
|
+
@theme1.scoped_associations.should be_empty
|
66
|
+
@theme2.scoped_associations.should be_empty
|
67
|
+
@theme3.scoped_associations.should be_empty
|
68
|
+
@theme4.scoped_associations.should be_empty
|
69
|
+
@test_theme.scoped_associations.size.should == 1
|
70
|
+
@test_theme.scoped_associations.should include(@assoc)
|
71
|
+
end
|
72
|
+
it "should give back an empty Array if there are no Associations which have this Topic in their scope" do
|
73
|
+
@theme0.scoped_associations.should be_empty
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#scoped_names" do
|
78
|
+
it "should give back all Names which have this Topic in their scope" do
|
79
|
+
@theme1.scoped_names.size.should == 2
|
80
|
+
@theme1.scoped_names.should include(@name1)
|
81
|
+
@theme1.scoped_names.should include(@name3)
|
82
|
+
@theme2.scoped_names.size.should == 2
|
83
|
+
@theme2.scoped_names.should include(@name1)
|
84
|
+
@theme2.scoped_names.should include(@name2)
|
85
|
+
@theme3.scoped_names.should be_empty
|
86
|
+
@theme4.scoped_names.size.should == 1
|
87
|
+
@theme4.scoped_names.should include(@name5)
|
88
|
+
@test_theme.scoped_names.size.should == 1
|
89
|
+
@test_theme.scoped_names.should include(@name2)
|
90
|
+
end
|
91
|
+
it "should give back an empty Array if there are no Names which have this Topic in their scope" do
|
92
|
+
@theme0.scoped_names.should be_empty
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#scoped_occurrences" do
|
97
|
+
it "should give back all Occurrences which have this Topic in their scope" do
|
98
|
+
@theme1.scoped_occurrences.should be_empty
|
99
|
+
@theme2.scoped_occurrences.should be_empty
|
100
|
+
@theme3.scoped_occurrences.size.should == 1
|
101
|
+
@theme3.scoped_occurrences.should include(@occ1)
|
102
|
+
@theme4.scoped_occurrences.should be_empty
|
103
|
+
@test_theme.scoped_occurrences.size.should == 1
|
104
|
+
@test_theme.scoped_occurrences.should include(@occ2)
|
105
|
+
end
|
106
|
+
it "should give back an empty Array if there are no Occurrences which have this Topic in their scope" do
|
107
|
+
@theme0.scoped_occurrences.should be_empty
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#scoped_variants" do
|
112
|
+
it "should give back all Variants which have this Topic in their scope" do
|
113
|
+
@theme1.scoped_variants.size.should == 1
|
114
|
+
@theme1.scoped_variants.should include(@variant)
|
115
|
+
@theme2.scoped_variants.size.should == 1
|
116
|
+
@theme2.scoped_variants.should include(@variant)
|
117
|
+
@theme3.scoped_variants.should be_empty
|
118
|
+
@theme4.scoped_variants.should be_empty
|
119
|
+
@test_theme.scoped_variants.size.should == 1
|
120
|
+
@test_theme.scoped_variants.should include(@variant)
|
121
|
+
end
|
122
|
+
it "should give back an empty Array if there are no Variants which have this Topic in their scope" do
|
123
|
+
@theme0.scoped_variants.should be_empty
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end #of describe self
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|