@civiq/entity-resolution 0.1.0

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 (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -0
  3. package/data/bioguide-fec-mapping.json +4186 -0
  4. package/data/sec-sic-data.json +10427 -0
  5. package/dist/__tests__/company-entity-resolver.test.d.ts +6 -0
  6. package/dist/__tests__/company-entity-resolver.test.d.ts.map +1 -0
  7. package/dist/__tests__/company-entity-resolver.test.js +267 -0
  8. package/dist/__tests__/company-entity-resolver.test.js.map +1 -0
  9. package/dist/__tests__/entity-resolution.test.d.ts +2 -0
  10. package/dist/__tests__/entity-resolution.test.d.ts.map +1 -0
  11. package/dist/__tests__/entity-resolution.test.js +296 -0
  12. package/dist/__tests__/entity-resolution.test.js.map +1 -0
  13. package/dist/__tests__/fec-entity-resolution.test.d.ts +2 -0
  14. package/dist/__tests__/fec-entity-resolution.test.d.ts.map +1 -0
  15. package/dist/__tests__/fec-entity-resolution.test.js +49 -0
  16. package/dist/__tests__/fec-entity-resolution.test.js.map +1 -0
  17. package/dist/bioguide-fec-mapping.d.ts +27 -0
  18. package/dist/bioguide-fec-mapping.d.ts.map +1 -0
  19. package/dist/bioguide-fec-mapping.js +57 -0
  20. package/dist/bioguide-fec-mapping.js.map +1 -0
  21. package/dist/cache.d.ts +18 -0
  22. package/dist/cache.d.ts.map +1 -0
  23. package/dist/cache.js +18 -0
  24. package/dist/cache.js.map +1 -0
  25. package/dist/committee-agency-map.d.ts +58 -0
  26. package/dist/committee-agency-map.d.ts.map +1 -0
  27. package/dist/committee-agency-map.js +658 -0
  28. package/dist/committee-agency-map.js.map +1 -0
  29. package/dist/committee-alias-table.d.ts +11 -0
  30. package/dist/committee-alias-table.d.ts.map +1 -0
  31. package/dist/committee-alias-table.js +191 -0
  32. package/dist/committee-alias-table.js.map +1 -0
  33. package/dist/company-alias-table.d.ts +36 -0
  34. package/dist/company-alias-table.d.ts.map +1 -0
  35. package/dist/company-alias-table.js +1307 -0
  36. package/dist/company-alias-table.js.map +1 -0
  37. package/dist/company-entity-resolver.d.ts +94 -0
  38. package/dist/company-entity-resolver.d.ts.map +1 -0
  39. package/dist/company-entity-resolver.js +282 -0
  40. package/dist/company-entity-resolver.js.map +1 -0
  41. package/dist/configure.d.ts +15 -0
  42. package/dist/configure.d.ts.map +1 -0
  43. package/dist/configure.js +19 -0
  44. package/dist/configure.js.map +1 -0
  45. package/dist/fec-entity-resolution.d.ts +88 -0
  46. package/dist/fec-entity-resolution.d.ts.map +1 -0
  47. package/dist/fec-entity-resolution.js +407 -0
  48. package/dist/fec-entity-resolution.js.map +1 -0
  49. package/dist/index.d.ts +30 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +33 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/industry-taxonomy.d.ts +90 -0
  54. package/dist/industry-taxonomy.d.ts.map +1 -0
  55. package/dist/industry-taxonomy.js +1026 -0
  56. package/dist/industry-taxonomy.js.map +1 -0
  57. package/dist/lda-issue-policy-map.d.ts +13 -0
  58. package/dist/lda-issue-policy-map.d.ts.map +1 -0
  59. package/dist/lda-issue-policy-map.js +193 -0
  60. package/dist/lda-issue-policy-map.js.map +1 -0
  61. package/dist/lobbying-committee-resolver.d.ts +23 -0
  62. package/dist/lobbying-committee-resolver.d.ts.map +1 -0
  63. package/dist/lobbying-committee-resolver.js +158 -0
  64. package/dist/lobbying-committee-resolver.js.map +1 -0
  65. package/dist/logger.d.ts +20 -0
  66. package/dist/logger.d.ts.map +1 -0
  67. package/dist/logger.js +20 -0
  68. package/dist/logger.js.map +1 -0
  69. package/dist/sic-sector-map.d.ts +32 -0
  70. package/dist/sic-sector-map.d.ts.map +1 -0
  71. package/dist/sic-sector-map.js +109 -0
  72. package/dist/sic-sector-map.js.map +1 -0
  73. package/dist/ticker-industry-resolver.d.ts +22 -0
  74. package/dist/ticker-industry-resolver.d.ts.map +1 -0
  75. package/dist/ticker-industry-resolver.js +254 -0
  76. package/dist/ticker-industry-resolver.js.map +1 -0
  77. package/dist/types.d.ts +30 -0
  78. package/dist/types.d.ts.map +1 -0
  79. package/dist/types.js +6 -0
  80. package/dist/types.js.map +1 -0
  81. package/package.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-2025 Mark Sandford
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # @civiq/entity-resolution
2
+
3
+ Entity resolution for civic data — committee/agency alias matching, industry taxonomy, ticker-to-sector resolution, FEC entity deduplication.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @civiq/entity-resolution
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import {
15
+ configure,
16
+ categorizeContribution,
17
+ resolveGovernmentEntity,
18
+ resolveTickerIndustry,
19
+ deduplicateContributions,
20
+ } from '@civiq/entity-resolution';
21
+
22
+ // Optional: provide your own logger and cache
23
+ configure({
24
+ logger: myLogger,
25
+ cache: myRedisAdapter,
26
+ });
27
+
28
+ // Categorize a campaign contribution by employer/occupation
29
+ const result = categorizeContribution('Goldman Sachs', 'Investment Banker');
30
+ // { sector: 'Finance/Insurance/Real Estate', category: 'Commercial Banks', confidence: 'high', ... }
31
+
32
+ // Resolve LDA government_entities to committees/agencies
33
+ const entity = resolveGovernmentEntity('Senate Committee on Finance');
34
+ // { type: 'committee', committeeCode: 'SSFI', committeeName: 'Finance', confidence: 1.0, ... }
35
+
36
+ // Resolve stock ticker to industry sector (async, uses SEC EDGAR)
37
+ const ticker = await resolveTickerIndustry('AAPL');
38
+ // { sector: 'Communications/Electronics', sicCode: '3571', confidence: 1.0 }
39
+
40
+ // Deduplicate FEC contributions by entity
41
+ const unique = deduplicateContributions(rawContributions);
42
+ ```
43
+
44
+ ## Subpath Exports
45
+
46
+ ```typescript
47
+ // Just the industry taxonomy
48
+ import { IndustrySector, categorizeContribution } from '@civiq/entity-resolution/industry-taxonomy';
49
+
50
+ // Just the committee-agency mapping
51
+ import {
52
+ ALL_COMMITTEE_MAPPINGS,
53
+ getAgenciesForCommittee,
54
+ } from '@civiq/entity-resolution/committee-agency-map';
55
+ ```
56
+
57
+ ## Configuration
58
+
59
+ By default, the package uses no-op logger and no-op cache. For production use, call `configure()` once at startup:
60
+
61
+ ```typescript
62
+ import { configure } from '@civiq/entity-resolution';
63
+
64
+ configure({
65
+ logger: {
66
+ debug: console.log,
67
+ info: console.log,
68
+ warn: console.warn,
69
+ error: console.error,
70
+ },
71
+ cache: {
72
+ get: async key => redis.get(key),
73
+ set: async (key, value, ttl) => redis.set(key, value, 'EX', ttl),
74
+ },
75
+ });
76
+ ```
77
+
78
+ ## API Reference
79
+
80
+ ### Industry Taxonomy
81
+
82
+ - `categorizeContribution(employer?, occupation?)` — Classify by employer/occupation keywords
83
+ - `categorizePACByName(name?)` — Classify PAC/committee by name
84
+ - `categorizeContributionSmart(employer?, occupation?, name?)` — Try all methods
85
+ - `aggregateByIndustrySector(contributions)` — Aggregate contributions by sector
86
+ - `getTopCategories(contributions, limit?)` — Top categories across sectors
87
+
88
+ ### Committee-Agency Map
89
+
90
+ - `getAgenciesForCommittee(name)` — Agencies a committee oversees
91
+ - `getCommitteesForAgency(slug)` — Committees that oversee an agency
92
+ - `getTopicsForCommittee(name)` — Topics for a committee
93
+ - `ALL_COMMITTEE_MAPPINGS` — All 29 committee mappings
94
+
95
+ ### Lobbying Resolution
96
+
97
+ - `resolveGovernmentEntity(entity)` — 3-tier resolution (noise/exact/fuzzy)
98
+ - `resolveFilingEntities(entities)` — Batch resolution
99
+ - `getResolvedCommittees(resolutions)` — Extract committee codes
100
+
101
+ ### Ticker Resolution
102
+
103
+ - `resolveTickerIndustry(ticker)` — Ticker to IndustrySector via SEC EDGAR
104
+
105
+ ### SIC Mapping
106
+
107
+ - `sicToSector(sicCode)` — SIC code to IndustrySector
108
+
109
+ ### LDA Issue Mapping
110
+
111
+ - `getLDAIssueLabel(code)` — Human-readable label
112
+ - `getPolicyAreasForLDAIssue(code)` — Congress.gov policyArea strings
113
+
114
+ ### FEC Entity Resolution
115
+
116
+ - `deduplicateContributions(contributions)` — Merge name variants
117
+ - `deduplicateDisbursements(disbursements)` — Merge recipients
118
+ - `entitiesMatch(entity1, entity2, threshold?)` — Levenshtein similarity
119
+
120
+ ### Bioguide-FEC Mapping
121
+
122
+ - `getFECIdFromBioguide(id)` — Bioguide ID to FEC candidate ID
123
+ - `getBioguideFromFEC(id)` — Reverse lookup
124
+
125
+ ## Data Sources
126
+
127
+ - FEC.gov — Contributor employer/occupation, PAC names
128
+ - Senate LDA API — Lobbying government entities, issue codes
129
+ - SEC EDGAR — Company tickers, SIC codes
130
+ - Congress.gov — Bill policy areas, committee assignments
131
+ - OpenSecrets — 13-sector classification model (inspiration)
132
+
133
+ ## License
134
+
135
+ MIT - Mark Sandford