-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
307 additions
and
162 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
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
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
69 changes: 69 additions & 0 deletions
69
packages/aila/src/features/americanisms/AilaAmericanisms.ts
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,69 @@ | ||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference | ||
/// <reference path="./american-british-english-translator.d.ts" /> | ||
import { textify } from "@oakai/core/src/models/lessonPlans"; | ||
import translator from "american-british-english-translator"; | ||
|
||
import type { AilaAmericanismsFeature } from "."; | ||
import type { | ||
AmericanismIssue, | ||
AmericanismIssueBySection, | ||
} from "../../features/americanisms"; | ||
import type { LessonPlanKeys, LooseLessonPlan } from "../../protocol/schema"; | ||
|
||
export type TranslationResult = Record< | ||
string, | ||
Array<{ [phrase: string]: { issue: string; details: string } }> | ||
>; | ||
|
||
export class AilaAmericanisms implements AilaAmericanismsFeature { | ||
private findSectionAmericanisms( | ||
section: LessonPlanKeys, | ||
lessonPlan: LooseLessonPlan, | ||
): AmericanismIssueBySection | undefined { | ||
const filterOutPhrases = new Set([ | ||
"practice", | ||
"practices", | ||
"gas", | ||
"gases", | ||
"period", | ||
"periods", | ||
"fall", | ||
"falls", | ||
]); | ||
|
||
const sectionContent = lessonPlan[section]; | ||
if (!sectionContent) return; | ||
|
||
const sectionText = textify(sectionContent); | ||
const sectionAmericanismScan: TranslationResult = translator.translate( | ||
sectionText, | ||
{ american: true }, | ||
); | ||
|
||
const issues: AmericanismIssue[] = []; | ||
Object.values(sectionAmericanismScan).forEach((lineIssues) => { | ||
lineIssues.forEach((lineIssue) => { | ||
const [phrase, issueDefinition] = Object.entries(lineIssue)[0] ?? []; | ||
if (phrase && issueDefinition && !filterOutPhrases.has(phrase)) { | ||
if (!issues.some((issue) => issue.phrase === phrase)) { | ||
issues.push({ phrase, ...issueDefinition }); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
return { section, issues }; | ||
} | ||
|
||
public findAmericanisms(lessonPlan: LooseLessonPlan) { | ||
return Object.keys(lessonPlan).flatMap((section) => { | ||
const sectionIssues = this.findSectionAmericanisms( | ||
section as LessonPlanKeys, | ||
lessonPlan, | ||
); | ||
return sectionIssues && sectionIssues.issues.length > 0 | ||
? [sectionIssues] | ||
: []; | ||
}); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/aila/src/features/americanisms/NullAilaAmericanisms.ts
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,7 @@ | ||
import type { AilaAmericanismsFeature } from "."; | ||
|
||
export class NullAilaAmericanisms implements AilaAmericanismsFeature { | ||
public findAmericanisms() { | ||
return []; | ||
} | ||
} |
File renamed without changes.
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,16 @@ | ||
import type { LooseLessonPlan } from "../../protocol/schema"; | ||
|
||
export type AmericanismIssueBySection = { | ||
section: string; | ||
issues: AmericanismIssue[]; | ||
}; | ||
|
||
export type AmericanismIssue = { | ||
phrase: string; | ||
issue?: string; | ||
details?: string; | ||
}; | ||
|
||
export interface AilaAmericanismsFeature { | ||
findAmericanisms(lessonPlan: LooseLessonPlan): AmericanismIssueBySection[]; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/aila/src/features/analytics/adapters/AnalyticsAdapter.ts
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
Oops, something went wrong.