rtm 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/DISCLAIMER +10 -33
- data/LICENSE +201 -0
- data/README +3 -3
- data/lib/rtm.rb +148 -74
- data/lib/rtm/axes.rb +295 -0
- data/lib/rtm/axes/association.rb +76 -0
- data/lib/rtm/axes/associations.rb +96 -0
- data/lib/rtm/axes/assocs_names_occs.rb +56 -0
- data/lib/rtm/axes/characteristic.rb +68 -0
- data/lib/rtm/axes/characteristics.rb +93 -0
- data/lib/rtm/axes/string.rb +76 -0
- data/lib/rtm/axes/strings.rb +87 -0
- data/lib/rtm/axes/topic.rb +233 -0
- data/lib/rtm/axes/topics.rb +280 -0
- data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
- data/lib/rtm/engine.rb +58 -0
- data/lib/rtm/extensions.rb +11 -1
- data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
- data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
- data/lib/rtm/helpers/uri.rb +13 -0
- data/lib/rtm/io.rb +18 -0
- data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
- data/lib/rtm/io/ontopia_io.rb +25 -0
- data/lib/rtm/io/tmapix.rb +234 -0
- data/lib/rtm/io/to_hash.rb +116 -0
- data/lib/rtm/io/to_jtm.rb +53 -103
- data/lib/rtm/io/to_rdf.rb +30 -0
- data/lib/rtm/io/to_string.rb +8 -6
- data/lib/rtm/io/to_xtm1.rb +6 -4
- data/lib/rtm/io/to_xtm2.rb +10 -8
- data/lib/rtm/io/to_yaml.rb +29 -98
- data/lib/rtm/navigation.rb +37 -0
- data/lib/rtm/navigation/association/players.rb +25 -0
- data/lib/rtm/navigation/name/atomify.rb +19 -0
- data/lib/rtm/navigation/name/characteristics.rb +33 -0
- data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
- data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/indicators.rb +31 -0
- data/lib/rtm/navigation/topic/items.rb +31 -0
- data/lib/rtm/navigation/topic/locators.rb +31 -0
- data/lib/rtm/navigation/topic/players.rb +27 -0
- data/lib/rtm/navigation/topic/supertypes.rb +162 -0
- data/lib/rtm/navigation/topic/traverse.rb +51 -0
- data/lib/rtm/navigation/topic/types.rb +107 -0
- data/lib/rtm/psi.rb +33 -2
- data/lib/rtm/sugar.rb +34 -0
- data/lib/rtm/sugar/association/hash_access.rb +46 -0
- data/lib/rtm/sugar/occurrence/dynamic_value.rb +75 -0
- data/lib/rtm/{pimp_my_api.rb → sugar/occurrence/externalize.rb} +3 -0
- data/lib/rtm/sugar/role/counterparts.rb +133 -46
- data/lib/rtm/sugar/topic/characteristics.rb +126 -12
- data/lib/rtm/sugar/topic/counterparts.rb +130 -7
- data/lib/rtm/sugar/topic/hash_access.rb +140 -30
- data/lib/rtm/sugar/topic/scoped.rb +65 -0
- data/lib/rtm/sugar/topic/topic_ref.rb +35 -0
- data/lib/rtm/sugar/topic/typed.rb +159 -0
- data/lib/rtm/sugar/typed/types.rb +38 -0
- data/lib/rtm/validation.rb +8 -5
- data/lib/rtm/version.rb +18 -0
- data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
- data/spec/rtm/axes/association_spec.rb +88 -0
- data/spec/rtm/axes/associations_spec.rb +60 -0
- data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
- data/spec/rtm/axes/characteristic_spec.rb +90 -0
- data/spec/rtm/axes/characteristics_spec.rb +85 -0
- data/spec/rtm/axes/string_spec.rb +145 -0
- data/spec/rtm/axes/strings_spec.rb +168 -0
- data/spec/rtm/axes/topic_spec.rb +124 -0
- data/spec/rtm/axes/topics_spec.rb +103 -0
- data/spec/rtm/base_spec.rb +32 -0
- data/spec/rtm/io/tmapix_spec.rb +85 -0
- data/spec/rtm/navigation/association/players_spec.rb +58 -0
- data/spec/rtm/navigation/association_spec.rb +52 -0
- data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/name_spec.rb +52 -0
- data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/occurrence_spec.rb +52 -0
- data/spec/rtm/navigation/string_spec.rb +51 -0
- data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
- data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
- data/spec/rtm/navigation/topic/items_spec.rb +44 -0
- data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
- data/spec/rtm/navigation/topic/players_spec.rb +48 -0
- data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
- data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
- data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
- data/spec/rtm/navigation/topic/types_spec.rb +195 -0
- data/spec/rtm/navigation/topic_spec.rb +153 -0
- data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
- data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +16 -0
- data/spec/rtm/sugar/role/counterparts_spec.rb +191 -0
- data/spec/rtm/sugar/topic/characteristics_spec.rb +318 -0
- data/spec/rtm/sugar/topic/counterparts_spec.rb +184 -0
- data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
- data/spec/rtm/sugar/topic/scoped_spec.rb +131 -0
- data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
- data/spec/rtm/sugar/topic/typed_spec.rb +155 -0
- data/spec/rtm/sugar/typed/types_spec.rb +24 -0
- data/spec/rtm/tmapi/core/association_spec.rb +169 -0
- data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
- data/spec/rtm/tmapi/core/name_spec.rb +85 -0
- data/spec/rtm/tmapi/core/occurrence_spec.rb +96 -0
- data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
- data/spec/rtm/tmapi/core/role_spec.rb +73 -0
- data/spec/rtm/tmapi/core/scoped_spec.rb +403 -0
- data/spec/rtm/tmapi/core/topic_map_spec.rb +648 -0
- data/spec/rtm/tmapi/core/topic_spec.rb +992 -0
- data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
- data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
- data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
- data/spec/rtm/tmapi_spec.rb +44 -0
- data/spec/rtm/utils/sparql_spec.rb +26 -0
- data/spec/rtm_spec.rb +94 -0
- data/spec/spec_helper.rb +23 -0
- data/test/base_unit_test.rb +161 -0
- data/test/{base_test.rb → base_unit_test_tmapi.rb} +46 -43
- metadata +122 -66
- data/COPYRIGHT +0 -4
- data/lib/Rakefile.rb +0 -42
- data/lib/activetopicmaps.rb +0 -278
- data/lib/rtm/backend/active_record.rb +0 -58
- data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
- data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
- data/lib/rtm/backend/active_record/locators.rb +0 -55
- data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
- data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
- data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
- data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
- data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
- data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
- data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
- data/lib/rtm/backend/active_record/tmdm.rb +0 -298
- data/lib/rtm/backend/active_record/topic.rb +0 -87
- data/lib/rtm/backend/active_record/topic_map.rb +0 -314
- data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
- data/lib/rtm/base.rb +0 -92
- data/lib/rtm/connect.rb +0 -92
- data/lib/rtm/core_ext.rb +0 -6
- data/lib/rtm/io/from_xtm2.rb +0 -263
- data/lib/rtm/merging/merging.rb +0 -307
- data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
- data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
- data/lib/run_main_project.rb +0 -16
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Occurrence
|
7
|
+
|
8
|
+
# Returns the atomic value of the Characteristic (Name/Occurrence).
|
9
|
+
#
|
10
|
+
# :call-seq:
|
11
|
+
# atomify -> String
|
12
|
+
#
|
13
|
+
def atomify
|
14
|
+
value
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Occurrence
|
7
|
+
|
8
|
+
# Returns the Topic this Characteristic (Name/Occurrence) belongs to.
|
9
|
+
# The optional argument identifier filters the
|
10
|
+
# Characteristic for its type. If the type
|
11
|
+
# does not match, nil is returned.
|
12
|
+
#
|
13
|
+
# The identifier may be a Topic or Topic-Reference.
|
14
|
+
#
|
15
|
+
# :call-seq:
|
16
|
+
# reverse_characteristics -> Topic
|
17
|
+
# reverse_characteristics(identifier) -> Topic or nil
|
18
|
+
#
|
19
|
+
def reverse_characteristics(type=:any)
|
20
|
+
return parent if type == :any
|
21
|
+
_topic = topic_map.get(type)
|
22
|
+
return nil unless _topic
|
23
|
+
#filter the Name/Occurrence for its type:
|
24
|
+
if _topic == self.type
|
25
|
+
return parent
|
26
|
+
else
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# Returns all Names and Occurrences of this Topic.
|
9
|
+
# If an identifier is given, only those Names and Occurrences are returned,
|
10
|
+
# whose type or supertypes include the identifier.
|
11
|
+
#
|
12
|
+
# Identifier may be a Topic or Topic-Reference.
|
13
|
+
#
|
14
|
+
# The result may be empty.
|
15
|
+
#
|
16
|
+
# :call-seq:
|
17
|
+
# characteristics -> Array of Names and Occurrences
|
18
|
+
# characteristics(identifier) -> Array of Names and Occurrences
|
19
|
+
#
|
20
|
+
def characteristics(type=:any)
|
21
|
+
# FIXME which version of the code?
|
22
|
+
return names.to_a + occurrences.to_a if type == :any
|
23
|
+
_topic = topic_map.get(type)
|
24
|
+
return [] unless _topic
|
25
|
+
#names.select{|n| n.type.include?(_topic) || n.type.supertypes.include?(_topic)}.to_a +
|
26
|
+
#occurrences.select{|o| o.type.include?(_topic) || o.type.supertypes.include?(_topic)}.to_a
|
27
|
+
names.select{|n| n.type.supertypes.include?(_topic)}.to_a +
|
28
|
+
occurrences.select{|o| o.type.supertypes.include?(_topic)}.to_a
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# Returns all indicators (subject identifiers) of this Topic.
|
9
|
+
#
|
10
|
+
# The result may be empty.
|
11
|
+
#
|
12
|
+
# :call-seq:
|
13
|
+
# indicators -> Array of Strings
|
14
|
+
#
|
15
|
+
def indicators
|
16
|
+
getSubjectIdentifiers.map{|locator| locator.value}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns one indicator (subject identifier) of this Topic or nil
|
20
|
+
# if this Topic has no indicator.
|
21
|
+
#
|
22
|
+
# :call-seq:
|
23
|
+
# indicator -> String or nil
|
24
|
+
#
|
25
|
+
def indicator
|
26
|
+
return indicators.empty? ? nil : indicators.sort.first # TODO Which sorting algorithm?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# Returns all item identifier of this Topic.
|
9
|
+
#
|
10
|
+
# The result may be empty.
|
11
|
+
#
|
12
|
+
# :call-seq:
|
13
|
+
# items -> Array of Strings
|
14
|
+
#
|
15
|
+
def items
|
16
|
+
getItemIdentifiers.map{|locator| locator.value}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns one item identifier of this Topic or nil
|
20
|
+
# if this Topic has no item identifier.
|
21
|
+
#
|
22
|
+
# :call-seq:
|
23
|
+
# item -> String or nil
|
24
|
+
#
|
25
|
+
def item
|
26
|
+
return items.empty? ? nil : items.sort.first # TODO Which sorting algorithm?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# Returns all subject locators of this Topic.
|
9
|
+
#
|
10
|
+
# The result may be empty.
|
11
|
+
#
|
12
|
+
# :call-seq:
|
13
|
+
# locators -> Array of Strings
|
14
|
+
#
|
15
|
+
def locators
|
16
|
+
getSubjectLocators.map{|locator| locator.value}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns one subject locator of this Topic or nil
|
20
|
+
# if this Topic has no subject locator.
|
21
|
+
#
|
22
|
+
# :call-seq:
|
23
|
+
# locator -> String or nil
|
24
|
+
#
|
25
|
+
def locator
|
26
|
+
return locators.empty? ? nil : locators.sort.first # TODO Which sorting algorithm?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# Returns all Associations in which this Topic plays a Role.
|
9
|
+
#
|
10
|
+
# The optional
|
11
|
+
# identifier specifies the type of the Roles to be considered.
|
12
|
+
# The identifier may be a Topic or Topic-Reference.
|
13
|
+
#
|
14
|
+
# Multiple instances of the same Association are possible.
|
15
|
+
# The result may be empty.
|
16
|
+
#
|
17
|
+
# :call-seq:
|
18
|
+
# reverse_players -> Array of Associations
|
19
|
+
# reverse_players(identifier) -> Array of Associations
|
20
|
+
#
|
21
|
+
def reverse_players(type = :any)
|
22
|
+
roles_played(type).map{|r| r.parent}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# Returns all Topic players that exist in binary supertype-subtype Associations
|
9
|
+
# where this Topic playes the subtype-Role.
|
10
|
+
#
|
11
|
+
# The result may be an empty Array.
|
12
|
+
#
|
13
|
+
# :call-seq:
|
14
|
+
# direct-supertypes -> Array of Topics
|
15
|
+
#
|
16
|
+
def direct_supertypes
|
17
|
+
roles_played(topic_map.get(RTM::PSI[:subtype]),topic_map.get(RTM::PSI[:supertype_subtype])).
|
18
|
+
reject{|r| r.getParent.getRoles.size!=2}.
|
19
|
+
map{|r| r.parent[RTM::PSI[:supertype]].first.player}.flatten.uniq
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a binary supertype-subtype-Association where identifier defines
|
23
|
+
# the player of the supertype-Role. The current Topic will play the
|
24
|
+
# subtype-Role. Returns the created Association.
|
25
|
+
#
|
26
|
+
# Identifier may be a Topic or Topic-Reference.
|
27
|
+
#
|
28
|
+
# :call-seq:
|
29
|
+
# add_supertype(identifier) -> Association
|
30
|
+
#
|
31
|
+
def add_supertype(new_supertype)
|
32
|
+
asso = topic_map.create_association(RTM::PSI[:supertype_subtype])
|
33
|
+
asso.create_role(RTM::PSI[:subtype],self)
|
34
|
+
asso.create_role(RTM::PSI[:supertype],new_supertype)
|
35
|
+
asso
|
36
|
+
end
|
37
|
+
|
38
|
+
# Creates one or several binary supertype-subtype-Associations where
|
39
|
+
# each identifier defines
|
40
|
+
# the player of a supertype-Role. The current topic will play the
|
41
|
+
# subtype-Role in each association. Returns the associations.
|
42
|
+
#
|
43
|
+
# The identifier may be topic references.
|
44
|
+
#
|
45
|
+
# :call-seq:
|
46
|
+
# add_supertypes(identifier1, identifier2, ...) -> Array of Associtions
|
47
|
+
#
|
48
|
+
def add_supertypes(*args)
|
49
|
+
args.flatten!
|
50
|
+
args.map{|identifier| add_supertype(identifier)}
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns all supertypes of this Topic. The result includes
|
54
|
+
# all direct supertypes
|
55
|
+
# and the supertypes of these direct supertypes.
|
56
|
+
#
|
57
|
+
# The result may be an empty Array.
|
58
|
+
#
|
59
|
+
# :call-seq:
|
60
|
+
# transitive_supertypes -> Array of Topics
|
61
|
+
#
|
62
|
+
def transitive_supertypes
|
63
|
+
result_types = new_s_t = direct_supertypes
|
64
|
+
until new_s_t.empty?
|
65
|
+
new_s_t = new_s_t.map{|s| s.direct_supertypes}.flatten.uniq
|
66
|
+
new_s_t = new_s_t.reject{|s| result_types.include?(s)}
|
67
|
+
result_types = result_types + new_s_t
|
68
|
+
end
|
69
|
+
return result_types
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns all supertypes of this Topic. The result includes the direct_supertypes
|
73
|
+
# and the supertypes of these direct_supertypes of this Topic as well as the Topic itself.
|
74
|
+
#
|
75
|
+
# :call-seq:
|
76
|
+
# transitive_supertypes_with_self -> Array of Topics
|
77
|
+
#
|
78
|
+
def transitive_supertypes_with_self
|
79
|
+
transitive_supertypes + self
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns all Topics that exist in binary supertype-subtype Associations
|
83
|
+
# where this Topic playes the supertype-Role.
|
84
|
+
#
|
85
|
+
# The result may be an empty Array.
|
86
|
+
#
|
87
|
+
# :call-seq:
|
88
|
+
# direct-subtypes -> Array of Topics
|
89
|
+
#
|
90
|
+
def direct_subtypes
|
91
|
+
roles(topic_map.get(RTM::PSI[:supertype]),topic_map.get(RTM::PSI[:supertype_subtype])).
|
92
|
+
reject{|r| r.getParent.getRoles.size!=2}.
|
93
|
+
map {|r| r.getParent[RTM::PSI[:subtype]].first.player}.flatten.uniq
|
94
|
+
end
|
95
|
+
|
96
|
+
# Creates a binary supertype-subtype-Association where identifier defines
|
97
|
+
# the player of the subtype-Role. The current Topic will play the
|
98
|
+
# supertype-Role. Returns the created Association.
|
99
|
+
#
|
100
|
+
# Identifier may be Topic or Topic Reference.
|
101
|
+
#
|
102
|
+
# :call-seq:
|
103
|
+
# add_subtype(identifier) -> Association
|
104
|
+
#
|
105
|
+
def add_subtype(new_subtype)
|
106
|
+
asso = topic_map.create_association(RTM::PSI[:supertype_subtype])
|
107
|
+
asso.create_role(RTM::PSI[:supertype],self)
|
108
|
+
asso.create_role(RTM::PSI[:subtype],new_subtype)
|
109
|
+
asso
|
110
|
+
end
|
111
|
+
|
112
|
+
# Creates one or several binary supertype-subtype-Associations where
|
113
|
+
# each identifier defines
|
114
|
+
# the player of a subtype-Role. The current topic will play the
|
115
|
+
# supertype-Role in each association. Returns the associations.
|
116
|
+
#
|
117
|
+
# The identifier may be topic references.
|
118
|
+
#
|
119
|
+
# :call-seq:
|
120
|
+
# add_subtypes(identifier1, identifier2, ...) -> Array of Associtions
|
121
|
+
#
|
122
|
+
def add_subtypes(*args)
|
123
|
+
args.flatten!
|
124
|
+
args.map{|identifier| add_subtype(identifier)}
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns all subtypes of this Topic. The result includes the direct subtypes
|
128
|
+
# and the subtypes of these direct subtypes.
|
129
|
+
#
|
130
|
+
# The result may be an empty Array.
|
131
|
+
#
|
132
|
+
# :call-seq:
|
133
|
+
# transitive_subtypes -> Array of Topics
|
134
|
+
#
|
135
|
+
def transitive_subtypes
|
136
|
+
result_types = new_s_t = direct_subtypes
|
137
|
+
until new_s_t.empty?
|
138
|
+
new_s_t = new_s_t.map{|s| s.direct_subtypes}.flatten.uniq
|
139
|
+
new_s_t = new_s_t.reject{|s| result_types.include?(s)}
|
140
|
+
result_types = result_types + new_s_t
|
141
|
+
end
|
142
|
+
return result_types
|
143
|
+
end
|
144
|
+
|
145
|
+
# Returns all subtypes of this Topic. The result includes the direct_subtypes
|
146
|
+
# and the subtypes of these direct_subtypes of this Topic as well as the Topic itself.
|
147
|
+
#
|
148
|
+
# :call-seq:
|
149
|
+
# transitive_subtypes_with_self -> Array of Topics
|
150
|
+
#
|
151
|
+
def transitive_subtypes_with_self
|
152
|
+
transitive_subtypes + self
|
153
|
+
end
|
154
|
+
|
155
|
+
alias :supertypes :transitive_supertypes
|
156
|
+
alias :subtypes :transitive_subtypes
|
157
|
+
alias :reverse_subtypes :supertypes
|
158
|
+
alias :reverse_supertypes :subtypes
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# First computes all Associations where this Topic playes a Role.
|
9
|
+
# There, the optional identifier filters the Associations for their type.
|
10
|
+
#
|
11
|
+
# Returns all Players of all Roles in these Associations.
|
12
|
+
# The current Topic is not included in the result.
|
13
|
+
# The result may be empty.
|
14
|
+
#
|
15
|
+
# The identifier may be a Topic or Topic-Reference.
|
16
|
+
#
|
17
|
+
# :call-seq:
|
18
|
+
# traverse(identifier) -> Array of Topics
|
19
|
+
#
|
20
|
+
def traverse(type = :any)
|
21
|
+
unless type == :any
|
22
|
+
_topic = topic_map.get(type)
|
23
|
+
return [] unless _topic
|
24
|
+
end
|
25
|
+
_res = roles_played.map{|r| r.parent} #associations
|
26
|
+
_res = _res.select{|a| a.type == _topic} unless type == :any
|
27
|
+
_res = _res.map{|a| a.roles.map{ |r| r.player}}.flatten #players of all roles in these associations
|
28
|
+
# unless _res.empty?
|
29
|
+
# _res.each_with_index do |x,i|
|
30
|
+
# if x == self
|
31
|
+
# _res.delete_at(i)
|
32
|
+
# break
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
_res =_res.reject{|p| p == self}
|
37
|
+
return _res
|
38
|
+
end
|
39
|
+
|
40
|
+
# Always returns an empty Array
|
41
|
+
#
|
42
|
+
# :call-seq:
|
43
|
+
# reverse_traverse -> Array
|
44
|
+
#
|
45
|
+
def reverse_traverse
|
46
|
+
Array.new
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM
|
5
|
+
module Navigation
|
6
|
+
module Topic
|
7
|
+
|
8
|
+
# Returns the topics this topic is an instance of.
|
9
|
+
#
|
10
|
+
# The result may be empty.
|
11
|
+
#
|
12
|
+
# :call-seq:
|
13
|
+
# types -> Set of Topics
|
14
|
+
#
|
15
|
+
def types
|
16
|
+
# NO SUPERISE IN Axes/NAVIGATION
|
17
|
+
raise "This method (types) should never be executed because the corresponding TMAPI function should be called"
|
18
|
+
getTypes
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the topic this topic is an instance of. It must have
|
22
|
+
# exactly one type, else an error is raised.
|
23
|
+
#
|
24
|
+
# Returns nil if this Topic has no type.
|
25
|
+
#
|
26
|
+
# :call-seq:
|
27
|
+
# type -> Topic or nil
|
28
|
+
#
|
29
|
+
def type
|
30
|
+
raise "Topic must have exactly one type to call the type-method. Use the types-method instead." unless types.size < 2
|
31
|
+
types.size == 1 ? types.to_a.first : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the topics which are instances of this topic.
|
35
|
+
# This method uses the TMAPI TypeInstanceIndex.
|
36
|
+
#
|
37
|
+
# The result may be empty.
|
38
|
+
#
|
39
|
+
# :call-seq:
|
40
|
+
# instances -> Set of Topics
|
41
|
+
#
|
42
|
+
def instances
|
43
|
+
type_instance_index.getTopics(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns the instance of this Topic. It must have exactly one
|
47
|
+
# instance, else an error is raised.
|
48
|
+
#
|
49
|
+
# Returns nil if this Topic has no instance.
|
50
|
+
#
|
51
|
+
# :call-seq:
|
52
|
+
# instance -> Topic
|
53
|
+
#
|
54
|
+
def instance
|
55
|
+
raise "Topic must have exactly one instance to call the instance-method. Use the instances-method instead." unless instances.size < 2
|
56
|
+
instances.size == 1 ? instances.to_a.first : nil
|
57
|
+
end
|
58
|
+
|
59
|
+
alias :reverse_types :instances
|
60
|
+
|
61
|
+
# Returns the types this topic is an instance of. Calls
|
62
|
+
# the TMAPI getTypes method.
|
63
|
+
#
|
64
|
+
# The result may be empty.
|
65
|
+
#
|
66
|
+
# :call-seq:
|
67
|
+
# reverse_instances -> Set of Topics
|
68
|
+
#
|
69
|
+
def reverse_instances
|
70
|
+
types
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the types and all transitive supertypes of the types of
|
74
|
+
# this topic. No duplicates are returned.
|
75
|
+
#
|
76
|
+
# The result may be empty.
|
77
|
+
#
|
78
|
+
# :call-seq:
|
79
|
+
# transitive_types -> Array of Topics
|
80
|
+
#
|
81
|
+
def transitive_types
|
82
|
+
trans_types = types.to_a #may be empty
|
83
|
+
types.each do |type|
|
84
|
+
trans_types.concat(type.transitive_supertypes)
|
85
|
+
end
|
86
|
+
trans_types = trans_types.uniq #no duplicates outside of tmql mode
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns instances and the instances of all transitive subtypes
|
90
|
+
# of this topic. No duplicates are returned.
|
91
|
+
#
|
92
|
+
# The result may be empty.
|
93
|
+
#
|
94
|
+
# :call-seq:
|
95
|
+
# transitive_instances -> Array of Topics
|
96
|
+
#
|
97
|
+
def transitive_instances
|
98
|
+
trans_instances = instances.to_a #may be empty
|
99
|
+
transitive_subtypes.each do |subtype|
|
100
|
+
trans_instances.concat(subtype.instances.to_a)
|
101
|
+
end
|
102
|
+
trans_instances = trans_instances.uniq #no duplicates outside of tmql mode
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|