COEUS 0.0.5 → 0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f38a74fb7c09ee5119370d31c461d588e5ae7116
4
- data.tar.gz: 314dced4f41da79eccb54469e0183ea85c978c56
3
+ metadata.gz: ba26929770fe3a9e85beaf004c4d687acc8eab2b
4
+ data.tar.gz: 38018d6156d4d7c6c5acd7d7093cf4abfd750178
5
5
  SHA512:
6
- metadata.gz: 0a52f0cfb3d253e00164386d2d2e78497fc7b3cf214382219b7ea7e66507a2981c1eb51d4ce6807d7f237e0d6c1c95be05af486806fade92ea79cb5fd5db8a39
7
- data.tar.gz: 06cf51b3899b1264a8454274fc7b5eebf414d9439d34fb5e21179dd77cd809489b0bf941e4eb05b8ffd822089d1a42ab33d6455804fb85450f24536afeaa832d
6
+ metadata.gz: 777550a2fb37b502fa37ad54492693fdbbd72b5355dda204faff6699eb48e96a89852648d52b55c0ab79f4c609958b0921d01fa41b2662e429f1b746eb922536
7
+ data.tar.gz: 6130c3c3520538f413e6c4df84639d08d0b775803c6a8449080b231ffb90bad68d751f68a2299699907c862515f255c6060f57a75db6643dad7f3d884e019a74
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/README.md CHANGED
@@ -20,17 +20,41 @@ Or install it yourself as:
20
20
 
21
21
  ```ruby
22
22
  # define COEUS base host address
23
- COEUS::COEUS.host(new_host)
23
+ COEUS::COEUS.host 'http://coeus.host'
24
24
  ```
25
25
 
26
26
  ```ruby
27
- # get triples from COEUS knowledge base (http://bioinformatics.ua.pt/coeus/documentation/#rest)
28
- # returns JSON array with binded objects
29
- COEUS::COEUS.triple(subject, predicate, object)
30
- ```
27
+ # define COEUS API key
28
+ COEUS::COEUS.key 'api key'
29
+ ```
31
30
 
32
31
  ```ruby
33
32
  # execute SPARQL query on COEUS host
34
33
  # returns RDF::Query::Solution array
35
34
  COEUS::COEUS.query(query)
36
35
  ```
36
+
37
+ ```ruby
38
+ # get triples from COEUS knowledge base (http://bioinformatics.ua.pt/coeus/documentation/#rest)
39
+ # returns array with binded objects
40
+ COEUS::COEUS.triple 'subject', 'predicate', 'object'
41
+ ```
42
+
43
+
44
+ ```ruby
45
+ # write triples to COEUS knowledge base (http://bioinformatics.ua.pt/coeus/documentation/#rest)
46
+ # returns true if data written
47
+ COEUS::COEUS.write 'subject','predicate','object'
48
+ ```
49
+
50
+ ```ruby
51
+ # updates triple in COEUS knowledge base (http://bioinformatics.ua.pt/coeus/documentation/#rest)
52
+ # returns true if data updated
53
+ COEUS::COEUS.update 'subject','predicate','old object', 'new object'
54
+ ```
55
+
56
+ ```ruby
57
+ # delete triple from COEUS knowledge base (http://bioinformatics.ua.pt/coeus/documentation/#rest)
58
+ # returns true if data deleted
59
+ COEUS::COEUS.deleted 'subject','predicate','object'
60
+ ```
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/test*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ desc "[COEUS] Run tests"
11
+
12
+ task :default => :test
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Pedro Lopes"]
10
10
  spec.email = ["pedrolopes@ua.pt"]
11
11
  spec.description = %q{COEUS: semantic web application framework}
12
- spec.summary = %q{This. Is. Semantic.}
12
+ spec.summary = %q{Ruby Gem providing direct access to a custom COEUS instance API methods.}
13
13
  spec.homepage = "http://bioinformatics.ua.pt/coeus/"
14
14
  spec.license = "MIT"
15
15
 
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "rdf"
25
25
  spec.add_dependency "sparql"
26
26
  spec.add_dependency "json"
27
+ spec.add_dependency "rake"
27
28
  end
@@ -14,7 +14,7 @@ module COEUS
14
14
  @host = 'http://bioinformatics.ua.pt/coeus/'
15
15
 
16
16
  # COEUS API key
17
- @key = 'uavr'
17
+ @key = ''
18
18
 
19
19
  ##
20
20
  # This method defines the base COEUS host for the next actions
@@ -27,15 +27,25 @@ module COEUS
27
27
  # * http://bioinformatics.ua.pt/coeus/
28
28
  #
29
29
  def self.host(host)
30
+ # verify if valid HTTP URL
30
31
  if host.start_with?('http')
31
32
  @host = host
33
+
34
+ # add final slash (/) if not available
35
+ if !@host.end_with?('/')
36
+ @host += '/'
37
+ end
32
38
  else
33
- puts 'Invalid host'
39
+ raise '[COEUS] Invalid host URL'
34
40
  end
35
41
  end
36
42
 
37
- def self.open
38
- puts @host
43
+ def self.get_host
44
+ @host
45
+ end
46
+
47
+ def self.print
48
+ puts "[COEUS] instance details\n\t- Host: #{@host}\n\t- API key: #{@key}"
39
49
  end
40
50
 
41
51
  ##
@@ -52,6 +62,10 @@ module COEUS
52
62
  @key = key
53
63
  end
54
64
 
65
+ def self.get_key
66
+ @key
67
+ end
68
+
55
69
  ##
56
70
  # This method uses COEUS API to get match triples based on provided parameters
57
71
  #
@@ -60,9 +74,6 @@ module COEUS
60
74
  # * +sub+ - the triple set subject
61
75
  # * +pred+ - the triple set predicate
62
76
  # * +obj+ - the triple set object
63
- #
64
- # ==== Default
65
- # * http://bioinformatics.ua.pt/coeus/
66
77
  #
67
78
  def self.triple(sub, pred, obj)
68
79
  content = URI.parse(@host + 'api/triple/' + sub + '/' + pred + '/' + obj + '/js').read
@@ -81,5 +92,79 @@ module COEUS
81
92
  sparql = SPARQL::Client.new(@host + 'sparql')
82
93
  return sparql.query(query)
83
94
  end
95
+
96
+ ##
97
+ # This method uses COEUS API to get write new triples based on provided parameters.
98
+ # *Note:* Requires that the API key is previously defined
99
+ #
100
+ # ==== Parameters
101
+ #
102
+ # * +sub+ - the new triple subject
103
+ # * +pred+ - the new triple predicate
104
+ # * +obj+ - the new riple object
105
+ #
106
+ def self.write(sub, pred, obj)
107
+ if @key == ''
108
+ raise '[COEUS] undefined API key'
109
+ else
110
+ content = URI.parse(@host + 'api/' + @key + '/write/' + sub + '/' + pred + '/' + obj).read
111
+ result = JSON.parse(content)
112
+ if result['status'] != 100
113
+ raise '[COEUS] unable to store triple: ' + result['message']
114
+ else
115
+ return true
116
+ end
117
+ end
118
+ end
119
+
120
+ ##
121
+ # This method uses COEUS API to get update existing triples based on provided parameters.
122
+ # *Note:* Requires that the API key is previously defined
123
+ #
124
+ # ==== Parameters
125
+ #
126
+ # * +sub+ - the triple subject
127
+ # * +pred+ - the triple predicate
128
+ # * +old_obj+ - the old triple object
129
+ # * +new_obj+ - the new triple object
130
+ #
131
+ def self.update(sub, pred, old_obj, new_obj)
132
+ if @key == ''
133
+ raise '[COEUS] undefined API key'
134
+ else
135
+ content = URI.parse(@host + 'api/' + @key + '/update/' + sub + '/' + pred + '/' + old_obj + ',' + new_obj).read
136
+ result = JSON.parse(content)
137
+ if result['status'] != 100
138
+ raise '[COEUS] unable to update triple: ' + result['message']
139
+ else
140
+ return true
141
+ end
142
+ end
143
+ end
144
+
145
+ ##
146
+ # This method uses COEUS API to get delete triples based on provided parameters.
147
+ # *Note:* Requires that the API key is previously defined
148
+ #
149
+ # ==== Parameters
150
+ #
151
+ # * +sub+ - the triple subject to delete
152
+ # * +pred+ - the triple predicate to delete
153
+ # * +obj+ - the riple object to delete
154
+ #
155
+ def self.delete(sub, pred, obj)
156
+ if @key == ''
157
+ raise '[COEUS] undefined API key'
158
+ else
159
+ content = URI.parse(@host + 'api/' + @key + '/delete/' + sub + '/' + pred + '/' + obj).read
160
+ result = JSON.parse(content)
161
+ if result['status'] != 100
162
+ raise '[COEUS] unable to delete triple: ' + result['message']
163
+ else
164
+ return true
165
+ end
166
+ end
167
+ end
168
+
84
169
  end
85
170
  end
@@ -1,4 +1,4 @@
1
1
  module COEUS
2
2
  # COEUS gem version info
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1"
4
4
  end
@@ -0,0 +1,65 @@
1
+ require 'test/unit'
2
+ require "open-uri"
3
+ require 'coeus'
4
+
5
+ class Test_COEUS < Test::Unit::TestCase
6
+ def test_host
7
+ COEUS::COEUS.host('http://bioinformatics.ua.pt/diseasecard')
8
+ assert_equal 'http://bioinformatics.ua.pt/diseasecard/', COEUS::COEUS.get_host
9
+ end
10
+
11
+ def test_key
12
+ COEUS::COEUS.key('12345')
13
+ assert_equal '12345', COEUS::COEUS.get_key
14
+ end
15
+
16
+ def test_sparql
17
+ @query = "PREFIX coeus: <http://bioinformatics.ua.pt/coeus/resource/>\nSELECT COUNT(DISTINCT ?tag) { ?tag coeus:hasConcept coeus:concept_UniProt}"
18
+ assert_equal COEUS::COEUS.query(@query).size, 1
19
+ end
20
+
21
+ def test_triple
22
+ @result = COEUS::COEUS.triple 'coeus:concept_UniProt', 'dc:title', 'obj'
23
+ assert_instance_of Array, @result
24
+ end
25
+
26
+ def test_write
27
+ COEUS::COEUS.key 'uavr'
28
+ @result = COEUS::COEUS.write 'coeus:gemx','dc:title','gemx'
29
+ assert @result
30
+ end
31
+
32
+ def test_update
33
+ COEUS::COEUS.key 'uavr'
34
+ @result = COEUS::COEUS.update 'coeus:gemx','dc:title','gemx','gemy'
35
+ assert @result
36
+ end
37
+
38
+ def test_delete
39
+ COEUS::COEUS.key 'uavr'
40
+ @result = COEUS::COEUS.delete 'coeus:gemx','dc:title','gemy'
41
+ assert @result
42
+ end
43
+
44
+ def test_all
45
+ # set API key
46
+ COEUS::COEUS.key 'uavr'
47
+
48
+ # write new triple
49
+ assert COEUS::COEUS.write('coeus:gem_x','dc:title','gem_x')
50
+
51
+ # check added triple output
52
+ @res = COEUS::COEUS.triple 'coeus:gem_x', 'dc:title', 'obj'
53
+ assert_equal @result[0]["obj"]["value"], "gem_x"
54
+
55
+ # update triple content
56
+ assert COEUS::COEUS.update('coeus:gem_x','dc:title','gem_x', 'coeus-gem')
57
+
58
+ # check updated triple content
59
+ @res = COEUS::COEUS.triple 'coeus:gem_x', 'dc:title', 'obj'
60
+ assert_equal @result[0]["obj"]["value"], "coeus-gem"
61
+
62
+ # delete triple
63
+ assert COEUS::COEUS.delete('coeus:gem_x','dc:title','coeus-gem')
64
+ end
65
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: COEUS
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Lopes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2013-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: 'COEUS: semantic web application framework'
84
98
  email:
85
99
  - pedrolopes@ua.pt
@@ -87,13 +101,14 @@ executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
104
+ - .gitignore
90
105
  - Gemfile
91
106
  - README.md
92
107
  - Rakefile
93
108
  - coeus.gemspec
94
109
  - lib/coeus.rb
95
110
  - lib/coeus/version.rb
96
- - test/test.rb
111
+ - test/test_coeus.rb
97
112
  homepage: http://bioinformatics.ua.pt/coeus/
98
113
  licenses:
99
114
  - MIT
@@ -117,6 +132,6 @@ rubyforge_project:
117
132
  rubygems_version: 2.0.3
118
133
  signing_key:
119
134
  specification_version: 4
120
- summary: This. Is. Semantic.
135
+ summary: Ruby Gem providing direct access to a custom COEUS instance API methods.
121
136
  test_files:
122
- - test/test.rb
137
+ - test/test_coeus.rb
@@ -1,15 +0,0 @@
1
- require 'coeus'
2
-
3
- class LOL
4
- #@result = COEUS::COEUS.triple 'coeus:uniprot_P78312', 'coeus:isAssociatedTo', 'obj'
5
-
6
- #@result['results']['bindings'].each do |item|
7
- # puts item['obj']['value']
8
- #end
9
- @query = "PREFIX coeus: <http://bioinformatics.ua.pt/coeus/resource/>\nPREFIX dc: <http://purl.org/dc/elements/1.1/>\nSELECT * { ?uniprot coeus:hasConcept coeus:concept_UniProt . ?uniprot dc:identifier ?id . ?uniprot dc:title ?name }"
10
-
11
-
12
- COEUS::COEUS.query(@query).each do |item|
13
- puts item[:id]
14
- end
15
- end