uri_service 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5012df111508e186ecb439067488e70ec5e511e5
4
- data.tar.gz: af2dbf25aec0882474d1a8909cc26fd81007b1b8
3
+ metadata.gz: e14cec0a40986cc0327fca1d58b15704fd25c2c6
4
+ data.tar.gz: 6fe6e37e9ab65ded6c9c15fdeefa06e1d38c2507
5
5
  SHA512:
6
- metadata.gz: 8a9c898ce08c8f34a2ca4d23f088b24c9d735cd3ac2ecf1f565bb47584ca2e46a333d89b956da404f56b4f5d517c8ee3625b16a45b555e60ee0fc5edeea4f704
7
- data.tar.gz: f6b423ecf9d89676b3661fd027ca5ba14bca37affffe3bb9e16415559d0de451b637554e7fc774b46339a4d108cb4d9b1f63f94690eeb93d7f080cf9fb2289ee
6
+ metadata.gz: f59f8f12ea92b925b3414bcb3c63106656fa3d6661081af07d613066d14d8a9dbe1ccbe6b0aeeff81391bcfc4f37fd3d9bfc54d20d3d5d55f0a668891da3810a
7
+ data.tar.gz: 3d890e422301dfbd32da4920661abad3a928e646d480d1be33439d35033cc0271317f7e79654e43aeaeeabc10caa515868647897ebbc8a32e8d8df3b7cb71311
data/README.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  A database-backed and Solr-cached lookup/creation service for URIs. Works with or without Rails.
4
4
 
5
+ ### Major Concepts:
6
+
7
+ **External Term (UriService::TermType::EXTERNAL)**
8
+
9
+ Used when caching a value/URI pair from an external controlled vocabulary within your UriService datastore. Example: We want to add an entry for U.S. President Abraham Lincoln to our UriService datastore, so we'll create an external term that references his Library of Congress URI.
10
+
11
+ **Local Term (UriService::TermType::LOCAL)**
12
+
13
+ Used when defining locally-managed terms in the UriService datastore. Automatically creates a local URI for a new local term. Example: We want to maintain a vocabulary for various departments within a university, and we want to create locally-managed URIs for these departments.
14
+
15
+ **Temporary Term (UriService::TermType::TEMPORARY)**
16
+
17
+ Used when you want to add a value to your UriService datastore, but have no authority information about the term and do not wish to create a local URI. Temporary term entries cannot store additional data fields, and no two temporary terms within the same vocabulary can have the same value. Basically, a termporary term is intended to identify an *exact string value* rather than identifiying an intellectual entity. Temporary terms should eventually be replaced by external or local terms later on when more information is known about the entity to which you are referring . Example: We want to record information about the author of an old and mysterious letter by "John Smith." We don't know which "John Smith," this refers to, so we'll create (or re-use) a temporary URI that's associated with the value "John Smith." One day, when we figure out more about the letter and the author, we'll be able to update the record information and refer to an external term that has a globally-recognized URI, or we'll create a local URI if an external URI is unavailable.
18
+
5
19
  ### Usage:
6
20
 
7
21
  **Install uri_service:**
@@ -132,16 +146,14 @@ UriService.client.list_vocabularies(limit, start)
132
146
 
133
147
  Create a term in a vocabulary:
134
148
  ```ruby
135
- # Creates a term in the 'names' vocabulary, using the given value, uri and a couple of custom key-value pairs
149
+ # Create an EXTERNAL term in the 'names' vocabulary, using an external URI
150
+ UriService.client.create_term(UriService::TermType::EXTERNAL, {vocabulary_string_key: 'names', value: 'Lincoln, Abraham, 1809-1865', uri: 'http://id.loc.gov/authorities/names/n79006779', additional_fields: {'is_awesome' => true, 'best_president' => true, 'hat_type' => 'Stove Pipe'}})
136
151
 
137
- UriService.client.create_term('names', 'Lincoln, Abraham, 1809-1865', 'http://id.loc.gov/authorities/names/n79006779', {'is_awesome' => true, 'best_president' => true, 'hat_type' => 'Stove Pipe'})
138
- ```
152
+ # Create a LOCAL term in the 'departments' vocabulary (note: A URI is not passed in because LOCAL terms generate their own URIs)
153
+ UriService.client.create_term(UriService::TermType::LOCAL, {vocabulary_string_key: 'departments', value: 'Chemistry', additional_fields: {'department_code' => 'CHEM'}})
139
154
 
140
- Create a LOCAL term in a vocabulary (when you don't have a URI for your term):
141
- ```ruby
142
- # Creates a new LOCAL term in the 'names' vocabulary. New URI is automatically generated.
143
-
144
- UriService.client.create_local_term('names', 'Baby, Newborn', {'is_baby' => true})
155
+ # Create a LOCAL term in the 'departments' vocabulary (note: A URI is not passed in because TEMPORARY terms generate their own URIs, and additional_fields are not allowed)
156
+ UriService.client.create_term(UriService::TermType::LOCAL, {vocabulary_string_key: 'names', value: 'Smith, John'})
145
157
  ```
146
158
 
147
159
  Searching by string query for a term in a vocabulary:
@@ -153,17 +165,37 @@ UriService.client.find_terms_by_query('names', 'batman')
153
165
  # 'uri' => 'http://id.loc.gov/authorities/names/n91059657',
154
166
  # 'value' => 'Batman, John, 1800-1839',
155
167
  # 'vocabulary_string_key' => 'names',
156
- # 'is_local' => false
168
+ # 'type' => 'external'
157
169
  # }
158
170
  # {
159
171
  # 'uri' => 'http://id.loc.gov/authorities/names/n82259885',
160
172
  # 'value' => 'Batman, Stephen, -1584',
161
173
  # 'vocabulary_string_key' => 'names',
162
- # 'is_local' => false
174
+ # 'type' => 'external'
163
175
  # },
164
176
  # ]
165
177
  ```
166
178
 
179
+ Alternate way to find terms without a text query:
180
+ ```ruby
181
+ UriService.client.find_terms_where(
182
+ {
183
+ 'vocabulary_string_key' => 'names',
184
+ 'value' => 'Smith, John',
185
+ 'type' => UriService::TermType::EXTERNAL
186
+ },
187
+ 11
188
+ )
189
+
190
+ # Above method call returns an array of up to 11 terms, or an empty array if no terms are found
191
+ ```
192
+
193
+ Finding a single term by URI:
194
+ ```ruby
195
+ UriService.client.find_term_by_uri('http://id.example.com/123')
196
+ # Returns a term hash or nil
197
+ ```
198
+
167
199
  Listing terms in a vocabulary:
168
200
  ```ruby
169
201
  limit = 10
@@ -175,7 +175,7 @@ class UriService::Client
175
175
  return create_term_impl(type, vocabulary_string_key, value, uri, additional_fields)
176
176
  else
177
177
  # URI should not be present
178
- raise UriService::InvalidOptsError, "A uri cannot supplied for term type: #{type}." unless uri.nil?
178
+ raise UriService::InvalidOptsError, "A uri cannot supplied for term type: #{type}" unless uri.nil?
179
179
 
180
180
  if type == UriService::TermType::TEMPORARY
181
181
  # No two TEMPORARY terms within the same vocabulary can have the same value, so we generate a unique URI from a hash of the (vocabulary_string_key + value) to ensure uniqueness.
@@ -512,6 +512,9 @@ class UriService::Client
512
512
  # - Returns an existing TEMPORARY term if a user attempts to
513
513
  # create a new TEMPORARY term with an existing value/vocabulary combo.
514
514
  def create_term_impl(type, vocabulary_string_key, value, uri, additional_fields)
515
+
516
+ raise UriService::InvalidTermTypeError, 'Invalid type: ' + type unless VALID_TYPES.include?(type)
517
+
515
518
  self.handle_database_disconnect do
516
519
 
517
520
  if type == UriService::TermType::TEMPORARY
@@ -1,6 +1,6 @@
1
1
  module UriService
2
2
 
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
 
5
5
  def self.version
6
6
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric O'Hanlon
@@ -207,3 +207,4 @@ specification_version: 4
207
207
  summary: A service for registering local URIs and performing both local and remote
208
208
  URI lookups.
209
209
  test_files: []
210
+ has_rdoc: