rtm 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,49 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM::Sugar::TopicMap
|
5
|
+
module Remove
|
6
|
+
|
7
|
+
# Removes all variants, names, occurrences, roles, asssociations and
|
8
|
+
# topics (esp. reifier) from this topic map.
|
9
|
+
def clear
|
10
|
+
set_reifier(nil)
|
11
|
+
|
12
|
+
variants.to_a.each do |v|
|
13
|
+
v.set_reifier(nil)
|
14
|
+
v.remove
|
15
|
+
end
|
16
|
+
|
17
|
+
names.to_a.each do |n|
|
18
|
+
n.set_reifier(nil)
|
19
|
+
n.remove
|
20
|
+
end
|
21
|
+
|
22
|
+
occurrences.to_a.each do |o|
|
23
|
+
o.set_reifier(nil)
|
24
|
+
o.remove
|
25
|
+
end
|
26
|
+
|
27
|
+
roles.to_a.each do |r|
|
28
|
+
r.set_reifier(nil)
|
29
|
+
r.remove
|
30
|
+
end
|
31
|
+
|
32
|
+
associations.to_a.each do |a|
|
33
|
+
a.set_reifier(nil)
|
34
|
+
a.remove
|
35
|
+
end
|
36
|
+
|
37
|
+
types.to_a.each do |type|
|
38
|
+
type.instances.to_a.each do |instance|
|
39
|
+
instance.remove_type(type)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
topics.to_a.each do |t|
|
44
|
+
t.remove
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
2
|
# License: Apache License, Version 2.0
|
3
3
|
|
4
|
-
|
5
4
|
module RTM::Sugar
|
6
5
|
module TopicMap
|
7
|
-
module
|
6
|
+
module Scoped
|
8
7
|
|
9
8
|
# Returns all topics in the topic map used
|
10
9
|
# in the scope property of Associations.
|
@@ -12,40 +11,40 @@ module RTM::Sugar
|
|
12
11
|
# The result may be empty.
|
13
12
|
#
|
14
13
|
# :call-seq:
|
15
|
-
# association_themes ->
|
14
|
+
# association_themes -> Collection of Topics
|
16
15
|
#
|
17
16
|
def association_themes
|
18
|
-
scoped_index.
|
17
|
+
scoped_index.getAssociationThemes
|
19
18
|
end
|
20
19
|
|
21
20
|
# Returns all topics in the topic map used
|
22
21
|
# in the scope property of Names.
|
23
22
|
#
|
24
23
|
# :call-seq:
|
25
|
-
# name_themes ->
|
24
|
+
# name_themes -> Collection of Topics
|
26
25
|
#
|
27
26
|
def name_themes
|
28
|
-
scoped_index.
|
27
|
+
scoped_index.getNameThemes
|
29
28
|
end
|
30
29
|
|
31
30
|
# Returns all topics in the topic map used
|
32
31
|
# in the scope property of Occurrences.
|
33
32
|
#
|
34
33
|
# :call-seq:
|
35
|
-
# occurrence_themes ->
|
34
|
+
# occurrence_themes -> Collection of Topics
|
36
35
|
#
|
37
36
|
def occurrence_themes
|
38
|
-
scoped_index.
|
37
|
+
scoped_index.getOccurrenceThemes
|
39
38
|
end
|
40
39
|
|
41
40
|
# Returns all topics in the topic map used
|
42
41
|
# in the scope property of Variants.
|
43
42
|
#
|
44
43
|
# :call-seq:
|
45
|
-
# variant_themes ->
|
44
|
+
# variant_themes -> Collection of Topics
|
46
45
|
#
|
47
46
|
def variant_themes
|
48
|
-
scoped_index.
|
47
|
+
scoped_index.getVariantThemes
|
49
48
|
end
|
50
49
|
|
51
50
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM::Sugar
|
5
|
+
module TopicMap
|
6
|
+
module Types
|
7
|
+
|
8
|
+
# Returns all topics in this topic map that are used
|
9
|
+
# as types of associations.
|
10
|
+
#
|
11
|
+
# :call-seq:
|
12
|
+
# association_types -> Collection of Topics
|
13
|
+
#
|
14
|
+
def association_types
|
15
|
+
type_instance_index.getAssociationTypes
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the all Topics in this TopicMap that are used
|
19
|
+
# as types of Roles.
|
20
|
+
#
|
21
|
+
# :call-seq:
|
22
|
+
# role_types -> Collection of Topics
|
23
|
+
#
|
24
|
+
def role_types
|
25
|
+
type_instance_index.getRoleTypes
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns all Topics in this TopicMap that are used
|
29
|
+
# as types of Names.
|
30
|
+
#
|
31
|
+
# :call-seq:
|
32
|
+
# name_types -> Collection of Topics
|
33
|
+
#
|
34
|
+
def name_types
|
35
|
+
type_instance_index.getNameTypes
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns all Topics in this TopicMap that are used
|
39
|
+
# as types of Occurrences.
|
40
|
+
#
|
41
|
+
# :call-seq:
|
42
|
+
# occurrence_types -> Collection of Topics
|
43
|
+
#
|
44
|
+
def occurrence_types
|
45
|
+
type_instance_index.getOccurrenceTypes
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM::Sugar::Variant
|
5
|
+
module Topic
|
6
|
+
|
7
|
+
# Return the topic this variant belongs to.
|
8
|
+
#
|
9
|
+
# :call-seq:
|
10
|
+
# topic -> Topic
|
11
|
+
#
|
12
|
+
def topic
|
13
|
+
return self.parent.parent
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/rtm/topology.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
module RTM
|
2
|
+
|
3
|
+
# Topology information about a Topic Map.
|
4
|
+
# This class provides some statistical and structural information about a topic map.
|
5
|
+
# All methods take an optional modifier OR block which specifies how a Topic Maps construct shall be transformed before it is returned.
|
6
|
+
# Some modifiers are defined in the sub module Modifier.
|
7
|
+
class Topology
|
8
|
+
# @return [RTM::TopicMap] The topic map this topology provides information about.
|
9
|
+
attr_reader :topic_map
|
10
|
+
|
11
|
+
def initialize(topic_map)
|
12
|
+
@topic_map = topic_map
|
13
|
+
end
|
14
|
+
|
15
|
+
# A list of constructs defined in TMDM which have a (single) type
|
16
|
+
SINGLE_TYPED_CONSTRUCTS = %w[name occurrence association role]
|
17
|
+
|
18
|
+
# A list of constructs defined in TMDM which may have multiple types
|
19
|
+
TYPED_CONSTRUCTS = ["topic"] + SINGLE_TYPED_CONSTRUCTS
|
20
|
+
|
21
|
+
# A list of constructs defined in TMDM which are scopeable
|
22
|
+
SCOPEABLE_CONSTRUCTS = %w[name variant occurrence association]
|
23
|
+
|
24
|
+
SINGLE_TYPED_CONSTRUCTS.each do |item|
|
25
|
+
# define_method "#{item}_types" do |modifier=nil, &block|
|
26
|
+
eval(<<-EOS)
|
27
|
+
def #{item}_types(modifier=nil, &block)
|
28
|
+
modifier ||= block || Modifier.default
|
29
|
+
@#{item}_types ||= Hash[@topic_map.#{item}_types.map{|i| [modifier.call(i), i.typed_#{item}s.size]}]
|
30
|
+
end
|
31
|
+
def #{item}_types_count(modifier=nil, &block)
|
32
|
+
@#{item}_types_count ||= @topic_map.#{item}_types.size
|
33
|
+
end
|
34
|
+
EOS
|
35
|
+
end
|
36
|
+
|
37
|
+
SCOPEABLE_CONSTRUCTS.each do |item|
|
38
|
+
eval(<<-EOS)
|
39
|
+
def #{item}_themes(modifier=nil, &block)
|
40
|
+
modifier ||= block || Modifier.default
|
41
|
+
@#{item}_themes ||= Hash[@topic_map.#{item}_themes.map{|i| [modifier.call(i), i.scoped_#{item}s.size]}]
|
42
|
+
end
|
43
|
+
def #{item}_themes_count(modifier=nil, &block)
|
44
|
+
@#{item}_themes_count ||= @topic_map.#{item}_themes.size
|
45
|
+
end
|
46
|
+
EOS
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# The number of topics in this topic map
|
51
|
+
# @return [Number]
|
52
|
+
def topics_count(modifier=nil, &block)
|
53
|
+
@topic_map.topics.size
|
54
|
+
end
|
55
|
+
|
56
|
+
# The number of associations in this topic map
|
57
|
+
# @return [Number]
|
58
|
+
def associations_count(modifier=nil, &block)
|
59
|
+
@topic_map.associations.size
|
60
|
+
end
|
61
|
+
|
62
|
+
# The following are not available in RTM yet
|
63
|
+
# def names_count
|
64
|
+
# @topic_map.names.size
|
65
|
+
# end
|
66
|
+
# def occurrences_count
|
67
|
+
# @topic_map.occurrences.size
|
68
|
+
# end
|
69
|
+
# def variants_count
|
70
|
+
# @topic_map.variants.size
|
71
|
+
# end
|
72
|
+
|
73
|
+
# All topology information in one step
|
74
|
+
# @return [Hash] with all topology information. Keys correspond to method names, values to their returned results.
|
75
|
+
def all(modifier=nil, &block)
|
76
|
+
modifier ||= block || Modifier.default
|
77
|
+
puts "modifier: #{modifier.inspect}"
|
78
|
+
ms = self.methods - Object.new.methods - %w[topic_map all]
|
79
|
+
Hash[ms.map {|m| [m, self.send(m, modifier)]}]
|
80
|
+
end
|
81
|
+
|
82
|
+
# String representation of all topology information
|
83
|
+
# @return [String] with all topology information
|
84
|
+
def to_s(modifier=nil, &block)
|
85
|
+
modifier ||= block || Modifier.best_name
|
86
|
+
all(modifier).sort_by{|k,v| k}.map {|k,v| "#{k}: #{v.inspect}"}.join("\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Manages Modifiers which may be applied to Constructs (or only to Topics?!)
|
91
|
+
module Modifier
|
92
|
+
# The nop Modifier just returns the construct given as is: <code>{|x| x}</code>
|
93
|
+
#
|
94
|
+
# @return [#call] The nop Modifier which is a callable object which takes one argument and returns this argument.
|
95
|
+
def nop
|
96
|
+
Proc.new {|x| x}
|
97
|
+
end
|
98
|
+
|
99
|
+
# The best_name Modifier returns the best name for a Construct: <code>{|x| x.best_name}</code>
|
100
|
+
#
|
101
|
+
# @return [#call] The best_name Modifier returns a name suitable for human consumption
|
102
|
+
def best_name
|
103
|
+
Proc.new {|x| x.best_name}
|
104
|
+
end
|
105
|
+
|
106
|
+
# The reference Modifier returns a reference for a Construct: <code>{|x| x.reference}</code>
|
107
|
+
#
|
108
|
+
# @return [#call] The reference Modifier returns a name suitable for human consumption
|
109
|
+
def reference
|
110
|
+
Proc.new {|x| x.reference}
|
111
|
+
end
|
112
|
+
|
113
|
+
# Make all instance methods available as class methods, too.
|
114
|
+
extend self
|
115
|
+
|
116
|
+
# The default modifier is {#nop}
|
117
|
+
# @return [#call] the default modifier
|
118
|
+
attr_reader :default
|
119
|
+
|
120
|
+
# Set the default modifier
|
121
|
+
@default = nop
|
122
|
+
end
|
123
|
+
|
124
|
+
# The TopologyExtension for RTM::TopicMap adds an #topology method to a topic map which provides an overview over a topic map.
|
125
|
+
module TopologyExtension
|
126
|
+
# Topology information about this TopicMap.
|
127
|
+
# @return [Topology] an object which provides some topology information
|
128
|
+
def topology
|
129
|
+
RTM::Topology.new(self)
|
130
|
+
end
|
131
|
+
RTM::TopicMap.register_extension(self)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/rtm/version.rb
CHANGED
@@ -6,22 +6,27 @@ module RTM # :nodoc:
|
|
6
6
|
# Try to determine version from Gem, if we're loaded from there
|
7
7
|
today = rtmgem.date
|
8
8
|
elsif File.exist?(File.join(File.dirname(__FILE__), "../../../.hg"))
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
begin
|
10
|
+
# Try to get the latest Mercurial commit date
|
11
|
+
hg_date_string = `hg --cwd "#{File.dirname(__FILE__)}" parent --template "{date|isodate}"`
|
12
|
+
today = Date.parse(hg_date_string)
|
13
|
+
rescue Exception => e
|
14
|
+
warn("We're running from Mercurial, but Mercurial binary 'hg' is not in system path (or something else with parsing version from hg went wront)")
|
15
|
+
end
|
15
16
|
end
|
17
|
+
# Fall back to current day if not set before
|
18
|
+
today ||= Date.today
|
19
|
+
|
16
20
|
DATE = [today.year, today.month, today.day]
|
17
21
|
ISODATE = "%04d-%02d-%02d" % DATE # => "2010-01-26"
|
18
22
|
COMPACTDATE = "%04d%02d%02d" % DATE # => "20100126"
|
19
23
|
|
20
24
|
MAJOR = 0
|
21
|
-
MINOR =
|
22
|
-
TINY =
|
25
|
+
MINOR = 3
|
26
|
+
TINY = 0
|
23
27
|
BUILD = ENV['BUILD_NUMBER'] || COMPACTDATE
|
24
28
|
|
29
|
+
#STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
|
25
30
|
STRING = [MAJOR, MINOR, TINY].compact.join('.')
|
26
31
|
|
27
32
|
SUMMARY = "rtm #{STRING}"
|
@@ -0,0 +1,45 @@
|
|
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
|
7
|
+
class Engine
|
8
|
+
|
9
|
+
describe self do
|
10
|
+
|
11
|
+
describe "#identifier" do
|
12
|
+
before(:all) do
|
13
|
+
@connection = RTM.connect(:implementation => implementation_for_spec)
|
14
|
+
@tested = false
|
15
|
+
end
|
16
|
+
it "should return :ontopia if ontopia is used" do
|
17
|
+
if implementation_for_spec == :ontopia
|
18
|
+
@connection.identifier.should == :ontopia
|
19
|
+
@tested = true
|
20
|
+
elsif implementation_for_spec == :tinytim
|
21
|
+
@connection.identifier.should == :tinytim
|
22
|
+
@tested = true
|
23
|
+
elsif implementation_for_spec == :activerecord
|
24
|
+
@connection.identifier.should == :activerecord
|
25
|
+
@tested = true
|
26
|
+
elsif implementation_for_spec == :tm2jdbc
|
27
|
+
@connection.identifier.should == :tm2jdbc
|
28
|
+
@tested = true
|
29
|
+
elsif implementation_for_spec == :hatana
|
30
|
+
@connection.identifier.should == :hatana
|
31
|
+
@tested = true
|
32
|
+
elsif implementation_for_spec == :sesametm
|
33
|
+
@connection.identifier.should == :sesametm
|
34
|
+
@tested = true
|
35
|
+
else
|
36
|
+
# engine not found
|
37
|
+
end
|
38
|
+
@tested.should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end # of describe self
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -14,31 +14,31 @@ module RTM::IO::TmapiXFrom::TopicMap
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#from_ltm" do
|
17
|
-
it "import into an empty topic map" do
|
17
|
+
it "should import into an empty topic map" do
|
18
18
|
@tm.from_ltm(File.dirname(__FILE__) + "/../../resources/toyTM.ltm")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "#from_ctm" do
|
23
|
-
it "import into an empty topic map" do
|
23
|
+
it "should import into an empty topic map" do
|
24
24
|
@tm.from_ctm(File.dirname(__FILE__) + "/../../resources/toyTM.ctm")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#from_jtm" do
|
29
|
-
it "import into an empty topic map" do
|
29
|
+
it "should import into an empty topic map" do
|
30
30
|
#@tm.from_jtm(File.dirname(__FILE__) + "/../../resources/toyTM.jtm")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "#from_tmxml" do
|
35
|
-
it "import into an empty topic map" do
|
35
|
+
it "should import into an empty topic map" do
|
36
36
|
#@tm.from_tmxml(File.dirname(__FILE__) + "/../../resources/toyTM.tmxml")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#from_xtm10" do
|
41
|
-
it "import into an empty topic map" do
|
41
|
+
it "should import into an empty topic map" do
|
42
42
|
#@tm.from_xtm10(File.dirname(__FILE__) + "/../../resources/toyTM_xtm10.xtm")
|
43
43
|
end
|
44
44
|
it "should provide an alias for from_xtm1" do
|
@@ -47,7 +47,7 @@ module RTM::IO::TmapiXFrom::TopicMap
|
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "#from_xtm20" do
|
50
|
-
it "import into an empty topic map" do
|
50
|
+
it "should import into an empty topic map" do
|
51
51
|
@tm.from_xtm20(File.dirname(__FILE__) + "/../../resources/toyTM.xtm")
|
52
52
|
end
|
53
53
|
it "should provide an alias for from_xtm2" do
|
@@ -56,10 +56,10 @@ module RTM::IO::TmapiXFrom::TopicMap
|
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "#from_xtm" do
|
59
|
-
it "import into an empty topic map from xtm v2.0" do
|
59
|
+
it "should import into an empty topic map from xtm v2.0" do
|
60
60
|
@tm.from_xtm20(File.dirname(__FILE__) + "/../../resources/toyTM.xtm")
|
61
61
|
end
|
62
|
-
it "import into an empty topic map from xtm v1.0" do
|
62
|
+
it "should import into an empty topic map from xtm v1.0" do
|
63
63
|
#@tm.from_xtm10(File.dirname(__FILE__) + "/../../resources/toyTM_xtm10.xtm")
|
64
64
|
end
|
65
65
|
end
|