rtm 0.2.0 → 0.2.1
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.
- data/README +38 -3
- data/lib/rtm.rb +25 -47
- data/lib/rtm/axes.rb +7 -4
- data/lib/rtm/axes/association.rb +1 -1
- data/lib/rtm/axes/associations.rb +1 -1
- data/lib/rtm/axes/characteristic.rb +1 -1
- data/lib/rtm/axes/characteristics.rb +1 -1
- data/lib/rtm/axes/topic.rb +3 -3
- data/lib/rtm/axes/topics.rb +3 -3
- data/lib/rtm/engine.rb +48 -5
- data/lib/rtm/extensions.rb +58 -8
- data/lib/rtm/io.rb +2 -1
- data/lib/rtm/io/tmapix_from.rb +155 -0
- data/lib/rtm/io/tmapix_to.rb +223 -0
- data/lib/rtm/io/to_hash.rb +79 -41
- data/lib/rtm/io/to_jtm.rb +1 -1
- data/lib/rtm/io/to_rdf.rb +20 -5
- data/lib/rtm/io/to_string.rb +13 -2
- data/lib/rtm/io/to_yaml.rb +39 -11
- data/lib/rtm/navigation.rb +1 -15
- data/lib/rtm/navigation/association/players.rb +1 -1
- data/lib/rtm/navigation/name/characteristics.rb +1 -1
- data/lib/rtm/navigation/occurrence/characteristics.rb +1 -1
- data/lib/rtm/navigation/topic/characteristics.rb +1 -1
- data/lib/rtm/navigation/topic/players.rb +1 -1
- data/lib/rtm/navigation/topic/supertypes.rb +21 -17
- data/lib/rtm/navigation/topic/traverse.rb +1 -1
- data/lib/rtm/navigation/topic/types.rb +6 -4
- data/lib/rtm/psi.rb +6 -0
- data/lib/rtm/sugar.rb +42 -29
- data/lib/rtm/sugar/association/hash_access.rb +3 -3
- data/lib/rtm/sugar/occurrence/dynamic_value.rb +39 -56
- data/lib/rtm/sugar/occurrence/external.rb +53 -0
- data/lib/rtm/sugar/reifiable/reifier.rb +21 -0
- data/lib/rtm/sugar/role/counterparts.rb +12 -6
- data/lib/rtm/sugar/topic/best_name.rb +74 -0
- data/lib/rtm/sugar/topic/characteristics.rb +10 -10
- data/lib/rtm/sugar/topic/counterparts.rb +131 -119
- data/lib/rtm/sugar/topic/scoped.rb +102 -53
- data/lib/rtm/sugar/topic/topic_ref.rb +63 -12
- data/lib/rtm/sugar/topic/typed.rb +50 -2
- data/lib/rtm/sugar/topic_map/query_cache.rb +66 -0
- data/lib/rtm/sugar/topic_map/themes.rb +53 -0
- data/lib/rtm/sugar/typed/types.rb +1 -1
- data/lib/rtm/validation.rb +2 -2
- data/lib/rtm/version.rb +18 -6
- data/spec/rtm/axes/string_spec.rb +7 -7
- data/spec/rtm/axes/strings_spec.rb +10 -10
- data/spec/rtm/io/tmapix_from_spec.rb +76 -0
- data/spec/rtm/io/tmapix_to_spec.rb +159 -0
- data/spec/rtm/io/to_hash_spec.rb +90 -0
- data/spec/rtm/io/to_rdf_spec.rb +37 -0
- data/spec/rtm/io/to_string_spec.rb +122 -0
- data/spec/rtm/io/to_yaml_spec.rb +89 -0
- data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +156 -1
- data/spec/rtm/sugar/occurrence/external_spec.rb +129 -0
- data/spec/rtm/sugar/reifiable/reifier_spec.rb +41 -0
- data/spec/rtm/sugar/role/counterparts_spec.rb +174 -172
- data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
- data/spec/rtm/sugar/topic/characteristics_spec.rb +20 -5
- data/spec/rtm/sugar/topic/counterparts_spec.rb +41 -1
- data/spec/rtm/sugar/topic/hash_access_spec.rb +1 -1
- data/spec/rtm/sugar/topic/scoped_spec.rb +178 -114
- data/spec/rtm/sugar/topic/topic_ref_spec.rb +10 -10
- data/spec/rtm/sugar/topic/typed_spec.rb +196 -134
- data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
- data/spec/rtm/sugar/typed/types_spec.rb +1 -1
- data/spec/rtm/tmapi/core/association_spec.rb +2 -2
- data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
- data/spec/rtm/tmapi/core/name_spec.rb +186 -1
- data/spec/rtm/tmapi/core/occurrence_spec.rb +24 -67
- data/spec/rtm/tmapi/core/reifiable_spec.rb +2 -2
- data/spec/rtm/tmapi/core/scoped_spec.rb +40 -2
- data/spec/rtm/tmapi/core/topic_map_spec.rb +98 -30
- data/spec/rtm/tmapi/core/topic_spec.rb +558 -82
- data/spec/rtm/tmapi/core/variant_spec.rb +3 -3
- data/spec/rtm_spec.rb +0 -1
- data/spec/spec_helper.rb +7 -2
- data/test/javalibs/junit-4.5.jar +0 -0
- data/test/javalibs/tmapi-2.0-tests.jar +0 -0
- data/test/tmapi_tests.rb +25 -0
- metadata +66 -11
- data/lib/rtm/io/ontopia_io.rb +0 -25
- data/lib/rtm/io/tmapix.rb +0 -234
- data/lib/rtm/sugar/occurrence/externalize.rb +0 -31
- data/spec/rtm/io/tmapix_spec.rb +0 -85
- data/test/base_unit_test.rb +0 -161
- data/test/base_unit_test_tmapi.rb +0 -165
|
@@ -0,0 +1,67 @@
|
|
|
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::TopicMap
|
|
7
|
+
module Themes
|
|
8
|
+
describe self do
|
|
9
|
+
before(:each) do
|
|
10
|
+
@tm = get_used_tm_sys_tm
|
|
11
|
+
@theme0 = @tm.get!("negative")
|
|
12
|
+
@theme1 = @tm.get!("german")
|
|
13
|
+
@theme2 = @tm.get!("english")
|
|
14
|
+
@theme3 = @tm.get!("2009")
|
|
15
|
+
@theme4 = @tm.get!("sorbian")
|
|
16
|
+
@test_theme = @tm.get!("dummy")
|
|
17
|
+
@leipzig = @tm.get!("leipzig")
|
|
18
|
+
@germany = @tm.get!("germany")
|
|
19
|
+
@name1 = @leipzig.create_name("Leipzig",[@theme1,@theme2])
|
|
20
|
+
@name2 = @germany.create_name("Germany",[@theme2,@test_theme])
|
|
21
|
+
@name3 = @germany.create_name("Deutschland",[@theme1])
|
|
22
|
+
@name4 = @leipzig.create_name("Leipzisch")
|
|
23
|
+
@name5 = @leipzig.create_name("Lipsk",[@theme4])
|
|
24
|
+
@occ1 = @leipzig.create_occurrence("inhabitants","500000", :scope => [@theme3])
|
|
25
|
+
@occ2 = @germany.create_occurrence("states","16", :scope => [@test_theme])
|
|
26
|
+
@occ3 = @leipzig.create_occurrence("state","Sachsen")
|
|
27
|
+
@tm.create_association("assoc_dummy")
|
|
28
|
+
@assoc = @tm.create_association("contained", [@test_theme])
|
|
29
|
+
@role1 = @assoc.create_role("containee",@leipzig)
|
|
30
|
+
@role2 = @assoc.create_role("container",@germany)
|
|
31
|
+
@variant = @name1.create_variant("LE",[@test_theme])
|
|
32
|
+
end
|
|
33
|
+
after(:each) do
|
|
34
|
+
@tm.close
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "#association_themes" do
|
|
38
|
+
it "return all topics that are used in the scope of Associations" do
|
|
39
|
+
@tm.should have(1).association_themes
|
|
40
|
+
@tm.association_themes.should include(@test_theme)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "#name_themes" do
|
|
45
|
+
it "return all topics that are used in the scope of Names" do
|
|
46
|
+
@tm.should have(4).name_themes
|
|
47
|
+
@tm.name_themes.should include(@theme1, @theme2, @test_theme, @theme4)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "#occurrence_themes" do
|
|
52
|
+
it "return all topics that are used in the scope of Occurrences" do
|
|
53
|
+
@tm.should have(2).occurrence_themes
|
|
54
|
+
@tm.occurrence_themes.should include(@theme3, @test_theme)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "#variant_themes" do
|
|
59
|
+
it "return all topics that are used in the scope of Variants" do
|
|
60
|
+
@tm.should have(3).variant_themes
|
|
61
|
+
@tm.variant_themes.should include(@theme1, @theme2, @test_theme)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end # of describe self
|
|
66
|
+
end # of module
|
|
67
|
+
end # of module
|
|
@@ -132,8 +132,8 @@ module RTM::Association
|
|
|
132
132
|
@asso.roles(t_type2).size.should == 1
|
|
133
133
|
@asso.roles(t_type2).should include(role3)
|
|
134
134
|
|
|
135
|
-
other_asso.roles(t_type3.
|
|
136
|
-
other_asso.roles(t_type3.
|
|
135
|
+
other_asso.roles(t_type3.references_as_locators.first).size.should == 1
|
|
136
|
+
other_asso.roles(t_type3.references_as_locators.first).should include(role4)
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
end # of describe self
|
|
@@ -0,0 +1,236 @@
|
|
|
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::DatatypeAware
|
|
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 "#value=" do
|
|
17
|
+
before(:each) do
|
|
18
|
+
@topic = @tm.get!("House")
|
|
19
|
+
end
|
|
20
|
+
describe "for Occurrence" do
|
|
21
|
+
it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI" do
|
|
22
|
+
occ = @topic.create_occurrence("street number", "1")
|
|
23
|
+
occ.datatype.to_external_form.should == RTM::PSI[:String]
|
|
24
|
+
occ.value = "http://www.example.org/House", RTM::PSI[:IRI]
|
|
25
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
26
|
+
occ.value.should == "http://www.example.org/House"
|
|
27
|
+
end
|
|
28
|
+
it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI and resolve the value using the base iri" do
|
|
29
|
+
occ = @topic.create_occurrence("street number", "1")
|
|
30
|
+
occ.datatype.to_external_form.should == RTM::PSI[:String]
|
|
31
|
+
occ.value = "House", RTM::PSI[:IRI]
|
|
32
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
33
|
+
occ.value.should == "http://www.topicmapslab.de/House"
|
|
34
|
+
end
|
|
35
|
+
it "should set the datatype to xsd:anyURI also if it was Integer before" do
|
|
36
|
+
occ = @topic.create_occurrence("street number", "1", :datatype => RTM::PSI[:Integer])
|
|
37
|
+
occ.value.should == "1"
|
|
38
|
+
occ.datatype.reference.should == RTM::PSI[:Integer]
|
|
39
|
+
occ.value = 1, RTM::PSI[:IRI]
|
|
40
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
41
|
+
occ.value.should == "http://www.topicmapslab.de/1"
|
|
42
|
+
end
|
|
43
|
+
it "should set an IRI value and the datatype to xsd:AnyURI if argument is a Locator" do
|
|
44
|
+
occ = @topic.create_occurrence("street number", "1")
|
|
45
|
+
occ.datatype.to_external_form.should == RTM::PSI[:String]
|
|
46
|
+
occ.value = @tm.create_locator("http://www.example.org/House")
|
|
47
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
48
|
+
occ.value.should == "http://www.example.org/House" # since we dont know if not */ as in case of ontopia
|
|
49
|
+
end
|
|
50
|
+
it "should set a String value and the datatype to xsd:String if argument is a String" do
|
|
51
|
+
occ = @topic.create_occurrence("Webseite", @tm.create_locator("http://www.example.org/House"))
|
|
52
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
53
|
+
occ.value=("1")
|
|
54
|
+
occ.datatype.to_external_form.should == RTM::PSI[:String]
|
|
55
|
+
occ.value.should == "1"
|
|
56
|
+
end
|
|
57
|
+
it "should set a Float value and the datatype to xsd:Float if arguement is a Float" do
|
|
58
|
+
occ = @topic.create_occurrence("Webseite", @tm.create_locator("http://www.example.org/House"))
|
|
59
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
60
|
+
0.5.class.should == Float
|
|
61
|
+
occ.value = 0.5
|
|
62
|
+
occ.datatype.to_external_form.should == RTM::PSI[:Float]
|
|
63
|
+
occ.value.should == "0.5"
|
|
64
|
+
end
|
|
65
|
+
it "should set a Fixnum value and the datatype to xsd:long if arguement is a Fixnum" do
|
|
66
|
+
occ = @topic.create_occurrence("Webseite", @tm.create_locator("http://www.example.org/House"))
|
|
67
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
68
|
+
1.class.should == Fixnum
|
|
69
|
+
occ.value = 1
|
|
70
|
+
occ.datatype.to_external_form.should == RTM::PSI[:Long]
|
|
71
|
+
occ.value.should == "1"
|
|
72
|
+
end
|
|
73
|
+
it "should set a Bignum value and the datatype to xsd:integer if arguement is a Bignum" do
|
|
74
|
+
occ = @topic.create_occurrence("Webseite", @tm.create_locator("http://www.example.org/House"))
|
|
75
|
+
occ.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
76
|
+
9999999999999999999.class.should == Bignum
|
|
77
|
+
occ.value = 9999999999999999999
|
|
78
|
+
occ.datatype.to_external_form.should == RTM::PSI[:Integer]
|
|
79
|
+
occ.value.should == "9999999999999999999"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
describe "for Variant" do
|
|
83
|
+
it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI" do
|
|
84
|
+
var = @topic.create_name("White House").create_variant("WH", ["short form"])
|
|
85
|
+
var.datatype.reference.should == RTM::PSI[:String]
|
|
86
|
+
var.value = "http://www.example.org/WhiteHouse", RTM::PSI[:IRI]
|
|
87
|
+
var.datatype.reference.should == RTM::PSI[:IRI]
|
|
88
|
+
var.value.should == "http://www.example.org/WhiteHouse"
|
|
89
|
+
end
|
|
90
|
+
it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI and resolve the value using the base iri" do
|
|
91
|
+
var = @topic.create_name("White House").create_variant("WH", ["short form"])
|
|
92
|
+
var.datatype.to_external_form.should == RTM::PSI[:String]
|
|
93
|
+
var.value = "White-House", RTM::PSI[:IRI]
|
|
94
|
+
var.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
95
|
+
var.value.should == "http://www.topicmapslab.de/White-House"
|
|
96
|
+
end
|
|
97
|
+
it "should set the datatype to xsd:anyURI also if it was Integer before" do
|
|
98
|
+
var = @topic.create_name("White House").create_variant("1", RTM::PSI[:Integer], ["short form"])
|
|
99
|
+
var.value.should == "1"
|
|
100
|
+
var.datatype.reference.should == RTM::PSI[:Integer]
|
|
101
|
+
var.value = 1, RTM::PSI[:IRI]
|
|
102
|
+
var.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
103
|
+
var.value.should == "http://www.topicmapslab.de/1"
|
|
104
|
+
end
|
|
105
|
+
it "should set an IRI value and the datatype to xsd:AnyURI if argument is a Locator" do
|
|
106
|
+
var = @topic.create_name("White House").create_variant("WH", ["short form"])
|
|
107
|
+
var.datatype.to_external_form.should == RTM::PSI[:String]
|
|
108
|
+
var.value = @tm.create_locator("http://www.example.org/House")
|
|
109
|
+
var.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
110
|
+
var.value.should == "http://www.example.org/House" # since we dont know if not */ as in case of ontopia
|
|
111
|
+
end
|
|
112
|
+
it "should set a String value and the datatype to xsd:String if argument is a String" do
|
|
113
|
+
var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"])
|
|
114
|
+
var.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
115
|
+
var.value=("1")
|
|
116
|
+
var.datatype.to_external_form.should == RTM::PSI[:String]
|
|
117
|
+
var.value.should == "1"
|
|
118
|
+
end
|
|
119
|
+
it "should set a Float value and the datatype to xsd:Float if arguement is a Float" do
|
|
120
|
+
var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"])
|
|
121
|
+
var.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
122
|
+
0.5.class.should == Float
|
|
123
|
+
var.value = 0.5
|
|
124
|
+
var.datatype.to_external_form.should == RTM::PSI[:Float]
|
|
125
|
+
var.value.should == "0.5"
|
|
126
|
+
end
|
|
127
|
+
it "should set a Fixnum value and the datatype to xsd:long if arguement is a Fixnum" do
|
|
128
|
+
var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"])
|
|
129
|
+
var.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
130
|
+
1.class.should == Fixnum
|
|
131
|
+
var.value = 1
|
|
132
|
+
var.datatype.to_external_form.should == RTM::PSI[:Long]
|
|
133
|
+
var.value.should == "1"
|
|
134
|
+
end
|
|
135
|
+
it "should set a Bignum value and the datatype to xsd:integer if arguement is a Bignum" do
|
|
136
|
+
var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"])
|
|
137
|
+
var.datatype.to_external_form.should == RTM::PSI[:IRI]
|
|
138
|
+
9999999999999999999.class.should == Bignum
|
|
139
|
+
var.value = 9999999999999999999
|
|
140
|
+
var.datatype.to_external_form.should == RTM::PSI[:Integer]
|
|
141
|
+
var.value.should == "9999999999999999999"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe "#datatype=" do
|
|
148
|
+
before(:each) do
|
|
149
|
+
@topic = @tm.get!("House")
|
|
150
|
+
end
|
|
151
|
+
describe "for Occurrence" do
|
|
152
|
+
it "should set the datatype to xsd:anyURI even if value is a String" do
|
|
153
|
+
occ = @topic.create_occurrence("street number", "1")
|
|
154
|
+
occ.datatype.reference.should == RTM::PSI[:String]
|
|
155
|
+
occ.datatype = RTM::PSI[:IRI]
|
|
156
|
+
occ.datatype.reference.should == RTM::PSI[:IRI]
|
|
157
|
+
end
|
|
158
|
+
it "should set the datatype to xsd:String even if value is a Locator" do
|
|
159
|
+
occ = @topic.create_occurrence("wesbite", @tm.create_locator("http://www.example.org/House"))
|
|
160
|
+
occ.value.should == "http://www.example.org/House"
|
|
161
|
+
occ.datatype.reference.should == RTM::PSI[:IRI]
|
|
162
|
+
occ.datatype = RTM::PSI[:String]
|
|
163
|
+
occ.value.should == "http://www.example.org/House"
|
|
164
|
+
occ.datatype.reference.should == RTM::PSI[:String]
|
|
165
|
+
end
|
|
166
|
+
it "should set the datatype to xsd:anyURI even if value is a number" do
|
|
167
|
+
occ = @topic.create_occurrence("street number", "1", :datatype => RTM::PSI[:Integer])
|
|
168
|
+
occ.value.should == "1"
|
|
169
|
+
occ.datatype.reference.should == RTM::PSI[:Integer]
|
|
170
|
+
occ.datatype = RTM::PSI[:IRI]
|
|
171
|
+
occ.value.should == "http://www.topicmapslab.de/1"
|
|
172
|
+
occ.datatype.reference.should == RTM::PSI[:IRI]
|
|
173
|
+
end
|
|
174
|
+
it "should set the datatype to xsd:Integer even if value is a String" do
|
|
175
|
+
occ = @topic.create_occurrence("street number", "1")
|
|
176
|
+
occ.value.should == "1"
|
|
177
|
+
occ.datatype.reference.should == RTM::PSI[:String]
|
|
178
|
+
occ.datatype = RTM::PSI[:Integer]
|
|
179
|
+
occ.value.should == "1"
|
|
180
|
+
occ.datatype.reference.should == RTM::PSI[:Integer]
|
|
181
|
+
end
|
|
182
|
+
it "should raise an error if datatype is no String or Locator" do
|
|
183
|
+
occ = @topic.create_occurrence("street number", "1")
|
|
184
|
+
occ.datatype.reference.should == RTM::PSI[:String]
|
|
185
|
+
lambda{occ.datatype = 1}.should raise_error
|
|
186
|
+
# don't test for symbols
|
|
187
|
+
#lambda{occ.datatype = :test}.should raise_error
|
|
188
|
+
lambda{occ.datatype = @tm.get!(RTM::PSI[:IRI])}.should raise_error
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
describe "for Variant" do
|
|
192
|
+
it "should set the datatype to xsd:anyURI even if value is a String" do
|
|
193
|
+
var = @topic.create_name("White House").create_variant("WH", ["short form"])
|
|
194
|
+
var.value.should == "WH"
|
|
195
|
+
var.datatype.reference.should == RTM::PSI[:String]
|
|
196
|
+
var.datatype = RTM::PSI[:IRI]
|
|
197
|
+
var.datatype.reference.should == RTM::PSI[:IRI]
|
|
198
|
+
end
|
|
199
|
+
it "should set the datatype to xsd:String even if value is a Locator" do
|
|
200
|
+
var = @topic.create_name("White House").create_variant(@tm.create_locator("http://www.example.org/House"), ["short form"])
|
|
201
|
+
var.value.should == "http://www.example.org/House"
|
|
202
|
+
var.datatype.reference.should == RTM::PSI[:IRI]
|
|
203
|
+
var.datatype = RTM::PSI[:String]
|
|
204
|
+
var.value.should == "http://www.example.org/House"
|
|
205
|
+
var.datatype.reference.should == RTM::PSI[:String]
|
|
206
|
+
end
|
|
207
|
+
it "should set the datatype to xsd:anyURI even if value is a number" do
|
|
208
|
+
var = @topic.create_name("White House").create_variant("1", RTM::PSI[:Integer], ["short form"])
|
|
209
|
+
var.value.should == "1"
|
|
210
|
+
var.datatype.reference.should == RTM::PSI[:Integer]
|
|
211
|
+
var.datatype = RTM::PSI[:IRI]
|
|
212
|
+
var.value.should == "http://www.topicmapslab.de/1"
|
|
213
|
+
var.datatype.reference.should == RTM::PSI[:IRI]
|
|
214
|
+
end
|
|
215
|
+
it "should set the datatype to xsd:Integer even if value is a String" do
|
|
216
|
+
occ = @topic.create_name("White House").create_variant("1", ["short form"])
|
|
217
|
+
occ.value.should == "1"
|
|
218
|
+
occ.datatype.reference.should == RTM::PSI[:String]
|
|
219
|
+
occ.datatype = RTM::PSI[:Integer]
|
|
220
|
+
occ.value.should == "1"
|
|
221
|
+
occ.datatype.reference.should == RTM::PSI[:Integer]
|
|
222
|
+
end
|
|
223
|
+
it "should raise an error if datatype is no String or Locator" do
|
|
224
|
+
var = @topic.create_name("White House").create_variant("1", ["short form"])
|
|
225
|
+
var.datatype.reference.should == RTM::PSI[:String]
|
|
226
|
+
lambda{var.datatype = 1}.should raise_error
|
|
227
|
+
# don't test for symbols
|
|
228
|
+
#lambda{var.datatype = :test}.should raise_error
|
|
229
|
+
lambda{var.datatype = @tm.get!(RTM::PSI[:IRI])}.should raise_error
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
end
|
|
236
|
+
end
|
|
@@ -52,7 +52,192 @@ module RTM::Name
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
describe "#create_variant" do
|
|
55
|
-
|
|
55
|
+
describe "in tmapi notation" do
|
|
56
|
+
describe "(errors)" do
|
|
57
|
+
it "should raise an error if the value's datatype is not supported" do
|
|
58
|
+
lambda{@testname.create_variant({:a => :b}, ["scope"])}.should raise_error
|
|
59
|
+
end
|
|
60
|
+
it "should not raise an error if a datatype is given, the value's datatype is not supported but the value may be converted to string" do
|
|
61
|
+
lambda{:a.to_s}.should_not raise_error
|
|
62
|
+
lambda{@testname.create_variant(:a, RTM::PSI[:String], ["scope"])}.should_not raise_error
|
|
63
|
+
end
|
|
64
|
+
it "should raise an error if no scope is given" do
|
|
65
|
+
lambda{@testname.create_variant("Uni Leipzig")}.should raise_error
|
|
66
|
+
end
|
|
67
|
+
it "should raise an error if the scope is an empty array" do
|
|
68
|
+
if implementation_for_spec == :ontopia
|
|
69
|
+
pending "ontopia" do
|
|
70
|
+
lambda{@testname.create_variant("Uni Leipzig", [])}.should raise_error
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
lambda{@testname.create_variant("Uni Leipzig", [])}.should raise_error
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
describe "given value and scope" do
|
|
78
|
+
after(:each) do
|
|
79
|
+
@var.should be_a_kind_of RTM::Variant
|
|
80
|
+
@var.scope.should_not be_empty
|
|
81
|
+
end
|
|
82
|
+
it "should create a variant with datatype xsd:string if value is a String" do
|
|
83
|
+
@var = @testname.create_variant("Uni Leipzig", ["short_form"])
|
|
84
|
+
@var.value.should == "Uni Leipzig"
|
|
85
|
+
@var.datatype.reference.should == RTM::PSI[:String]
|
|
86
|
+
@var.scope.size.should == 1
|
|
87
|
+
@var.scope.should include(@tm.get("short_form"))
|
|
88
|
+
end
|
|
89
|
+
it "should create a variant with datatype xsd:anyURI if value is a Locator" do
|
|
90
|
+
@var = @testname.create_variant(@tm.create_locator("http://example.org/testvariant"), [@tm.create_locator("short form")])
|
|
91
|
+
@var.value.should == "http://example.org/testvariant"
|
|
92
|
+
@var.datatype.reference.should == RTM::PSI[:IRI]
|
|
93
|
+
@var.scope.size.should == 1
|
|
94
|
+
@var.scope.should include(@tm.get("short form"))
|
|
95
|
+
end
|
|
96
|
+
it "should create a variant with datatype xsd:float if value is a Float" do
|
|
97
|
+
@var = @testname.create_variant(0.5, [@tm.get!("theme1"), "theme2"])
|
|
98
|
+
@var.value.should == "0.5"
|
|
99
|
+
@var.datatype.reference.should == RTM::PSI[:Float]
|
|
100
|
+
@var.scope.size.should == 2
|
|
101
|
+
@var.scope.should include(@tm.get("theme1"), @tm.get("theme2"))
|
|
102
|
+
end
|
|
103
|
+
it "should create a variant with datatype xsd:long if value is a Fixnum" do
|
|
104
|
+
@var = @testname.create_variant(5, [@tm.get!("theme1"), @tm.create_locator("theme2")])
|
|
105
|
+
@var.value.should == "5"
|
|
106
|
+
@var.datatype.reference.should == RTM::PSI[:Long]
|
|
107
|
+
@var.scope.size.should == 2
|
|
108
|
+
@var.scope.should include(@tm.get("theme1"), @tm.get("theme2"))
|
|
109
|
+
end
|
|
110
|
+
it "should create a variant with datatype xsd:integer if value is a Bignum" do
|
|
111
|
+
number = 9999999999999999999
|
|
112
|
+
number.class.should == Bignum
|
|
113
|
+
@var = @testname.create_variant(number, [@tm.get!("theme1"), "theme2"])
|
|
114
|
+
@var.value.should == number.to_s
|
|
115
|
+
@var.datatype.reference.should == RTM::PSI[:Integer]
|
|
116
|
+
@var.scope.size.should == 2
|
|
117
|
+
@var.scope.should include(@tm.get("theme1"), @tm.get("theme2"))
|
|
118
|
+
end
|
|
119
|
+
describe "given a parent name with scope" do
|
|
120
|
+
it "should create a variant" do
|
|
121
|
+
@name = @topic.create_name("University of Leipzig", ["en", "official"])
|
|
122
|
+
@name.scope.size.should == 2
|
|
123
|
+
@name.scope.should include(@tm.get("en"), @tm.get("official"))
|
|
124
|
+
@var = @name.create_variant("U o L", ["short form"])
|
|
125
|
+
@var.scope.size.should == 3
|
|
126
|
+
@var.scope.should include(@tm.get("en"), @tm.get("official"), @tm.get("short form"))
|
|
127
|
+
@var.datatype.reference.should == RTM::PSI[:String]
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
describe "given value, datatype and scope" do
|
|
132
|
+
after(:each) do
|
|
133
|
+
if @var
|
|
134
|
+
@var.should be_a_kind_of RTM::Variant
|
|
135
|
+
@var.scope.should_not be_empty
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
describe "and value is a String" do
|
|
139
|
+
after(:each) do
|
|
140
|
+
if @var
|
|
141
|
+
@var.scope.size.should == 1
|
|
142
|
+
@var.scope.should include(@tm.get("short_form"))
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
it "should create a variant if datatye is xsd:string" do
|
|
146
|
+
@var = @testname.create_variant("Uni Leipzig", RTM::PSI[:String], ["short_form"])
|
|
147
|
+
@var.value.should == "Uni Leipzig"
|
|
148
|
+
@var.datatype.reference.should == RTM::PSI[:String]
|
|
149
|
+
end
|
|
150
|
+
it "should create a variant if datatye is xsd:anyURI" do
|
|
151
|
+
@var = @testname.create_variant("Uni Leipzig", RTM::PSI[:IRI], ["short_form"])
|
|
152
|
+
@var.value.should == "http://www.topicmapslab.de/Uni Leipzig"
|
|
153
|
+
@var.datatype.reference.should == RTM::PSI[:IRI]
|
|
154
|
+
end
|
|
155
|
+
it "should create a variant if datatye is xsd:float" do
|
|
156
|
+
@var = @testname.create_variant("0.5", RTM::PSI[:Float], ["short_form"])
|
|
157
|
+
@var.value.should == "0.5"
|
|
158
|
+
@var.datatype.reference.should == RTM::PSI[:Float]
|
|
159
|
+
end
|
|
160
|
+
it "should create a variant if datatye is xsd:long" do
|
|
161
|
+
@var = @testname.create_variant("5", RTM::PSI[:Long], ["short_form"])
|
|
162
|
+
@var.value.should == "5"
|
|
163
|
+
@var.datatype.reference.should == RTM::PSI[:Long]
|
|
164
|
+
end
|
|
165
|
+
it "should create a variant if datatye is xsd:integer" do
|
|
166
|
+
number = 9999999999999999999
|
|
167
|
+
number.class.should == Bignum
|
|
168
|
+
@var = @testname.create_variant(number.to_s, RTM::PSI[:Integer], ["short_form"])
|
|
169
|
+
@var.value.should == number.to_s
|
|
170
|
+
@var.datatype.reference.should == RTM::PSI[:Integer]
|
|
171
|
+
end
|
|
172
|
+
describe "but value is not a number" do
|
|
173
|
+
it "should create a variant if datatye is xsd:float" do
|
|
174
|
+
@var = @testname.create_variant("no number", RTM::PSI[:Float], ["short_form"])
|
|
175
|
+
@var.value.should == "no number"
|
|
176
|
+
@var.datatype.reference.should == RTM::PSI[:Float]
|
|
177
|
+
end
|
|
178
|
+
it "should create a variant if datatye is xsd:long" do
|
|
179
|
+
@var = @testname.create_variant("no number", RTM::PSI[:Long], ["short_form"])
|
|
180
|
+
@var.value.should == "no number"
|
|
181
|
+
@var.datatype.reference.should == RTM::PSI[:Long]
|
|
182
|
+
end
|
|
183
|
+
it "should create a variant if datatye is xsd:integer" do
|
|
184
|
+
if implementation_for_spec == :tinytim
|
|
185
|
+
lambda{@testname.create_variant("no number", RTM::PSI[:Integer], ["short_form"])}.should raise_error
|
|
186
|
+
else
|
|
187
|
+
@var = @testname.create_variant("no number", RTM::PSI[:Integer], ["short_form"])
|
|
188
|
+
@var.value.should == "no number"
|
|
189
|
+
@var.datatype.reference.should == RTM::PSI[:Integer]
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
describe "and value is a Locator" do
|
|
195
|
+
it "should create a variant if value is a Number and datatype is xsd:string"
|
|
196
|
+
it "should create a variant if value is a Number and datatype is xsd:anyURI"
|
|
197
|
+
it "should create a variant if value is a Number and datatype is xsd:float"
|
|
198
|
+
it "should create a variant if value is a Number and datatype is xsd:long"
|
|
199
|
+
it "should create a variant if value is a Number and datatype is xsd:integer"
|
|
200
|
+
describe "but value is not a number" do
|
|
201
|
+
it "should create a variant if datatye is xsd:float"
|
|
202
|
+
it "should create a variant if datatye is xsd:long"
|
|
203
|
+
it "should create a variant if datatye is xsd:integer"
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
describe "and value is a Number" do
|
|
207
|
+
it "should create a variant if value is a Number and datatype is xsd:string"
|
|
208
|
+
it "should create a variant if value is a Number and datatype is xsd:anyURI"
|
|
209
|
+
it "should create a variant if value is a Number and datatype is xsd:float"
|
|
210
|
+
it "should create a variant if value is a Number and datatype is xsd:long"
|
|
211
|
+
it "should create a variant if value is a Number and datatype is xsd:integer"
|
|
212
|
+
it "should be tested further"
|
|
213
|
+
end
|
|
214
|
+
describe "given a parent name with scope" do
|
|
215
|
+
it "should create a variant" do
|
|
216
|
+
@name = @topic.create_name("University of Leipzig", ["en", "official"])
|
|
217
|
+
@name.scope.size.should == 2
|
|
218
|
+
@name.scope.should include(@tm.get("en"), @tm.get("official"))
|
|
219
|
+
@var = @name.create_variant("U o L", RTM::PSI[:IRI], ["short form"])
|
|
220
|
+
@var.scope.size.should == 3
|
|
221
|
+
@var.scope.should include(@tm.get("en"), @tm.get("official"), @tm.get("short form"))
|
|
222
|
+
@var.datatype.reference.should == RTM::PSI[:IRI]
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
describe "in hash notation" do
|
|
228
|
+
describe "given value and scope" do
|
|
229
|
+
it "should create a variant with datatype xsd:string if value is a String"
|
|
230
|
+
it "should create a variant with datatype xsd:anyURI if value is a Locator"
|
|
231
|
+
it "should create a variant with datatype xsd:float if value is a Float"
|
|
232
|
+
it "should create a variant with datatype xsd:long if value is a Fixnum"
|
|
233
|
+
it "should create a variant with datatype xsd:integer if value is a Bignum"
|
|
234
|
+
it "should create a variant if scope is an empty array"
|
|
235
|
+
it "should raise an error if value's datatype is not supported"
|
|
236
|
+
end
|
|
237
|
+
describe "given value, datatype and scope" do
|
|
238
|
+
it "should be implemented and tested"
|
|
239
|
+
end
|
|
240
|
+
end
|
|
56
241
|
end
|
|
57
242
|
|
|
58
243
|
end # of describe self
|