@willwade/aac-processors 0.1.7 → 0.1.9

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 (39) hide show
  1. package/dist/analytics.d.ts +7 -0
  2. package/dist/analytics.js +23 -0
  3. package/dist/browser/index.browser.js +5 -0
  4. package/dist/browser/metrics.js +17 -0
  5. package/dist/browser/processors/gridset/helpers.js +390 -0
  6. package/dist/browser/processors/gridset/pluginTypes.js +1 -0
  7. package/dist/browser/processors/gridsetProcessor.js +68 -1
  8. package/dist/browser/processors/obfProcessor.js +21 -13
  9. package/dist/browser/processors/snap/helpers.js +252 -0
  10. package/dist/browser/utilities/analytics/history.js +116 -0
  11. package/dist/browser/utilities/analytics/metrics/comparison.js +477 -0
  12. package/dist/browser/utilities/analytics/metrics/core.js +775 -0
  13. package/dist/browser/utilities/analytics/metrics/effort.js +221 -0
  14. package/dist/browser/utilities/analytics/metrics/obl-types.js +6 -0
  15. package/dist/browser/utilities/analytics/metrics/obl.js +282 -0
  16. package/dist/browser/utilities/analytics/metrics/sentence.js +121 -0
  17. package/dist/browser/utilities/analytics/metrics/types.js +6 -0
  18. package/dist/browser/utilities/analytics/metrics/vocabulary.js +138 -0
  19. package/dist/browser/utilities/analytics/reference/browser.js +67 -0
  20. package/dist/browser/utilities/analytics/reference/index.js +129 -0
  21. package/dist/browser/utils/dotnetTicks.js +17 -0
  22. package/dist/index.browser.d.ts +1 -0
  23. package/dist/index.browser.js +18 -1
  24. package/dist/index.node.d.ts +2 -2
  25. package/dist/index.node.js +5 -5
  26. package/dist/metrics.d.ts +17 -0
  27. package/dist/metrics.js +44 -0
  28. package/dist/processors/gridset/pluginTypes.d.ts +1 -0
  29. package/dist/processors/gridset/pluginTypes.js +1 -0
  30. package/dist/processors/gridsetProcessor.js +68 -1
  31. package/dist/processors/obfProcessor.js +21 -13
  32. package/dist/utilities/analytics/metrics/comparison.d.ts +2 -1
  33. package/dist/utilities/analytics/metrics/comparison.js +3 -3
  34. package/dist/utilities/analytics/metrics/vocabulary.d.ts +2 -2
  35. package/dist/utilities/analytics/reference/browser.d.ts +31 -0
  36. package/dist/utilities/analytics/reference/browser.js +73 -0
  37. package/dist/utilities/analytics/reference/index.d.ts +21 -0
  38. package/dist/utilities/analytics/reference/index.js +22 -46
  39. package/package.json +9 -1
@@ -5,12 +5,13 @@
5
5
  * analyze vocabulary differences, and generate CARE component scores.
6
6
  */
7
7
  import { MetricsResult, ComparisonResult } from './types';
8
+ import { type ReferenceDataProvider } from '../reference/index';
8
9
  import { MetricsOptions } from './types';
9
10
  export declare class ComparisonAnalyzer {
10
11
  private vocabAnalyzer;
11
12
  private sentenceAnalyzer;
12
13
  private referenceLoader;
13
- constructor();
14
+ constructor(referenceLoader?: ReferenceDataProvider);
14
15
  private normalize;
15
16
  /**
16
17
  * Compare two board sets
@@ -12,10 +12,10 @@ const vocabulary_1 = require("./vocabulary");
12
12
  const index_1 = require("../reference/index");
13
13
  const effort_1 = require("./effort");
14
14
  class ComparisonAnalyzer {
15
- constructor() {
16
- this.vocabAnalyzer = new vocabulary_1.VocabularyAnalyzer();
15
+ constructor(referenceLoader) {
16
+ this.vocabAnalyzer = new vocabulary_1.VocabularyAnalyzer(referenceLoader);
17
17
  this.sentenceAnalyzer = new sentence_1.SentenceAnalyzer();
18
- this.referenceLoader = new index_1.ReferenceLoader();
18
+ this.referenceLoader = referenceLoader || new index_1.ReferenceLoader();
19
19
  }
20
20
  normalize(word) {
21
21
  return word
@@ -5,7 +5,7 @@
5
5
  * and identifies missing/extra words compared to reference lists.
6
6
  */
7
7
  import { MetricsResult } from './types';
8
- import { ReferenceLoader } from '../reference/index';
8
+ import { type ReferenceDataProvider } from '../reference/index';
9
9
  export interface VocabularyAnalysis {
10
10
  core_coverage: {
11
11
  [listId: string]: {
@@ -33,7 +33,7 @@ export interface VocabularyAnalysis {
33
33
  }
34
34
  export declare class VocabularyAnalyzer {
35
35
  private referenceLoader;
36
- constructor(referenceLoader?: ReferenceLoader);
36
+ constructor(referenceLoader?: ReferenceDataProvider);
37
37
  /**
38
38
  * Analyze vocabulary coverage against core lists
39
39
  */
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Browser-friendly reference data loader using fetch.
3
+ */
4
+ import type { CoreList, CommonWordsData, SynonymsData } from '../metrics/types';
5
+ import type { ReferenceDataProvider } from './index';
6
+ export interface ReferenceData {
7
+ coreLists: CoreList[];
8
+ commonWords: CommonWordsData;
9
+ synonyms: SynonymsData;
10
+ sentences: string[][];
11
+ fringe: string[];
12
+ baseWords: {
13
+ [word: string]: boolean;
14
+ };
15
+ }
16
+ export declare class InMemoryReferenceLoader implements ReferenceDataProvider {
17
+ private data;
18
+ constructor(data: ReferenceData);
19
+ loadCoreLists(): CoreList[];
20
+ loadCommonWords(): CommonWordsData;
21
+ loadSynonyms(): SynonymsData;
22
+ loadSentences(): string[][];
23
+ loadFringe(): string[];
24
+ loadBaseWords(): {
25
+ [word: string]: boolean;
26
+ };
27
+ loadCommonFringe(): string[];
28
+ loadAll(): ReferenceData;
29
+ }
30
+ export declare function loadReferenceDataFromUrl(baseUrl: string, locale?: string): Promise<ReferenceData>;
31
+ export declare function createBrowserReferenceLoader(baseUrl: string, locale?: string): Promise<InMemoryReferenceLoader>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Browser-friendly reference data loader using fetch.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InMemoryReferenceLoader = void 0;
7
+ exports.loadReferenceDataFromUrl = loadReferenceDataFromUrl;
8
+ exports.createBrowserReferenceLoader = createBrowserReferenceLoader;
9
+ class InMemoryReferenceLoader {
10
+ constructor(data) {
11
+ this.data = data;
12
+ }
13
+ loadCoreLists() {
14
+ return this.data.coreLists;
15
+ }
16
+ loadCommonWords() {
17
+ return this.data.commonWords;
18
+ }
19
+ loadSynonyms() {
20
+ return this.data.synonyms;
21
+ }
22
+ loadSentences() {
23
+ return this.data.sentences;
24
+ }
25
+ loadFringe() {
26
+ return this.data.fringe;
27
+ }
28
+ loadBaseWords() {
29
+ return this.data.baseWords;
30
+ }
31
+ loadCommonFringe() {
32
+ const commonWords = new Set(this.data.commonWords.words.map((w) => w.toLowerCase()));
33
+ const coreWords = new Set();
34
+ this.data.coreLists.forEach((list) => {
35
+ list.words.forEach((word) => coreWords.add(word.toLowerCase()));
36
+ });
37
+ return Array.from(commonWords).filter((word) => !coreWords.has(word));
38
+ }
39
+ loadAll() {
40
+ return this.data;
41
+ }
42
+ }
43
+ exports.InMemoryReferenceLoader = InMemoryReferenceLoader;
44
+ async function loadReferenceDataFromUrl(baseUrl, locale = 'en') {
45
+ const root = baseUrl.replace(/\/$/, '');
46
+ const fetchJson = async (name) => {
47
+ const res = await fetch(`${root}/${name}.${locale}.json`);
48
+ if (!res.ok) {
49
+ throw new Error(`Failed to load ${name}.${locale}.json`);
50
+ }
51
+ return (await res.json());
52
+ };
53
+ const [coreLists, commonWords, synonyms, sentences, fringe, baseWords] = await Promise.all([
54
+ fetchJson('core_lists'),
55
+ fetchJson('common_words'),
56
+ fetchJson('synonyms'),
57
+ fetchJson('sentences'),
58
+ fetchJson('fringe'),
59
+ fetchJson('base_words'),
60
+ ]);
61
+ return {
62
+ coreLists,
63
+ commonWords,
64
+ synonyms,
65
+ sentences,
66
+ fringe,
67
+ baseWords,
68
+ };
69
+ }
70
+ async function createBrowserReferenceLoader(baseUrl, locale = 'en') {
71
+ const data = await loadReferenceDataFromUrl(baseUrl, locale);
72
+ return new InMemoryReferenceLoader(data);
73
+ }
@@ -5,6 +5,27 @@
5
5
  * for AAC metrics analysis.
6
6
  */
7
7
  import { CoreList, CommonWordsData, SynonymsData } from '../metrics/types';
8
+ export interface ReferenceDataProvider {
9
+ loadCoreLists(): CoreList[];
10
+ loadCommonWords(): CommonWordsData;
11
+ loadSynonyms(): SynonymsData;
12
+ loadSentences(): string[][];
13
+ loadFringe(): string[];
14
+ loadBaseWords(): {
15
+ [word: string]: boolean;
16
+ };
17
+ loadCommonFringe(): string[];
18
+ loadAll(): {
19
+ coreLists: CoreList[];
20
+ commonWords: CommonWordsData;
21
+ synonyms: SynonymsData;
22
+ sentences: string[][];
23
+ fringe: string[];
24
+ baseWords: {
25
+ [word: string]: boolean;
26
+ };
27
+ };
28
+ }
8
29
  export declare class ReferenceLoader {
9
30
  private dataDir;
10
31
  private locale;
@@ -5,35 +5,11 @@
5
5
  * Loads reference vocabulary lists, core lists, and sentences
6
6
  * for AAC metrics analysis.
7
7
  */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
8
  Object.defineProperty(exports, "__esModule", { value: true });
32
9
  exports.ReferenceLoader = void 0;
33
10
  exports.getReferenceDataPath = getReferenceDataPath;
34
11
  exports.hasReferenceData = hasReferenceData;
35
- const fs = __importStar(require("fs"));
36
- const path = __importStar(require("path"));
12
+ const io_1 = require("../../../utils/io");
37
13
  class ReferenceLoader {
38
14
  constructor(dataDir, locale = 'en') {
39
15
  this.locale = locale;
@@ -43,48 +19,48 @@ class ReferenceLoader {
43
19
  else {
44
20
  // Resolve the data directory relative to this file's location
45
21
  // Use __dirname which works correctly after compilation
46
- this.dataDir = path.join(__dirname, 'data');
22
+ this.dataDir = (0, io_1.getPath)().join(__dirname, 'data');
47
23
  }
48
24
  }
49
25
  /**
50
26
  * Load core vocabulary lists
51
27
  */
52
28
  loadCoreLists() {
53
- const filePath = path.join(this.dataDir, `core_lists.${this.locale}.json`);
54
- const content = fs.readFileSync(filePath, 'utf-8');
55
- return JSON.parse(content);
29
+ const filePath = (0, io_1.getPath)().join(this.dataDir, `core_lists.${this.locale}.json`);
30
+ const content = (0, io_1.getFs)().readFileSync(filePath, 'utf-8');
31
+ return JSON.parse(String(content));
56
32
  }
57
33
  /**
58
34
  * Load common words with baseline effort scores
59
35
  */
60
36
  loadCommonWords() {
61
- const filePath = path.join(this.dataDir, `common_words.${this.locale}.json`);
62
- const content = fs.readFileSync(filePath, 'utf-8');
63
- return JSON.parse(content);
37
+ const filePath = (0, io_1.getPath)().join(this.dataDir, `common_words.${this.locale}.json`);
38
+ const content = (0, io_1.getFs)().readFileSync(filePath, 'utf-8');
39
+ return JSON.parse(String(content));
64
40
  }
65
41
  /**
66
42
  * Load synonym mappings
67
43
  */
68
44
  loadSynonyms() {
69
- const filePath = path.join(this.dataDir, `synonyms.${this.locale}.json`);
70
- const content = fs.readFileSync(filePath, 'utf-8');
71
- return JSON.parse(content);
45
+ const filePath = (0, io_1.getPath)().join(this.dataDir, `synonyms.${this.locale}.json`);
46
+ const content = (0, io_1.getFs)().readFileSync(filePath, 'utf-8');
47
+ return JSON.parse(String(content));
72
48
  }
73
49
  /**
74
50
  * Load test sentences
75
51
  */
76
52
  loadSentences() {
77
- const filePath = path.join(this.dataDir, `sentences.${this.locale}.json`);
78
- const content = fs.readFileSync(filePath, 'utf-8');
79
- return JSON.parse(content);
53
+ const filePath = (0, io_1.getPath)().join(this.dataDir, `sentences.${this.locale}.json`);
54
+ const content = (0, io_1.getFs)().readFileSync(filePath, 'utf-8');
55
+ return JSON.parse(String(content));
80
56
  }
81
57
  /**
82
58
  * Load fringe vocabulary
83
59
  */
84
60
  loadFringe() {
85
- const filePath = path.join(this.dataDir, `fringe.${this.locale}.json`);
86
- const content = fs.readFileSync(filePath, 'utf-8');
87
- const data = JSON.parse(content);
61
+ const filePath = (0, io_1.getPath)().join(this.dataDir, `fringe.${this.locale}.json`);
62
+ const content = (0, io_1.getFs)().readFileSync(filePath, 'utf-8');
63
+ const data = JSON.parse(String(content));
88
64
  // Flatten nested category words if needed
89
65
  if (Array.isArray(data) && data.length > 0 && data[0].categories) {
90
66
  const flattened = [];
@@ -101,9 +77,9 @@ class ReferenceLoader {
101
77
  * Load base words hash map
102
78
  */
103
79
  loadBaseWords() {
104
- const filePath = path.join(this.dataDir, `base_words.${this.locale}.json`);
105
- const content = fs.readFileSync(filePath, 'utf-8');
106
- return JSON.parse(content);
80
+ const filePath = (0, io_1.getPath)().join(this.dataDir, `base_words.${this.locale}.json`);
81
+ const content = (0, io_1.getFs)().readFileSync(filePath, 'utf-8');
82
+ return JSON.parse(String(content));
107
83
  }
108
84
  /**
109
85
  * Load common fringe vocabulary
@@ -141,7 +117,7 @@ exports.ReferenceLoader = ReferenceLoader;
141
117
  * Get the default reference data path
142
118
  */
143
119
  function getReferenceDataPath() {
144
- return path.join(__dirname, 'data');
120
+ return String((0, io_1.getPath)().join(__dirname, 'data'));
145
121
  }
146
122
  /**
147
123
  * Check if reference data files exist
@@ -155,5 +131,5 @@ function hasReferenceData() {
155
131
  'synonyms.en.json',
156
132
  'fringe.en.json',
157
133
  ];
158
- return requiredFiles.every((file) => fs.existsSync(path.join(dataPath, file)));
134
+ return requiredFiles.every((file) => (0, io_1.getFs)().existsSync((0, io_1.getPath)().join(dataPath, file)));
159
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willwade/aac-processors",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "A comprehensive TypeScript library for processing AAC (Augmentative and Alternative Communication) file formats with translation support",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/browser/index.browser.js",
@@ -67,6 +67,14 @@
67
67
  "./validation": {
68
68
  "types": "./dist/validation.d.ts",
69
69
  "default": "./dist/validation.js"
70
+ },
71
+ "./metrics": {
72
+ "types": "./dist/metrics.d.ts",
73
+ "default": "./dist/metrics.js"
74
+ },
75
+ "./analytics": {
76
+ "types": "./dist/analytics.d.ts",
77
+ "default": "./dist/analytics.js"
70
78
  }
71
79
  },
72
80
  "files": [