Class: EpoOps::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 raw_biblio

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.



75
76
77
78
79
80
81
82
# File 'lib/epo_ops/register.rb', line 75

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

.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)



42
43
44
45
46
47
# File 'lib/epo_ops/register.rb', line 42

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



52
53
54
55
56
# File 'lib/epo_ops/register.rb', line 52

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)
  minimum_result_set.count
end

.raw_search(query, raw = false) ⇒ RegisterSearchResult

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:



89
90
91
92
93
94
95
96
97
98
# File 'lib/epo_ops/register.rb', line 89

def self.raw_search(query, raw = false)
  data = Client.request(
    :get,
    '/3.1/rest-services/register/search?' + query
  ).parsed

  EpoOps::Factories::RegisterSearchResultFactory.build(data)
rescue EpoOps::Error::NotFound
  raw ? nil : EpoOps::RegisterSearchResult::NullResult.new
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:

  • (Array)

    Array of SearchEntry



63
64
65
66
67
68
69
# File 'lib/epo_ops/register.rb', line 63

def self.search(ipc_class = nil, date = nil)
  queries = all_queries(ipc_class, date)
  search_entries = queries.map { |query| raw_search(query) }
  applications = search_entries.collect(&:patents)

  EpoOps::RegisterSearchResult.new(applications,applications.count)
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:



29
30
31
32
33
34
35
# File 'lib/epo_ops/register.rb', line 29

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
    EpoOps::SearchQueryBuilder.build(ipc_class, date, start, range_end)
  end
end