Class: Epo::Ops::Register

Inherits:
Object
  • Object
show all
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

Class Method Details

.all_queries(ipc_class = nil, date = nil) ⇒ Array

builds all queries necessary to find all patent references on a given date.

Returns:

  • (Array)

    Array of Strings containing queries applicable to raw_search.



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.

Parameters:

  • search_entry (SearchEntry)

    a search entry which should be retrieved.

Returns:



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.

Parameters:

  • date (Date)

    date on which patents should be counted

Returns:

  • (Hash)

    Hash ipc_class => count (ipc_class A-H)



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.

Parameters:

  • date (Date) (defaults to: nil)
  • ipc_class (String) (defaults to: nil)

    up to now should only be between A-H

Returns:

  • (Integer)

    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

Parameters:

  • reference_id (String)

    identifier for document. Format similar to EP1000000

  • format (String) (defaults to: 'epodoc')

    epodoc is a format defined by the EPO for a document id. see their documentation.

  • type (String) (defaults to: 'application')

    may be ‘application` or `publication` make sure that the `reference_id` is matching

  • raw (Boolean) (defaults to: false)

    flag if the result should be returned as a raw Hash or parsed as BibliographicDocument

Returns:



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.

Parameters:

  • query

    A query built with SearchQueryBuilder

  • raw (defaults to: false)

    if ‘true` the result will be the raw response as a nested hash. if false(default) the result will be parsed further, returning a list of [SearchEntry]

Returns:



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

Note:

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.

Returns:



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.

Parameters:

  • patent_count (Integer)

    number of overall results expected. See published_patents_count

Returns:

  • (Array)

    of Strings, each a query to put into raw_search

See Also:



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