emissions-api-sdk 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +65 -2
  2. package/dist/Constants.js +7 -1
  3. package/dist/api/AuditExport.js +73 -0
  4. package/dist/api/AuditLog.js +99 -0
  5. package/dist/api/EconomicActivity.js +69 -0
  6. package/dist/api/Factor.js +16 -0
  7. package/dist/api/PhysicalActivity.js +87 -0
  8. package/dist/api/RealEstate.js +25 -1
  9. package/dist/api/TypeRecommender.js +19 -2
  10. package/dist/coverage/clover.xml +172 -89
  11. package/dist/coverage/coverage-final.json +15 -8
  12. package/dist/coverage/lcov-report/index.html +21 -21
  13. package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
  14. package/dist/coverage/lcov-report/src/Constants.ts.html +45 -27
  15. package/dist/coverage/lcov-report/src/api/AuditExport.ts.html +355 -0
  16. package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
  17. package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
  18. package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +212 -5
  19. package/dist/coverage/lcov-report/src/api/Factor.ts.html +54 -3
  20. package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
  21. package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
  22. package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
  23. package/dist/coverage/lcov-report/src/api/Metadata.ts.html +1 -1
  24. package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
  25. package/dist/coverage/lcov-report/src/api/PhysicalActivity.ts.html +361 -0
  26. package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +78 -6
  27. package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
  28. package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
  29. package/dist/coverage/lcov-report/src/api/TypeRecommender.ts.html +55 -4
  30. package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
  31. package/dist/coverage/lcov-report/src/api/index.html +51 -6
  32. package/dist/coverage/lcov-report/src/index.html +7 -7
  33. package/dist/coverage/lcov-report/src/request.ts.html +8 -5
  34. package/dist/coverage/lcov-report/src/utils.ts.html +6 -6
  35. package/dist/coverage/lcov-report/test/index.html +1 -1
  36. package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +151 -0
  37. package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
  38. package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
  39. package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
  40. package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
  41. package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
  42. package/dist/coverage/lcov-report/test/mocks/PhysicalActivityEVICRequest.ts.html +148 -0
  43. package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
  44. package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
  45. package/dist/coverage/lcov-report/test/mocks/index.html +63 -3
  46. package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
  47. package/dist/coverage/lcov.info +284 -124
  48. package/dist/index.js +4 -1
  49. package/dist/interfaces/response/AuditExportResponse.js +2 -0
  50. package/dist/interfaces/response/AuditLogResponse.js +2 -0
  51. package/dist/request.js +1 -0
  52. package/dist/types/Constants.d.ts +6 -0
  53. package/dist/types/api/AuditExport.d.ts +42 -0
  54. package/dist/types/api/AuditLog.d.ts +37 -0
  55. package/dist/types/api/EconomicActivity.d.ts +69 -0
  56. package/dist/types/api/Factor.d.ts +16 -0
  57. package/dist/types/api/PhysicalActivity.d.ts +76 -0
  58. package/dist/types/api/RealEstate.d.ts +25 -1
  59. package/dist/types/api/TypeRecommender.d.ts +19 -2
  60. package/dist/types/index.d.ts +6 -0
  61. package/dist/types/interfaces/Api.d.ts +17 -1
  62. package/dist/types/interfaces/Config.d.ts +5 -1
  63. package/dist/types/interfaces/common.d.ts +40 -0
  64. package/dist/types/interfaces/response/AuditExportResponse.d.ts +66 -0
  65. package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
  66. package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +2 -0
  67. package/docs/_sources/authentication.rst.txt +26 -4
  68. package/docs/_sources/getting_started.rst.txt +762 -74
  69. package/docs/_sources/index.rst.txt +13 -0
  70. package/docs/_sources/reference.rst.txt +48 -0
  71. package/docs/_sources/troubleshooting.rst.txt +77 -12
  72. package/docs/_static/basic.css +8 -0
  73. package/docs/_static/doctools.js +5 -6
  74. package/docs/_static/language_data.js +186 -7
  75. package/docs/_static/pygments.css +146 -164
  76. package/docs/_static/searchtools.js +60 -121
  77. package/docs/_static/sphinx_highlight.js +31 -36
  78. package/docs/_static/styles/furo.css +1 -1
  79. package/docs/_static/styles/furo.css.map +1 -1
  80. package/docs/authentication.html +61 -26
  81. package/docs/client.html +33 -22
  82. package/docs/genindex.html +77 -24
  83. package/docs/getting_started.html +969 -103
  84. package/docs/index.html +69 -21
  85. package/docs/reference.html +747 -66
  86. package/docs/sdk.html +32 -21
  87. package/docs/search.html +32 -21
  88. package/docs/searchindex.js +1 -1
  89. package/docs/troubleshooting.html +105 -38
  90. package/package.json +8 -3
  91. package/sphinx-build/source/authentication.rst +26 -4
  92. package/sphinx-build/source/getting_started.rst +762 -74
  93. package/sphinx-build/source/index.rst +13 -0
  94. package/sphinx-build/source/reference.rst +48 -0
  95. package/sphinx-build/source/troubleshooting.rst +77 -12
  96. package/src/Constants.ts +6 -0
  97. package/src/api/AuditExport.ts +90 -0
  98. package/src/api/AuditLog.ts +102 -0
  99. package/src/api/EconomicActivity.ts +69 -0
  100. package/src/api/Factor.ts +17 -1
  101. package/src/api/PhysicalActivity.ts +92 -0
  102. package/src/api/RealEstate.ts +25 -1
  103. package/src/api/TypeRecommender.ts +19 -2
  104. package/src/index.ts +15 -1
  105. package/src/interfaces/Api.ts +22 -6
  106. package/src/interfaces/Config.ts +6 -1
  107. package/src/interfaces/common.ts +46 -0
  108. package/src/interfaces/response/AuditExportResponse.ts +88 -0
  109. package/src/interfaces/response/AuditLogResponse.ts +47 -0
  110. package/src/interfaces/response/TypeRecommenderResponse.ts +3 -0
  111. package/src/request.ts +1 -0
  112. package/test/apiTest.test.ts +59 -3
  113. package/test/auditExport.test.ts +68 -0
  114. package/test/auditLog.test.ts +216 -0
  115. package/test/mocks/AttributionRequest.ts +23 -0
  116. package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
  117. package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
  118. package/test/mocks/PhysicalActivityRequest.ts +23 -0
  119. package/docs/_static/base-stemmer.js +0 -476
  120. package/docs/_static/english-stemmer.js +0 -1066
@@ -7,6 +7,8 @@ IBM Envizi - Emissions API Node.js SDK
7
7
 
8
8
  getting_started
9
9
  sdk
10
+ authentication
11
+ client
10
12
  reference
11
13
  troubleshooting
12
14
 
@@ -27,6 +29,17 @@ Supported Emission Types
27
29
  * **Transportation & distribution** – logistics and supply chain activities
28
30
  * **Real Estate** – emissions from commercial and residential properties
29
31
  * **Economic Activity** – spend-based emissions from business activities
32
+ * **Physical Activity** – scope 3 emissions from physical activities with attribution for private companies (equity/debt or EVIC-based)
30
33
  * **Generic** – custom emission calculations
31
34
 
32
35
  The SDK is designed for embedding emission calculations in applications, building sustainability dashboards, automating large-scale datasets, and tracking carbon footprints.
36
+
37
+ Additional capabilities
38
+ -----------------------
39
+
40
+ * **Metadata API** – query supported types, areas, and units across endpoints
41
+ * **Type Recommender API** – semantic search to identify likely activity types, with optional reranker control and scope in results
42
+ * **Factor Search API** – search for emission factors with unit and scope filtering, with optional reranker control
43
+ * **Usage API** – retrieve organization billing-period or historical usage
44
+ * **Audit Log API** – manage whether API requests and responses are stored for auditing
45
+ * **Audit Export API** – export, monitor, and download organization audit data
@@ -15,6 +15,8 @@ API
15
15
 
16
16
  .. js:autofunction:: Factor.retrieveFactor
17
17
 
18
+ .. js:autofunction:: Factor.search
19
+
18
20
  .. js:autofunction:: Fugitive.calculate
19
21
 
20
22
  .. js:autofunction:: Calculation.calculate
@@ -30,6 +32,36 @@ API
30
32
  .. js:autofunction:: RealEstate.calculate
31
33
 
32
34
  .. js:autofunction:: EconomicActivity.calculate
35
+
36
+ .. js:autofunction:: PhysicalActivity.calculate
37
+
38
+ Type Recommender API
39
+ ====================
40
+
41
+ .. js:autofunction:: TypeRecommender.search
42
+
43
+
44
+ Audit Log API
45
+ =============
46
+
47
+ Controls whether the organization's API requests and responses are stored for auditing.
48
+ Organizations can disable storage if they don't need their API calls to be audited.
49
+
50
+ .. js:autofunction:: AuditLog.getAuditConfig
51
+
52
+ .. js:autofunction:: AuditLog.updateAuditConfig
53
+
54
+
55
+ Audit Export API
56
+ ================
57
+
58
+ The Audit Export API asynchronously generates an audit-data ZIP archive for an admin user. Call ``trigger`` to create an export, ``getStatus`` until it is complete, and ``download`` to retrieve the archive.
59
+
60
+ .. js:autofunction:: AuditExport.trigger
61
+
62
+ .. js:autofunction:: AuditExport.getStatus
63
+
64
+ .. js:autofunction:: AuditExport.download
33
65
 
34
66
 
35
67
  Global Metadata API
@@ -113,3 +145,19 @@ Interfaces
113
145
  .. js:autoclass:: Config.RequestConfig
114
146
 
115
147
  .. js:autoclass:: Config.ClientConfig
148
+
149
+ .. js:autoclass:: AuditLogResponse.AuditLogResponse
150
+
151
+ .. js:autoclass:: AuditLogResponse.AuditLogRequest
152
+
153
+ .. js:autoclass:: TypeRecommenderResponse.TypeRecommenderResponse
154
+
155
+ .. js:autoclass:: TypeRecommenderResponse.ActivityRequest
156
+
157
+ .. js:autoclass:: AuditExportResponse.AuditExportRequest
158
+
159
+ .. js:autoclass:: AuditExportResponse.AuditExportResponse
160
+
161
+ .. js:autoclass:: AuditExportResponse.AuditExportStatusResponse
162
+
163
+ .. js:autoclass:: AuditExportResponse.AuditExportLinks
@@ -99,12 +99,61 @@ These errors occur when ``Client.getClient()`` is called with invalid or missing
99
99
 
100
100
  ----
101
101
 
102
+ 4. Missing Client ID with PAT Token
103
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104
+
105
+ **Error Message:**
106
+
107
+ .. code-block:: text
108
+
109
+ Error: If patToken is provided, "clientId" must also be provided.
110
+
111
+ **Cause:** Personal Access Token (PAT) provided without client ID
112
+
113
+ **Solution:** Provide ``clientId`` parameter when using a PAT token
114
+
115
+ **Sample Function Call That Causes This Error:**
116
+
117
+ .. code-block:: typescript
118
+
119
+ await Client.getClient({
120
+ patToken: 'your-pat-token'
121
+ // Missing clientId parameter
122
+ });
123
+
124
+ ----
125
+
126
+ 5. Organization ID Provided with PAT Token
127
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128
+
129
+ **Error Message:**
130
+
131
+ .. code-block:: text
132
+
133
+ Error: orgId should not be provided when using patToken.
134
+
135
+ **Cause:** Organization ID should not be used with Personal Access Token authentication
136
+
137
+ **Solution:** Remove ``orgId`` parameter when using PAT token authentication
138
+
139
+ **Sample Function Call That Causes This Error:**
140
+
141
+ .. code-block:: typescript
142
+
143
+ await Client.getClient({
144
+ patToken: 'your-pat-token',
145
+ clientId: 'client123',
146
+ orgId: 'org456' // This should not be provided with PAT token
147
+ });
148
+
149
+ ----
150
+
102
151
  Authentication Errors (HTTP 401)
103
152
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104
153
 
105
154
  These errors occur when authentication credentials are invalid or expired.
106
155
 
107
- 4. Invalid API Key
156
+ 6. Invalid API Key
108
157
  ^^^^^^^^^^^^^^^^^^
109
158
 
110
159
  **Error Response:**
@@ -135,7 +184,7 @@ These errors occur when authentication credentials are invalid or expired.
135
184
 
136
185
  ----
137
186
 
138
- 5. Invalid Organization ID
187
+ 7. Invalid Organization ID
139
188
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
140
189
 
141
190
  **Error Response:**
@@ -166,7 +215,7 @@ These errors occur when authentication credentials are invalid or expired.
166
215
 
167
216
  ----
168
217
 
169
- 6. Invalid Client ID
218
+ 8. Invalid Client ID
170
219
  ^^^^^^^^^^^^^^^^^^^^^
171
220
 
172
221
  **Error Response:**
@@ -197,7 +246,7 @@ These errors occur when authentication credentials are invalid or expired.
197
246
 
198
247
  ----
199
248
 
200
- 7. Empty Token Response
249
+ 9. Empty Token Response
201
250
  ^^^^^^^^^^^^^^^^^^^^^^^^
202
251
 
203
252
  **Error Message:**
@@ -233,8 +282,8 @@ These errors occur when authentication credentials are invalid or expired.
233
282
 
234
283
  ----
235
284
 
236
- 8. Missing Expiry Field in Token
237
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
285
+ 10. Missing Expiry Field in Token
286
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238
287
 
239
288
  **Error Message:**
240
289
 
@@ -341,6 +390,14 @@ Error Summary Table
341
390
  - ``If apiKey is provided , "clientId" and "OrgId" must also be provided.``
342
391
  - N/A
343
392
  - Provide all three parameters
393
+ * - Configuration
394
+ - ``If patToken is provided, "clientId" must also be provided.``
395
+ - N/A
396
+ - Provide clientId with PAT token
397
+ * - Configuration
398
+ - ``orgId should not be provided when using patToken.``
399
+ - N/A
400
+ - Remove orgId when using PAT token
344
401
  * - Authentication
345
402
  - ``Cannot pass the security checks...``
346
403
  - 401
@@ -369,14 +426,22 @@ Required Configuration Parameters
369
426
 
370
427
  When calling ``Client.getClient()``, the following parameters are required based on authentication method:
371
428
 
372
- API Key Authentication (Recommended)
373
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
429
+ Personal Access Token (PAT) Authentication (Recommended)
430
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
431
+
432
+ - ``patToken`` - Your Personal Access Token
433
+ - ``clientId`` - Your client ID
434
+
435
+ **Note:** Do not provide ``orgId`` when using PAT token authentication.
436
+
437
+ API Key Authentication
438
+ ~~~~~~~~~~~~~~~~~~~~~~
374
439
 
375
440
  - ``apiKey`` - Your IBM Cloud API key
376
441
  - ``clientId`` - Your client ID
377
442
  - ``orgId`` - Your organization ID
378
- - ``host`` - API host URL
379
- - ``authUrl`` - Authentication URL
443
+ - ``host`` - API host URL (optional, uses default if not provided)
444
+ - ``authUrl`` - Authentication URL (optional, uses default if not provided)
380
445
 
381
446
  Token Authentication
382
447
  ~~~~~~~~~~~~~~~~~~~~
@@ -479,8 +544,8 @@ For issues not covered in this guide:
479
544
 
480
545
  ----
481
546
 
482
- **Last Updated:** 2025-11-24
547
+ **Last Updated:** 2026-05-31
483
548
 
484
- **SDK Version:** 1.0.1
549
+ **SDK Version:** 1.0.2
485
550
 
486
551
  **Coverage:** SDK initialization, client instance, and authentication errors
@@ -741,6 +741,14 @@ abbr, acronym {
741
741
  cursor: help;
742
742
  }
743
743
 
744
+ .translated {
745
+ background-color: rgba(207, 255, 207, 0.2)
746
+ }
747
+
748
+ .untranslated {
749
+ background-color: rgba(255, 207, 207, 0.2)
750
+ }
751
+
744
752
  /* -- code displays --------------------------------------------------------- */
745
753
 
746
754
  pre {
@@ -59,7 +59,7 @@ const Documentation = {
59
59
  Object.assign(Documentation.TRANSLATIONS, catalog.messages);
60
60
  Documentation.PLURAL_EXPR = new Function(
61
61
  "n",
62
- `return (${catalog.plural_expr})`,
62
+ `return (${catalog.plural_expr})`
63
63
  );
64
64
  Documentation.LOCALE = catalog.locale;
65
65
  },
@@ -89,7 +89,7 @@ const Documentation = {
89
89
 
90
90
  const togglerElements = document.querySelectorAll("img.toggler");
91
91
  togglerElements.forEach((el) =>
92
- el.addEventListener("click", (event) => toggler(event.currentTarget)),
92
+ el.addEventListener("click", (event) => toggler(event.currentTarget))
93
93
  );
94
94
  togglerElements.forEach((el) => (el.style.display = ""));
95
95
  if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) togglerElements.forEach(toggler);
@@ -98,15 +98,14 @@ const Documentation = {
98
98
  initOnKeyListeners: () => {
99
99
  // only install a listener if it is really needed
100
100
  if (
101
- !DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS
102
- && !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS
101
+ !DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
102
+ !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS
103
103
  )
104
104
  return;
105
105
 
106
106
  document.addEventListener("keydown", (event) => {
107
107
  // bail for input elements
108
- if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName))
109
- return;
108
+ if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return;
110
109
  // bail with special keys
111
110
  if (event.altKey || event.ctrlKey || event.metaKey) return;
112
111
 
@@ -1,13 +1,192 @@
1
1
  /*
2
2
  * This script contains the language-specific data used by searchtools.js,
3
- * namely the set of stopwords, stemmer, scorer and splitter.
3
+ * namely the list of stopwords, stemmer, scorer and splitter.
4
4
  */
5
5
 
6
- const stopwords = new Set(["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can't", "cannot", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't", "down", "during", "each", "few", "for", "from", "further", "had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't", "it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't", "my", "myself", "no", "nor", "not", "of", "off", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same", "shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll", "we're", "we've", "were", "weren't", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "who's", "whom", "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves"]);
7
- window.stopwords = stopwords; // Export to global scope
6
+ var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"];
8
7
 
9
8
 
10
- /* Non-minified versions are copied as separate JavaScript files, if available */
11
- BaseStemmer=function(){this.current="",this.cursor=0,this.limit=0,this.limit_backward=0,this.bra=0,this.ket=0,this.setCurrent=function(t){this.current=t,this.cursor=0,this.limit=this.current.length,this.limit_backward=0,this.bra=this.cursor,this.ket=this.limit},this.getCurrent=function(){return this.current},this.copy_from=function(t){this.current=t.current,this.cursor=t.cursor,this.limit=t.limit,this.limit_backward=t.limit_backward,this.bra=t.bra,this.ket=t.ket},this.in_grouping=function(t,r,i){return!(this.cursor>=this.limit||i<(i=this.current.charCodeAt(this.cursor))||i<r||0==(t[(i-=r)>>>3]&1<<(7&i))||(this.cursor++,0))},this.go_in_grouping=function(t,r,i){for(;this.cursor<this.limit;){var s=this.current.charCodeAt(this.cursor);if(i<s||s<r)return!0;if(0==(t[(s-=r)>>>3]&1<<(7&s)))return!0;this.cursor++}return!1},this.in_grouping_b=function(t,r,i){return!(this.cursor<=this.limit_backward||i<(i=this.current.charCodeAt(this.cursor-1))||i<r||0==(t[(i-=r)>>>3]&1<<(7&i))||(this.cursor--,0))},this.go_in_grouping_b=function(t,r,i){for(;this.cursor>this.limit_backward;){var s=this.current.charCodeAt(this.cursor-1);if(i<s||s<r)return!0;if(0==(t[(s-=r)>>>3]&1<<(7&s)))return!0;this.cursor--}return!1},this.out_grouping=function(t,r,i){return!(this.cursor>=this.limit)&&(i<(i=this.current.charCodeAt(this.cursor))||i<r||0==(t[(i-=r)>>>3]&1<<(7&i)))&&(this.cursor++,!0)},this.go_out_grouping=function(t,r,i){for(;this.cursor<this.limit;){var s=this.current.charCodeAt(this.cursor);if(s<=i&&r<=s&&0!=(t[(s-=r)>>>3]&1<<(7&s)))return!0;this.cursor++}return!1},this.out_grouping_b=function(t,r,i){return!(this.cursor<=this.limit_backward)&&(i<(i=this.current.charCodeAt(this.cursor-1))||i<r||0==(t[(i-=r)>>>3]&1<<(7&i)))&&(this.cursor--,!0)},this.go_out_grouping_b=function(t,r,i){for(;this.cursor>this.limit_backward;){var s=this.current.charCodeAt(this.cursor-1);if(s<=i&&r<=s&&0!=(t[(s-=r)>>>3]&1<<(7&s)))return!0;this.cursor--}return!1},this.eq_s=function(t){return!(this.limit-this.cursor<t.length||this.current.slice(this.cursor,this.cursor+t.length)!=t||(this.cursor+=t.length,0))},this.eq_s_b=function(t){return!(this.cursor-this.limit_backward<t.length||this.current.slice(this.cursor-t.length,this.cursor)!=t||(this.cursor-=t.length,0))},this.find_among=function(t){for(var r=0,i=t.length,s=this.cursor,h=this.limit,e=0,n=0,c=!1;;){for(var u=r+(i-r>>>1),o=0,a=e<n?e:n,l=t[u],f=a;f<l[0].length;f++){if(s+a==h){o=-1;break}if(0!=(o=this.current.charCodeAt(s+a)-l[0].charCodeAt(f)))break;a++}if(o<0?(i=u,n=a):(r=u,e=a),i-r<=1){if(0<r)break;if(i==r)break;if(c)break;c=!0}}do{if(e>=(l=t[r])[0].length){if(this.cursor=s+l[0].length,l.length<4)return l[2];var g=l[3](this);if(this.cursor=s+l[0].length,g)return l[2]}}while(0<=(r=l[1]));return 0},this.find_among_b=function(t){for(var r=0,i=t.length,s=this.cursor,h=this.limit_backward,e=0,n=0,c=!1;;){for(var u,o=r+(i-r>>1),a=0,l=e<n?e:n,f=(u=t[o])[0].length-1-l;0<=f;f--){if(s-l==h){a=-1;break}if(0!=(a=this.current.charCodeAt(s-1-l)-u[0].charCodeAt(f)))break;l++}if(a<0?(i=o,n=l):(r=o,e=l),i-r<=1){if(0<r)break;if(i==r)break;if(c)break;c=!0}}do{if(e>=(u=t[r])[0].length){if(this.cursor=s-u[0].length,u.length<4)return u[2];var g=u[3](this);if(this.cursor=s-u[0].length,g)return u[2]}}while(0<=(r=u[1]));return 0},this.replace_s=function(t,r,i){var s=i.length-(r-t);return this.current=this.current.slice(0,t)+i+this.current.slice(r),this.limit+=s,this.cursor>=r?this.cursor+=s:this.cursor>t&&(this.cursor=t),s},this.slice_check=function(){return!(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>this.current.length)},this.slice_from=function(t){var r=!1;return this.slice_check()&&(this.replace_s(this.bra,this.ket,t),r=!0),r},this.slice_del=function(){return this.slice_from("")},this.insert=function(t,r,i){r=this.replace_s(t,r,i);t<=this.bra&&(this.bra+=r),t<=this.ket&&(this.ket+=r)},this.slice_to=function(){var t="";return t=this.slice_check()?this.current.slice(this.bra,this.ket):t},this.assign_to=function(){return this.current.slice(0,this.limit)}};
12
- var EnglishStemmer=function(){var a=new BaseStemmer,c=[["arsen",-1,-1],["commun",-1,-1],["emerg",-1,-1],["gener",-1,-1],["later",-1,-1],["organ",-1,-1],["past",-1,-1],["univers",-1,-1]],o=[["'",-1,1],["'s'",0,1],["'s",-1,1]],u=[["ied",-1,2],["s",-1,3],["ies",1,2],["sses",1,1],["ss",1,-1],["us",1,-1]],t=[["succ",-1,1],["proc",-1,1],["exc",-1,1]],l=[["even",-1,2],["cann",-1,2],["inn",-1,2],["earr",-1,2],["herr",-1,2],["out",-1,2],["y",-1,1]],n=[["",-1,-1],["ed",0,2],["eed",1,1],["ing",0,3],["edly",0,2],["eedly",4,1],["ingly",0,2]],f=[["",-1,3],["bb",0,2],["dd",0,2],["ff",0,2],["gg",0,2],["bl",0,1],["mm",0,2],["nn",0,2],["pp",0,2],["rr",0,2],["at",0,1],["tt",0,2],["iz",0,1]],_=[["anci",-1,3],["enci",-1,2],["ogi",-1,14],["li",-1,16],["bli",3,12],["abli",4,4],["alli",3,8],["fulli",3,9],["lessli",3,15],["ousli",3,10],["entli",3,5],["aliti",-1,8],["biliti",-1,12],["iviti",-1,11],["tional",-1,1],["ational",14,7],["alism",-1,8],["ation",-1,7],["ization",17,6],["izer",-1,6],["ator",-1,7],["iveness",-1,11],["fulness",-1,9],["ousness",-1,10],["ogist",-1,13]],m=[["icate",-1,4],["ative",-1,6],["alize",-1,3],["iciti",-1,4],["ical",-1,4],["tional",-1,1],["ational",5,2],["ful",-1,5],["ness",-1,5]],b=[["ic",-1,1],["ance",-1,1],["ence",-1,1],["able",-1,1],["ible",-1,1],["ate",-1,1],["ive",-1,1],["ize",-1,1],["iti",-1,1],["al",-1,1],["ism",-1,1],["ion",-1,2],["er",-1,1],["ous",-1,1],["ant",-1,1],["ent",-1,1],["ment",15,1],["ement",16,1]],k=[["e",-1,1],["l",-1,2]],g=[["andes",-1,-1],["atlas",-1,-1],["bias",-1,-1],["cosmos",-1,-1],["early",-1,5],["gently",-1,3],["howe",-1,-1],["idly",-1,2],["news",-1,-1],["only",-1,6],["singly",-1,7],["skies",-1,1],["sky",-1,-1],["ugly",-1,4]],d=[17,64],v=[17,65,16,1],i=[1,17,65,208,1],w=[55,141,2],p=!1,y=0,h=0;function q(){var r=a.limit-a.cursor;return!!(a.out_grouping_b(i,89,121)&&a.in_grouping_b(v,97,121)&&a.out_grouping_b(v,97,121)||(a.cursor=a.limit-r,a.out_grouping_b(v,97,121)&&a.in_grouping_b(v,97,121)&&!(a.cursor>a.limit_backward))||(a.cursor=a.limit-r,a.eq_s_b("past")))}function z(){return h<=a.cursor}function Y(){return y<=a.cursor}this.stem=function(){var r=a.cursor;if(!(()=>{var r;if(a.bra=a.cursor,0!=(r=a.find_among(g))&&(a.ket=a.cursor,!(a.cursor<a.limit))){switch(r){case 1:if(a.slice_from("sky"))break;return;case 2:if(a.slice_from("idl"))break;return;case 3:if(a.slice_from("gentl"))break;return;case 4:if(a.slice_from("ugli"))break;return;case 5:if(a.slice_from("earli"))break;return;case 6:if(a.slice_from("onli"))break;return;case 7:if(a.slice_from("singl"))break;return}return 1}})()){a.cursor=r;var i=a.cursor,e=a.cursor+3;if(e>a.limit)a.cursor=i;else{a.cursor=e,a.cursor=r,(()=>{p=!1;var r=a.cursor;if(a.bra=a.cursor,!a.eq_s("'")||(a.ket=a.cursor,a.slice_del())){a.cursor=r;r=a.cursor;if(a.bra=a.cursor,a.eq_s("y")){if(a.ket=a.cursor,!a.slice_from("Y"))return;p=!0}a.cursor=r;for(r=a.cursor;;){var i=a.cursor;r:{for(;;){var e=a.cursor;if(a.in_grouping(v,97,121)&&(a.bra=a.cursor,a.eq_s("y"))){a.ket=a.cursor,a.cursor=e;break}if(a.cursor=e,a.cursor>=a.limit)break r;a.cursor++}if(!a.slice_from("Y"))return;p=!0;continue}a.cursor=i;break}a.cursor=r}})(),h=a.limit,y=a.limit;i=a.cursor;r:{var s=a.cursor;if(0==a.find_among(c)){if(a.cursor=s,!a.go_out_grouping(v,97,121))break r;if(a.cursor++,!a.go_in_grouping(v,97,121))break r;a.cursor++}h=a.cursor,a.go_out_grouping(v,97,121)&&(a.cursor++,a.go_in_grouping(v,97,121))&&(a.cursor++,y=a.cursor)}a.cursor=i,a.limit_backward=a.cursor,a.cursor=a.limit;var e=a.limit-a.cursor,r=((()=>{var r=a.limit-a.cursor;if(a.ket=a.cursor,0==a.find_among_b(o))a.cursor=a.limit-r;else if(a.bra=a.cursor,!a.slice_del())return;if(a.ket=a.cursor,0!=(r=a.find_among_b(u)))switch(a.bra=a.cursor,r){case 1:if(a.slice_from("ss"))break;return;case 2:r:{var i=a.limit-a.cursor,e=a.cursor-2;if(!(e<a.limit_backward)){if(a.cursor=e,a.slice_from("i"))break r;return}if(a.cursor=a.limit-i,!a.slice_from("ie"))return}break;case 3:if(a.cursor<=a.limit_backward)return;if(a.cursor--,!a.go_out_grouping_b(v,97,121))return;if(a.cursor--,a.slice_del())break}})(),a.cursor=a.limit-e,a.limit-a.cursor),i=((()=>{a.ket=a.cursor,o=a.find_among_b(n),a.bra=a.cursor;r:{var r=a.limit-a.cursor;i:{switch(o){case 1:var i=a.limit-a.cursor;e:{var e=a.limit-a.cursor;if(0==a.find_among_b(t)||a.cursor>a.limit_backward){if(a.cursor=a.limit-e,!z())break e;if(!a.slice_from("ee"))return}}a.cursor=a.limit-i;break;case 2:break i;case 3:if(0==(o=a.find_among_b(l)))break i;switch(o){case 1:var s=a.limit-a.cursor;if(!a.out_grouping_b(v,97,121))break i;if(a.cursor>a.limit_backward)break i;if(a.cursor=a.limit-s,a.bra=a.cursor,a.slice_from("ie"))break;return;case 2:if(a.cursor>a.limit_backward)break i}}break r}a.cursor=a.limit-r;var c=a.limit-a.cursor;if(!a.go_out_grouping_b(v,97,121))return;if(a.cursor--,a.cursor=a.limit-c,!a.slice_del())return;a.ket=a.cursor,a.bra=a.cursor;var o,c=a.limit-a.cursor;switch(o=a.find_among_b(f)){case 1:return a.slice_from("e");case 2:var u=a.limit-a.cursor;if(a.in_grouping_b(d,97,111)&&!(a.cursor>a.limit_backward))return;a.cursor=a.limit-u;break;case 3:return a.cursor!=h||(u=a.limit-a.cursor,q()&&(a.cursor=a.limit-u,a.slice_from("e")))}if(a.cursor=a.limit-c,a.ket=a.cursor,a.cursor<=a.limit_backward)return;if(a.cursor--,a.bra=a.cursor,!a.slice_del())return}})(),a.cursor=a.limit-r,a.limit-a.cursor),r=(a.ket=a.cursor,e=a.limit-a.cursor,(a.eq_s_b("y")||(a.cursor=a.limit-e,a.eq_s_b("Y")))&&(a.bra=a.cursor,a.out_grouping_b(v,97,121))&&a.cursor>a.limit_backward&&a.slice_from("i"),a.cursor=a.limit-i,a.limit-a.cursor),e=((()=>{var r;if(a.ket=a.cursor,0!=(r=a.find_among_b(_))&&(a.bra=a.cursor,z()))switch(r){case 1:if(a.slice_from("tion"))break;return;case 2:if(a.slice_from("ence"))break;return;case 3:if(a.slice_from("ance"))break;return;case 4:if(a.slice_from("able"))break;return;case 5:if(a.slice_from("ent"))break;return;case 6:if(a.slice_from("ize"))break;return;case 7:if(a.slice_from("ate"))break;return;case 8:if(a.slice_from("al"))break;return;case 9:if(a.slice_from("ful"))break;return;case 10:if(a.slice_from("ous"))break;return;case 11:if(a.slice_from("ive"))break;return;case 12:if(a.slice_from("ble"))break;return;case 13:if(a.slice_from("og"))break;return;case 14:if(!a.eq_s_b("l"))return;if(a.slice_from("og"))break;return;case 15:if(a.slice_from("less"))break;return;case 16:if(!a.in_grouping_b(w,99,116))return;if(a.slice_del())break}})(),a.cursor=a.limit-r,a.limit-a.cursor),i=((()=>{var r;if(a.ket=a.cursor,0!=(r=a.find_among_b(m))&&(a.bra=a.cursor,z()))switch(r){case 1:if(a.slice_from("tion"))break;return;case 2:if(a.slice_from("ate"))break;return;case 3:if(a.slice_from("al"))break;return;case 4:if(a.slice_from("ic"))break;return;case 5:if(a.slice_del())break;return;case 6:if(!Y())return;if(a.slice_del())break}})(),a.cursor=a.limit-e,a.limit-a.cursor),r=((()=>{var r;if(a.ket=a.cursor,0!=(r=a.find_among_b(b))&&(a.bra=a.cursor,Y()))switch(r){case 1:if(a.slice_del())break;return;case 2:var i=a.limit-a.cursor;if(!a.eq_s_b("s")&&(a.cursor=a.limit-i,!a.eq_s_b("t")))return;if(a.slice_del())break}})(),a.cursor=a.limit-i,a.limit-a.cursor),e=((()=>{var r;if(a.ket=a.cursor,0!=(r=a.find_among_b(k)))switch(a.bra=a.cursor,r){case 1:if(!Y()){if(!z())return;var i=a.limit-a.cursor;if(q())return;a.cursor=a.limit-i}if(a.slice_del())break;return;case 2:if(!Y())return;if(!a.eq_s_b("l"))return;if(a.slice_del())break}})(),a.cursor=a.limit-r,a.cursor=a.limit_backward,a.cursor);(()=>{if(p)for(;;){var r=a.cursor;r:{for(;;){var i=a.cursor;if(a.bra=a.cursor,a.eq_s("Y")){a.ket=a.cursor,a.cursor=i;break}if(a.cursor=i,a.cursor>=a.limit)break r;a.cursor++}if(a.slice_from("y"))continue;return}a.cursor=r;break}})(),a.cursor=e}}return!0},this.stemWord=function(r){return a.setCurrent(r),this.stem(),a.getCurrent()}};
13
- window.Stemmer = EnglishStemmer;
9
+ /* Non-minified version is copied as a separate JS file, if available */
10
+
11
+ /**
12
+ * Porter Stemmer
13
+ */
14
+ var Stemmer = function() {
15
+
16
+ var step2list = {
17
+ ational: 'ate',
18
+ tional: 'tion',
19
+ enci: 'ence',
20
+ anci: 'ance',
21
+ izer: 'ize',
22
+ bli: 'ble',
23
+ alli: 'al',
24
+ entli: 'ent',
25
+ eli: 'e',
26
+ ousli: 'ous',
27
+ ization: 'ize',
28
+ ation: 'ate',
29
+ ator: 'ate',
30
+ alism: 'al',
31
+ iveness: 'ive',
32
+ fulness: 'ful',
33
+ ousness: 'ous',
34
+ aliti: 'al',
35
+ iviti: 'ive',
36
+ biliti: 'ble',
37
+ logi: 'log'
38
+ };
39
+
40
+ var step3list = {
41
+ icate: 'ic',
42
+ ative: '',
43
+ alize: 'al',
44
+ iciti: 'ic',
45
+ ical: 'ic',
46
+ ful: '',
47
+ ness: ''
48
+ };
49
+
50
+ var c = "[^aeiou]"; // consonant
51
+ var v = "[aeiouy]"; // vowel
52
+ var C = c + "[^aeiouy]*"; // consonant sequence
53
+ var V = v + "[aeiou]*"; // vowel sequence
54
+
55
+ var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0
56
+ var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1
57
+ var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1
58
+ var s_v = "^(" + C + ")?" + v; // vowel in stem
59
+
60
+ this.stemWord = function (w) {
61
+ var stem;
62
+ var suffix;
63
+ var firstch;
64
+ var origword = w;
65
+
66
+ if (w.length < 3)
67
+ return w;
68
+
69
+ var re;
70
+ var re2;
71
+ var re3;
72
+ var re4;
73
+
74
+ firstch = w.substr(0,1);
75
+ if (firstch == "y")
76
+ w = firstch.toUpperCase() + w.substr(1);
77
+
78
+ // Step 1a
79
+ re = /^(.+?)(ss|i)es$/;
80
+ re2 = /^(.+?)([^s])s$/;
81
+
82
+ if (re.test(w))
83
+ w = w.replace(re,"$1$2");
84
+ else if (re2.test(w))
85
+ w = w.replace(re2,"$1$2");
86
+
87
+ // Step 1b
88
+ re = /^(.+?)eed$/;
89
+ re2 = /^(.+?)(ed|ing)$/;
90
+ if (re.test(w)) {
91
+ var fp = re.exec(w);
92
+ re = new RegExp(mgr0);
93
+ if (re.test(fp[1])) {
94
+ re = /.$/;
95
+ w = w.replace(re,"");
96
+ }
97
+ }
98
+ else if (re2.test(w)) {
99
+ var fp = re2.exec(w);
100
+ stem = fp[1];
101
+ re2 = new RegExp(s_v);
102
+ if (re2.test(stem)) {
103
+ w = stem;
104
+ re2 = /(at|bl|iz)$/;
105
+ re3 = new RegExp("([^aeiouylsz])\\1$");
106
+ re4 = new RegExp("^" + C + v + "[^aeiouwxy]$");
107
+ if (re2.test(w))
108
+ w = w + "e";
109
+ else if (re3.test(w)) {
110
+ re = /.$/;
111
+ w = w.replace(re,"");
112
+ }
113
+ else if (re4.test(w))
114
+ w = w + "e";
115
+ }
116
+ }
117
+
118
+ // Step 1c
119
+ re = /^(.+?)y$/;
120
+ if (re.test(w)) {
121
+ var fp = re.exec(w);
122
+ stem = fp[1];
123
+ re = new RegExp(s_v);
124
+ if (re.test(stem))
125
+ w = stem + "i";
126
+ }
127
+
128
+ // Step 2
129
+ re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
130
+ if (re.test(w)) {
131
+ var fp = re.exec(w);
132
+ stem = fp[1];
133
+ suffix = fp[2];
134
+ re = new RegExp(mgr0);
135
+ if (re.test(stem))
136
+ w = stem + step2list[suffix];
137
+ }
138
+
139
+ // Step 3
140
+ re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
141
+ if (re.test(w)) {
142
+ var fp = re.exec(w);
143
+ stem = fp[1];
144
+ suffix = fp[2];
145
+ re = new RegExp(mgr0);
146
+ if (re.test(stem))
147
+ w = stem + step3list[suffix];
148
+ }
149
+
150
+ // Step 4
151
+ re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
152
+ re2 = /^(.+?)(s|t)(ion)$/;
153
+ if (re.test(w)) {
154
+ var fp = re.exec(w);
155
+ stem = fp[1];
156
+ re = new RegExp(mgr1);
157
+ if (re.test(stem))
158
+ w = stem;
159
+ }
160
+ else if (re2.test(w)) {
161
+ var fp = re2.exec(w);
162
+ stem = fp[1] + fp[2];
163
+ re2 = new RegExp(mgr1);
164
+ if (re2.test(stem))
165
+ w = stem;
166
+ }
167
+
168
+ // Step 5
169
+ re = /^(.+?)e$/;
170
+ if (re.test(w)) {
171
+ var fp = re.exec(w);
172
+ stem = fp[1];
173
+ re = new RegExp(mgr1);
174
+ re2 = new RegExp(meq1);
175
+ re3 = new RegExp("^" + C + v + "[^aeiouwxy]$");
176
+ if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
177
+ w = stem;
178
+ }
179
+ re = /ll$/;
180
+ re2 = new RegExp(mgr1);
181
+ if (re.test(w) && re2.test(w)) {
182
+ re = /.$/;
183
+ w = w.replace(re,"");
184
+ }
185
+
186
+ // and turn initial Y back to y
187
+ if (firstch == "y")
188
+ w = firstch.toLowerCase() + w.substr(1);
189
+ return w;
190
+ }
191
+ }
192
+