rtm 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -1
- data/lib/rtm.rb +23 -95
- data/lib/rtm/connection.rb +51 -0
- data/lib/rtm/engine.rb +29 -18
- data/lib/rtm/extensions.rb +2 -5
- data/lib/rtm/helpers/uri.rb +1 -1
- data/lib/rtm/io/tmapix_from.rb +8 -8
- data/lib/rtm/io/tmapix_to.rb +6 -6
- data/lib/rtm/io/to_rdf.rb +1 -1
- data/lib/rtm/io/to_string.rb +22 -14
- data/lib/rtm/navigation/topic/supertypes.rb +2 -2
- data/lib/rtm/navigation/topic/types.rb +1 -1
- data/lib/rtm/psi.rb +3 -1
- data/lib/rtm/sugar.rb +8 -3
- data/lib/rtm/sugar/topic/best_name.rb +31 -50
- data/lib/rtm/sugar/topic/scoped.rb +9 -9
- data/lib/rtm/sugar/topic/topic_ref.rb +115 -72
- data/lib/rtm/sugar/topic_map/remove.rb +49 -0
- data/lib/rtm/sugar/topic_map/{themes.rb → scoped.rb} +9 -10
- data/lib/rtm/sugar/topic_map/types.rb +50 -0
- data/lib/rtm/sugar/variant/topic.rb +17 -0
- data/lib/rtm/topology.rb +134 -0
- data/lib/rtm/version.rb +13 -8
- data/spec/rtm/engine_spec.rb +45 -0
- data/spec/rtm/io/tmapix_from_spec.rb +8 -8
- data/spec/rtm/io/tmapix_to_spec.rb +38 -38
- data/spec/rtm/io/to_yaml_spec.rb +7 -0
- data/spec/rtm/javatmapi_spec.rb +64 -0
- data/spec/rtm/navigation/topic/scope_spec.rb +1 -1
- data/spec/rtm/sugar/topic/best_name_spec.rb +54 -2
- data/spec/rtm/sugar/topic/topic_ref_spec.rb +59 -35
- data/spec/rtm/sugar/topic_map/remove_spec.rb +50 -0
- data/spec/rtm/sugar/topic_map/{themes_spec.rb → scoped_spec.rb} +1 -1
- data/spec/rtm/sugar/topic_map/types_spec.rb +34 -0
- data/spec/rtm/sugar/variant/topic_spec.rb +28 -0
- data/spec/rtm/tmapi/core/name_spec.rb +1 -7
- data/spec/rtm/tmapi/core/topic_map_spec.rb +103 -51
- data/spec/rtm/tmapi/core/topic_spec.rb +3 -0
- data/spec/rtm_spec.rb +3 -12
- data/test/javalibs/tmapi-2.0-tests.jar +0 -0
- metadata +26 -9
data/lib/rtm/io/to_rdf.rb
CHANGED
data/lib/rtm/io/to_string.rb
CHANGED
@@ -5,6 +5,14 @@ module RTM::IO
|
|
5
5
|
# Each Topic Maps Construct gets a custom to_s method which supports optional :short or :long output.
|
6
6
|
module ToString
|
7
7
|
|
8
|
+
module Construct
|
9
|
+
def delocatorized(identifier_list)
|
10
|
+
identifier_list.map do |locator|
|
11
|
+
locator.value
|
12
|
+
end.inspect
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
8
16
|
module TopicMap
|
9
17
|
# Returns different String representations. Try :short (default), :long, :super (original)
|
10
18
|
def to_s(style=:short)
|
@@ -27,14 +35,14 @@ module RTM::IO
|
|
27
35
|
def to_s(style=:short)
|
28
36
|
case style
|
29
37
|
when :short
|
30
|
-
ssid = " sids=#{subject_identifiers
|
31
|
-
sslo = " slos=#{subject_locators
|
32
|
-
siid = " iids=#{item_identifiers
|
38
|
+
ssid = " sids=#{delocatorized subject_identifiers}" unless subject_identifiers.empty?
|
39
|
+
sslo = " slos=#{delocatorized subject_locators}" unless subject_locators.empty?
|
40
|
+
siid = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
33
41
|
"#<RTM::Topic id=#{id}#{ssid}#{sslo}#{siid}>"
|
34
42
|
when :long
|
35
|
-
ssid = " sids=#{subject_identifiers
|
36
|
-
sslo = " slos=#{subject_locators
|
37
|
-
siid = " iids=#{item_identifiers
|
43
|
+
ssid = " sids=#{delocatorized subject_identifiers}" unless subject_identifiers.empty?
|
44
|
+
sslo = " slos=#{delocatorized subject_locators}" unless subject_locators.empty?
|
45
|
+
siid = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
38
46
|
"#<RTM::Topic id=#{id}#{ssid}#{sslo}#{siid} names:#{names.size} occurrences:#{occurrences.size}>"
|
39
47
|
when :name
|
40
48
|
return names.first.to_s(:short) if names.first
|
@@ -50,11 +58,11 @@ module RTM::IO
|
|
50
58
|
case style
|
51
59
|
when :short
|
52
60
|
r = " #{reifier.to_s(:short)}" if reifier
|
53
|
-
i = " iids=#{item_identifiers
|
61
|
+
i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
54
62
|
"#<RTM::Association id=#{id}#{i}#{r}>"
|
55
63
|
when :long
|
56
64
|
r = " #{reifier.to_s(:short)}" if reifier
|
57
|
-
i = " iids=#{item_identifiers
|
65
|
+
i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
58
66
|
"#<RTM::Association id=#{id}#{i}#{r} type=#{type.to_s(:short)} roles=[#{roles.entries.map { |ar| ar.to_s(:long) }.join(", ")}]>"
|
59
67
|
else
|
60
68
|
super() # these () are needed, otherwise the own parameters are passed in
|
@@ -67,12 +75,12 @@ module RTM::IO
|
|
67
75
|
case style
|
68
76
|
when :short
|
69
77
|
r = " #{reifier.to_s(:short)}" if reifier
|
70
|
-
i = " iids=#{item_identifiers
|
78
|
+
i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
71
79
|
"#<RTM::Role id=#{id}#{i}#{r}>"
|
72
80
|
when :long
|
73
81
|
r = " #{reifier.to_s(:short)}" if reifier
|
74
|
-
i = " iids=#{item_identifiers
|
75
|
-
"#<RTM::
|
82
|
+
i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
83
|
+
"#<RTM::Role id=#{id}#{i}#{r} type=#{type.to_s(:short)} player=#{player.to_s(:short)}>"
|
76
84
|
else
|
77
85
|
super() # these () are needed, otherwise the own parameters are passed in
|
78
86
|
end
|
@@ -86,7 +94,7 @@ module RTM::IO
|
|
86
94
|
value
|
87
95
|
when :long
|
88
96
|
r = " #{reifier.to_s(:short)}" if reifier
|
89
|
-
i = " iids=#{item_identifiers
|
97
|
+
i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
90
98
|
"#<RTM::Name id=#{id}#{i}#{r} type=#{type.to_s(:short)} value=#{value} variants:#{variants.size}>"
|
91
99
|
else
|
92
100
|
super() # these () are needed, otherwise the own parameters are passed in
|
@@ -101,7 +109,7 @@ module RTM::IO
|
|
101
109
|
value
|
102
110
|
when :long
|
103
111
|
r = " #{reifier.to_s(:short)}" if reifier
|
104
|
-
i = " iids=#{item_identifiers
|
112
|
+
i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
105
113
|
"#<RTM::Occurrence id=#{id}#{i}#{r} type=#{type.to_s(:short)} value=#{value} datatype=#{datatype}>"
|
106
114
|
else
|
107
115
|
super() # these () are needed, otherwise the own parameters are passed in
|
@@ -116,7 +124,7 @@ module RTM::IO
|
|
116
124
|
value
|
117
125
|
when :long
|
118
126
|
r = " #{reifier.to_s(:short)}" if reifier
|
119
|
-
i = " iids=#{item_identifiers
|
127
|
+
i = " iids=#{delocatorized item_identifiers}" unless item_identifiers.empty?
|
120
128
|
"#<RTM::Variant id=#{id}#{i}#{r} value=#{value} scope=[scope.to_s]>"
|
121
129
|
else
|
122
130
|
super() # these () are needed, otherwise the own parameters are passed in
|
@@ -78,7 +78,7 @@ module RTM
|
|
78
78
|
# transitive_supertypes_with_self -> Array of Topics
|
79
79
|
#
|
80
80
|
def transitive_supertypes_with_self
|
81
|
-
transitive_supertypes + self
|
81
|
+
transitive_supertypes + [self]
|
82
82
|
end
|
83
83
|
|
84
84
|
# Returns all Topics that exist in binary supertype-subtype Associations
|
@@ -153,7 +153,7 @@ module RTM
|
|
153
153
|
# transitive_subtypes_with_self -> Array of Topics
|
154
154
|
#
|
155
155
|
def transitive_subtypes_with_self
|
156
|
-
transitive_subtypes + self
|
156
|
+
transitive_subtypes + [self]
|
157
157
|
end
|
158
158
|
|
159
159
|
alias :supertypes :transitive_supertypes
|
data/lib/rtm/psi.rb
CHANGED
@@ -100,11 +100,13 @@ module RTM
|
|
100
100
|
PSI1[:display] = "http://www.topicmaps.org/xtm/1.0/core.xtm#display"
|
101
101
|
|
102
102
|
PREFIX = {}
|
103
|
-
PREFIX[:
|
103
|
+
PREFIX[:tmdm] = "http://psi.topicmaps.org/iso13250/model/" # This is the namespace for the concepts defined by TMDM.
|
104
104
|
PREFIX[:glossary] = "http://psi.topicmaps.org/iso13250/glossary/"
|
105
105
|
PREFIX[:xsd] = "http://www.w3.org/2001/XMLSchema#" # This is the namespace for the XML Schema Datatypes.
|
106
106
|
PREFIX[:tmql] = "http://psi.topicmaps.org/tmql/1.0/" # Under this prefix the concepts of Axes itself are located.
|
107
107
|
PREFIX[:fn] = "http://psi.topicmaps.org/tmql/1.0/functions" # Under this prefix user-callable functions of the predefined Axes environment are located.
|
108
108
|
PREFIX[:xtm1] = "http://www.topicmaps.org/xtm/1.0/core.xtm#"
|
109
109
|
PREFIX[:language] = "http://psi.oasis-open.org/iso/639/#" # This is the namespace for the languae PSIs
|
110
|
+
PREFIX[:tmcl] = "http://psi.topicmaps.org/tmcl/"
|
111
|
+
PREFIX[:iso] = "http://psi.topicmaps.org/iso13250/"
|
110
112
|
end
|
data/lib/rtm/sugar.rb
CHANGED
@@ -37,11 +37,16 @@ require 'rtm/sugar/reifiable/reifier'
|
|
37
37
|
RTM::Reifiable.register_extension(RTM::Sugar::Reifiable::CreateReifier)
|
38
38
|
|
39
39
|
require 'rtm/sugar/topic_map/query_cache'
|
40
|
-
require 'rtm/sugar/topic_map/
|
40
|
+
require 'rtm/sugar/topic_map/scoped'
|
41
|
+
require 'rtm/sugar/topic_map/types'
|
42
|
+
require 'rtm/sugar/topic_map/remove'
|
41
43
|
module RTM::TopicMap
|
42
|
-
include RTM::Reifiable
|
43
44
|
@query_cache = nil #disables query caching
|
44
45
|
end
|
45
46
|
RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::QueryCache)
|
46
|
-
RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::
|
47
|
+
RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Scoped)
|
48
|
+
RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Types)
|
49
|
+
RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Remove)
|
47
50
|
|
51
|
+
require "rtm/sugar/variant/topic"
|
52
|
+
RTM::Variant.register_extension(RTM::Sugar::Variant::Topic)
|
@@ -5,70 +5,51 @@ module RTM::Sugar::Topic::BestName
|
|
5
5
|
|
6
6
|
# Tries to find the best matching name for a given topic.
|
7
7
|
#
|
8
|
-
def best_name
|
8
|
+
def best_name(theme = nil)
|
9
9
|
all_names = self.names
|
10
10
|
|
11
11
|
# return last part of identifier if no name exist
|
12
|
-
return find_user_friendly_identifier
|
12
|
+
return find_user_friendly_identifier if all_names.empty
|
13
13
|
|
14
|
-
|
15
|
-
default_names = []
|
16
|
-
all_names.each do |name|
|
17
|
-
type_of_name = name.getType
|
18
|
-
|
19
|
-
next if type_of_name.nil?
|
20
|
-
type_identifiers = type_of_name.subject_identifiers.to_a
|
14
|
+
resulting_names = []
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
16
|
+
if theme
|
17
|
+
resulting_names = self["- @#{theme.reference}"]
|
18
|
+
if resulting_names.empty?
|
19
|
+
resulting_names = all_names.select{|name| name.scope.include?(theme)}
|
27
20
|
end
|
28
21
|
end
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# get default name with the minimum number of scopes
|
35
|
-
min_scoped_name = default_names.sort_by{|n| n.value}.min {|n1,n2| n1.getScope.size <=> n2.getScope.size}
|
36
|
-
min_scoped_name.value
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def find_user_friendly_identifier(topic)
|
41
|
-
return psi_prefix topic.
|
42
|
-
subject_identifiers.
|
43
|
-
sort_by{|sid| sid.value.length}.
|
44
|
-
first.
|
45
|
-
value unless topic.subject_identifiers.empty?
|
23
|
+
# collect name with default name type
|
24
|
+
if resulting_names.empty?
|
25
|
+
resulting_names = self["-"]
|
26
|
+
end
|
46
27
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
first
|
28
|
+
# use all names
|
29
|
+
if resulting_names.empty?
|
30
|
+
resulting_names = all_names
|
31
|
+
end
|
52
32
|
|
53
|
-
#
|
54
|
-
|
33
|
+
# get the name with the smalles scope and smallest value
|
34
|
+
min_scoped_name = resulting_names.sort_by{|name| [name.scope.size, name.value.length, name.value]}.first
|
35
|
+
return min_scoped_name.value
|
55
36
|
end
|
56
37
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
iid_iri = item_identifier.value
|
62
|
-
iid_iri.scan(/(file:)?\/*#{base_iri}#(.*)/) { |pair| return "^#{pair[1]}" }
|
63
|
-
end
|
38
|
+
# Returns the shortest most significant identifier in yaml-style.
|
39
|
+
def shortest_topic_identifier
|
40
|
+
return self.references(:outputstyle => :yaml, :resolve_qnames => :true, :resolve_base_iri => :true, :sort_by_length => :true).
|
41
|
+
first unless references.empty?
|
64
42
|
|
65
|
-
|
66
|
-
|
67
|
-
# throw('Unable to create simplified identifier from topic.', topic)
|
43
|
+
raise("Runtime Exception: Topic has no identifiers.")
|
68
44
|
end
|
69
45
|
|
70
|
-
|
71
|
-
|
72
|
-
|
46
|
+
private
|
47
|
+
# Returns a subject identifier, subject locator or item identifier in this
|
48
|
+
# preference. Qnames will be resolved backwards.
|
49
|
+
def find_user_friendly_identifier
|
50
|
+
return self.references(:outputstyle => :blank, :resolve_qnames => :true, :resolve_base_iri => :true, :sort_by_length => :true).
|
51
|
+
first unless references.empty?
|
52
|
+
|
53
|
+
raise("Runtime Exception: Topic has no identifiers.")
|
73
54
|
end
|
74
55
|
end
|
@@ -13,7 +13,7 @@ module RTM::Sugar::Topic
|
|
13
13
|
#
|
14
14
|
def scoped
|
15
15
|
_index = scoped_index
|
16
|
-
_index.
|
16
|
+
_index.getAssociations(self).to_a + _index.getNames(self).to_a + _index.getOccurrences(self).to_a + _index.getVariants(self).to_a
|
17
17
|
end
|
18
18
|
|
19
19
|
# Returns the Associations whose scope contains this Topic.
|
@@ -21,10 +21,10 @@ module RTM::Sugar::Topic
|
|
21
21
|
# The result may be empty.
|
22
22
|
#
|
23
23
|
# :call-seq:
|
24
|
-
# scoped_associations ->
|
24
|
+
# scoped_associations -> Collection of Associations
|
25
25
|
#
|
26
26
|
def scoped_associations
|
27
|
-
scoped_index.
|
27
|
+
scoped_index.getAssociations(self)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Returns the Names whose scope contains this Topic.
|
@@ -32,19 +32,19 @@ module RTM::Sugar::Topic
|
|
32
32
|
# The result may be empty.
|
33
33
|
#
|
34
34
|
# :call-seq:
|
35
|
-
# scoped_names ->
|
35
|
+
# scoped_names -> Collection of Names
|
36
36
|
#
|
37
37
|
def scoped_names
|
38
|
-
scoped_index.
|
38
|
+
scoped_index.getNames(self)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Returns the Occurrences whose scope contains this Topic.
|
42
42
|
#
|
43
43
|
# :call-seq:
|
44
|
-
# scoped_occurrences ->
|
44
|
+
# scoped_occurrences -> Collection of Occurrences
|
45
45
|
#
|
46
46
|
def scoped_occurrences
|
47
|
-
scoped_index.
|
47
|
+
scoped_index.getOccurrences(self)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Returns the Variants whose scope (including the scope of the parent Name)
|
@@ -53,10 +53,10 @@ module RTM::Sugar::Topic
|
|
53
53
|
# The result may be empty.
|
54
54
|
#
|
55
55
|
# :call-seq:
|
56
|
-
# scoped_variants ->
|
56
|
+
# scoped_variants -> Collection of Variants
|
57
57
|
#
|
58
58
|
def scoped_variants
|
59
|
-
scoped_index.
|
59
|
+
scoped_index.getVariants(self)
|
60
60
|
end
|
61
61
|
|
62
62
|
# States if this topic occurs as theme in the scope of a scoped Construct.
|
@@ -1,86 +1,129 @@
|
|
1
1
|
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
2
|
# License: Apache License, Version 2.0
|
3
3
|
|
4
|
-
module RTM::Sugar
|
5
|
-
module
|
6
|
-
module TopicRef
|
4
|
+
module RTM::Sugar::Topic
|
5
|
+
module TopicRef
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
item_identifiers.map{ |ii| "^#{ii.reference}"}
|
7
|
+
# Returns an Array including all identifiers of this Topic.
|
8
|
+
#
|
9
|
+
# This method takes a Hash as argument.
|
10
|
+
#
|
11
|
+
# The key :ouputstyle defines if the ctm style (value :ctm, this is
|
12
|
+
# the default), the YAML
|
13
|
+
# style (value :yaml) or no style (value :blank) is supported.
|
14
|
+
#
|
15
|
+
# In ctm style an item identifier starts with a "^",
|
16
|
+
# a subject locator starts with a "=" and
|
17
|
+
# a subject identifiers contains no prefix.
|
18
|
+
#
|
19
|
+
# In yaml style an item identifiers start with a "ii:",
|
20
|
+
# a subject locator starts with a "sl:" and
|
21
|
+
# a subject identifier start with a "si:".
|
22
|
+
#
|
23
|
+
# :call-seq:
|
24
|
+
# references -> Array of Strings
|
25
|
+
# references(params = {}) -> Array of Strings
|
26
|
+
#
|
27
|
+
def references(params = {})
|
28
|
+
default_hash = {:outputstyle => :ctm, :resolve_qnames => :false, :resolve_base_iri => :false, :sort_by_length => :false}
|
29
|
+
params = default_hash.merge(params) if params.is_a? Hash
|
30
|
+
prefixes = topic_map.prefixes
|
31
|
+
|
32
|
+
set_of_si = subject_identifiers.map{|si| si.reference}
|
33
|
+
set_of_sl = subject_locators.map{|si| si.reference}
|
34
|
+
set_of_ii = item_identifiers.map{|si| si.reference}
|
35
|
+
|
36
|
+
if params[:resolve_qnames] == :true
|
37
|
+
unless prefixes.empty?
|
38
|
+
prefixes.each do |identifier, reference|
|
39
|
+
set_of_si = set_of_si.map{|si| si.index(reference) == 0 ? si.sub(reference, identifier + ":") : si}
|
40
|
+
set_of_sl = set_of_sl.map{|sl| sl.index(reference) == 0 ? sl.sub(reference, identifier + ":") : sl}
|
41
|
+
set_of_ii = set_of_ii.map{|ii| ii.index(reference) == 0 ? ii.sub(reference, identifier + ":") : ii}
|
42
|
+
end
|
45
43
|
end
|
46
|
-
return identifiers
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# a subject locator starts with a "=" and
|
60
|
-
# a subject identifiers contains no prefix.
|
61
|
-
#
|
62
|
-
# In yaml style an item identifiers start with a "ii:",
|
63
|
-
# a subject locator starts with a "sl:" and
|
64
|
-
# a subject identifier start with a "si:".
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# :call-seq:
|
68
|
-
# reference -> String
|
69
|
-
# reference(params = {}) -> String
|
70
|
-
#
|
71
|
-
def reference(params = {})
|
72
|
-
return references(params).sort_by{|identifier| identifier.size}.reverse.first
|
46
|
+
if params[:resolve_base_iri] == :true
|
47
|
+
set_of_si = set_of_si.map{|si| unresolve(si)}
|
48
|
+
set_of_sl = set_of_sl.map{|sl| unresolve(sl)}
|
49
|
+
set_of_ii = set_of_ii.map{|ii| unresolve(ii)}
|
50
|
+
end
|
51
|
+
|
52
|
+
if params[:sort_by_length] == :true
|
53
|
+
set_of_si = set_of_si.sort_by{|si| si.length}
|
54
|
+
set_of_sl = set_of_sl.sort_by{|sl| sl.length}
|
55
|
+
set_of_ii = set_of_ii.sort_by{|ii| ii.length}
|
73
56
|
end
|
74
57
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
58
|
+
case params[:outputstyle]
|
59
|
+
when :yaml
|
60
|
+
identifiers = set_of_si.map{ |si| "si:#{si}"} +
|
61
|
+
set_of_sl.map{ |sl| "sl:#{sl}"} +
|
62
|
+
set_of_ii.map{ |ii| "ii:#{ii}"}
|
63
|
+
when :blank
|
64
|
+
identifiers = set_of_si +
|
65
|
+
set_of_sl +
|
66
|
+
set_of_ii
|
67
|
+
else #:ctm default
|
68
|
+
identifiers = set_of_si +
|
69
|
+
set_of_sl.map{ |sl| "=#{sl}"} +
|
70
|
+
set_of_ii.map{ |ii| "^#{ii}"}
|
82
71
|
end
|
72
|
+
return identifiers
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns one identifier of this topic. If several exist, the shortest one
|
76
|
+
# is returned.
|
77
|
+
#
|
78
|
+
# This method takes a Hash as argument.
|
79
|
+
#
|
80
|
+
# The key :ouputstyle defines if the ctm style (value :ctm, this is
|
81
|
+
# the default), the YAML
|
82
|
+
# style (value :yaml) or no style (value :blank) is supported.
|
83
|
+
#
|
84
|
+
# In ctm style an item identifier starts with a "^",
|
85
|
+
# a subject locator starts with a "=" and
|
86
|
+
# a subject identifiers contains no prefix.
|
87
|
+
#
|
88
|
+
# In yaml style an item identifiers start with a "ii:",
|
89
|
+
# a subject locator starts with a "sl:" and
|
90
|
+
# a subject identifier start with a "si:".
|
91
|
+
#
|
92
|
+
#
|
93
|
+
# :call-seq:
|
94
|
+
# reference -> String
|
95
|
+
# reference(params = {}) -> String
|
96
|
+
#
|
97
|
+
def reference(params = {})
|
98
|
+
return references(params).sort_by{|identifier| identifier.size}.reverse.first
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns all identifiers of this Topic as Array of Locators.
|
102
|
+
#
|
103
|
+
# :call-seq:
|
104
|
+
# references_as_locators -> Array of Locators
|
105
|
+
#
|
106
|
+
def references_as_locators
|
107
|
+
subject_identifiers.to_a + subject_locators.to_a + item_identifiers.to_a
|
108
|
+
end
|
83
109
|
|
110
|
+
# Unresolves the identifier against the base_iri.
|
111
|
+
def unresolve(identifier)
|
112
|
+
raise("identifier must be a String") unless identifier.is_a?(String)
|
113
|
+
base_iri = topic_map.base_iri
|
114
|
+
if identifier.index(base_iri) == 0
|
115
|
+
short_form = identifier.sub(base_iri, "")
|
116
|
+
if topic_map.create_locator(short_form).reference == identifier
|
117
|
+
return short_form
|
118
|
+
end
|
119
|
+
# if short_form[0] == "/"
|
120
|
+
# short_form = short_form.sub("/", "")
|
121
|
+
#
|
122
|
+
# end
|
123
|
+
else
|
124
|
+
return identifier #nothing happened
|
125
|
+
end
|
84
126
|
end
|
127
|
+
|
85
128
|
end
|
86
129
|
end
|