A search interface for data from the Politics of Patents case study (part of Copim WP6): this parses data from the archive of RTF files and provides additional data from the European Patent Office API. https://patents.copim.ac.uk
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. # @name: ops_api.php
  3. # @version: 0.1
  4. # @creation_date: 2021-09-24
  5. # @license: The MIT License <https://opensource.org/licenses/MIT>
  6. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  7. # @purpose: Performs functions against the European Patent Office's Open Patent Services (OPS) API
  8. # @acknowledgements:
  9. # OPS documented at https://www.epo.org/searching-for-patents/data/web-services/ops.html
  10. # OPS RESTful API specification at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf
  11. # OPS API functions list at https://developers.epo.org/ops-v3-2/apis
  12. function get_access_token() {
  13. // OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf)
  14. $ops_url = $_ENV["OPS_URL"] . '3.2/auth/accesstoken';
  15. $auth = base64_encode($_ENV["CONSUMER_KEY"] . ":" . $_ENV["CONSUMER_SECRET"]);
  16. // Set up API call
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_URL, $ops_url);
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  20. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic $auth","Content-Type: application/x-www-form-urlencoded"));
  21. curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
  22. curl_setopt($ch, CURLOPT_POST, true);
  23. // Give back curl result
  24. $response = curl_exec($ch);
  25. curl_close($ch);
  26. // Turn the API response into useful Json
  27. $json = json_decode($response);
  28. $access_token = $json->access_token;
  29. return $access_token;
  30. }
  31. function get_publication_details($document_reference) {
  32. $access_token = get_access_token();
  33. // OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf)
  34. $ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/docdb/' . $document_reference . '/biblio';
  35. // Set up API call
  36. $ch = curl_init();
  37. curl_setopt($ch, CURLOPT_URL, $ops_url);
  38. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  39. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token", "Accept: application/json"));
  40. // Give back curl result
  41. $response = curl_exec($ch);
  42. curl_close($ch);
  43. if (strpos($response,"No results found") === false ) {
  44. // Turn the API response into useful Json
  45. $json = json_decode($response);
  46. // For each invention title, check if it's in the original language
  47. foreach ($json->{'ops:world-patent-data'}->{'exchange-documents'}->{'exchange-document'}->{'bibliographic-data'}->{'invention-title'} as $invention_title){
  48. if ($invention_title->{'@lang'} === 'ol'){
  49. $output['original_title'] = $invention_title->{'$'};
  50. }
  51. }
  52. // For each abstract, check if it's in the original language
  53. foreach ($json->{'ops:world-patent-data'}->{'exchange-documents'}->{'exchange-document'}->{'abstract'} as $abstract){
  54. if ($abstract->{'@lang'} === 'ol'){
  55. $output['original_abstract'] = $abstract->p->{'$'};
  56. }
  57. }
  58. return $output;
  59. }
  60. }
  61. function check_for_images($document_reference) {
  62. $access_token = get_access_token();
  63. // OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf)
  64. $ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/docdb/' . $document_reference . '/images';
  65. // Set up API call
  66. $ch = curl_init();
  67. curl_setopt($ch, CURLOPT_URL, $ops_url);
  68. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  69. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));
  70. // Give back curl result
  71. $response = curl_exec($ch);
  72. curl_close($ch);
  73. if (strpos($response,"No results found") === false ) {
  74. return $response;
  75. }
  76. }
  77. function get_images($document_reference){
  78. $access_token = get_access_token();
  79. // OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf)
  80. $ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/docdb/' . $document_reference . '/images';
  81. // Set up API call
  82. $ch = curl_init();
  83. curl_setopt($ch, CURLOPT_URL, $ops_url);
  84. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  85. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));
  86. // Give back curl result
  87. $response = curl_exec($ch);
  88. curl_close($ch);
  89. if (strpos($response,"No results found") === false ) {
  90. // Turn the API response into useful XML
  91. $xml = new SimpleXMLElement($response);
  92. // Retrieve image path from that XML
  93. $drawings_url = $_ENV["OPS_URL_IMAGES"] . '3.2/rest-services/' . $xml->xpath("///ops:document-instance[@desc='Drawing']/@link")[0][0]->__toString() . '?Range=1';
  94. // Set up API call
  95. $ch = curl_init();
  96. curl_setopt($ch, CURLOPT_URL, $drawings_url);
  97. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  98. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token","Accept: application/pdf"));
  99. // Give back curl result
  100. $response = curl_exec($ch);
  101. curl_close($ch);
  102. // Return the PDF response
  103. return $response;
  104. }
  105. }
  106. ?>