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
@@ -1,14 +1,137 @@
|
|
1
|
-
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module Sugar
|
2
5
|
module Topic
|
3
6
|
module Counterparts
|
7
|
+
|
8
|
+
# Returns all Roles belonging to Associations in which this Topic
|
9
|
+
# is a player and for which this Topic is not the player.
|
10
|
+
#
|
11
|
+
# A filter-hash may be used to filter for the the type
|
12
|
+
# of the Role this Topic playes
|
13
|
+
# (:rtype), for the Association type (:atype) and/or
|
14
|
+
# for the type of the returned Roles (:otype). The
|
15
|
+
# identifier may be a Topic, String-Reference or Locator.
|
16
|
+
#
|
17
|
+
# The result may be empty.
|
18
|
+
#
|
19
|
+
# :call-seq:
|
20
|
+
# counterparts -> Array of Roles
|
21
|
+
# counterparts({:rtype => identifier}) -> Array of Roles
|
22
|
+
# counterparts({:atype => identifier}) -> Array of Roles
|
23
|
+
# counterparts({:otype => identifier}) -> Array of Roles
|
24
|
+
# counterparts({:rtype => identifier, :atype => identifier}) -> Array of Roles
|
25
|
+
# counterparts({:rtype => identifier, :atype => identifier, :otype => identifier}) -> Array of Roles
|
26
|
+
#
|
4
27
|
def counterparts(filter={})
|
5
|
-
self.
|
6
|
-
|
7
|
-
|
8
|
-
inject([]){|all,r| all+=r.counterparts(filter)}
|
28
|
+
roles.select{|r| filter[:rtype] ? r.type == self.topic_map.get(filter[:rtype]) : true}.
|
29
|
+
select{|r| filter[:atype] ? r.parent.type == self.topic_map.get(filter[:atype]) : true}.
|
30
|
+
inject([]){|all,r| all+=r.counterparts(filter)}
|
9
31
|
end
|
10
|
-
|
11
|
-
|
32
|
+
|
33
|
+
# Returns all Topics that are players of Roles belonging to Associations
|
34
|
+
# in which this Topic is another player. The resulting Array does
|
35
|
+
# not contain duplicates.
|
36
|
+
#
|
37
|
+
# A filter-hash may be used to filter for the the type
|
38
|
+
# of the Role this Topic playes
|
39
|
+
# (:rtype), for the Association type (:atype) and/or
|
40
|
+
# for the type of the Roles the returned Topics play (:otype). The
|
41
|
+
# identifier may be a Topic, String-Reference or Locator.
|
42
|
+
#
|
43
|
+
# The result may be empty.
|
44
|
+
#
|
45
|
+
# :call-seq:
|
46
|
+
# counterplayers -> Array of Topics
|
47
|
+
# counterplayers(:rtype => identifier) -> Array of Topics
|
48
|
+
# counterplayers(:atype => identifier) -> Array of Topics
|
49
|
+
# counterplayers(:otype => identifier) -> Array of Topics
|
50
|
+
# counterplayers(:rtype => identifier1, :atype => identifier2) -> Array of Topics
|
51
|
+
# counterplayers(:rtype => identifier1, :atype => identifier2, :otype => identifier3) -> Array of Topics
|
52
|
+
#
|
53
|
+
def counterplayers(filter={})
|
54
|
+
return counterparts(filter).map{|r| r.player}.uniq
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns all players (Topics) which share a counterplayer with this Topic (player),
|
58
|
+
# If type is given, it may constrain the type of the Role this Topic should play
|
59
|
+
# (and therefore the type of the Roles the peers play)
|
60
|
+
# or the type of the Association this Topic plays a Role in
|
61
|
+
# (and therefore the type of the Associations the peers play an Role in).
|
62
|
+
#
|
63
|
+
# Type may be a Topic or Topic-Reference.
|
64
|
+
#
|
65
|
+
# The result may be empty.
|
66
|
+
#
|
67
|
+
# :call-seq:
|
68
|
+
# peers -> Array of Topics
|
69
|
+
# peers(type) -> Array of Topics
|
70
|
+
#
|
71
|
+
def peers(type=:any)
|
72
|
+
_peers = []
|
73
|
+
if type == :any
|
74
|
+
self.roles.each do |r|
|
75
|
+
_peers = _peers + r.peers(:arity => :loose, :atype => :loose, :otype => :loose, :rtype => :loose)
|
76
|
+
end
|
77
|
+
else
|
78
|
+
type = topic_map.get(type)
|
79
|
+
if type
|
80
|
+
if self.roles.map{|r| r.type}.include?(type) #-> rtype
|
81
|
+
self.roles(type).each do |r|
|
82
|
+
_peers = _peers + r.peers(:arity => :loose, :atype => :loose, :otype => :loose, :rtype => :strict)
|
83
|
+
end
|
84
|
+
elsif self.roles.map{|r| r.parent.type}.include?(type) #->atype
|
85
|
+
self.roles.select{|r| r.parent.type == type}.each do |r|
|
86
|
+
_peers = _peers + r.peers(:arity => :loose, :atype => :strict, :otype => :loose, :rtype => :strict)
|
87
|
+
end
|
88
|
+
elsif self.roles.map{|r| r.counterparts}.flatten.map{|r| r.type}.include?(type) #-> otype
|
89
|
+
# nothing can happen so far
|
90
|
+
else
|
91
|
+
return []
|
92
|
+
end
|
93
|
+
else
|
94
|
+
return []
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return _peers.map{|r| r.player}
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns all Associations in which this Topic
|
101
|
+
# is a player.
|
102
|
+
#
|
103
|
+
# A filter-hash may be used to filter
|
104
|
+
# for the type of the Role this Topic plays (:rtype),
|
105
|
+
# for the Association type (:atype),
|
106
|
+
# for the type of another role (:otype) as well as
|
107
|
+
# for the player of this other role (:oplayer).
|
108
|
+
# Each value of this filter-hash may be a Topic, String-Reference or Locator.
|
109
|
+
#
|
110
|
+
# The result may be empty.
|
111
|
+
#
|
112
|
+
# :call-seq:
|
113
|
+
# associations_played -> Array of Associations
|
114
|
+
# associations_played({:rtype => identifier}) -> Array of Associations
|
115
|
+
# associations_played({:atype => identifier}) -> Array of Associations
|
116
|
+
# associations_played({:otype => identifier}) -> Array of Associations
|
117
|
+
# associations_played({:otype => identifier, :oplayer => identifier}) -> Array of Associations
|
118
|
+
# associations_played({:rtype => identifier, :atype => identifier}) -> Array of Associations
|
119
|
+
# associations_played({:rtype => identifier, :atype => identifier, :otype => identifier}) -> Array of Associations
|
120
|
+
# associations_played({:rtype => identifier, :atype => identifier, :otype => identifier, :oplayer => identifier}) -> Array of Associations
|
121
|
+
#
|
122
|
+
def associations_played(filter = {})
|
123
|
+
roles = self.counterparts(filter)
|
124
|
+
|
125
|
+
if filter[:oplayer]
|
126
|
+
oplayer = topic_map.get(filter[:oplayer])
|
127
|
+
roles = roles.map do |role|
|
128
|
+
(role.player==oplayer)?role:nil
|
129
|
+
end.compact
|
130
|
+
end
|
131
|
+
|
132
|
+
roles.map do |role|
|
133
|
+
role.parent
|
134
|
+
end.uniq
|
12
135
|
end
|
13
136
|
end
|
14
137
|
end
|
@@ -1,52 +1,162 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
1
4
|
module RTM::Sugar
|
2
5
|
module Topic
|
6
|
+
# This module implements methods for Hash-like access in Topics.
|
3
7
|
module HashAccess
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
+
|
9
|
+
# Returns an Array of Names or Occurrences of
|
10
|
+
# this Topic depending on the argument given.
|
11
|
+
#
|
12
|
+
# If argument is a Topic, an Array of Occurrences of this Topic which
|
13
|
+
# have the specified type is returned.
|
14
|
+
#
|
15
|
+
# Argument may be a String. Then the structure should resemble "-type @scope"
|
16
|
+
# or "type @scope".
|
17
|
+
#
|
18
|
+
# If argument starts with a "-", an Array of Names of this
|
19
|
+
# Topic, which have the specified type (trailing the "-"),
|
20
|
+
# is returned.
|
21
|
+
#
|
22
|
+
# If argument equals "-", Names that have the standard name type
|
23
|
+
# are returned.
|
24
|
+
#
|
25
|
+
# If argument starts with a "*", both Names and Occurrences, which have the
|
26
|
+
# specified type (trailing the "*") are returned as Array.
|
27
|
+
#
|
28
|
+
# If argument equals "*", all Names and Occurrences of this Topic are
|
29
|
+
# returned. In this case this method equals the characteristics()-method.
|
30
|
+
#
|
31
|
+
# Else, if argument is a String, an Array of Occurrences
|
32
|
+
# of this Topic, which have the specified type,
|
33
|
+
# is returned.
|
34
|
+
#
|
35
|
+
# The argument may include an "@" after the type.
|
36
|
+
# The String trailing the @ defines the
|
37
|
+
# scope the selected Names and Occurrences should live in. Themes in the
|
38
|
+
# scope may be c.
|
39
|
+
#
|
40
|
+
# Examples:
|
41
|
+
# topic[occtype_topic]
|
42
|
+
# topic["-"]
|
43
|
+
# topic["*"]
|
44
|
+
# topic["-nametype"]
|
45
|
+
# topic["-nametype @scope]
|
46
|
+
# topic["occtype @scope1, scope2"]
|
47
|
+
# topic["*type"]
|
48
|
+
# topic["*type @scope"]
|
49
|
+
#
|
50
|
+
# :call-seq:
|
51
|
+
# [argument=Topic] -> Array of Occurrences
|
52
|
+
# [argument=String] -> Array of Names and/or Occurrences
|
53
|
+
#
|
54
|
+
def [](identifier = :any)
|
55
|
+
# return occurrences by type if topic is given
|
56
|
+
return [] unless identifier
|
57
|
+
return occurrences(identifier).to_a if (identifier.is_a?(RTM::Topic) || identifier == :any)
|
58
|
+
prefix, type_reference, scope_reference = resolve_characteristic(identifier)
|
59
|
+
if prefix == :name
|
8
60
|
type_reference = RTM::PSI[:name_type] if type_reference == :any
|
9
|
-
|
10
|
-
|
61
|
+
ret = names(type_reference).to_a
|
62
|
+
elsif prefix == :occurrence
|
11
63
|
raise "No occurrence type given" if type_reference == :any
|
12
|
-
|
64
|
+
ret = occurrences(type_reference).to_a
|
65
|
+
elsif prefix == :both
|
66
|
+
ret = names(type_reference).to_a + occurrences(type_reference).to_a # type_reference == :any or not :any
|
67
|
+
else
|
68
|
+
|
69
|
+
end
|
70
|
+
# we now have a list of names or occurrences, now we have to select for scope
|
71
|
+
return ret if scope_reference == :any
|
72
|
+
if scope_reference == :ucs
|
73
|
+
ret.select{|i| i.scope.size == 0}
|
74
|
+
else
|
75
|
+
ret = ret.select{|i| scope_reference.all?{|sr| i.scope.include? getParent.get(sr)}}
|
13
76
|
end
|
77
|
+
ret
|
14
78
|
end
|
15
79
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
80
|
+
# Creates a Name or Occurrence of this Topic depending on the
|
81
|
+
# argument given and returns this Name/Occurrence.
|
82
|
+
#
|
83
|
+
# Argument may be a String whose structure should resemble "-type @scope"
|
84
|
+
# or "type @scope".
|
85
|
+
#
|
86
|
+
# If argument starts with a "-", a Name that has the specified type
|
87
|
+
# (trailing the "-") is created.
|
88
|
+
#
|
89
|
+
# If argument equals "-", a Name that hase the standard name type
|
90
|
+
# is created.
|
91
|
+
#
|
92
|
+
# Else, an Occurrence that has the specified type is created.
|
93
|
+
#
|
94
|
+
# The argument may include an "@" after the type. The String trailing
|
95
|
+
# the @ defines the optional scope the Name or Occurrence
|
96
|
+
# should live in. Themes in the scope may be comma- and/or space-separated.
|
97
|
+
#
|
98
|
+
# The value should be a String.
|
99
|
+
#
|
100
|
+
# Example:
|
101
|
+
# topic[occtype]= "occvalue"
|
102
|
+
# topic["-"]= "name"
|
103
|
+
# topic["-nametype"]= "name"
|
104
|
+
# topic["-nametype @scope]= "name"
|
105
|
+
# topic["occtype @scope1, scope2"]= "occvalue"
|
106
|
+
#
|
107
|
+
# :call-seq:
|
108
|
+
# [argument]= value
|
109
|
+
#
|
110
|
+
def []=(identifier, value)
|
111
|
+
prefix, type_reference, scope_reference = resolve_characteristic(identifier)
|
112
|
+
if prefix == :name
|
113
|
+
nametype = (type_reference==:any) ? topic_map.get!(RTM::PSI[:name_type]) : type_reference
|
114
|
+
scope_reference = scope_reference==:any ? [] : scope_reference
|
115
|
+
raise("Value is not a String") unless value.is_a?(String)
|
116
|
+
ret = create_name(nametype, value, scope_reference)
|
117
|
+
elsif prefix == :occurrence
|
24
118
|
raise "No occurrence type given" if type_reference == :any
|
25
|
-
|
26
|
-
|
119
|
+
ret = create_occurrence(type_reference, value)
|
120
|
+
else
|
121
|
+
return nil
|
27
122
|
end
|
123
|
+
# return object without scope if any or ucs
|
124
|
+
return ret if [:any, :ucs].include? scope_reference
|
125
|
+
# set scope
|
126
|
+
ret.add_scope(scope_reference)
|
127
|
+
ret
|
28
128
|
end
|
29
|
-
|
129
|
+
|
30
130
|
private
|
31
|
-
|
32
|
-
|
33
|
-
|
131
|
+
|
132
|
+
def resolve_characteristic(identifier)
|
133
|
+
# spaces(-|*)?spaces(anything)
|
134
|
+
prefix = :occurrence
|
135
|
+
identifier =~ /^\s*(-|\*)?\s*(.+)?$/ # - or * and then everything else
|
136
|
+
if $1
|
137
|
+
prefix = ($1 == "-") ? :name : :both
|
138
|
+
end
|
34
139
|
type, scope = resolve_type_and_scope($2)
|
35
|
-
[
|
140
|
+
[prefix, type, scope]
|
36
141
|
end
|
37
|
-
|
142
|
+
|
38
143
|
def resolve_type_and_scope(ref)
|
39
144
|
return [:any, :any] unless ref
|
40
|
-
|
41
|
-
type, scope = ref.split('@', -1)
|
42
|
-
if type.blank?
|
145
|
+
if ref[0] == ?@
|
43
146
|
type = :any
|
147
|
+
scope = ref[1..-1] #cut "@"
|
44
148
|
else
|
45
|
-
type.
|
149
|
+
type, scope = ref.split(' @', -1) # -1 -> trailing null fields are not suppressed
|
150
|
+
if (type == nil) || (type.length == 0)
|
151
|
+
type = :any
|
152
|
+
else
|
153
|
+
type.strip! #\s removed
|
154
|
+
end
|
46
155
|
end
|
156
|
+
|
47
157
|
if scope
|
48
|
-
scope = scope.strip.split(/\s+/)
|
49
|
-
scope = :ucs if scope.
|
158
|
+
scope = scope.strip.split(/\s*,?\s+/) #divided at \s,\s
|
159
|
+
scope = :ucs if (scope == nil) || (scope.length == 0)
|
50
160
|
else
|
51
161
|
scope = :any
|
52
162
|
end
|
@@ -54,4 +164,4 @@ module RTM::Sugar
|
|
54
164
|
end
|
55
165
|
end
|
56
166
|
end
|
57
|
-
end
|
167
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module Sugar
|
5
|
+
module Topic
|
6
|
+
module Scoped
|
7
|
+
|
8
|
+
# Returns the Associations, Names, Occurrences and Variants
|
9
|
+
# whose scope contains this Topic. Beware: The scope of a Variant includes
|
10
|
+
# the themes of the Name this Variant belongs to.
|
11
|
+
#
|
12
|
+
# :call-seq:
|
13
|
+
# scoped -> Array of Associations, Names, Occurrences and Variants
|
14
|
+
#
|
15
|
+
def scoped
|
16
|
+
_index = topic_map.scoped_index
|
17
|
+
_index.get_associations(self).to_a + _index.get_names(self).to_a + _index.get_occurrences(self).to_a + _index.get_variants(self).to_a
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the Associations whose scope contains this Topic.
|
21
|
+
#
|
22
|
+
# The result may be empty.
|
23
|
+
#
|
24
|
+
# :call-seq:
|
25
|
+
# scoped_associations -> Array of Associations
|
26
|
+
#
|
27
|
+
def scoped_associations
|
28
|
+
topic_map.scoped_index.get_associations(self).to_a
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the Names whose scope contains this Topic.
|
32
|
+
#
|
33
|
+
# The result may be empty.
|
34
|
+
#
|
35
|
+
# :call-seq:
|
36
|
+
# scoped_names -> Array of Names
|
37
|
+
#
|
38
|
+
def scoped_names
|
39
|
+
topic_map.scoped_index.get_names(self).to_a
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the Occurrences whose scope contains this Topic.
|
43
|
+
#
|
44
|
+
# :call-seq:
|
45
|
+
# scoped_occurrences -> Array of Occurrences
|
46
|
+
#
|
47
|
+
def scoped_occurrences
|
48
|
+
topic_map.scoped_index.get_occurrences(self).to_a
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the Variants whose scope (including the scope of the parent Name)
|
52
|
+
# contains this Topic.
|
53
|
+
#
|
54
|
+
# The result may be empty.
|
55
|
+
#
|
56
|
+
# :call-seq:
|
57
|
+
# scoped_variants -> Array of Variants
|
58
|
+
#
|
59
|
+
def scoped_variants
|
60
|
+
topic_map.scoped_index.get_variants(self).to_a
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module Sugar
|
5
|
+
module Topic
|
6
|
+
module TopicRef
|
7
|
+
|
8
|
+
# Returns an Array including all identifiers of this Topic.
|
9
|
+
# Item identifiers start with a "^", subject locators start
|
10
|
+
# with a "=", subject identifiers contain no prefix.
|
11
|
+
#
|
12
|
+
# :call-seq:
|
13
|
+
# topic_references -> Array of Strings
|
14
|
+
#
|
15
|
+
def topic_references
|
16
|
+
#def identifiers
|
17
|
+
subject_identifiers.map{|si| si.reference} +
|
18
|
+
subject_locators.map{|sl| "=#{sl.reference}"} +
|
19
|
+
item_identifiers.map{|ii| "^#{ii.reference}"}
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Returns all identifiers of this Topic as Array of Locators.
|
24
|
+
#
|
25
|
+
# :call-seq:
|
26
|
+
# topic_references_as_locators -> Array of Locators
|
27
|
+
#
|
28
|
+
def topic_references_as_locators
|
29
|
+
# TODO Spec
|
30
|
+
subject_identifiers.to_a + subject_locators.to_a + item_identifiers.to_a
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module Sugar
|
5
|
+
module Topic
|
6
|
+
module Typed
|
7
|
+
|
8
|
+
# Returns the associations, names, occurrences and roles whose
|
9
|
+
# type equals this topic.
|
10
|
+
#
|
11
|
+
# The result may be empty.
|
12
|
+
#
|
13
|
+
# :call-seq:
|
14
|
+
# typed -> Array of Associations, Names, Occurrences and Roles
|
15
|
+
#
|
16
|
+
def typed
|
17
|
+
_index = topic_map.type_instance_index
|
18
|
+
_index.get_associations(self).to_a + _index.get_names(self).to_a + _index.get_occurrences(self).to_a + _index.get_roles(self).to_a
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the associations, names, occurrences and roles whose
|
22
|
+
# type equals this topic or subtypes
|
23
|
+
# of this topic.
|
24
|
+
#
|
25
|
+
# The result may be empty.
|
26
|
+
#
|
27
|
+
# :call-seq:
|
28
|
+
# transitive_typed -> Array of Associations, Names, Occurrences and Roles
|
29
|
+
#
|
30
|
+
def transitive_typed
|
31
|
+
trans_typed = typed #may be empty
|
32
|
+
transitive_subtypes.each do |subtype|
|
33
|
+
trans_typed.concat(subtype.typed)
|
34
|
+
end
|
35
|
+
trans_typed = trans_typed.uniq #no duplicates outside of tmql mode
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the associations whose type equals this topic.
|
39
|
+
#
|
40
|
+
# The result may be empty.
|
41
|
+
#
|
42
|
+
# :call-seq:
|
43
|
+
# typed_associations -> Array of Associations
|
44
|
+
#
|
45
|
+
def typed_associations
|
46
|
+
topic_map.type_instance_index.get_associations(self).to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns the associations whose type equals this topic or subtypes
|
50
|
+
# of this topic.
|
51
|
+
#
|
52
|
+
# The result may be empty.
|
53
|
+
#
|
54
|
+
# :call-seq:
|
55
|
+
# transitive_typed_associations -> Array of Associations
|
56
|
+
#
|
57
|
+
def transitive_typed_associations
|
58
|
+
trans_types_assocs = typed_associations #may be empty
|
59
|
+
transitive_subtypes.each do |subtype|
|
60
|
+
trans_types_assocs.concat(subtype.typed_associations)
|
61
|
+
end
|
62
|
+
trans_types_assocs = trans_types_assocs.uniq #no duplicates outside of tmql mode
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns the names whose type equals this topic.
|
66
|
+
#
|
67
|
+
# The result may be empty.
|
68
|
+
#
|
69
|
+
# :call-seq:
|
70
|
+
# typed_names -> Array of Names
|
71
|
+
#
|
72
|
+
def typed_names
|
73
|
+
topic_map.type_instance_index.get_names(self).to_a
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns the names whose type equals this topic or subtypes
|
77
|
+
# of this topic.
|
78
|
+
#
|
79
|
+
# The result may be empty.
|
80
|
+
#
|
81
|
+
# :call-seq:
|
82
|
+
# transitive_typed_names -> Array of Associations
|
83
|
+
#
|
84
|
+
def transitive_typed_names
|
85
|
+
trans_types_names = typed_names #may be empty
|
86
|
+
transitive_subtypes.each do |subtype|
|
87
|
+
trans_types_names.concat(subtype.typed_names)
|
88
|
+
end
|
89
|
+
trans_types_names = trans_types_names.uniq #no duplicates outside of tmql mode
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the occurrences whose type equals this topic.
|
93
|
+
#
|
94
|
+
# The result may be empty.
|
95
|
+
#
|
96
|
+
# :call-seq:
|
97
|
+
# typed_occurrences -> Array of Occurrences
|
98
|
+
#
|
99
|
+
def typed_occurrences
|
100
|
+
topic_map.type_instance_index.get_occurrences(self).to_a
|
101
|
+
end
|
102
|
+
|
103
|
+
# Returns the occurrences whose type equals this topic or subtypes
|
104
|
+
# of this topic.
|
105
|
+
#
|
106
|
+
# The result may be empty.
|
107
|
+
#
|
108
|
+
# :call-seq:
|
109
|
+
# transitive_typed_occurrences -> Array of Associations
|
110
|
+
#
|
111
|
+
def transitive_typed_occurrences
|
112
|
+
trans_types_occs = typed_occurrences #may be empty
|
113
|
+
transitive_subtypes.each do |subtype|
|
114
|
+
trans_types_occs.concat(subtype.typed_occurrences)
|
115
|
+
end
|
116
|
+
trans_types_occs = trans_types_occs.uniq #no duplicates outside of tmql mode
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns the roles whose type equals this topic.
|
120
|
+
#
|
121
|
+
# The result may be empty.
|
122
|
+
#
|
123
|
+
# :call-seq:
|
124
|
+
# typed_roles -> Array of Roles
|
125
|
+
#
|
126
|
+
def typed_roles
|
127
|
+
topic_map.type_instance_index.get_roles(self).to_a
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns the roles whose type equals this topic or subtypes
|
131
|
+
# of this topic.
|
132
|
+
#
|
133
|
+
# The result may be empty.
|
134
|
+
#
|
135
|
+
# :call-seq:
|
136
|
+
# transitive_typed_roles -> Array of Associations
|
137
|
+
#
|
138
|
+
def transitive_typed_roles
|
139
|
+
trans_types_roles = typed_roles #may be empty
|
140
|
+
transitive_subtypes.each do |subtype|
|
141
|
+
trans_types_roles.concat(subtype.typed_roles)
|
142
|
+
end
|
143
|
+
trans_types_roles = trans_types_roles.uniq #no duplicates outside of tmql mode
|
144
|
+
end
|
145
|
+
|
146
|
+
# Determines whether this topic is instance (directly or indirectly)
|
147
|
+
# of the argument type.
|
148
|
+
#
|
149
|
+
# Type may be a topic reference.
|
150
|
+
#
|
151
|
+
# :call-seq:
|
152
|
+
# topic_is_a?(type)
|
153
|
+
#
|
154
|
+
def topic_is_a?(type)
|
155
|
+
self.transitive_types.include?(topic_map.get(type))
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|