rtm 0.1.6 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/DISCLAIMER +10 -33
- data/LICENSE +201 -0
- data/README +32 -3
- data/lib/rtm.rb +126 -74
- data/lib/rtm/axes.rb +298 -0
- data/lib/rtm/axes/association.rb +76 -0
- data/lib/rtm/axes/associations.rb +96 -0
- data/lib/rtm/axes/assocs_names_occs.rb +56 -0
- data/lib/rtm/axes/characteristic.rb +68 -0
- data/lib/rtm/axes/characteristics.rb +93 -0
- data/lib/rtm/axes/string.rb +76 -0
- data/lib/rtm/axes/strings.rb +87 -0
- data/lib/rtm/axes/topic.rb +233 -0
- data/lib/rtm/axes/topics.rb +280 -0
- data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
- data/lib/rtm/engine.rb +101 -0
- data/lib/rtm/extensions.rb +65 -5
- data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
- data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
- data/lib/rtm/helpers/uri.rb +13 -0
- data/lib/rtm/io.rb +19 -0
- data/lib/rtm/io/from_xtm2_libxml.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 +154 -0
- data/lib/rtm/io/to_jtm.rb +53 -103
- data/lib/rtm/io/to_rdf.rb +45 -0
- data/lib/rtm/io/to_string.rb +21 -8
- data/lib/rtm/io/to_xtm1.rb +6 -4
- data/lib/rtm/io/to_xtm2.rb +10 -8
- data/lib/rtm/io/to_yaml.rb +59 -100
- data/lib/rtm/navigation.rb +23 -0
- data/lib/rtm/navigation/association/players.rb +25 -0
- data/lib/rtm/navigation/name/atomify.rb +19 -0
- data/lib/rtm/navigation/name/characteristics.rb +33 -0
- data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
- data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/indicators.rb +31 -0
- data/lib/rtm/navigation/topic/items.rb +31 -0
- data/lib/rtm/navigation/topic/locators.rb +31 -0
- data/lib/rtm/navigation/topic/players.rb +27 -0
- data/lib/rtm/navigation/topic/supertypes.rb +166 -0
- data/lib/rtm/navigation/topic/traverse.rb +51 -0
- data/lib/rtm/navigation/topic/types.rb +109 -0
- data/lib/rtm/psi.rb +39 -2
- data/lib/rtm/sugar.rb +47 -0
- data/lib/rtm/sugar/association/hash_access.rb +46 -0
- data/lib/rtm/sugar/occurrence/dynamic_value.rb +58 -0
- 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 +139 -46
- data/lib/rtm/sugar/topic/best_name.rb +74 -0
- data/lib/rtm/sugar/topic/characteristics.rb +126 -12
- data/lib/rtm/sugar/topic/counterparts.rb +145 -10
- data/lib/rtm/sugar/topic/hash_access.rb +140 -30
- data/lib/rtm/sugar/topic/scoped.rb +114 -0
- data/lib/rtm/sugar/topic/topic_ref.rb +86 -0
- data/lib/rtm/sugar/topic/typed.rb +207 -0
- 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 +38 -0
- data/lib/rtm/validation.rb +7 -4
- data/lib/rtm/version.rb +30 -0
- data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
- data/spec/rtm/axes/association_spec.rb +88 -0
- data/spec/rtm/axes/associations_spec.rb +60 -0
- data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
- data/spec/rtm/axes/characteristic_spec.rb +90 -0
- data/spec/rtm/axes/characteristics_spec.rb +85 -0
- data/spec/rtm/axes/string_spec.rb +145 -0
- data/spec/rtm/axes/strings_spec.rb +168 -0
- data/spec/rtm/axes/topic_spec.rb +124 -0
- data/spec/rtm/axes/topics_spec.rb +103 -0
- data/spec/rtm/base_spec.rb +32 -0
- data/spec/rtm/io/tmapix_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/navigation/association/players_spec.rb +58 -0
- data/spec/rtm/navigation/association_spec.rb +52 -0
- data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/name_spec.rb +52 -0
- data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/occurrence_spec.rb +52 -0
- data/spec/rtm/navigation/string_spec.rb +51 -0
- data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
- data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
- data/spec/rtm/navigation/topic/items_spec.rb +44 -0
- data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
- data/spec/rtm/navigation/topic/players_spec.rb +48 -0
- data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
- data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
- data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
- data/spec/rtm/navigation/topic/types_spec.rb +195 -0
- data/spec/rtm/navigation/topic_spec.rb +153 -0
- data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
- data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +171 -0
- 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 +193 -0
- data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
- data/spec/rtm/sugar/topic/characteristics_spec.rb +333 -0
- data/spec/rtm/sugar/topic/counterparts_spec.rb +224 -0
- data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
- data/spec/rtm/sugar/topic/scoped_spec.rb +195 -0
- data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
- data/spec/rtm/sugar/topic/typed_spec.rb +217 -0
- data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
- data/spec/rtm/sugar/typed/types_spec.rb +24 -0
- data/spec/rtm/tmapi/core/association_spec.rb +169 -0
- data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
- data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
- data/spec/rtm/tmapi/core/name_spec.rb +270 -0
- data/spec/rtm/tmapi/core/occurrence_spec.rb +53 -0
- data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
- data/spec/rtm/tmapi/core/role_spec.rb +73 -0
- data/spec/rtm/tmapi/core/scoped_spec.rb +441 -0
- data/spec/rtm/tmapi/core/topic_map_spec.rb +716 -0
- data/spec/rtm/tmapi/core/topic_spec.rb +1468 -0
- data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
- data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
- data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
- data/spec/rtm/tmapi_spec.rb +44 -0
- data/spec/rtm/utils/sparql_spec.rb +26 -0
- data/spec/rtm_spec.rb +93 -0
- data/spec/spec_helper.rb +28 -0
- 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 +169 -65
- data/COPYRIGHT +0 -4
- data/lib/Rakefile.rb +0 -42
- data/lib/activetopicmaps.rb +0 -278
- data/lib/rtm/backend/active_record.rb +0 -58
- data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
- data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
- data/lib/rtm/backend/active_record/locators.rb +0 -55
- data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
- data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
- data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
- data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
- data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
- data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
- data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
- data/lib/rtm/backend/active_record/tmdm.rb +0 -298
- data/lib/rtm/backend/active_record/topic.rb +0 -87
- data/lib/rtm/backend/active_record/topic_map.rb +0 -314
- data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
- data/lib/rtm/base.rb +0 -92
- data/lib/rtm/connect.rb +0 -92
- data/lib/rtm/core_ext.rb +0 -6
- data/lib/rtm/io/from_xtm2.rb +0 -263
- data/lib/rtm/merging/merging.rb +0 -307
- data/lib/rtm/pimp_my_api.rb +0 -28
- data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
- data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
- data/lib/run_main_project.rb +0 -16
- data/test/base_test.rb +0 -162
@@ -0,0 +1,171 @@
|
|
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::Occurrence::DynamicValue
|
7
|
+
describe self do
|
8
|
+
before(:each) do
|
9
|
+
@tm = get_used_tm_sys_tm
|
10
|
+
@topic = @tm.get!("Leipzig")
|
11
|
+
end
|
12
|
+
after(:each) do
|
13
|
+
@tm.close
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#dynamic value" do
|
17
|
+
it "should return a Locator if the datatype is xsd:anyURI" do
|
18
|
+
@occ = @topic.create_occurrence("Website", "http://www.example.org/Leipzig", :datatype => RTM::PSI[:IRI])
|
19
|
+
@occ.datatype.reference.should == RTM::PSI[:IRI]
|
20
|
+
@occ.value.should == "http://www.example.org/Leipzig"
|
21
|
+
@occ.dynamic_value.should == @tm.create_locator("http://www.example.org/Leipzig")
|
22
|
+
###
|
23
|
+
@occ = @topic.create_occurrence("Website", "Leipzig", :datatype => RTM::PSI[:IRI])
|
24
|
+
@occ.datatype.reference.should == RTM::PSI[:IRI]
|
25
|
+
@occ.value.should == "http://www.topicmapslab.de/Leipzig"
|
26
|
+
@occ.dynamic_value.should == @tm.create_locator("http://www.topicmapslab.de/Leipzig")
|
27
|
+
end
|
28
|
+
it "should return a String if the datatype is xsd:string" do
|
29
|
+
@occ = @topic.create_occurrence("Website", "http://www.example.org/Leipzig", :datatype => RTM::PSI[:String])
|
30
|
+
@occ.datatype.reference.should == RTM::PSI[:String]
|
31
|
+
@occ.value.should == "http://www.example.org/Leipzig"
|
32
|
+
@occ.dynamic_value.should == "http://www.example.org/Leipzig"
|
33
|
+
end
|
34
|
+
it "should return a Float if the datatype is xsd:float" do
|
35
|
+
3.5.class.should == Float
|
36
|
+
@occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Float])
|
37
|
+
@occ.datatype.reference.should == RTM::PSI[:Float]
|
38
|
+
@occ.value.should == "3.5"
|
39
|
+
@occ.dynamic_value.should == 3.5
|
40
|
+
@occ.dynamic_value.class.should == Float
|
41
|
+
###
|
42
|
+
@occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Float])
|
43
|
+
@occ.datatype.reference.should == RTM::PSI[:Float]
|
44
|
+
@occ.value.should == "1"
|
45
|
+
@occ.dynamic_value.should == 1.0
|
46
|
+
@occ.dynamic_value.class.should == Float
|
47
|
+
end
|
48
|
+
it "should return a Float if the datatype is xsd:double" do
|
49
|
+
3.5.class.should == Float
|
50
|
+
@occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Double])
|
51
|
+
@occ.datatype.reference.should == RTM::PSI[:Double]
|
52
|
+
@occ.value.should == "3.5"
|
53
|
+
@occ.dynamic_value.should == 3.5
|
54
|
+
@occ.dynamic_value.class.should == Float
|
55
|
+
###
|
56
|
+
@occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Double])
|
57
|
+
@occ.datatype.reference.should == RTM::PSI[:Double]
|
58
|
+
@occ.value.should == "1"
|
59
|
+
@occ.dynamic_value.should == 1.0
|
60
|
+
@occ.dynamic_value.class.should == Float
|
61
|
+
end
|
62
|
+
it "should return a Float if the datatype is xsd:decimal" do
|
63
|
+
3.5.class.should == Float
|
64
|
+
@occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Decimal])
|
65
|
+
@occ.datatype.reference.should == RTM::PSI[:Decimal]
|
66
|
+
@occ.value.should == "3.5"
|
67
|
+
@occ.dynamic_value.should == 3.5
|
68
|
+
@occ.dynamic_value.class.should == Float
|
69
|
+
###
|
70
|
+
@occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Decimal])
|
71
|
+
@occ.datatype.reference.should == RTM::PSI[:Decimal]
|
72
|
+
@occ.value.should == "1" unless implementation_for_spec == :tinytim
|
73
|
+
@occ.dynamic_value.should == 1.0
|
74
|
+
@occ.dynamic_value.class.should == Float
|
75
|
+
end
|
76
|
+
it "should return a Fixnum/Bignum if the datatype is xsd:int" do
|
77
|
+
3.5.class.should == Float
|
78
|
+
@occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Int])
|
79
|
+
@occ.datatype.reference.should == RTM::PSI[:Int]
|
80
|
+
@occ.value.should == "3.5"
|
81
|
+
@occ.dynamic_value.should == 3
|
82
|
+
@occ.dynamic_value.class.should == Fixnum
|
83
|
+
###
|
84
|
+
@occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Int])
|
85
|
+
@occ.datatype.reference.should == RTM::PSI[:Int]
|
86
|
+
@occ.value.should == "1"
|
87
|
+
@occ.dynamic_value.should == 1
|
88
|
+
@occ.dynamic_value.class.should == Fixnum
|
89
|
+
####
|
90
|
+
number = 9999999999999999999
|
91
|
+
number.class.should == Bignum
|
92
|
+
@occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Int])
|
93
|
+
@occ.datatype.reference.should == RTM::PSI[:Int]
|
94
|
+
@occ.value.should == number.to_s
|
95
|
+
@occ.dynamic_value.should == number
|
96
|
+
@occ.dynamic_value.class.should == Bignum
|
97
|
+
end
|
98
|
+
it "should return a Fixnum/Bignum if the datatype is xsd:integer" do
|
99
|
+
unless implementation_for_spec == :tinytim
|
100
|
+
3.5.class.should == Float
|
101
|
+
@occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Integer])
|
102
|
+
@occ.datatype.reference.should == RTM::PSI[:Integer]
|
103
|
+
@occ.value.should == "3.5"
|
104
|
+
@occ.dynamic_value.should == 3
|
105
|
+
@occ.dynamic_value.class.should == Fixnum
|
106
|
+
end
|
107
|
+
###
|
108
|
+
@occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Integer])
|
109
|
+
@occ.datatype.reference.should == RTM::PSI[:Integer]
|
110
|
+
@occ.value.should == "1"
|
111
|
+
@occ.dynamic_value.should == 1
|
112
|
+
@occ.dynamic_value.class.should == Fixnum
|
113
|
+
####
|
114
|
+
number = 9999999999999999999
|
115
|
+
number.class.should == Bignum
|
116
|
+
@occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Integer])
|
117
|
+
@occ.datatype.reference.should == RTM::PSI[:Integer]
|
118
|
+
@occ.value.should == number.to_s
|
119
|
+
@occ.dynamic_value.should == number
|
120
|
+
@occ.dynamic_value.class.should == Bignum
|
121
|
+
end
|
122
|
+
it "should return a Fixnum/Bignum if the datatype is xsd:integer" do
|
123
|
+
3.5.class.should == Float
|
124
|
+
@occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Long])
|
125
|
+
@occ.datatype.reference.should == RTM::PSI[:Long]
|
126
|
+
@occ.value.should == "3.5"
|
127
|
+
@occ.dynamic_value.should == 3
|
128
|
+
@occ.dynamic_value.class.should == Fixnum
|
129
|
+
###
|
130
|
+
@occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Long])
|
131
|
+
@occ.datatype.reference.should == RTM::PSI[:Long]
|
132
|
+
@occ.value.should == "1"
|
133
|
+
@occ.dynamic_value.should == 1
|
134
|
+
@occ.dynamic_value.class.should == Fixnum
|
135
|
+
####
|
136
|
+
number = 9999999999999999999
|
137
|
+
number.class.should == Bignum
|
138
|
+
@occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Long])
|
139
|
+
@occ.datatype.reference.should == RTM::PSI[:Long]
|
140
|
+
@occ.value.should == number.to_s
|
141
|
+
@occ.dynamic_value.should == number
|
142
|
+
@occ.dynamic_value.class.should == Bignum
|
143
|
+
end
|
144
|
+
it "should return a Time if the datatype is xsd:time" do
|
145
|
+
time = Time.new
|
146
|
+
@occ = @topic.create_occurrence("Number", time)
|
147
|
+
@occ.datatype.reference.should == RTM::PSI[:Time]
|
148
|
+
@occ.value.should == time.to_s
|
149
|
+
#@occ.dynamic_value.should == time # cannot be tested this way
|
150
|
+
@occ.dynamic_value.class.should == Time
|
151
|
+
end
|
152
|
+
it "should return a Date if the datatype is xsd:date" do
|
153
|
+
date = Date.new
|
154
|
+
@occ = @topic.create_occurrence("Number", date)
|
155
|
+
@occ.datatype.reference.should == RTM::PSI[:Date]
|
156
|
+
@occ.value.should == date.to_s
|
157
|
+
@occ.dynamic_value.should == date
|
158
|
+
@occ.dynamic_value.class.should == Date
|
159
|
+
end
|
160
|
+
it "should return a DateTime if the datatype is xsd:dateTime" do
|
161
|
+
dateTime = DateTime.new
|
162
|
+
@occ = @topic.create_occurrence("Number", dateTime)
|
163
|
+
@occ.datatype.reference.should == RTM::PSI[:DateTime]
|
164
|
+
@occ.value.should == dateTime.to_s
|
165
|
+
@occ.dynamic_value.should == dateTime
|
166
|
+
@occ.dynamic_value.class.should == DateTime
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,129 @@
|
|
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::Occurrence::DynamicValue
|
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 "#externalize" do
|
16
|
+
before(:each) do
|
17
|
+
@leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig")
|
18
|
+
end
|
19
|
+
it "should create an association and two roles out of the occurrence if the value is of type xsd:String" do
|
20
|
+
occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/")
|
21
|
+
occ.value.should be_a_kind_of String
|
22
|
+
occ.value.should == "http://www.leipzig.de/"
|
23
|
+
occ.datatype.value.should == RTM::PSI[:String]
|
24
|
+
### now create the association
|
25
|
+
association = occ.externalize
|
26
|
+
### type must be RTM::PSI[:subject_representation]
|
27
|
+
assoc_type = @tm.get(RTM::PSI[:subject_representation])
|
28
|
+
assoc_type.should_not be_nil
|
29
|
+
association.type.should == assoc_type
|
30
|
+
### 2 roles
|
31
|
+
association.should have(2).roles
|
32
|
+
### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic)
|
33
|
+
association.roles(RTM::PSI[:represented_subject]).size.should == 1
|
34
|
+
role1 = association.roles(RTM::PSI[:represented_subject]).first
|
35
|
+
role1.player.should == @leipzig
|
36
|
+
### the other role of type occ_type and player: topic with subject locator occ_value
|
37
|
+
association.roles("Webpage").size.should == 1
|
38
|
+
role2 = association.roles("Webpage").first
|
39
|
+
r2player = @tm.get("=http://www.leipzig.de/")
|
40
|
+
r2player.should_not be_nil
|
41
|
+
role2.player.should == r2player
|
42
|
+
end
|
43
|
+
it "should create an association and two roles out of the occurrence if the value is of type xsd:anyURI" do
|
44
|
+
occ = @leipzig.create_occurrence("Webpage", @tm.create_locator("http://www.leipzig.de/"))
|
45
|
+
occ.value.should be_a_kind_of String
|
46
|
+
occ.value.should == "http://www.leipzig.de/"
|
47
|
+
occ.datatype.value.should == RTM::PSI[:IRI]
|
48
|
+
### now create the association
|
49
|
+
association = occ.externalize
|
50
|
+
### type must be RTM::PSI[:subject_representation]
|
51
|
+
assoc_type = @tm.get(RTM::PSI[:subject_representation])
|
52
|
+
assoc_type.should_not be_nil
|
53
|
+
association.type.should == assoc_type
|
54
|
+
### 2 roles
|
55
|
+
association.should have(2).roles
|
56
|
+
### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic)
|
57
|
+
association.roles(RTM::PSI[:represented_subject]).size.should == 1
|
58
|
+
role1 = association.roles(RTM::PSI[:represented_subject]).first
|
59
|
+
role1.player.should == @leipzig
|
60
|
+
### the other role of type occ_type and player: topic with subject locator occ_value
|
61
|
+
association.roles("Webpage").size.should == 1
|
62
|
+
role2 = association.roles("Webpage").first
|
63
|
+
r2player = @tm.get("=http://www.leipzig.de/")
|
64
|
+
r2player.should_not be_nil
|
65
|
+
role2.player.should == r2player
|
66
|
+
end
|
67
|
+
it "should resolve relative identifiers = occ values" do
|
68
|
+
occ = @leipzig.create_occurrence(@tm.get!("Webpage"), "foobar")
|
69
|
+
occ.value.should be_a_kind_of String
|
70
|
+
occ.value.should == "foobar"
|
71
|
+
occ.datatype.value.should == RTM::PSI[:String]
|
72
|
+
### now create the association
|
73
|
+
association = occ.externalize
|
74
|
+
### type must be RTM::PSI[:subject_representation]
|
75
|
+
assoc_type = @tm.get(RTM::PSI[:subject_representation])
|
76
|
+
assoc_type.should_not be_nil
|
77
|
+
association.type.should == assoc_type
|
78
|
+
### 2 roles
|
79
|
+
association.should have(2).roles
|
80
|
+
### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic)
|
81
|
+
association.roles(RTM::PSI[:represented_subject]).size.should == 1
|
82
|
+
role1 = association.roles(RTM::PSI[:represented_subject]).first
|
83
|
+
role1.player.should == @leipzig
|
84
|
+
### the other role of type occ_type and player: topic with subject locator occ_value
|
85
|
+
association.roles("Webpage").size.should == 1
|
86
|
+
role2 = association.roles("Webpage").first
|
87
|
+
r2player = @tm.get("=http://www.topicmapslab.de/foobar")
|
88
|
+
r2player.should_not be_nil
|
89
|
+
role2.player.should == r2player
|
90
|
+
end
|
91
|
+
it "should perhaps be tested for other datatypes"
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#externalize!" do
|
95
|
+
before(:each) do
|
96
|
+
@leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig")
|
97
|
+
end
|
98
|
+
it "should remove the occurrence also" do
|
99
|
+
occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/", :scope => ["theme1", "theme2"])
|
100
|
+
@leipzig.should have(1).occurrences
|
101
|
+
association = occ.externalize!
|
102
|
+
@leipzig.occurrences.should be_empty
|
103
|
+
end
|
104
|
+
it "should remove the occurrence also, even if it has a reifier" do
|
105
|
+
occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/", :scope => ["theme1", "theme2"])
|
106
|
+
occ.reifier = "a_reifier"
|
107
|
+
occ.reifier.should_not be_nil
|
108
|
+
@leipzig.should have(1).occurrences
|
109
|
+
association = occ.externalize!
|
110
|
+
@leipzig.occurrences.should be_empty
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#external?" do
|
115
|
+
before(:each) do
|
116
|
+
@leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig")
|
117
|
+
end
|
118
|
+
it "should return true if this occurrence is an external occurrence" do
|
119
|
+
occ = @leipzig.create_occurrence("Webpage", @tm.create_locator("http://www.leipzig.de/"))
|
120
|
+
occ.external?.should be_true
|
121
|
+
end
|
122
|
+
it "should return false if this occurrence is not an external occurrence" do
|
123
|
+
occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/")
|
124
|
+
occ.external?.should be_false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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::Reifiable
|
7
|
+
module Reifier
|
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 "#reifier!" do
|
17
|
+
it "should not return nil if the Reifiable has no reifier" do
|
18
|
+
@tm.reifier.should be_nil
|
19
|
+
@tm.reifier!.should_not be_nil
|
20
|
+
end
|
21
|
+
it "should return the reifier if the Reifiable has a reifier" do
|
22
|
+
@tm.get("reifier_for_tm").should be_nil
|
23
|
+
@tm.reifier = "reifier_for_tm"
|
24
|
+
@tm.get("reifier_for_tm").should_not be_nil
|
25
|
+
@tm.reifier!.should == @tm.get("reifier_for_tm")
|
26
|
+
end
|
27
|
+
it "should create a topic as reifier for the Reifiable otherwise" do
|
28
|
+
topic1 = @tm.create_topic
|
29
|
+
@tm.should have(1).topics
|
30
|
+
@tm.reifier.should be_nil
|
31
|
+
result = @tm.reifier!
|
32
|
+
result.should be_a_kind_of(RTM::Topic)
|
33
|
+
@tm.should have(2).topics
|
34
|
+
@tm.topics.should include(topic1, result)
|
35
|
+
@tm.reifier.should == result
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,193 @@
|
|
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::Role
|
7
|
+
module Counterparts
|
8
|
+
describe self do
|
9
|
+
before(:each) do
|
10
|
+
@tm = get_used_tm_sys_tm
|
11
|
+
@t1,@t2,@t3,@t4,@t5 = @tm.get!(["t1","t2","t3","t4","t5"])
|
12
|
+
@t_a1,@t_a2,@t_a3 = @tm.get!(["t_a1","t_a2","t_a3"])
|
13
|
+
@t_r1,@t_r2,@t_r3,@t_r4,@t_r5 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5"])
|
14
|
+
@a1 = @tm.create_association(@t_a1)
|
15
|
+
@a2 = @tm.create_association(@t_a2)
|
16
|
+
@a3 = @tm.create_association(@t_a1)
|
17
|
+
@a4 = @tm.create_association(@t_a3)
|
18
|
+
@a5 = @tm.create_association(@t_a1)
|
19
|
+
@r1 = @a1.create_role(@t_r1, @t1)
|
20
|
+
@r2 = @a1.create_role(@t_r2, @t2)
|
21
|
+
@r3 = @a1.create_role(@t_r1, @t4)
|
22
|
+
@r4 = @a2.create_role(@t_r1, @t1)
|
23
|
+
@r5 = @a2.create_role(@t_r3, @t3)
|
24
|
+
@r6 = @a3.create_role(@t_r4, @t1)
|
25
|
+
@r7 = @a3.create_role(@t_r5, @t5)
|
26
|
+
@r8 = @a4.create_role(@t_r4, @t4)
|
27
|
+
@r9 = @a4.create_role(@t_r5, @t4)
|
28
|
+
@r10= @a5.create_role(@t_r2, @t5)
|
29
|
+
end
|
30
|
+
after(:each) do
|
31
|
+
@tm.close
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#counterparts" do
|
35
|
+
it "should give back all counterparts (roles) if no otype is given" do
|
36
|
+
@r1.should have(2).counterparts
|
37
|
+
@r1.counterparts.should include @r2, @r3
|
38
|
+
@r8.should have(1).counterparts
|
39
|
+
@r8.counterparts.should include @r9
|
40
|
+
end
|
41
|
+
it "should give back some counterparts (roles) if otype is given" do
|
42
|
+
@r1.counterparts(:otype=>@t_r1).size.should == 1
|
43
|
+
@r1.counterparts(:otype=>@t_r1).should include @r3
|
44
|
+
@r6.counterparts(:otype=>@t_r1).should be_empty
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#counterplayers" do
|
49
|
+
it "should give back all counterplayers (topics) if no otype is given" do
|
50
|
+
@r1.should have(2).counterplayers
|
51
|
+
@r1.counterplayers.should include @t2, @t4
|
52
|
+
@r8.should have(1).counterplayers
|
53
|
+
@r8.counterplayers.should include @t4
|
54
|
+
end
|
55
|
+
it "should give back some counterplayers (topics) if otype is given " do
|
56
|
+
@r1.counterplayers(:otype=>@t_r1).size.should == 1
|
57
|
+
@r1.counterplayers(:otype=>@t_r1).should include @t4
|
58
|
+
@r4.counterplayers(:otype=>@t_r2).size.should == 0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#counterpart" do
|
63
|
+
it "should give back the counterpart Role if the parent association is binary" do
|
64
|
+
@r4.counterpart.should == @r5
|
65
|
+
@r5.counterpart.should == @r4
|
66
|
+
end
|
67
|
+
it "should raise an error if the üparent association includes more than 2 roles" do
|
68
|
+
lambda {@r2.counterpart}.should raise_error
|
69
|
+
end
|
70
|
+
it "should give back nil if the parent association is unary" do
|
71
|
+
@r10.counterpart.should be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#counterplayer" do
|
76
|
+
it "should give back the counterplayer Topic if the parent association is binary" do
|
77
|
+
@r6.counterplayer.should == @t5
|
78
|
+
@r5.counterplayer.should == @t1
|
79
|
+
end
|
80
|
+
it "should raise an error if the parent association includes more than 2 roles" do
|
81
|
+
lambda {@r2.counterplayer}.should raise_error
|
82
|
+
end
|
83
|
+
it "should give back nil if the parent association is unary" do
|
84
|
+
@r10.counterplayer.should be_nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe self do
|
90
|
+
before(:each) do
|
91
|
+
@tm = get_used_tm_sys_tm
|
92
|
+
t1,t2,t3,t4,t5,t6,t7,t8 = @tm.get!(["t1","t2","t3","t4","t5","t6","t7","t8"])
|
93
|
+
t_a1,t_a2 = @tm.get!(["t_a1","t_a2"])
|
94
|
+
@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"])
|
95
|
+
a1 = @tm.create_association(t_a1)
|
96
|
+
a2 = @tm.create_association(t_a1)
|
97
|
+
a3 = @tm.create_association(t_a1)
|
98
|
+
a4 = @tm.create_association(t_a1)
|
99
|
+
a5 = @tm.create_association(t_a1)
|
100
|
+
a6 = @tm.create_association(t_a2)
|
101
|
+
@r1 = a1.create_role(@t_r1, t1)
|
102
|
+
@r2 = a1.create_role(@t_r3, t2)
|
103
|
+
@r4 = a2.create_role(@t_r1, t1)
|
104
|
+
@r5 = a2.create_role(@t_r3, t3)
|
105
|
+
@r6 = a3.create_role(@t_r1, t1)
|
106
|
+
@r7 = a3.create_role(@t_r5, t5)
|
107
|
+
@r3 = a4.create_role(@t_r1, t1)
|
108
|
+
@r8 = a4.create_role(@t_r3, t4)
|
109
|
+
@r9 = a4.create_role(@t_r6, t6)
|
110
|
+
@r10 = a5.create_role(@t_r4, t1)
|
111
|
+
@r11 = a5.create_role(@t_r3, t7)
|
112
|
+
@r12 = a6.create_role(@t_r4,t1)
|
113
|
+
@r13 = a6.create_role(@t_r2,t8)
|
114
|
+
end
|
115
|
+
after(:each) do
|
116
|
+
@tm.close
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#peers" do
|
120
|
+
it "should give back roles of other associations (with same size and atype) that have the same rtype and otype" do
|
121
|
+
@r5.peers.size.should == 1
|
122
|
+
@r5.peers.should include @r2
|
123
|
+
@r5.peers(:arity => :stuff, :otype => :stuff, :atype => :stuff, :rtyoe => :stuff).should == @r5.peers
|
124
|
+
end
|
125
|
+
it "should give back roles of other associations (with any size but same atype) that have the same rtype and otype" do
|
126
|
+
@r5.peers(:arity => :loose).size.should == 2
|
127
|
+
@r5.peers(:arity => :loose).should include @r2
|
128
|
+
@r5.peers(:arity => :loose).should include @r8
|
129
|
+
end
|
130
|
+
it "should give back roles of other associations (with same size and atype) that have the same otype but not rtype" do
|
131
|
+
@r5.peers(:rtype => :loose).size.should == 2
|
132
|
+
@r5.peers(:rtype => :loose).should include @r2,@r7
|
133
|
+
end
|
134
|
+
it "should give back roles of other associations (with any size but same atype) that have the same otype but not rtype" do
|
135
|
+
@r5.peers(:arity => :loose, :rtype => :loose).size.should == 4
|
136
|
+
@r5.peers(:arity => :loose, :rtype => :loose).should include @r2,@r7,@r8,@r9
|
137
|
+
end
|
138
|
+
it "should give back roles of other associations (with same size and atype) that have any otype but same rtype" do
|
139
|
+
@r5.peers(:otype => :loose).size.should == 2
|
140
|
+
@r5.peers(:otype => :loose).should include @r2,@r11
|
141
|
+
end
|
142
|
+
it "should give back roles of other associations (with same size but any atype) that have any otype and rtype" do
|
143
|
+
@r5.peers(:atype => :loose, :otype => :loose, :rtype => :loose).size == 4
|
144
|
+
@r5.peers(:atype => :loose, :otype => :loose, :rtype => :loose).should include @r7,@r13,@r2,@r11
|
145
|
+
end
|
146
|
+
it "should raise an error if argument is not a Hash" do
|
147
|
+
lambda{@r5.peers("something")}.should raise_error
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe self do
|
153
|
+
before(:each) do
|
154
|
+
@tm = get_used_tm_sys_tm
|
155
|
+
@dad1 = @tm.get!("dad1")
|
156
|
+
@dad2 = @tm.get!("dad2")
|
157
|
+
@mom1 = @tm.get!("mom1")
|
158
|
+
@mom2 = @tm.fet!("mom2")
|
159
|
+
@kid1 = @tm.get!("kid1")
|
160
|
+
@kid2 = @tm.get!("kid2")
|
161
|
+
@kid3 = @tm.get!("kid3")
|
162
|
+
@kid4 = @tm.get!("kid4")
|
163
|
+
@pk = @tm.get!("parent_kid")
|
164
|
+
@mr = @tm.get!("mom_role")
|
165
|
+
@dr = @tm.get!("dad_role")
|
166
|
+
@kr = @tm.get!("kid_role")
|
167
|
+
@assoc1 = @tm.create_association(@pk)
|
168
|
+
@r_a1_k1 = @assoc1.create_role(@kr,@kid1)
|
169
|
+
@r_a1_m1 = @assoc1.create_role(@mr,@mom1)
|
170
|
+
@r_a1_d1 = @assoc1.create_role(@dr,@dad1)
|
171
|
+
@assoc2 = @tm.create_association(@pk)
|
172
|
+
@r_a2_k2 = @assoc2.create_role(@kr,@kid2)
|
173
|
+
@r_a2_m1 = @assoc2.create_role(@mr,@mom1)
|
174
|
+
@r_a2_d1 = @assoc2.create_role(@dr,@dad1)
|
175
|
+
@assoc3 = @tm.create_association(@pk)
|
176
|
+
@r_a3_k3 = @assoc3.create_role(@kr,@kid3)
|
177
|
+
@r_a3_m2 = @assoc3.create_role(@mr,@mom2)
|
178
|
+
@r_a3_d1 = @assoc3.create_role(@dr,@dad1)
|
179
|
+
@assoc4 = @tm.create_association(@pk)
|
180
|
+
@r_a4_k4 = @assoc4.create_role(@kr,@kid4)
|
181
|
+
@r_a4_m1 = @assoc4.create_role(@mr,@mom1)
|
182
|
+
@r_a4_d2 = @assoc4.create_role(@dr,@dad2)
|
183
|
+
end
|
184
|
+
after(:each) do
|
185
|
+
@tm.close
|
186
|
+
end
|
187
|
+
describe "#peers the second time" do
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|