ontopia-topicmaps 0.0.1-java → 0.0.2-java

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5966ec6b70b10968e7311f649c1b018bc429033a
4
+ data.tar.gz: cc2cff4490ff724db07d64745a3ffcff0e33628b
5
+ SHA512:
6
+ metadata.gz: 21c036850b417905985b1fe9c950f18dd4d58aa7a5aff34ac18f85a001c00d4e139c887421c3fead9d568d44e813b134e5d9b2074194321c7b86053781c214f3
7
+ data.tar.gz: 2ae4bf7f7623e394e828ee62aecc8c8a413fe635b31a7f308dd2b7008cabb3728a8135f59df5851c5aa19bfb550995c1498ecaf339ea4a576fcf506b09c1449a
data/ChangeLog CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  = Revision history for ontopia-topicmaps
4
4
 
5
+ == 0.0.2 [2013-07-25]
6
+
7
+ * Added Ontopia::Topicmaps::Topicmap#query_maps.
8
+ * Added Ontopia::Topicmaps::Topicmap#extract_query_projection.
9
+ * Changed stringifier usage (breaking backwards-compatibility).
10
+
5
11
  == 0.0.1 [2013-07-19]
6
12
 
7
13
  * Birthday :-)
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ontopia-topicmaps version 0.0.1
5
+ This documentation refers to ontopia-topicmaps version 0.0.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -21,6 +21,7 @@ Documentation:: http://blackwinter.github.com/ontopia-topicmaps
21
21
  Source code:: http://github.com/blackwinter/ontopia-topicmaps
22
22
  RubyGem:: http://rubygems.org/gems/ontopia-topicmaps
23
23
  Ontopia:: http://ontopia.net/
24
+ Demo:: http://ixtrieve.fh-koeln.de/ghn
24
25
 
25
26
 
26
27
  == AUTHORS
@@ -28,6 +28,7 @@ module Ontopia
28
28
 
29
29
  PACKAGES = {
30
30
  'net.ontopia.infoset.impl.basic' => %w[URIFragmentLocator],
31
+ 'net.ontopia.topicmaps.core' => %w[TopicIF TypedIF],
31
32
  'net.ontopia.topicmaps.query.utils' => %w[QueryWrapper RowMapperIF],
32
33
  'net.ontopia.topicmaps.utils' => %w[TopicStringifiers],
33
34
  'net.ontopia.topicmaps.utils.ctm' => %w[CTMTopicMapReader],
@@ -28,12 +28,37 @@ module Ontopia
28
28
 
29
29
  NO_VALUE = '[No ID]'.freeze
30
30
 
31
- Topicmaps.init(self, :StringifierIF) {
31
+ Topicmaps.register_stringifier(self, :id) {
32
32
  URIFragmentLocator.field_accessor :fragment
33
33
  }
34
34
 
35
35
  def to_string(object)
36
- (id = object.get_item_identifiers.first) ? id.fragment : NO_VALUE
36
+ case object
37
+ when TopicIF then to_string(object.get_item_identifiers.first)
38
+ when TypedIF then to_string(object.get_type)
39
+ when URIFragmentLocator then object.fragment
40
+ else NO_VALUE
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ class AnyNameStringifier
47
+
48
+ NO_VALUE = '[No Name]'.freeze
49
+
50
+ Topicmaps.register_stringifier(self, :name)
51
+
52
+ def initialize
53
+ @topic_str = Topicmaps.topic_stringifier
54
+ end
55
+
56
+ def to_string(object)
57
+ case object
58
+ when TopicIF then @topic_str[object]
59
+ when TypedIF then to_string(object.get_type)
60
+ else NO_VALUE
61
+ end
37
62
  end
38
63
 
39
64
  end
@@ -50,6 +50,17 @@ select count($TOPIC) from
50
50
  EOT
51
51
  }
52
52
 
53
+ QUERY_PROJECTION_RE = %r{\bselect\s+(.+)\s+from\b}i
54
+
55
+ class << self
56
+
57
+ def extract_query_projection(query)
58
+ projection = query[QUERY_PROJECTION_RE, 1]
59
+ projection.delete('$,').split if projection
60
+ end
61
+
62
+ end
63
+
53
64
  def initialize(file)
54
65
  Topicmaps.setup_classpath
55
66
 
@@ -68,20 +79,29 @@ select count($TOPIC) from
68
79
 
69
80
  def query(query = nil, declarations = nil, str = nil)
70
81
  str = Topicmaps.stringifier(str || :default)
71
- res = query_for_list(query, declarations, &block_given? ?
72
- lambda { |i,| yield(i, str) } : lambda { |i,| str.to_string(i) }).to_a
82
+
83
+ query_for_list(query, declarations, &block_given? ?
84
+ lambda { |i,| yield(i, str) } : lambda { |i,| str[i] }).to_a
85
+ end
86
+
87
+ def query_maps(query = nil, declarations = nil)
88
+ query_wrapper(declarations).query_for_maps(query_string(query)).to_a
73
89
  end
74
90
 
75
91
  def topics(value_str = nil, key_str = nil)
76
92
  hash, key_str = {}, Topicmaps.stringifier(key_str || :id)
77
93
 
78
94
  query(:all_topics, nil, value_str) { |i, str|
79
- hash[key_str.to_string(i)] = str.to_string(i)
95
+ hash[key_str[i]] = str[i]
80
96
  }
81
97
 
82
98
  hash
83
99
  end
84
100
 
101
+ def extract_query_projection(query)
102
+ self.class.extract_query_projection(query)
103
+ end
104
+
85
105
  private
86
106
 
87
107
  def read(file, reader = nil)
@@ -93,16 +113,22 @@ select count($TOPIC) from
93
113
  raise "Error reading topic map: #{err}"
94
114
  end
95
115
 
96
- def query_for_list(query, declarations, &block)
97
- args = [QUERY.has_key?(query ||= :all_topics) ? QUERY[query] :
98
- query.is_a?(Symbol) ? raise("No such query: #{query}") : query]
99
-
100
- args << RowMapper.new(&block) if block
116
+ def query_string(query)
117
+ QUERY.has_key?(query ||= :all_topics) ? QUERY[query] :
118
+ query.is_a?(Symbol) ? raise("No such query: #{query}") : query
119
+ end
101
120
 
121
+ def query_wrapper(declarations = nil)
102
122
  qw = QueryWrapper.new(tm)
103
123
  qw.set_declarations(declarations) if declarations
124
+ qw
125
+ end
126
+
127
+ def query_for_list(query, declarations = nil, &block)
128
+ args = [query_string(query)]
129
+ args << RowMapper.new(&block) if block
104
130
 
105
- qw.query_for_list(*args)
131
+ query_wrapper(declarations).query_for_list(*args)
106
132
  rescue OntopiaRuntimeException => err
107
133
  raise "Query error: #{err}"
108
134
  end
@@ -28,7 +28,7 @@ module Ontopia
28
28
 
29
29
  MAJOR = 0
30
30
  MINOR = 0
31
- TINY = 1
31
+ TINY = 2
32
32
 
33
33
  class << self
34
34
 
@@ -50,16 +50,12 @@ module Ontopia
50
50
  @default_stringifier ||= name_stringifier
51
51
  end
52
52
 
53
- def name_stringifier
54
- self::TopicStringifiers.get_default_stringifier
55
- end
56
-
57
- def id_stringifier
58
- IdStringifier.new
59
- end
60
-
61
53
  def stringifier(str)
62
- str.is_a?(Symbol) ? send("#{str}_stringifier") : str
54
+ case str
55
+ when self::StringifierIF then str.method(:to_string)
56
+ when Symbol then send("#{str}_stringifier")
57
+ else str
58
+ end
63
59
  end
64
60
 
65
61
  def count(file, *args)
@@ -70,6 +66,10 @@ module Ontopia
70
66
  Topicmap.new(file).query(*args, &block)
71
67
  end
72
68
 
69
+ def query_maps(file, *args)
70
+ Topicmap.new(file).query_maps(*args)
71
+ end
72
+
73
73
  def topics(file, *args)
74
74
  Topicmap.new(file).topics(*args)
75
75
  end
@@ -103,9 +103,27 @@ module Ontopia
103
103
  klass ? Topicmaps.init[klass] = [modules, block] : @init
104
104
  end
105
105
 
106
+ def define_stringifier(name)
107
+ define_singleton_method(attr = "#{name}_stringifier") {
108
+ singleton_class.send(:attr_reader, attr)
109
+ instance_variable_set("@#{attr}", stringifier(yield))
110
+ }
111
+ end
112
+
113
+ def register_stringifier(klass, name)
114
+ init(klass, :StringifierIF) {
115
+ Topicmaps.define_stringifier(name) { new }
116
+ yield if block_given?
117
+ }
118
+ end
119
+
106
120
  end
107
121
 
108
- init(self)
122
+ init(self) {
123
+ define_stringifier(:topic) {
124
+ self::TopicStringifiers.get_default_stringifier
125
+ }
126
+ }
109
127
 
110
128
  end
111
129
  end
@@ -0,0 +1,37 @@
1
+ describe Ontopia::Topicmaps::Topicmap do
2
+
3
+ describe '::extract_query_projection' do
4
+
5
+ example do
6
+ Ontopia::Topicmaps::Topicmap.extract_query_projection(
7
+ Ontopia::Topicmaps::Topicmap::QUERY[:all_topics]
8
+ ).should == %w[TOPIC]
9
+ end
10
+
11
+ example do
12
+ Ontopia::Topicmaps::Topicmap.extract_query_projection(
13
+ Ontopia::Topicmaps::Topicmap::QUERY[:count_all_topics]
14
+ ).should == %w[count(TOPIC)]
15
+ end
16
+
17
+ example do
18
+ Ontopia::Topicmaps::Topicmap.extract_query_projection(
19
+ 'select $FOO, $BAR from $BAZ?'
20
+ ).should == %w[FOO BAR]
21
+ end
22
+
23
+ example do
24
+ Ontopia::Topicmaps::Topicmap.extract_query_projection(
25
+ 'SELECT $BAR, $FOO FrOm $BAZ?'
26
+ ).should == %w[BAR FOO]
27
+ end
28
+
29
+ example do
30
+ Ontopia::Topicmaps::Topicmap.extract_query_projection(
31
+ '$FOO, $BAR'
32
+ ).should be_nil
33
+ end
34
+
35
+ end
36
+
37
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ontopia-topicmaps
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.1
4
+ version: 0.0.2
6
5
  platform: java
7
6
  authors:
8
7
  - Jens Wille
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Query topic maps with Ontopia.
15
14
  email: jens.wille@gmail.com
@@ -33,19 +32,21 @@ files:
33
32
  - spec/data/ItalianOpera.ltm
34
33
  - spec/data/JillsMusic.xtm
35
34
  - spec/data/ghn.xtm
35
+ - spec/ontopia/topicmaps/topicmap_spec.rb
36
36
  - spec/ontopia/topicmaps_spec.rb
37
37
  - spec/spec_helper.rb
38
38
  homepage: http://github.com/blackwinter/ontopia-topicmaps
39
39
  licenses:
40
40
  - AGPL
41
- post_install_message:
41
+ metadata: {}
42
+ post_install_message:
42
43
  rdoc_options:
43
44
  - --charset
44
45
  - UTF-8
45
46
  - --line-numbers
46
47
  - --all
47
48
  - --title
48
- - ontopia-topicmaps Application documentation (v0.0.1)
49
+ - ontopia-topicmaps Application documentation (v0.0.2)
49
50
  - --main
50
51
  - README
51
52
  require_paths:
@@ -55,17 +56,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
56
  - - '>='
56
57
  - !ruby/object:Gem::Version
57
58
  version: '0'
58
- none: false
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
- none: false
65
64
  requirements: []
66
- rubyforge_project:
67
- rubygems_version: 1.8.24
68
- signing_key:
69
- specification_version: 3
65
+ rubyforge_project:
66
+ rubygems_version: 2.0.5
67
+ signing_key:
68
+ specification_version: 4
70
69
  summary: Query topic maps with Ontopia.
71
70
  test_files: []