-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switching bill topic format per dev feedback, extracting topic parser for later use, adding unit tests for topic parser * Prettier fixes
- Loading branch information
Showing
6 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { assignCategoriesToTopics } from "./topicParser" | ||
|
||
describe("assignCategoriesToTopics", () => { | ||
it("assigns categories to topics", () => { | ||
const topics = [ | ||
"Consumer protection", | ||
"Correctional facilities", | ||
"Property crimes" | ||
] | ||
const categories = assignCategoriesToTopics(topics) | ||
expect(categories).toEqual([ | ||
{ category: "Commerce", topic: "Consumer protection" }, | ||
{ | ||
category: "Crime and Law Enforcement", | ||
topic: "Correctional facilities" | ||
}, | ||
{ category: "Crime and Law Enforcement", topic: "Property crimes" } | ||
]) | ||
}) | ||
|
||
it("ignores topics with missing categories", () => { | ||
const topics = ["Consumer protection", "Unknown topic"] | ||
const categories = assignCategoriesToTopics(topics) | ||
expect(categories).toEqual([ | ||
{ category: "Commerce", topic: "Consumer protection" } | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BillTopic, CATEGORIES_BY_TOPIC } from "./types" | ||
|
||
// The ML model will return a list of topics without categories | ||
// We need to enrich the topics with the associated topic categories for the hierachical facets | ||
export const assignCategoriesToTopics = (billTopics: string[]) => { | ||
return billTopics.reduce((acc, topic) => { | ||
const category = CATEGORIES_BY_TOPIC[topic] | ||
if (category) { | ||
acc.push({ category, topic }) | ||
} else { | ||
console.error(`No category found for topic ${topic}`) | ||
} | ||
return acc | ||
}, [] as BillTopic[]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters