Class: Epo::Ops::Register
- Inherits:
-
Object
- Object
- Epo::Ops::Register
- Defined in:
- lib/epo/ops/register.rb
Overview
Access to the register endpoint of the EPO OPS API.
By now you can search and retrieve patents by using the type ‘application` in the `epodoc` format.
Search queries are limited by size, not following these limits will result in errors. You should probably use Register.search which handles the limits itself.
For more fine grained control use Register.raw_search and Register.raw_biblio
Defined Under Namespace
Classes: Reference, SearchEntry
Class Method Summary collapse
-
.all_queries(ipc_class = nil, date = nil) ⇒ Array
builds all queries necessary to find all patent references on a given date.
-
.biblio(search_entry) ⇒ BibliographicDocument
A parsed document.
-
.patent_counts_per_ipc_class(date) ⇒ Hash
Makes the requests to find how many patents are in each top level ipc class on a given date.
-
.published_patents_counts(ipc_class = nil, date = nil) ⇒ Integer
Number of patents with given parameters.
- .raw_biblio(reference_id, type = 'application', format = 'epodoc', raw = false) ⇒ BibliographicDocument, Hash
-
.raw_search(query, raw = false) ⇒ Array
Containing SearchEntry.
-
.search(ipc_class = nil, date = nil) ⇒ Array
Search method returning all unique register references on a given date, with optional ipc_class.
-
.split_by_size_limits(ipc_class, date, patent_count) ⇒ Array
A helper method which creates queries that take API limits into account.
Class Method Details
.all_queries(ipc_class = nil, date = nil) ⇒ Array
builds all queries necessary to find all patent references on a given date.
76 77 78 79 80 81 82 83 |
# File 'lib/epo/ops/register.rb', line 76 def self.all_queries(ipc_class = nil, date = nil) count = published_patents_counts(ipc_class, date) if count > Limits::MAX_QUERY_RANGE IpcClassUtil.children(ipc_class).flat_map { |ic| all_queries(ic, date) } else split_by_size_limits(ipc_class, date, count) end end |
.biblio(search_entry) ⇒ BibliographicDocument
Returns a parsed document.
101 102 103 |
# File 'lib/epo/ops/register.rb', line 101 def self.biblio(search_entry) raw_biblio(search_entry.application_reference.epodoc_reference) end |
.patent_counts_per_ipc_class(date) ⇒ Hash
Makes the requests to find how many patents are in each top level ipc class on a given date.
44 45 46 47 48 49 |
# File 'lib/epo/ops/register.rb', line 44 def self.patent_counts_per_ipc_class(date) %w( A B C D E F G H ).inject({}) do |mem, icc| mem[icc] = published_patents_counts(icc, date) mem end end |
.published_patents_counts(ipc_class = nil, date = nil) ⇒ Integer
Returns number of patents with given parameters.
54 55 56 57 58 59 |
# File 'lib/epo/ops/register.rb', line 54 def self.published_patents_counts(ipc_class = nil, date = nil) query = SearchQueryBuilder.build(ipc_class, date, 1, 2) minimum_result_set = Register.raw_search(query, true) return 0 if minimum_result_set.empty? minimum_result_set['world_patent_data']['register_search']['total_result_count'].to_i end |
.raw_biblio(reference_id, type = 'application', format = 'epodoc', raw = false) ⇒ BibliographicDocument, Hash
114 115 116 117 118 |
# File 'lib/epo/ops/register.rb', line 114 def self.raw_biblio(reference_id, type = 'application', format = 'epodoc', raw = false) request = "#{register_api_string}#{type}/#{format}/#{reference_id}/biblio" result = Client.request(:get, request).parsed raw ? result : BibliographicDocument.new(result) end |
.raw_search(query, raw = false) ⇒ Array
Returns containing SearchEntry.
90 91 92 93 94 95 96 |
# File 'lib/epo/ops/register.rb', line 90 def self.raw_search(query, raw = false) hash = Client.request(:get, register_api_string + 'search?' + query).parsed return parse_search_results(hash) unless raw hash rescue Epo::Ops::Error::NotFound [] end |
.search(ipc_class = nil, date = nil) ⇒ Array
This method does more than one query; it may happen that you exceed your API limits
Search method returning all unique register references on a given date, with optional ipc_class.
66 67 68 69 70 |
# File 'lib/epo/ops/register.rb', line 66 def self.search(ipc_class = nil, date = nil) queries = all_queries(ipc_class, date) search_entries = queries.flat_map { |query| raw_search(query) } search_entries.uniq { |se| se.application_reference.epodoc_reference } end |
.split_by_size_limits(ipc_class, date, patent_count) ⇒ Array
A helper method which creates queries that take API limits into account.
31 32 33 34 35 36 37 |
# File 'lib/epo/ops/register.rb', line 31 def self.split_by_size_limits(ipc_class, date, patent_count) max_interval = Limits::MAX_QUERY_INTERVAL (1..patent_count).step(max_interval).map do |start| range_end = [start + max_interval - 1, patent_count].min Epo::Ops::SearchQueryBuilder.build(ipc_class, date, start, range_end) end end |