rtm 0.1.6 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +32 -3
  4. data/lib/rtm.rb +126 -74
  5. data/lib/rtm/axes.rb +298 -0
  6. data/lib/rtm/axes/association.rb +76 -0
  7. data/lib/rtm/axes/associations.rb +96 -0
  8. data/lib/rtm/axes/assocs_names_occs.rb +56 -0
  9. data/lib/rtm/axes/characteristic.rb +68 -0
  10. data/lib/rtm/axes/characteristics.rb +93 -0
  11. data/lib/rtm/axes/string.rb +76 -0
  12. data/lib/rtm/axes/strings.rb +87 -0
  13. data/lib/rtm/axes/topic.rb +233 -0
  14. data/lib/rtm/axes/topics.rb +280 -0
  15. data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
  16. data/lib/rtm/engine.rb +101 -0
  17. data/lib/rtm/extensions.rb +65 -5
  18. data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
  19. data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
  20. data/lib/rtm/helpers/uri.rb +13 -0
  21. data/lib/rtm/io.rb +19 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/tmapix_from.rb +155 -0
  24. data/lib/rtm/io/tmapix_to.rb +223 -0
  25. data/lib/rtm/io/to_hash.rb +154 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +45 -0
  28. data/lib/rtm/io/to_string.rb +21 -8
  29. data/lib/rtm/io/to_xtm1.rb +6 -4
  30. data/lib/rtm/io/to_xtm2.rb +10 -8
  31. data/lib/rtm/io/to_yaml.rb +59 -100
  32. data/lib/rtm/navigation.rb +23 -0
  33. data/lib/rtm/navigation/association/players.rb +25 -0
  34. data/lib/rtm/navigation/name/atomify.rb +19 -0
  35. data/lib/rtm/navigation/name/characteristics.rb +33 -0
  36. data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
  37. data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
  38. data/lib/rtm/navigation/topic/characteristics.rb +33 -0
  39. data/lib/rtm/navigation/topic/indicators.rb +31 -0
  40. data/lib/rtm/navigation/topic/items.rb +31 -0
  41. data/lib/rtm/navigation/topic/locators.rb +31 -0
  42. data/lib/rtm/navigation/topic/players.rb +27 -0
  43. data/lib/rtm/navigation/topic/supertypes.rb +166 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +109 -0
  46. data/lib/rtm/psi.rb +39 -2
  47. data/lib/rtm/sugar.rb +47 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +58 -0
  50. data/lib/rtm/sugar/occurrence/external.rb +53 -0
  51. data/lib/rtm/sugar/reifiable/reifier.rb +21 -0
  52. data/lib/rtm/sugar/role/counterparts.rb +139 -46
  53. data/lib/rtm/sugar/topic/best_name.rb +74 -0
  54. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  55. data/lib/rtm/sugar/topic/counterparts.rb +145 -10
  56. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  57. data/lib/rtm/sugar/topic/scoped.rb +114 -0
  58. data/lib/rtm/sugar/topic/topic_ref.rb +86 -0
  59. data/lib/rtm/sugar/topic/typed.rb +207 -0
  60. data/lib/rtm/sugar/topic_map/query_cache.rb +66 -0
  61. data/lib/rtm/sugar/topic_map/themes.rb +53 -0
  62. data/lib/rtm/sugar/typed/types.rb +38 -0
  63. data/lib/rtm/validation.rb +7 -4
  64. data/lib/rtm/version.rb +30 -0
  65. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  66. data/spec/rtm/axes/association_spec.rb +88 -0
  67. data/spec/rtm/axes/associations_spec.rb +60 -0
  68. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  69. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  70. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  71. data/spec/rtm/axes/string_spec.rb +145 -0
  72. data/spec/rtm/axes/strings_spec.rb +168 -0
  73. data/spec/rtm/axes/topic_spec.rb +124 -0
  74. data/spec/rtm/axes/topics_spec.rb +103 -0
  75. data/spec/rtm/base_spec.rb +32 -0
  76. data/spec/rtm/io/tmapix_from_spec.rb +76 -0
  77. data/spec/rtm/io/tmapix_to_spec.rb +159 -0
  78. data/spec/rtm/io/to_hash_spec.rb +90 -0
  79. data/spec/rtm/io/to_rdf_spec.rb +37 -0
  80. data/spec/rtm/io/to_string_spec.rb +122 -0
  81. data/spec/rtm/io/to_yaml_spec.rb +89 -0
  82. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  83. data/spec/rtm/navigation/association_spec.rb +52 -0
  84. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  85. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  86. data/spec/rtm/navigation/name_spec.rb +52 -0
  87. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  88. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  89. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  90. data/spec/rtm/navigation/string_spec.rb +51 -0
  91. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  92. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  93. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  94. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  95. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  96. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  97. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  98. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  99. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  100. data/spec/rtm/navigation/topic_spec.rb +153 -0
  101. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  102. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +171 -0
  103. data/spec/rtm/sugar/occurrence/external_spec.rb +129 -0
  104. data/spec/rtm/sugar/reifiable/reifier_spec.rb +41 -0
  105. data/spec/rtm/sugar/role/counterparts_spec.rb +193 -0
  106. data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
  107. data/spec/rtm/sugar/topic/characteristics_spec.rb +333 -0
  108. data/spec/rtm/sugar/topic/counterparts_spec.rb +224 -0
  109. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  110. data/spec/rtm/sugar/topic/scoped_spec.rb +195 -0
  111. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  112. data/spec/rtm/sugar/topic/typed_spec.rb +217 -0
  113. data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
  114. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  115. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  116. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  117. data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
  118. data/spec/rtm/tmapi/core/name_spec.rb +270 -0
  119. data/spec/rtm/tmapi/core/occurrence_spec.rb +53 -0
  120. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  121. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  122. data/spec/rtm/tmapi/core/scoped_spec.rb +441 -0
  123. data/spec/rtm/tmapi/core/topic_map_spec.rb +716 -0
  124. data/spec/rtm/tmapi/core/topic_spec.rb +1468 -0
  125. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  126. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  127. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  128. data/spec/rtm/tmapi_spec.rb +44 -0
  129. data/spec/rtm/utils/sparql_spec.rb +26 -0
  130. data/spec/rtm_spec.rb +93 -0
  131. data/spec/spec_helper.rb +28 -0
  132. data/test/javalibs/junit-4.5.jar +0 -0
  133. data/test/javalibs/tmapi-2.0-tests.jar +0 -0
  134. data/test/tmapi_tests.rb +25 -0
  135. metadata +169 -65
  136. data/COPYRIGHT +0 -4
  137. data/lib/Rakefile.rb +0 -42
  138. data/lib/activetopicmaps.rb +0 -278
  139. data/lib/rtm/backend/active_record.rb +0 -58
  140. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  141. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  142. data/lib/rtm/backend/active_record/locators.rb +0 -55
  143. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  144. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  145. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  146. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  147. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  148. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  149. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  150. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  151. data/lib/rtm/backend/active_record/topic.rb +0 -87
  152. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  153. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  154. data/lib/rtm/base.rb +0 -92
  155. data/lib/rtm/connect.rb +0 -92
  156. data/lib/rtm/core_ext.rb +0 -6
  157. data/lib/rtm/io/from_xtm2.rb +0 -263
  158. data/lib/rtm/merging/merging.rb +0 -307
  159. data/lib/rtm/pimp_my_api.rb +0 -28
  160. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  161. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  162. data/lib/run_main_project.rb +0 -16
  163. data/test/base_test.rb +0 -162
@@ -0,0 +1,25 @@
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 RTM::Sugar::Topic::BestName
7
+ describe self do
8
+ before(:each) do
9
+ @tm = get_used_tm_sys_tm
10
+ end
11
+ after(:each) do
12
+ @tm.close
13
+ end
14
+
15
+ describe "#best_name" do
16
+ before(:each) do
17
+ @topic = @tm.get!("Leipzig")
18
+ end
19
+ it "should return a String" do
20
+ @topic.best_name.should be_a_kind_of String
21
+ #puts @topic.best_name
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,333 @@
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 RTM::Sugar::Topic::Characteristics
7
+ describe self do
8
+ before(:each) do
9
+ @tm = get_used_tm_sys_tm
10
+ end
11
+ after(:each) do
12
+ @tm.close
13
+ end
14
+
15
+ describe "#internal_occurrences" do
16
+ before(:each) do
17
+ @uni_leipzig = @tm.get!("Uni_LE")
18
+ @occ1 = @uni_leipzig.create_occurrence("Alter","600")
19
+ @occ2 = @uni_leipzig.create_occurrence("Heimat","Sachsen")
20
+ @occ3 = @uni_leipzig.create_occurrence("Webseite",@tm.create_locator("http://www.example.org/uni-leipzig"))
21
+ end
22
+ it "should give back all occurrences that are not of Datatype AnyURI" do
23
+ @uni_leipzig.internal_occurrences.size.should == 2
24
+ @uni_leipzig.internal_occurrences.should include(@occ1)
25
+ @uni_leipzig.internal_occurrences.should include(@occ2)
26
+ end
27
+ end #of describe "#internal_occurrences" do
28
+
29
+ describe "#external_occurrences" do
30
+ before(:each) do
31
+ @uni_leipzig = @tm.get!("Uni_LE")
32
+ @occ1 = @uni_leipzig.create_occurrence("Alter","600")
33
+ @occ2 = @uni_leipzig.create_occurrence("Heimat","Sachsen")
34
+ @occ3 = @uni_leipzig.create_occurrence("Webseite",@tm.create_locator("http://www.example.org/uni-leipzig"))
35
+ end
36
+ it "should give back all occurrences that are of Datatype AnyURI" do
37
+ @uni_leipzig.external_occurrences.size.should == 1
38
+ @uni_leipzig.external_occurrences.should include(@occ3)
39
+ end
40
+ end #of describe "#external_occurrences"
41
+
42
+ describe "#names_by" do
43
+ before(:each) do
44
+ @topic = @tm.get!("Hans")
45
+ @name1 = @topic.create_name("first_name","Hans-Peter")
46
+ @name2 = @topic.create_name("last_name","Mueller")
47
+ @name3 = @topic.create_name("Hans",["mum"])
48
+ @name4 = @topic.create_name("full_name","Hans-Peter Mueller",["official"])
49
+ @name5 = @topic.create_name("Hansi",["endearment","mum"])
50
+ end
51
+ it "should give back all names if no argument is given" do
52
+ @topic.should have(5).names_by
53
+ @topic.names_by.should include @name1, @name2, @name3, @name4, @name5
54
+ end
55
+ it "should give back all names if all values in the argument hash equal :any" do
56
+ @topic.names_by(:type => :any, :value => :any, :scope => :any).size.should == 5
57
+ @topic.names_by(:type => :any, :value => :any, :scope => :any).should include @name1, @name2, @name3, @name4, @name5
58
+ end
59
+ it "should give back some names if a type is given (identifier is a String)" do
60
+ @topic.names_by(:type => "first_name").size.should == 1
61
+ @topic.names_by(:type => "first_name").should include @name1
62
+ @topic.names_by(:type => ["first_name"]).should == @topic.names_by(:type => "first_name")
63
+ end
64
+ it "should give back some names if a type is given (identifier == :default)" do
65
+ @topic.names_by(:type => :default).size.should == 2
66
+ @topic.names_by(:type => :default).should include @name3, @name5
67
+ @topic.names_by(:type => [:default]).should == @topic.names_by(:type => :default)
68
+ end
69
+ it "should give back some names if a type is given (identifier is a Locator)" do
70
+ locator = @tm.create_locator("full_name")
71
+ locator.should be_a_kind_of RTM::Locator
72
+ @topic.names_by(:type => locator).size.should == 1
73
+ @topic.names_by(:type => locator).should include @name4
74
+ @topic.names_by(:type => [locator]).should == @topic.names_by(:type => locator)
75
+ end
76
+ it "should give back some names if a type is given (identifier is a Topic)" do
77
+ topic = @tm.get("last_name")
78
+ topic.should be_a_kind_of RTM::Topic
79
+ @topic.names_by(:type => topic).size.should == 1
80
+ @topic.names_by(:type => topic).should include @name2
81
+ @topic.names_by(:type => [topic]).should == @topic.names_by(:type => topic)
82
+ end
83
+ it "should give back some names if several types are given (identifier is an Array)" do
84
+ string = "first_name"
85
+ locator = @tm.create_locator("full_name")
86
+ topic = @tm.get("last_name")
87
+ symbol = :default
88
+ @topic.names_by(:type => [string,symbol,locator,topic]).size.should == 5
89
+ @topic.names_by(:type => [string,symbol,locator,topic]).should include @name1, @name2, @name3, @name4, @name5
90
+ end
91
+ it "should give back no names if a type is given but not a type of a name" do
92
+ @tm.get!("existing_dummy")
93
+ @topic.names_by(:type => "dummy").should be_empty
94
+ @topic.names_by(:type => "existing_dummy").should be_empty
95
+ @topic.names_by(:type => @tm.create_locator("dummy")).should be_empty
96
+ @topic.names_by(:type => @tm.create_locator("existing_dummy")).should be_empty
97
+ @topic.names_by(:type => @tm.get("dummy")).should be_empty
98
+ @topic.names_by(:type => @tm.get("existing_dummy")).should be_empty
99
+ end
100
+ it "should give back some names if several types are given but some are not types of names" do
101
+ @topic.names_by(:type => ["dummy",:default,"first_name"]).size.should == 3
102
+ @topic.names_by(:type => ["dummy",:default,"first_name"]).should include @name1, @name3, @name5
103
+ end
104
+ it "should not give back a name several times if several equals types are given" do
105
+ @topic.names_by(:type => ["first_name","first_name"]).should == @topic.names_by(:type => "first_name")
106
+ end
107
+ it "should give back some names if a value is given" do
108
+ @topic.names_by(:value => "Hansi").size.should == 1
109
+ @topic.names_by(:value => "Hansi").should include @name5
110
+ @topic.names_by(:value => ["Hansi"]).should == @topic.names_by(:value => "Hansi")
111
+ end
112
+ it "should give back some names if several values are given" do
113
+ @topic.names_by(:value => ["Mueller","Hans-Peter"]).size.should == 2
114
+ @topic.names_by(:value => ["Mueller","Hans-Peter"]).should include @name1, @name2
115
+ end
116
+ it "should give back no names if a value is given which is not a value of a name" do
117
+ @topic.names_by(:value => "dummy").should be_empty
118
+ end
119
+ it "should give back some names if values are given but if not all are values of names" do
120
+ @topic.names_by(:value => ["Hans","dummy"]).size.should == 1
121
+ @topic.names_by(:value => ["Hans","dummy"]).should include @name3
122
+ end
123
+ it "should not give back a name several times if several equal values are given" do
124
+ @topic.names_by(:value => ["Hans","Hans"]).should == @topic.names_by(:value => "Hans")
125
+ end
126
+ it "should give back no names if a value is given which is not a String" do
127
+ @topic.names_by(:value => 1).should be_empty
128
+ @topic.names_by(:value => [1]).should be_empty
129
+ end
130
+ it "should give back some names if a scope is given (one theme, String)" do
131
+ @topic.names_by(:scope => "mum").size.should == 2
132
+ @topic.names_by(:scope => "mum").should include @name3, @name5
133
+ end
134
+ it "should give back some names if a scope is given (one theme, Locator)" do
135
+ locator = @tm.create_locator("official")
136
+ @topic.names_by(:scope => locator).size.should == 1
137
+ @topic.names_by(:scope => locator).should include @name4
138
+ end
139
+ it "should give back some names if a scope is given (one theme, Topic)" do
140
+ topic = @tm.get("endearment")
141
+ @topic.names_by(:scope => topic).size.should == 1
142
+ @topic.names_by(:scope => topic).should include @name5
143
+ end
144
+ it "should give back some names if a scope is given (several themes)" do
145
+ string = "mum"
146
+ locator = @tm.create_locator("official")
147
+ topic = @tm.get("endearment")
148
+ @topic.names_by(:scope => [string,locator,topic]).size.should == 3
149
+ @topic.names_by(:scope => [string,locator,topic]).should include @name3, @name4, @name5
150
+ end
151
+ it "should give back no names if a scope is given which is not a scope of a name" do
152
+ @topic.names_by(:scope => "dummy").should be_empty
153
+ end
154
+ it "should give back some names if a scope is given (several themes) but if not all are in the scope of names" do
155
+ @topic.names_by(:scope => ["mum","dummy"]).size.should == 2
156
+ @topic.names_by(:scope => ["mum","dummy"]).should include @name3, @name5
157
+ end
158
+ it "should give back no names if a scope is given which is not a String, Locator or Topic" do
159
+ lambda{topic.names_by(:scope => 1)}.should raise_error
160
+ lambda{@topic.names_by(:scope => [1])}.should raise_error
161
+ end
162
+ it "should give back some names if scope is set to :ucs" do
163
+ @topic.names_by(:scope => :ucs).size.should == 2
164
+ @topic.names_by(:scope => :ucs).should include(@name1, @name2)
165
+ end
166
+ it "should give back some names (in the unconstrained scope) if scope is []" do
167
+ @topic.names_by(:scope => []).size.should == 2
168
+ @topic.names_by(:scope => []).should include(@name1, @name2)
169
+ end
170
+ it "should not give back a name several times if several equal themes are given" do
171
+ @topic.names_by(:scope => ["official","official"]).should == @topic.names_by(:scope => "official")
172
+ end
173
+ it "should give back name in the unconstrained scope if scope equals :ucs"
174
+ it "should not create Topics" do
175
+ @tm.get("dummy1").should be_nil
176
+ @tm.get("dummy2").should be_nil
177
+ @tm.get("dummy3").should be_nil
178
+ @topic.names_by(:type => "dummy1", :value => "dummy2", :scope => "dummy3").should be_empty
179
+ @tm.get("dummy1").should be_nil
180
+ @tm.get("dummy2").should be_nil
181
+ @tm.get("dummy3").should be_nil
182
+ end
183
+ end
184
+
185
+ describe "#occurrences_by" do
186
+ before(:each) do
187
+ @topic = @tm.get!("Hans")
188
+ @occ1 = @topic.create_occurrence("birthyear","1980")
189
+ @occ2 = @topic.create_occurrence("favourite_colour","blue")
190
+ @occ3 = @topic.create_occurrence("age","29",:scope => ["2009"])
191
+ @occ4 = @topic.create_occurrence("hair_colour","blue",:scope => ["2009","halloween"])
192
+ @occ5 = @topic.create_occurrence("age","20",:datatype => RTM::PSI[:Integer],:scope => ["2000"])
193
+ end
194
+ it "should give back all occurrences if no argument is given" do
195
+ @topic.should have(5).occurrences_by
196
+ @topic.occurrences_by.should include @occ1, @occ2, @occ3, @occ4, @occ5
197
+ end
198
+ it "should give back all occurrences if all values in the argument hash equal :any" do
199
+ @topic.occurrences_by(:type => :any, :value => :any, :scope => :any, :datatype => :any).size.should == 5
200
+ @topic.occurrences_by(:type => :any, :value => :any, :scope => :any, :datatype => :any).should include @occ1, @occ2, @occ3, @occ4, @occ5
201
+ end
202
+ it "should give back some occurrences if a type is given (identifier is a String)" do
203
+ @topic.occurrences_by(:type => "birthyear").size.should == 1
204
+ @topic.occurrences_by(:type => "birthyear").should include @occ1
205
+ end
206
+ it "should give back some occurrences if a type is given (identifier is a Locator)" do
207
+ locator = @tm.create_locator("age")
208
+ locator.should be_a_kind_of RTM::Locator
209
+ @topic.occurrences_by(:type => locator).size.should == 2
210
+ @topic.occurrences_by(:type => locator).should include @occ3, @occ5
211
+ end
212
+ it "should give back some occurrences if a type is given (identifier is a Topic)" do
213
+ topic = @tm.get("hair_colour")
214
+ topic.should be_a_kind_of RTM::Topic
215
+ @topic.occurrences_by(:type => topic).size.should == 1
216
+ @topic.occurrences_by(:type => topic).should include @occ4
217
+ end
218
+ it "should give back some occurrences if several types are given (identifier is an Array)" do
219
+ string = "birthyear"
220
+ locator = @tm.create_locator("age")
221
+ topic = @tm.get("hair_colour")
222
+ @topic.occurrences_by(:type => [string,locator,topic]).size.should == 4
223
+ @topic.occurrences_by(:type => [string,locator,topic]).should include @occ1, @occ3, @occ4, @occ5
224
+ end
225
+ it "should give back no occurrences if a type is given which is not a type of an occurrence" do
226
+ @tm.get!("existing_dummy")
227
+ @topic.occurrences_by(:type => "dummy").should be_empty
228
+ @topic.occurrences_by(:type => "existing_dummy").should be_empty
229
+ @topic.occurrences_by(:type => @tm.create_locator("dummy")).should be_empty
230
+ @topic.occurrences_by(:type => @tm.create_locator("existing_dummy")).should be_empty
231
+ @topic.occurrences_by(:type => @tm.get("dummy")).should be_empty
232
+ @topic.occurrences_by(:type => @tm.get("existing_dummy")).should be_empty
233
+ end
234
+ it "should give back some occurrences if several types are given but some are not types of occurrences" do
235
+ @topic.occurrences_by(:type => ["dummy","age"]).size.should == 2
236
+ @topic.occurrences_by(:type => ["dummy","age"]).should include @occ3, @occ5
237
+ end
238
+ it "should not give back an occurrence several times if several equal types are given" do
239
+ @topic.occurrences_by(:type => ["birthyear","birthyear"]).should == @topic.occurrences_by(:type => "birthyear")
240
+ end
241
+ it "should give back some occurrences if a value is given" do
242
+ @topic.occurrences_by(:value => "1980").size.should == 1
243
+ @topic.occurrences_by(:value => "1980").should include @occ1
244
+ @topic.occurrences_by(:value => "29").size.should == 1
245
+ @topic.occurrences_by(:value => "29").should include @occ3
246
+ end
247
+ it "should give back some occurrences if several values are given" do
248
+ @topic.occurrences_by(:value => ["blue","20"]).size.should == 3
249
+ @topic.occurrences_by(:value => ["blue","20"]).should include @occ2, @occ4, @occ5
250
+ end
251
+ it "should give back no occurrences if a value is given which is not a value of an occurrence" do
252
+ @topic.occurrences_by(:value => "dummy").should be_empty
253
+ end
254
+ it "should give back some occurrences if several values are given but some are not values of occurrences" do
255
+ @topic.occurrences_by(:value => ["blue","dummy","29"]).size.should == 3
256
+ @topic.occurrences_by(:value => ["blue","dummy","29"]).should include @occ2, @occ3, @occ4
257
+ end
258
+ it "should not give back an occurrence several times if several equal values are given" do
259
+ @topic.occurrences_by(:value => ["20","20"]).should == @topic.occurrences_by(:value => "20")
260
+ end
261
+ it "should give back no names if a value is given which is not a String" do
262
+ @topic.occurrences_by(:value => 20).should be_empty
263
+ @topic.occurrences_by(:value => [20]).should be_empty
264
+ end
265
+ it "should give back some occurrences if a scope is given (one theme, String)" do
266
+ @topic.occurrences_by(:scope => "2009").size.should == 2
267
+ @topic.occurrences_by(:scope => "2009").should include @occ3, @occ4
268
+ end
269
+ it "should give back some occurrences if a scope is given (one theme, Locator)" do
270
+ locator = @tm.create_locator("2000")
271
+ @topic.occurrences_by(:scope => locator).size.should == 1
272
+ @topic.occurrences_by(:scope => locator).should include @occ5
273
+ end
274
+ it "should give back some occurrences if a scope is given (one theme, Topic)" do
275
+ topic = @tm.get("halloween")
276
+ @topic.occurrences_by(:scope => topic).size.should == 1
277
+ @topic.occurrences_by(:scope => topic).should include @occ4
278
+ end
279
+ it "should give back some occurrences if a scope is given (several themes)" do
280
+ string = "2000"
281
+ locator = @tm.create_locator("2009")
282
+ topic = @tm.get("halloween")
283
+ @topic.occurrences_by(:scope => [string,locator,topic]).size.should == 3
284
+ @topic.occurrences_by(:scope => [string,locator,topic]).should include @occ3, @occ4, @occ5
285
+ end
286
+ it "should give back no occurrences if a scope is given which is not a scope of an occurrence" do
287
+ @topic.occurrences_by(:scope => "dummy").should be_empty
288
+ end
289
+ it "should give back some occurrences if a scope is given (several themes) but if not all are in the scope of occurrences" do
290
+ @topic.occurrences_by(:scope => ["2000","dummy"]).size.should == 1
291
+ @topic.occurrences_by(:scope => ["2000","dummy"]).should include @occ5
292
+ end
293
+ it "should give back no occurrences if a scope is given which is not a String, Locator or Topic" do
294
+ lambda{topic.occurrences_by(:scope => 1)}.should raise_error
295
+ lambda{@topic.occurrences_by(:scope => [1])}.should raise_error
296
+ end
297
+ it "should not give back an occurrence several times if several equal themes are given" do
298
+ @topic.occurrences_by(:scope => ["2009","2009"]).should == @topic.occurrences_by(:scope => "2009")
299
+ end
300
+ it "should give back some occurrences (in the unconstrained scope) if scope is set to :ucs" do
301
+ @topic.occurrences_by(:scope => :ucs).size.should == 2
302
+ @topic.occurrences_by(:scope => :ucs).should include(@occ1, @occ2)
303
+ end
304
+ it "should give back some occurrences (in the unconstrained scope) if scope is []" do
305
+ @topic.occurrences_by(:scope => []).size.should == 2
306
+ @topic.occurrences_by(:scope => []).should include(@occ1, @occ2)
307
+ end
308
+ it "should test datatype"
309
+ it "should not create Topics" do
310
+ @tm.get("dummy1").should be_nil
311
+ @tm.get("dummy2").should be_nil
312
+ @tm.get("dummy3").should be_nil
313
+ @tm.get("dummy4").should be_nil
314
+ @topic.occurrences_by(:type => "dummy1", :value => "dummy2", :datatype => "dummy3", :scope => "dummy4").should be_empty
315
+ @tm.get("dummy1").should be_nil
316
+ @tm.get("dummy2").should be_nil
317
+ @tm.get("dummy3").should be_nil
318
+ @tm.get("dummy4").should be_nil
319
+ end
320
+ end
321
+
322
+ # describe "#characteristics_by" do
323
+ # before(:each) do
324
+ #
325
+ # end
326
+ # it "should be testend .." do
327
+ #
328
+ # end
329
+ # end
330
+
331
+
332
+ end # of describe self
333
+ end # of module
@@ -0,0 +1,224 @@
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 RTM::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
+ describe self do
184
+ describe "unary associations" do
185
+ before(:each) do
186
+ @tm = get_used_tm_sys_tm
187
+ @player = @tm.get!("player")
188
+ end
189
+ after(:each) do
190
+ @tm.close
191
+ end
192
+ describe "#counterparts" do
193
+ it "should handle unary associations" do
194
+ @tm.create_association("assoc_type", "roletype" => "player")
195
+ @player.counterparts.should be_empty
196
+ @player.counterparts(:atype => "1", :rtype => "2", :otype => "3").should be_empty
197
+ end
198
+ end
199
+ describe "#counterplayers" do
200
+ it "should handle unary associations" do
201
+ @tm.create_association("assoc_type", "roletype" => "player")
202
+ @player.counterplayers.should be_empty
203
+ @player.counterplayers(:atype => "1", :rtype => "2", :otype => "3").should be_empty
204
+ end
205
+ end
206
+ describe "#peers" do
207
+ it "should handle unary associations" do
208
+ @tm.create_association("assoc_type", "roletype" => "player")
209
+ @player.peers.should be_empty
210
+ @player.peers("1").should be_empty
211
+ end
212
+ end
213
+ describe "#associations_played" do
214
+ it "should handle unary associations" do
215
+ assoc = @tm.create_association("assoc_type", "roletype" => "player")
216
+ @player.associations_played.size.should == 1
217
+ @player.associations_played.should include(assoc)
218
+ end
219
+ end
220
+ end
221
+ end
222
+
223
+ end
224
+