rtm 0.1.6 → 0.2.0

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 (146) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +3 -3
  4. data/lib/rtm.rb +148 -74
  5. data/lib/rtm/axes.rb +295 -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 +58 -0
  17. data/lib/rtm/extensions.rb +11 -1
  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 +18 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/ontopia_io.rb +25 -0
  24. data/lib/rtm/io/tmapix.rb +234 -0
  25. data/lib/rtm/io/to_hash.rb +116 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +30 -0
  28. data/lib/rtm/io/to_string.rb +8 -6
  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 +29 -98
  32. data/lib/rtm/navigation.rb +37 -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 +162 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +107 -0
  46. data/lib/rtm/psi.rb +33 -2
  47. data/lib/rtm/sugar.rb +34 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +75 -0
  50. data/lib/rtm/{pimp_my_api.rb → sugar/occurrence/externalize.rb} +3 -0
  51. data/lib/rtm/sugar/role/counterparts.rb +133 -46
  52. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  53. data/lib/rtm/sugar/topic/counterparts.rb +130 -7
  54. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  55. data/lib/rtm/sugar/topic/scoped.rb +65 -0
  56. data/lib/rtm/sugar/topic/topic_ref.rb +35 -0
  57. data/lib/rtm/sugar/topic/typed.rb +159 -0
  58. data/lib/rtm/sugar/typed/types.rb +38 -0
  59. data/lib/rtm/validation.rb +8 -5
  60. data/lib/rtm/version.rb +18 -0
  61. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  62. data/spec/rtm/axes/association_spec.rb +88 -0
  63. data/spec/rtm/axes/associations_spec.rb +60 -0
  64. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  65. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  66. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  67. data/spec/rtm/axes/string_spec.rb +145 -0
  68. data/spec/rtm/axes/strings_spec.rb +168 -0
  69. data/spec/rtm/axes/topic_spec.rb +124 -0
  70. data/spec/rtm/axes/topics_spec.rb +103 -0
  71. data/spec/rtm/base_spec.rb +32 -0
  72. data/spec/rtm/io/tmapix_spec.rb +85 -0
  73. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  74. data/spec/rtm/navigation/association_spec.rb +52 -0
  75. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  76. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  77. data/spec/rtm/navigation/name_spec.rb +52 -0
  78. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  79. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  80. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  81. data/spec/rtm/navigation/string_spec.rb +51 -0
  82. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  83. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  84. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  85. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  86. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  87. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  88. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  89. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  90. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  91. data/spec/rtm/navigation/topic_spec.rb +153 -0
  92. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  93. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +16 -0
  94. data/spec/rtm/sugar/role/counterparts_spec.rb +191 -0
  95. data/spec/rtm/sugar/topic/characteristics_spec.rb +318 -0
  96. data/spec/rtm/sugar/topic/counterparts_spec.rb +184 -0
  97. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  98. data/spec/rtm/sugar/topic/scoped_spec.rb +131 -0
  99. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  100. data/spec/rtm/sugar/topic/typed_spec.rb +155 -0
  101. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  102. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  103. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  104. data/spec/rtm/tmapi/core/name_spec.rb +85 -0
  105. data/spec/rtm/tmapi/core/occurrence_spec.rb +96 -0
  106. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  107. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  108. data/spec/rtm/tmapi/core/scoped_spec.rb +403 -0
  109. data/spec/rtm/tmapi/core/topic_map_spec.rb +648 -0
  110. data/spec/rtm/tmapi/core/topic_spec.rb +992 -0
  111. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  112. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  113. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  114. data/spec/rtm/tmapi_spec.rb +44 -0
  115. data/spec/rtm/utils/sparql_spec.rb +26 -0
  116. data/spec/rtm_spec.rb +94 -0
  117. data/spec/spec_helper.rb +23 -0
  118. data/test/base_unit_test.rb +161 -0
  119. data/test/{base_test.rb → base_unit_test_tmapi.rb} +46 -43
  120. metadata +122 -66
  121. data/COPYRIGHT +0 -4
  122. data/lib/Rakefile.rb +0 -42
  123. data/lib/activetopicmaps.rb +0 -278
  124. data/lib/rtm/backend/active_record.rb +0 -58
  125. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  126. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  127. data/lib/rtm/backend/active_record/locators.rb +0 -55
  128. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  129. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  130. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  131. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  132. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  133. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  134. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  135. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  136. data/lib/rtm/backend/active_record/topic.rb +0 -87
  137. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  138. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  139. data/lib/rtm/base.rb +0 -92
  140. data/lib/rtm/connect.rb +0 -92
  141. data/lib/rtm/core_ext.rb +0 -6
  142. data/lib/rtm/io/from_xtm2.rb +0 -263
  143. data/lib/rtm/merging/merging.rb +0 -307
  144. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  145. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  146. data/lib/run_main_project.rb +0 -16
@@ -0,0 +1,96 @@
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::Occurrence
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
+
16
+ describe "#parent" do
17
+ it "should give back the Topic the Occurrence belongs to" do
18
+ topic = @tm.create_topic_by("Haus")
19
+ topic.should be_a_kind_of RTM::Topic
20
+ @tm.get("Haus").should be_a_kind_of RTM::Topic
21
+ testocc = topic.create_occurrence("Hausnummer", "1")
22
+ testocc.should be_a_kind_of RTM::Occurrence
23
+ testocc.parent.should == topic
24
+ end
25
+ end
26
+
27
+ describe "#value=" do
28
+ before(:each) do
29
+ @topic = @tm.create_topic_by("Haus")
30
+ end
31
+ it "should set an IRI value and the datatype to xsd:AnyURI if arguement is a Locator" do
32
+ occ= @topic.create_occurrence("Hausnummer", "1")
33
+ occ.datatype.to_external_form.should == RTM::PSI[:String]
34
+ occ.value=(@tm.create_locator("http://www.haus.de"))
35
+ occ.datatype.to_external_form.should == RTM::PSI[:IRI]
36
+ occ.value.should include "http://www.haus.de" # since we dont know if not */ as in case of ontopia
37
+ end
38
+ it "should set an String value and the datatype to xsd:String if arguement is a String" do
39
+ occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de"))
40
+ occ.datatype.to_external_form.should == RTM::PSI[:IRI]
41
+ occ.value=("1")
42
+ occ.datatype.to_external_form.should == RTM::PSI[:String]
43
+ occ.value.should == "1"
44
+ end
45
+ it "should set a Float value and the datatype to xsd:Float if arguement is a Float" do
46
+ occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de"))
47
+ occ.datatype.to_external_form.should == RTM::PSI[:IRI]
48
+ 0.5.class.should == Float
49
+ occ.value=(0.5)
50
+ occ.datatype.to_external_form.should == RTM::PSI[:Float]
51
+ occ.value.should == "0.5"
52
+ end
53
+ it "should set a Fixnum value and the datatype to xsd:long if arguement is a Fixnum" do
54
+ occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de"))
55
+ occ.datatype.to_external_form.should == RTM::PSI[:IRI]
56
+ 1.class.should == Fixnum
57
+ occ.value=(1)
58
+ occ.datatype.to_external_form.should == RTM::PSI[:Long]
59
+ occ.value.should == "1"
60
+ end
61
+ it "should set a Bignum value and the datatype to xsd:integer if arguement is a Bignum" do
62
+ occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de"))
63
+ occ.datatype.to_external_form.should == RTM::PSI[:IRI]
64
+ 9999999999999999999.class.should == Bignum
65
+ occ.value=(9999999999999999999)
66
+ occ.datatype.to_external_form.should == RTM::PSI[:Integer]
67
+ occ.value.should == "9999999999999999999"
68
+ end
69
+ end
70
+ end # of describe self
71
+
72
+ describe self do
73
+ describe "#remove" do
74
+ before(:each) do
75
+ @tm = get_used_tm_sys_tm
76
+ @topic1 = @tm.get!("topic1")
77
+ @topic2 = @tm.get!("topic2")
78
+ @occ = @topic1.create_occurrence("birthyear","2000")
79
+ @topic2.create_occurrence("birthyear","1980")
80
+ @topic1.should have(1).occurrences
81
+ @topic1.occurrences.should include @occ
82
+ end
83
+ after(:each) do
84
+ @tm.close
85
+ end
86
+ it "should remove this name from the container (topic)" do
87
+ @tm.literal_index.getOccurrences("2000").size.should == 1
88
+ @occ.remove
89
+ @tm.literal_index.getOccurrences("2000").size.should == 0
90
+ @tm.literal_index.getOccurrences("1980").size.should == 1
91
+ @topic1.should have(0).occurrences
92
+ end
93
+ end
94
+ end # of describe self
95
+
96
+ end # of module
@@ -0,0 +1,168 @@
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::Reifiable
7
+ describe self do
8
+ before(:each) do
9
+ @tm = get_used_tm_sys_tm
10
+ @topic = @tm.get!("test_topic")
11
+ end
12
+ after(:each) do
13
+ @tm.close
14
+ end
15
+
16
+ describe "#reifier=" do
17
+ before(:each) do
18
+ @a_reifier = @tm.get!("test_reifier")
19
+ @a_reifier.should be_a_kind_of RTM::Topic
20
+ @a_reifier["-"] = "since"
21
+ @a_reifier["date"] = "2009"
22
+ @locator = @tm.create_locator("test_reifier")
23
+ @locator.should be_a_kind_of RTM::Locator
24
+ @name = @topic.create_name("Hans")
25
+ @name.should be_a_kind_of RTM::Name
26
+ @name.reifier.should be_nil
27
+ @variant = @name.create_variant("Hansi",["endearment"])
28
+ @variant.should be_a_kind_of RTM::Variant
29
+ @variant.reifier.should be_nil
30
+ @occ = @topic.create_occurrence("favourite_colour","red")
31
+ @occ.should be_a_kind_of RTM::Occurrence
32
+ @assoc = @tm.create_association("mother_child")
33
+ @assoc.should be_a_kind_of RTM::Association
34
+ @assoc.reifier.should be_nil
35
+ @role = @assoc.create_role("child",@topic)
36
+ @role.should be_a_kind_of RTM::Role
37
+ @role.reifier.should be_nil
38
+ end
39
+ it "should set the reifier if the Construct is a Name and identifier a String" do
40
+ @name.reifier = "test_reifier"
41
+ @name.reifier.should == @a_reifier
42
+ end
43
+ it "should set the reifier if the Construct is a Name and identifier a Locator" do
44
+ @name.reifier = @locator
45
+ @name.reifier.should == @a_reifier
46
+ end
47
+ it "should set the reifier if the Construct is a Name and identifier a Topic" do
48
+ @name.reifier = @a_reifier
49
+ @name.reifier.should == @a_reifier
50
+ end
51
+ it "should set the reifier if the Construct is a Variant and identifier a String" do
52
+ @variant.reifier = "test_reifier"
53
+ @variant.reifier.should == @a_reifier
54
+ end
55
+ it "should set the reifier if the Construct is a Variant and identifier a Locator" do
56
+ @variant.reifier = @locator
57
+ @variant.reifier.should == @a_reifier
58
+ end
59
+ it "should set the reifier if the Construct is a Variant and identifier a Topic" do
60
+ @variant.reifier = @a_reifier
61
+ @variant.reifier.should == @a_reifier
62
+ end
63
+ it "should set the reifier if the Construct is an Occurrence and identifier a String" do
64
+ @occ.reifier = "test_reifier"
65
+ @occ.reifier.should == @a_reifier
66
+ end
67
+ it "should set the reifier if the Construct is an Occurrence and identifier a Locator" do
68
+ @occ.reifier = @locator
69
+ @occ.reifier.should == @a_reifier
70
+ end
71
+ it "should set the reifier if the Construct is an Occurrence and identifier a Topic" do
72
+ @occ.reifier = @a_reifier
73
+ @occ.reifier.should == @a_reifier
74
+ end
75
+ it "should set the reifier if the Construct is an Association and identifier a String" do
76
+ @assoc.reifier = "test_reifier"
77
+ @assoc.reifier.should == @a_reifier
78
+ end
79
+ it "should set the reifier if the Construct is an Association and identifier a Locator" do
80
+ @assoc.reifier = @locator
81
+ @assoc.reifier.should == @a_reifier
82
+ end
83
+ it "should set the reifier if the Construct is an Association and identifier a Topic" do
84
+ @assoc.reifier = @a_reifier
85
+ @assoc.reifier.should == @a_reifier
86
+ end
87
+ it "should set the reifier if the Construct is a Role and identifier a String" do
88
+ @role.reifier = "test_reifier"
89
+ @role.reifier.should == @a_reifier
90
+ end
91
+ it "should set the reifier if the Construct is a Role and identifier a Locator" do
92
+ @role.reifier = @locator
93
+ @role.reifier.should == @a_reifier
94
+ end
95
+ it "should set the reifier if the Construct is a Role and identifier a Topic" do
96
+ @role.reifier = @a_reifier
97
+ @role.reifier.should == @a_reifier
98
+ end
99
+ it "should set the reifier if the Construct is a TopicMap and identifier a String" do
100
+ @tm.reifier = "test_reifier"
101
+ @tm.reifier.should == @a_reifier
102
+ end
103
+ it "should set the reifier if the Construct is a TopicMap and identifier a Locator" do
104
+ @tm.reifier = @locator
105
+ @tm.reifier.should == @a_reifier
106
+ end
107
+ it "should set the reifier if the Construct is a TopicMap and identifier a Topic" do
108
+ @tm.reifier = @a_reifier
109
+ @tm.reifier.should == @a_reifier
110
+ end
111
+ it "should remove a reifier if the identifier is nil or not given" do
112
+ @name.reifier = "test_reifier"
113
+ @name.reifier.should == @a_reifier
114
+ @name.reifier = nil
115
+ @name.reifier.should be_nil
116
+ @a_reifier.should have(1).names
117
+ @occ.reifier = "test_reifier"
118
+ @occ.reifier.should == @a_reifier
119
+ @occ.reifier = ()
120
+ @occ.reifier.should be_nil
121
+ @variant.reifier = "test_reifier"
122
+ @variant.reifier.should == @a_reifier
123
+ @variant.reifier = nil
124
+ @variant.reifier.should be_nil
125
+ @assoc.reifier = "test_reifier"
126
+ @assoc.reifier.should == @a_reifier
127
+ @assoc.reifier = ()
128
+ @assoc.reifier.should be_nil
129
+ @role.reifier = "test_reifier"
130
+ @role.reifier.should == @a_reifier
131
+ @role.reifier = nil
132
+ @role.reifier.should be_nil
133
+ @tm.reifier = "test_reifier"
134
+ @tm.reifier.should == @a_reifier
135
+ @tm.reifier = ()
136
+ @tm.reifier.should be_nil
137
+ end
138
+ it "should raise an error if the identifier referes to a Topic which already reifies another information item" do
139
+ @name.reifier = "test_reifier"
140
+ lambda{@occ.reifier = "test_reifier"}.should raise_error
141
+ end
142
+ end
143
+
144
+ describe "merging of two reifier" do
145
+ it "should merge two reifier if their reified constructs are merged" do
146
+ topic = @tm.get!("Hans_Peter")
147
+ name1 = topic.create_name("Hans")
148
+ name2 = topic.create_name("Peter")
149
+ name1.reifier = "ii:reifier1"
150
+ name2.reifier = "ii:reifier2"
151
+ name1.reifier.should == @tm.get("ii:reifier1")
152
+ name2.reifier.should == @tm.get("ii:reifier2")
153
+ @tm.get("ii:reifier1").should_not == @tm.get!("ii:reifier2")
154
+ topic.should have(2).names
155
+ name1.value = "Peter"
156
+ if implementation_for_spec == :sesametm
157
+ topic.should have(1).names
158
+ else
159
+ pending "cannot automerge unless engine is SesameTM" do
160
+ topic.should have(1).names
161
+ end
162
+ end
163
+ #puts @basis.tmsf.getFeature("http://tmapi.org/features/automerge")
164
+ end
165
+ end
166
+
167
+ end # of describe self
168
+ end # of module
@@ -0,0 +1,73 @@
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::Role
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 "#parent" do
16
+ it "should give back the Association to which this Role belongs" do
17
+ topic = @tm.create_topic_by("Haus")
18
+ topic.should be_a_kind_of(RTM::Topic)
19
+ @tm.get("Haus").should be_a_kind_of(RTM::Topic)
20
+ topic_instance = @tm.create_topic_by("Weisses_Haus")
21
+ topic_instance.should be_a_kind_of RTM::Topic
22
+ @tm.get("Weisses_Haus").should be_a_kind_of(RTM::Topic)
23
+ testassoc = @tm.create_association("Haus-Nummer-Beziehung")
24
+ testrole = testassoc.create_role(topic, topic_instance) #TMAPI function
25
+ testassoc.should be_a_kind_of(RTM::Association)
26
+ testrole.should be_a_kind_of(RTM::Role)
27
+ testrole.parent.should == testassoc
28
+ end
29
+ end
30
+
31
+ describe "#player=" do
32
+ before(:each) do
33
+ assoc = @tm.create_association("mother_child")
34
+ @role = assoc.create_role("child","Hans")
35
+ @role.should be_a_kind_of RTM::Role
36
+ end
37
+ it "should set the player of the Role if identifier is a String" do
38
+ previous_player = @role.player
39
+ @role.player = "Tim"
40
+ @role.player.should_not == previous_player
41
+ @role.player.should == @tm.get("Tim")
42
+ end
43
+ it "should set the player of the Role if identifier is a Locator" do
44
+ previous_player = @role.player
45
+ @role.player = @tm.create_locator("Tim")
46
+ @role.player.should_not == previous_player
47
+ @role.player.should == @tm.get("Tim")
48
+ end
49
+ it "should set the player of the Role if identifier is a Topic" do
50
+ previous_player = @role.player
51
+ @role.player = @tm.get!("Tim")
52
+ @role.player.should_not == previous_player
53
+ @role.player.should == @tm.get("Tim")
54
+ end
55
+ end
56
+
57
+ describe "#remove" do
58
+ before(:each) do
59
+ @assoc = @tm.create_association("assoc")
60
+ @role1 = @assoc.create_role("r1","t1")
61
+ @role2 = @assoc.create_role("r2","t2")
62
+ end
63
+ it "should remove this Role from the container (Association)" do
64
+ @assoc.should have(2).children
65
+ @role1.remove
66
+ @assoc.should have(1).children
67
+ @role2.remove
68
+ @assoc.should have(0).children
69
+ end
70
+ end
71
+
72
+ end # of describe self
73
+ end #of module
@@ -0,0 +1,403 @@
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::Scoped
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
+ describe "#scope" do
15
+ before(:each) do
16
+ @topic = @tm.get!("Hans")
17
+ @name1 = @topic.create_name("Hans")
18
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
19
+ @occ1 = @topic.create_occurrence("birthyear","1982")
20
+ @occ2 = @topic.create_occurrence("birthplace","Berlin",:scope => ["german"])
21
+ @variant1 = @name1.create_variant("Bubi",["endearment"])
22
+ @variant2 = @name2.create_variant("Bubi",["home","endearment"])
23
+ @assoc1 = @tm.create_association("birth")
24
+ @assoc2 = @tm.create_association("home",["german"])
25
+ end
26
+ it "should give back a empty set if no scope is set" do
27
+ @name1.should have(0).scope
28
+ @name1.should have(0).themes
29
+ @occ1.should have(0).scope
30
+ @occ1.should have(0).themes
31
+ @assoc1.should have(0).scope
32
+ @assoc1.should have(0).themes
33
+ end
34
+ it "should give back a container" do
35
+ @name1.scope.should respond_to(:each)
36
+ @name1.scope.should_not be_a_kind_of String
37
+ @name2.scope.should respond_to(:each)
38
+ @name2.scope.should_not be_a_kind_of String
39
+ @occ1.scope.should respond_to(:each)
40
+ @occ1.scope.should_not be_a_kind_of String
41
+ @occ2.scope.should respond_to(:each)
42
+ @occ2.scope.should_not be_a_kind_of String
43
+ @variant1.scope.should respond_to(:each)
44
+ @variant1.scope.should_not be_a_kind_of String
45
+ @variant2.scope.should respond_to(:each)
46
+ @variant2.scope.should_not be_a_kind_of String
47
+ @assoc1.scope.should respond_to(:each)
48
+ @assoc1.scope.should_not be_a_kind_of String
49
+ @assoc2.scope.should respond_to(:each)
50
+ @assoc2.scope.should_not be_a_kind_of String
51
+ end
52
+ it "should give back the topics in the scope" do
53
+ @name2.should have(1).scope
54
+ @occ2.should have(1).scope
55
+ @variant2.should have(2).scope
56
+ @assoc2.should have(1).scope
57
+ @name2.should have(1).themes
58
+ @occ2.should have(1).themes
59
+ @variant2.should have(2).themes
60
+ @assoc2.should have(1).themes
61
+ end
62
+ it "should give back RTM::Topics" do
63
+ @name2.scope.each{|t| t.should be_a_kind_of RTM::Topic}
64
+ @occ2.scope.each{|t| t.should be_a_kind_of RTM::Topic}
65
+ @variant2.scope.each{|t| t.should be_a_kind_of RTM::Topic}
66
+ @assoc2.scope.each{|t| t.should be_a_kind_of RTM::Topic}
67
+ end
68
+ it "should be told, if a theme is in the returned scope or not" do
69
+ @name2.scope.include?(@tm.get("something"))
70
+ @occ2.scope.include?(@tm.get("something"))
71
+ @variant2.scope.include?(@tm.get("something"))
72
+ @assoc2.scope.include?(@tm.get("something"))
73
+ ###
74
+ existing_topic = @tm.get!("existing")
75
+ @name2.scope.should_not include(existing_topic)
76
+ @occ2.scope.should_not include(existing_topic)
77
+ @variant2.scope.should_not include(existing_topic)
78
+ @assoc2.scope.should_not include(existing_topic)
79
+ ###
80
+ #p @name2.scope.inspect
81
+ @name2.scope.should include(@tm.get("home"))
82
+ @occ2.scope.should include(@tm.get("german"))
83
+ @variant2.scope.should include(@tm.get("endearment"))
84
+ @assoc2.scope.should include(@tm.get("german"))
85
+ end
86
+ end
87
+
88
+ describe "#add_theme" do
89
+ before(:each) do
90
+ @topic = @tm.get!("Hans")
91
+ @name1 = @topic.create_name("Hans")
92
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
93
+ @occ1 = @topic.create_occurrence("birthyear","1982")
94
+ @occ2 = @topic.create_occurrence("birthplace","Berlin",:scope => ["german"])
95
+ @variant1 = @name1.create_variant("Bubi",["endearment"])
96
+ @variant2 = @name2.create_variant("Bubi",["home","endearment"])
97
+ @assoc1 = @tm.create_association("birth")
98
+ @assoc2 = @tm.create_association("home",["german"])
99
+ end
100
+ it "should add one Topic to the scope of a Name" do
101
+ @name1.should be_a_kind_of RTM::Name
102
+ @name2.should be_a_kind_of RTM::Name
103
+ ###
104
+ @name1.scope.should be_empty
105
+ @name1.add_theme("test_scope_1")
106
+ @name1.should have(1).themes
107
+ @name1.add_theme(@tm.create_locator("test_scope_2"))
108
+ @name1.should have(2).themes
109
+ @name1.add_theme(@tm.get!("test_scope_3"))
110
+ @name1.should have(3).themes
111
+ @name1.scope.should include @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
112
+ ###
113
+ @name2.should have(1).themes
114
+ @name2.scope.should include @tm.get("home")
115
+ @name2.add_theme("test_scope_1")
116
+ @name2.should have(2).themes
117
+ @name2.add_theme(@tm.create_locator("test_scope_2"))
118
+ @name2.should have(3).themes
119
+ @name2.add_theme(@tm.get!("test_scope_3"))
120
+ @name2.should have(4).themes
121
+ @name2.scope.should include @tm.get("home"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
122
+ end
123
+ it "should add one Topic to the scope of an Occurrence" do
124
+ @occ1.should be_a_kind_of RTM::Occurrence
125
+ @occ2.should be_a_kind_of RTM::Occurrence
126
+ ###
127
+ @occ1.scope.should be_empty
128
+ @occ1.add_theme("test_scope_1")
129
+ @occ1.should have(1).themes
130
+ @occ1.add_theme(@tm.create_locator("test_scope_2"))
131
+ @occ1.should have(2).themes
132
+ @occ1.add_theme(@tm.get!("test_scope_3"))
133
+ @occ1.should have(3).themes
134
+ @occ1.scope.should include @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
135
+ ###
136
+ @occ2.should have(1).themes
137
+ @occ2.scope.should include @tm.get("german")
138
+ @occ2.add_theme("test_scope_1")
139
+ @occ2.should have(2).themes
140
+ @occ2.add_theme(@tm.create_locator("test_scope_2"))
141
+ @occ2.should have(3).themes
142
+ @occ2.add_theme(@tm.get!("test_scope_3"))
143
+ @occ2.should have(4).themes
144
+ @occ2.scope.should include @tm.get("german"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
145
+ end
146
+ it "should add one Topic to the scope of a Variant" do
147
+ @variant1.should be_a_kind_of RTM::Variant
148
+ @variant2.should be_a_kind_of RTM::Variant
149
+ ###
150
+ @variant1.should have(1).themes
151
+ @variant1.scope.should include @tm.get("endearment")
152
+ @variant1.add_theme("test_scope_1")
153
+ @variant1.should have(2).themes
154
+ @variant1.add_theme(@tm.create_locator("test_scope_2"))
155
+ @variant1.should have(3).themes
156
+ @variant1.add_theme(@tm.get!("test_scope_3"))
157
+ @variant1.should have(4).themes
158
+ @variant1.scope.should include @tm.get("endearment"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
159
+ ###
160
+ @variant2.should have(2).themes
161
+ @variant2.scope.should include @tm.get("home"), @tm.get("endearment")
162
+ @variant2.add_theme("test_scope_1")
163
+ @variant2.should have(3).themes
164
+ @variant2.add_theme(@tm.create_locator("test_scope_2"))
165
+ @variant2.should have(4).themes
166
+ @variant2.add_theme(@tm.get!("test_scope_3"))
167
+ @variant2.should have(5).themes
168
+ @variant2.scope.should include @tm.get("home"), @tm.get("endearment"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
169
+ end
170
+ it "should add one Topic to the scope of an Association" do
171
+ @assoc1.should be_a_kind_of RTM::Association
172
+ @assoc2.should be_a_kind_of RTM::Association
173
+ ###
174
+ @assoc1.scope.should be_empty
175
+ @assoc1.add_theme("test_scope_1")
176
+ @assoc1.should have(1).themes
177
+ @assoc1.add_theme(@tm.create_locator("test_scope_2"))
178
+ @assoc1.should have(2).themes
179
+ @assoc1.add_theme(@tm.get!("test_scope_3"))
180
+ @assoc1.should have(3).themes
181
+ @assoc1.scope.should include @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
182
+ ###
183
+ @assoc2.should have(1).themes
184
+ @assoc2.scope.should include @tm.get("german")
185
+ @assoc2.add_theme("test_scope_1")
186
+ @assoc2.should have(2).themes
187
+ @assoc2.add_theme(@tm.create_locator("test_scope_2"))
188
+ @assoc2.should have(3).themes
189
+ @assoc2.add_theme(@tm.get!("test_scope_3"))
190
+ @assoc2.should have(4).themes
191
+ @assoc2.scope.should include @tm.get("german"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3")
192
+ end
193
+ it "should raise an error if identifier is not a Topic or Topic-Reference" do
194
+ lambda{@name1.add_theme(["test_scope"])}.should raise_error
195
+ lambda{@occ1.add_theme(["test_scope"])}.should raise_error
196
+ lambda{@variant1.add_theme(["test_scope"])}.should raise_error
197
+ lambda{@association1.add_theme(["test_scope"])}.should raise_error
198
+ end
199
+ it "should raise an error if argument consists of several identifiers" do
200
+ lambda{@name1.add_theme("testscope1", "testscope2")}.should raise_error
201
+ end
202
+ end
203
+
204
+ describe "#add_themes" do
205
+ before(:each) do
206
+ @topic = @tm.get!("Hans")
207
+ end
208
+ it "should not add a theme if no argument is given" do
209
+ @name1 = @topic.create_name("Hans")
210
+ @name1.should have(0).themes
211
+ @name1.add_themes()
212
+ @name1.should have(0).themes
213
+ ###
214
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
215
+ @name2.should have(1).themes
216
+ @name2.add_themes()
217
+ @name2.should have(1).themes
218
+ end
219
+ it "should add one theme if one argument is given" do
220
+ # adding one
221
+ @name1 = @topic.create_name("Hans")
222
+ @name1.should have(0).themes
223
+ @name1.add_themes("home")
224
+ @name1.should have(1).themes
225
+ # adding another
226
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
227
+ @name2.should have(1).themes
228
+ @name2.add_themes("mom")
229
+ @name2.should have(2).themes
230
+ # adding t2 again -> should still have 2 themes
231
+ @name2.add_themes("home")
232
+ @name2.should have(2).themes
233
+ end
234
+ it "should add several themes if several arguments are given" do
235
+ @name1 = @topic.create_name("Hans")
236
+ @name1.should have(0).themes
237
+ @name1.add_themes("home", "mom")
238
+ @name1.should have(2).themes
239
+ end
240
+ it "should add several themes if several arrays with arguments are given" do
241
+ @name1 = @topic.create_name("Hans")
242
+ @name1.should have(0).themes
243
+ @name1.add_themes(["home", "mom"], "testscope")
244
+ @name1.should have(3).themes
245
+ end
246
+ it "should raise an error if a hash is given" do
247
+ @name1 = @topic.create_name("Hans")
248
+ @name1.should have(0).themes
249
+ lambda{@name1.add_themes("x" => "y")}.should raise_error
250
+ end
251
+ end
252
+
253
+ describe "#remove_theme" do
254
+ before(:each) do
255
+ @topic = @tm.get!("Hans")
256
+ @name = @topic.create_name("first", "Hansi", ["home","mom"])
257
+ @occ = @topic.create_occurrence("birthplace","Berlin",:scope => ["german","english"])
258
+ @variant = @name.create_variant("Bubi",["endearment"])
259
+ @assoc = @tm.create_association("home",["german","english"])
260
+ @existing_dummy = @tm.get!("existing_dummy")
261
+ end
262
+ it "should remove a Topic from the scope of a Name" do
263
+ @name.should be_a_kind_of RTM::Name
264
+ ###
265
+ @name.should have(2).themes
266
+ @name.scope.should include @tm.get("home"), @tm.get("mom")
267
+ @name.remove_theme("home")
268
+ @name.should have(1).themes
269
+ @name.scope.should include @tm.get("mom")
270
+ @name.remove_theme("mom")
271
+ @name.scope.should be_empty
272
+ @name.remove_theme("mom")
273
+ @name.scope.should be_empty
274
+ end
275
+ it "should remove a Topic from the scope of an Occurrence" do
276
+ @occ.should be_a_kind_of RTM::Occurrence
277
+ ###
278
+ @occ.should have(2).themes
279
+ @occ.scope.should include @tm.get("german"), @tm.get("english")
280
+ @occ.remove_theme("german")
281
+ @occ.should have(1).themes
282
+ @occ.scope.should include @tm.get("english")
283
+ @occ.remove_theme("english")
284
+ @occ.scope.should be_empty
285
+ @occ.remove_theme("english")
286
+ @occ.scope.should be_empty
287
+ end
288
+ it "should remove a Topic from the scope of a Variant" do
289
+ @variant.should be_a_kind_of RTM::Variant
290
+ ###
291
+ @variant.should have(3).themes
292
+ @variant.scope.should include @tm.get("home"), @tm.get("mom"), @tm.get("endearment")
293
+ @variant.remove_theme("endearment")
294
+ @variant.should have(2).themes
295
+ @variant.scope.should include @tm.get("home"), @tm.get("mom")
296
+ @variant.should be_a_kind_of RTM::Variant
297
+ end
298
+ it "should remove a Topic from the scope of an Association" do
299
+ @assoc.should be_a_kind_of RTM::Association
300
+ ###
301
+ @assoc.should have(2).themes
302
+ @assoc.scope.should include @tm.get("german"), @tm.get("english")
303
+ @assoc.remove_theme("german")
304
+ @assoc.should have(1).themes
305
+ @assoc.scope.should include @tm.get("english")
306
+ @assoc.remove_theme("english")
307
+ @assoc.scope.should be_empty
308
+ @assoc.remove_theme("english")
309
+ @assoc.scope.should be_empty
310
+ end
311
+ it "should not fail if the Topic_to_be_removed is not in the scope" do
312
+ @name.should have(2).themes
313
+ @name.remove_theme("dummy")
314
+ @name.remove_theme("existing_dummy")
315
+ @name.should have(2).themes
316
+ end
317
+ it "should raise an error if argument consists of several identifiers" do
318
+ lambda{@name.remove_theme("testscope1", "testscope2")}.should raise_error
319
+ end
320
+ end
321
+
322
+ describe "#remove_themes" do
323
+ before(:each) do
324
+ @topic = @tm.get!("Hans")
325
+ # @name1 = @topic.create_name("Hans")
326
+ # @name2 = @topic.create_name("first", "Hansi", ["home"])
327
+ # @occ1 = @topic.create_occurrence("birthyear","1982")
328
+ # @occ2 = @topic.create_occurrence("birthplace","Berlin",:scope => ["german"])
329
+ # @variant1 = @name1.create_variant("Bubi",["endearment"])
330
+ # @variant2 = @name2.create_variant("Bubi",["home","endearment"])
331
+ # @assoc1 = @tm.create_association("birth")
332
+ # @assoc2 = @tm.create_association("home",["german"])
333
+ end
334
+ it "should not remove a theme if no argument is given" do
335
+ @name1 = @topic.create_name("Hans")
336
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
337
+ @name1.should have(0).themes
338
+ @name1.remove_themes()
339
+ @name1.should have(0).themes
340
+ @name2.should have(1).themes
341
+ @name2.remove_themes()
342
+ @name2.should have(1).themes
343
+ end
344
+ it "should remove one theme if one argument is given" do
345
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
346
+ @variant2 = @name2.create_variant("Bubi",["home","endearment"])
347
+ # removing one
348
+ @variant2.should have(2).themes
349
+ @variant2.remove_themes("endearment")
350
+ @variant2.should have(1).themes
351
+ # removing a non existing
352
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
353
+ @name2.should have(1).themes
354
+ @name2.remove_theme("non_existing")
355
+ end
356
+ it "should remove a theme that occurs in a variant also" do
357
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
358
+ @variant2 = @name2.create_variant("Bubi",["home","endearment"])
359
+ @name2.should have(1).themes
360
+ @name2.remove_theme("home")
361
+ @name2.should have(0).themes
362
+ @variant2.should have(2).themes
363
+ end
364
+ it "should remove several themes if several arguments are given" do
365
+ @name2 = @topic.create_name("first", "Hansi", ["home","endearment","mom"])
366
+ @name2.should have(3).themes
367
+ @name2.remove_themes("home", "mom", "not_existing")
368
+ @name2.should have(1).themes
369
+ end
370
+ it "should remove several themes if several arrays with arguments are given" do
371
+ @name2 = @topic.create_name("first", "Hansi", ["home","endearment","mom"])
372
+ @name2.should have(3).themes
373
+ @name2.remove_themes("home", ["mom", "not_existing"])
374
+ @name2.should have(1).themes
375
+ end
376
+ it "should raise an error if a hash is given" do
377
+ @name2 = @topic.create_name("first", "Hansi", ["home"])
378
+ lambda{@name1.remove_themes("x" => "y")}.should raise_error
379
+ end
380
+ end
381
+
382
+ describe "#scope=" do
383
+ before(:each) do
384
+ @topic = @tm.get!("Hans")
385
+ @name = @topic.create_name("first", "Hansi", ["home","mom"])
386
+ @occ = @topic.create_occurrence("birthplace","Berlin",:scope => ["german","english"])
387
+ @variant = @name.create_variant("Bubi",["endearment"])
388
+ @assoc = @tm.create_association("home",["german","english"])
389
+ @existing_dummy = @tm.get!("existing_dummy")
390
+ end
391
+ it "should set the scope to empty upon request" do
392
+ @name.should be_a_kind_of RTM::Name
393
+ @name.should have(2).themes
394
+ pending
395
+ @name.scope = []
396
+ @name.should have(0).themes
397
+ end
398
+ end
399
+ end
400
+ end
401
+
402
+
403
+