learngraph 0.1.1 → 0.2.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 (96) hide show
  1. package/LICENSE +190 -21
  2. package/README.md +83 -2
  3. package/dist/cjs/parsers/base.js +189 -0
  4. package/dist/cjs/parsers/base.js.map +1 -0
  5. package/dist/cjs/parsers/demo.js +159 -0
  6. package/dist/cjs/parsers/demo.js.map +1 -0
  7. package/dist/cjs/parsers/extractor.js +191 -0
  8. package/dist/cjs/parsers/extractor.js.map +1 -0
  9. package/dist/cjs/parsers/index.js +43 -4
  10. package/dist/cjs/parsers/index.js.map +1 -1
  11. package/dist/cjs/parsers/json.js +157 -0
  12. package/dist/cjs/parsers/json.js.map +1 -0
  13. package/dist/cjs/parsers/markdown.js +168 -0
  14. package/dist/cjs/parsers/markdown.js.map +1 -0
  15. package/dist/cjs/parsers/samples.js +139 -0
  16. package/dist/cjs/parsers/samples.js.map +1 -0
  17. package/dist/cjs/storage/base.js +231 -0
  18. package/dist/cjs/storage/base.js.map +1 -0
  19. package/dist/cjs/storage/errors.js +128 -0
  20. package/dist/cjs/storage/errors.js.map +1 -0
  21. package/dist/cjs/storage/index.js +92 -5
  22. package/dist/cjs/storage/index.js.map +1 -1
  23. package/dist/cjs/storage/levelgraph.js +855 -0
  24. package/dist/cjs/storage/levelgraph.js.map +1 -0
  25. package/dist/cjs/storage/memory.js +447 -0
  26. package/dist/cjs/storage/memory.js.map +1 -0
  27. package/dist/cjs/storage/neo4j.js +866 -0
  28. package/dist/cjs/storage/neo4j.js.map +1 -0
  29. package/dist/cjs/storage/seeds.js +565 -0
  30. package/dist/cjs/storage/seeds.js.map +1 -0
  31. package/dist/cjs/types/parser.js +8 -0
  32. package/dist/cjs/types/parser.js.map +1 -0
  33. package/dist/esm/parsers/base.js +179 -0
  34. package/dist/esm/parsers/base.js.map +1 -0
  35. package/dist/esm/parsers/demo.js +154 -0
  36. package/dist/esm/parsers/demo.js.map +1 -0
  37. package/dist/esm/parsers/extractor.js +187 -0
  38. package/dist/esm/parsers/extractor.js.map +1 -0
  39. package/dist/esm/parsers/index.js +24 -5
  40. package/dist/esm/parsers/index.js.map +1 -1
  41. package/dist/esm/parsers/json.js +153 -0
  42. package/dist/esm/parsers/json.js.map +1 -0
  43. package/dist/esm/parsers/markdown.js +164 -0
  44. package/dist/esm/parsers/markdown.js.map +1 -0
  45. package/dist/esm/parsers/samples.js +136 -0
  46. package/dist/esm/parsers/samples.js.map +1 -0
  47. package/dist/esm/storage/base.js +221 -0
  48. package/dist/esm/storage/base.js.map +1 -0
  49. package/dist/esm/storage/errors.js +116 -0
  50. package/dist/esm/storage/errors.js.map +1 -0
  51. package/dist/esm/storage/index.js +71 -6
  52. package/dist/esm/storage/index.js.map +1 -1
  53. package/dist/esm/storage/levelgraph.js +818 -0
  54. package/dist/esm/storage/levelgraph.js.map +1 -0
  55. package/dist/esm/storage/memory.js +443 -0
  56. package/dist/esm/storage/memory.js.map +1 -0
  57. package/dist/esm/storage/neo4j.js +829 -0
  58. package/dist/esm/storage/neo4j.js.map +1 -0
  59. package/dist/esm/storage/seeds.js +561 -0
  60. package/dist/esm/storage/seeds.js.map +1 -0
  61. package/dist/esm/types/parser.js +7 -0
  62. package/dist/esm/types/parser.js.map +1 -0
  63. package/dist/types/parsers/base.d.ts +39 -0
  64. package/dist/types/parsers/base.d.ts.map +1 -0
  65. package/dist/types/parsers/demo.d.ts +87 -0
  66. package/dist/types/parsers/demo.d.ts.map +1 -0
  67. package/dist/types/parsers/extractor.d.ts +43 -0
  68. package/dist/types/parsers/extractor.d.ts.map +1 -0
  69. package/dist/types/parsers/index.d.ts +10 -0
  70. package/dist/types/parsers/index.d.ts.map +1 -1
  71. package/dist/types/parsers/json.d.ts +71 -0
  72. package/dist/types/parsers/json.d.ts.map +1 -0
  73. package/dist/types/parsers/markdown.d.ts +43 -0
  74. package/dist/types/parsers/markdown.d.ts.map +1 -0
  75. package/dist/types/parsers/samples.d.ts +27 -0
  76. package/dist/types/parsers/samples.d.ts.map +1 -0
  77. package/dist/types/storage/base.d.ts +39 -0
  78. package/dist/types/storage/base.d.ts.map +1 -0
  79. package/dist/types/storage/errors.d.ts +74 -0
  80. package/dist/types/storage/errors.d.ts.map +1 -0
  81. package/dist/types/storage/index.d.ts +50 -2
  82. package/dist/types/storage/index.d.ts.map +1 -1
  83. package/dist/types/storage/levelgraph.d.ts +92 -0
  84. package/dist/types/storage/levelgraph.d.ts.map +1 -0
  85. package/dist/types/storage/memory.d.ts +70 -0
  86. package/dist/types/storage/memory.d.ts.map +1 -0
  87. package/dist/types/storage/neo4j.d.ts +88 -0
  88. package/dist/types/storage/neo4j.d.ts.map +1 -0
  89. package/dist/types/storage/seeds.d.ts +27 -0
  90. package/dist/types/storage/seeds.d.ts.map +1 -0
  91. package/dist/types/types/index.d.ts +1 -0
  92. package/dist/types/types/index.d.ts.map +1 -1
  93. package/dist/types/types/parser.d.ts +208 -0
  94. package/dist/types/types/parser.d.ts.map +1 -0
  95. package/package.json +4 -2
  96. package/scripts/postinstall.js +68 -0
package/LICENSE CHANGED
@@ -1,21 +1,190 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 LearnGraph Team
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.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 LearnGraph Team
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -76,14 +76,94 @@ LearnGraph is built on decades of peer-reviewed educational psychology research:
76
76
  | **Spaced Repetition** | Memory consolidation optimization | Long-term retention |
77
77
  | **Cognitive Load Theory** | Working memory management | Prevents overwhelm |
78
78
 
79
+ ## Storage Adapters
80
+
81
+ LearnGraph supports multiple storage backends. Use the one that fits your needs:
82
+
83
+ ### In-Memory Storage (Built-in)
84
+
85
+ Perfect for testing, prototyping, and serverless functions:
86
+
87
+ ```typescript
88
+ import { MemoryStorage } from 'learngraph/storage';
89
+
90
+ const storage = new MemoryStorage();
91
+ await storage.connect({ backend: 'memory' });
92
+
93
+ // Create a skill
94
+ const skill = await storage.createSkill({
95
+ name: 'Add Fractions',
96
+ description: 'Add fractions with like denominators',
97
+ bloomLevel: 'apply',
98
+ difficulty: 0.4,
99
+ isThresholdConcept: false,
100
+ masteryThreshold: 0.8,
101
+ estimatedMinutes: 30,
102
+ tags: ['math', 'fractions'],
103
+ metadata: {}
104
+ });
105
+
106
+ // Create prerequisite relationships
107
+ await storage.createPrerequisite({
108
+ sourceId: basicMathSkill.id,
109
+ targetId: skill.id,
110
+ strength: 0.9,
111
+ type: 'hard',
112
+ metadata: {}
113
+ });
114
+
115
+ // Query the graph
116
+ const prerequisites = await storage.getPrerequisitesOf(skill.id);
117
+ const stats = await storage.getStats();
118
+ ```
119
+
120
+ ### LevelGraph Storage (Embedded)
121
+
122
+ For persistent, file-based storage without external databases:
123
+
124
+ ```bash
125
+ npm install level levelgraph
126
+ ```
127
+
128
+ ```typescript
129
+ import { LevelGraphStorage } from 'learngraph/storage';
130
+
131
+ const storage = new LevelGraphStorage();
132
+ await storage.connect({
133
+ backend: 'levelgraph',
134
+ path: './data/learngraph'
135
+ });
136
+ ```
137
+
138
+ ### Neo4j Storage (Production)
139
+
140
+ For production deployments with full graph database capabilities:
141
+
142
+ ```bash
143
+ npm install neo4j-driver
144
+ ```
145
+
146
+ ```typescript
147
+ import { Neo4jStorage } from 'learngraph/storage';
148
+
149
+ const storage = new Neo4jStorage();
150
+ await storage.connect({
151
+ backend: 'neo4j',
152
+ uri: 'bolt://localhost:7687',
153
+ username: 'neo4j',
154
+ password: 'password',
155
+ database: 'learngraph'
156
+ });
157
+ ```
158
+
79
159
  ## Submodule Exports
80
160
 
81
161
  ```typescript
82
162
  // Core types and utilities
83
163
  import { SkillNode, SkillEdge } from 'learngraph';
84
164
 
85
- // Storage adapters (Neo4j, LevelGraph)
86
- import { GraphStorage } from 'learngraph/storage';
165
+ // Storage adapters (Memory, LevelGraph, Neo4j)
166
+ import { MemoryStorage, LevelGraphStorage, Neo4jStorage } from 'learngraph/storage';
87
167
 
88
168
  // LLM integration for curriculum decomposition
89
169
  import { LLMProvider } from 'learngraph/llm';
@@ -108,6 +188,7 @@ import { detectBloomLevel, hasMastery } from 'learngraph/education';
108
188
 
109
189
  **Dr. Ernesto Lee** - Educational technologist and learning scientist
110
190
 
191
+ - Website: [https://DrLee.ai](https://DrLee.ai)
111
192
  - Email: dr.ernesto.lee@gmail.com
112
193
  - GitHub: [@fenago](https://github.com/fenago)
113
194
 
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ /**
3
+ * Base parser utilities
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.DEFAULT_PARSE_OPTIONS = void 0;
9
+ exports.extractTime = extractTime;
10
+ exports.isObjectiveLine = isObjectiveLine;
11
+ exports.cleanText = cleanText;
12
+ exports.objectiveToSkillName = objectiveToSkillName;
13
+ exports.createObjective = createObjective;
14
+ exports.createEmptyResult = createEmptyResult;
15
+ exports.calculateStats = calculateStats;
16
+ const bloom_js_1 = require("../types/bloom.js");
17
+ /**
18
+ * Default parse options
19
+ */
20
+ exports.DEFAULT_PARSE_OPTIONS = {
21
+ detectBloom: true,
22
+ extractTime: true,
23
+ suggestNames: true,
24
+ includeRaw: false,
25
+ sectionHeaders: [
26
+ 'module',
27
+ 'chapter',
28
+ 'unit',
29
+ 'week',
30
+ 'section',
31
+ 'part',
32
+ 'lesson',
33
+ 'topic',
34
+ ],
35
+ objectiveMarkers: [
36
+ 'students will be able to',
37
+ 'learners will',
38
+ 'by the end of this',
39
+ 'learning objectives',
40
+ 'objectives:',
41
+ 'learning outcomes',
42
+ 'outcomes:',
43
+ 'lo:',
44
+ 'swbat',
45
+ '•',
46
+ '-',
47
+ '*',
48
+ ],
49
+ };
50
+ /**
51
+ * Common time patterns in syllabi
52
+ * Note: Decimal hours pattern must come before integer hours pattern
53
+ */
54
+ const TIME_PATTERNS = [
55
+ /(\d+)\s*(?:min(?:ute)?s?|mins?)/i,
56
+ /(\d+\.\d+)\s*(?:hour?s?|hrs?)/i,
57
+ /(\d+)\s*(?:hour?s?|hrs?)/i,
58
+ ];
59
+ /**
60
+ * Extract estimated time from text
61
+ */
62
+ function extractTime(text) {
63
+ for (const pattern of TIME_PATTERNS) {
64
+ const match = text.match(pattern);
65
+ if (match && match[1]) {
66
+ const value = parseFloat(match[1]);
67
+ if (pattern.source.includes('hour')) {
68
+ return Math.round(value * 60);
69
+ }
70
+ return Math.round(value);
71
+ }
72
+ }
73
+ return undefined;
74
+ }
75
+ /**
76
+ * Detect if a line is a learning objective
77
+ */
78
+ function isObjectiveLine(line, markers) {
79
+ const lower = line.toLowerCase().trim();
80
+ return markers.some((marker) => lower.includes(marker.toLowerCase()));
81
+ }
82
+ /**
83
+ * Clean and normalize text
84
+ */
85
+ function cleanText(text) {
86
+ return text
87
+ .replace(/\s+/g, ' ')
88
+ .replace(/^\s*[-•*]\s*/, '')
89
+ .replace(/^\d+\.\s*/, '')
90
+ .trim();
91
+ }
92
+ /**
93
+ * Generate a skill name from an objective
94
+ */
95
+ function objectiveToSkillName(objective) {
96
+ const cleaned = cleanText(objective);
97
+ // Remove common prefixes
98
+ const prefixes = [
99
+ /^students will be able to\s+/i,
100
+ /^learners will\s+/i,
101
+ /^by the end of this [\w\s]+,?\s*/i,
102
+ /^the student will\s+/i,
103
+ /^understand\s+/i,
104
+ /^learn\s+/i,
105
+ ];
106
+ let result = cleaned;
107
+ for (const prefix of prefixes) {
108
+ result = result.replace(prefix, '');
109
+ }
110
+ // Capitalize first letter
111
+ result = result.charAt(0).toUpperCase() + result.slice(1);
112
+ // Truncate if too long
113
+ if (result.length > 80) {
114
+ result = result.substring(0, 77) + '...';
115
+ }
116
+ return result;
117
+ }
118
+ /**
119
+ * Create a learning objective from text
120
+ */
121
+ function createObjective(text, section, week) {
122
+ const cleaned = cleanText(text);
123
+ const bloomLevel = (0, bloom_js_1.detectBloomLevel)(cleaned);
124
+ const objective = {
125
+ text: cleaned,
126
+ bloomLevel,
127
+ bloomConfidence: bloomLevel ? 0.8 : 0,
128
+ suggestedName: objectiveToSkillName(cleaned),
129
+ };
130
+ if (section !== undefined) {
131
+ objective.section = section;
132
+ }
133
+ if (week !== undefined) {
134
+ objective.week = week;
135
+ }
136
+ return objective;
137
+ }
138
+ /**
139
+ * Create empty parse result
140
+ */
141
+ function createEmptyResult(source, format) {
142
+ return {
143
+ metadata: {
144
+ source,
145
+ format,
146
+ parsedAt: new Date().toISOString(),
147
+ },
148
+ modules: [],
149
+ topics: [],
150
+ objectives: [],
151
+ warnings: [],
152
+ stats: {
153
+ moduleCount: 0,
154
+ topicCount: 0,
155
+ objectiveCount: 0,
156
+ bloomDetectedCount: 0,
157
+ durationMs: 0,
158
+ },
159
+ };
160
+ }
161
+ /**
162
+ * Calculate parse statistics
163
+ */
164
+ function calculateStats(result, startTime) {
165
+ let objectiveCount = result.objectives.length;
166
+ let bloomDetectedCount = result.objectives.filter((o) => o.bloomLevel).length;
167
+ for (const topic of result.topics) {
168
+ objectiveCount += topic.objectives.length;
169
+ bloomDetectedCount += topic.objectives.filter((o) => o.bloomLevel).length;
170
+ }
171
+ for (const mod of result.modules) {
172
+ objectiveCount += mod.objectives.length;
173
+ bloomDetectedCount += mod.objectives.filter((o) => o.bloomLevel).length;
174
+ for (const topic of mod.topics) {
175
+ objectiveCount += topic.objectives.length;
176
+ bloomDetectedCount += topic.objectives.filter((o) => o.bloomLevel).length;
177
+ }
178
+ }
179
+ const topicCount = result.topics.length +
180
+ result.modules.reduce((sum, m) => sum + m.topics.length, 0);
181
+ return {
182
+ moduleCount: result.modules.length,
183
+ topicCount,
184
+ objectiveCount,
185
+ bloomDetectedCount,
186
+ durationMs: Date.now() - startTime,
187
+ };
188
+ }
189
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/parsers/base.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA0DH,kCAYC;AAKD,0CAGC;AAKD,8BAMC;AAKD,oDA2BC;AAKD,0CAuBC;AAKD,8CAsBC;AAKD,wCA6BC;AAzMD,gDAAqD;AAErD;;GAEG;AACU,QAAA,qBAAqB,GAA2B;IAC3D,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,KAAK;IACjB,cAAc,EAAE;QACd,QAAQ;QACR,SAAS;QACT,MAAM;QACN,MAAM;QACN,SAAS;QACT,MAAM;QACN,QAAQ;QACR,OAAO;KACR;IACD,gBAAgB,EAAE;QAChB,0BAA0B;QAC1B,eAAe;QACf,oBAAoB;QACpB,qBAAqB;QACrB,aAAa;QACb,mBAAmB;QACnB,WAAW;QACX,KAAK;QACL,OAAO;QACP,GAAG;QACH,GAAG;QACH,GAAG;KACJ;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,aAAa,GAAG;IACpB,kCAAkC;IAClC,gCAAgC;IAChC,2BAA2B;CAC5B,CAAC;AAEF;;GAEG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,UAAU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CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAE9D,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM;QAClC,UAAU;QACV,cAAc;QACd,kBAAkB;QAClB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;KACnC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ /**
3
+ * Demo utilities for quick testing and exploration
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.tryWithSample = tryWithSample;
9
+ exports.tryWithSyllabus = tryWithSyllabus;
10
+ exports.printDemoResults = printDemoResults;
11
+ const markdown_js_1 = require("./markdown.js");
12
+ const extractor_js_1 = require("./extractor.js");
13
+ const memory_js_1 = require("../storage/memory.js");
14
+ const samples_js_1 = require("./samples.js");
15
+ /**
16
+ * Try LearnGraph with a sample syllabus
17
+ *
18
+ * This is the easiest way to see LearnGraph in action.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { tryWithSample } from 'learngraph/parsers';
23
+ *
24
+ * // Try with physics syllabus
25
+ * const result = await tryWithSample('physics');
26
+ * console.log(`Created ${result.skills.length} skills!`);
27
+ * console.log('Skills:', result.skills.map(s => s.name));
28
+ *
29
+ * // Try with kindergarten math
30
+ * const kResult = await tryWithSample('kindergarten');
31
+ * console.log(`Kindergarten: ${kResult.skills.length} skills`);
32
+ * ```
33
+ */
34
+ async function tryWithSample(sample = 'physics') {
35
+ const syllabus = samples_js_1.SAMPLE_SYLLABI[sample];
36
+ return tryWithSyllabus(syllabus);
37
+ }
38
+ /**
39
+ * Try LearnGraph with your own syllabus
40
+ *
41
+ * Paste your syllabus as markdown and see the magic happen!
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { tryWithSyllabus } from 'learngraph/parsers';
46
+ *
47
+ * const mySyllabus = `
48
+ * # My Course
49
+ *
50
+ * ## Week 1: Introduction
51
+ *
52
+ * ### Learning Objectives
53
+ * - Understand the course structure
54
+ * - Identify key topics
55
+ * - Apply basic concepts
56
+ * `;
57
+ *
58
+ * const result = await tryWithSyllabus(mySyllabus);
59
+ * console.log('Found', result.parseResult.stats.objectiveCount, 'objectives');
60
+ * console.log('Created', result.skills.length, 'skills');
61
+ *
62
+ * // See the skills
63
+ * for (const skill of result.skills) {
64
+ * console.log(`- ${skill.name} (${skill.bloomLevel}, difficulty: ${skill.difficulty})`);
65
+ * }
66
+ * ```
67
+ */
68
+ async function tryWithSyllabus(syllabus, options) {
69
+ // Parse the syllabus
70
+ const parser = new markdown_js_1.MarkdownParser();
71
+ const parseResult = await parser.parse(syllabus);
72
+ // Extract skills
73
+ const extractor = new extractor_js_1.BasicExtractor();
74
+ const extraction = await extractor.extract(parseResult, options);
75
+ // Create storage and populate
76
+ const storage = new memory_js_1.MemoryStorage();
77
+ await storage.connect({ backend: 'memory' });
78
+ // Create skills
79
+ const skills = [];
80
+ const skillMap = new Map();
81
+ for (const { skill: input } of extraction.skills) {
82
+ const skill = await storage.createSkill(input);
83
+ skills.push(skill);
84
+ skillMap.set(skill.name, skill);
85
+ }
86
+ // Create edges
87
+ const edges = [];
88
+ for (const suggested of extraction.suggestedEdges) {
89
+ const source = skillMap.get(suggested.sourceName);
90
+ const target = skillMap.get(suggested.targetName);
91
+ if (source && target) {
92
+ const edgeInput = {
93
+ sourceId: source.id,
94
+ targetId: target.id,
95
+ strength: suggested.strength,
96
+ type: suggested.strength >= 0.8 ? 'hard' : 'soft',
97
+ metadata: {},
98
+ };
99
+ if (suggested.reasoning) {
100
+ edgeInput.reasoning = suggested.reasoning;
101
+ }
102
+ const edge = await storage.createPrerequisite(edgeInput);
103
+ edges.push(edge);
104
+ }
105
+ }
106
+ // Get stats
107
+ const stats = await storage.getStats();
108
+ await storage.disconnect();
109
+ return {
110
+ parseResult,
111
+ extraction,
112
+ skills,
113
+ edges,
114
+ stats,
115
+ };
116
+ }
117
+ /**
118
+ * Quick console output of demo results
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * import { tryWithSample, printDemoResults } from 'learngraph/parsers';
123
+ *
124
+ * const result = await tryWithSample('physics');
125
+ * printDemoResults(result);
126
+ * ```
127
+ */
128
+ function printDemoResults(result) {
129
+ console.log('\n' + '='.repeat(60));
130
+ console.log('LearnGraph Demo Results');
131
+ console.log('='.repeat(60));
132
+ console.log(`\nCourse: ${result.parseResult.metadata.title || 'Untitled'}`);
133
+ console.log(`Format: ${result.parseResult.metadata.format}`);
134
+ console.log('\n--- Parse Statistics ---');
135
+ console.log(`Modules: ${result.parseResult.stats.moduleCount}`);
136
+ console.log(`Topics: ${result.parseResult.stats.topicCount}`);
137
+ console.log(`Objectives: ${result.parseResult.stats.objectiveCount}`);
138
+ console.log(`Bloom's Detected: ${result.parseResult.stats.bloomDetectedCount}`);
139
+ console.log('\n--- Skills Created ---');
140
+ for (const skill of result.skills) {
141
+ console.log(` - ${skill.name} [${skill.bloomLevel}] (difficulty: ${skill.difficulty.toFixed(2)})`);
142
+ }
143
+ console.log('\n--- Prerequisites ---');
144
+ for (const edge of result.edges) {
145
+ const source = result.skills.find((s) => s.id === edge.sourceId);
146
+ const target = result.skills.find((s) => s.id === edge.targetId);
147
+ if (source && target) {
148
+ console.log(` ${source.name} → ${target.name} (${edge.type})`);
149
+ }
150
+ }
151
+ console.log('\n--- Graph Statistics ---');
152
+ console.log(`Total Skills: ${result.stats.nodeCount}`);
153
+ console.log(`Total Edges: ${result.stats.edgeCount}`);
154
+ console.log(`Root Skills: ${result.stats.rootNodeCount}`);
155
+ console.log(`Max Depth: ${result.stats.maxDepth}`);
156
+ console.log(`Bloom Distribution:`, result.stats.bloomDistribution);
157
+ console.log('\n' + '='.repeat(60) + '\n');
158
+ }
159
+ //# sourceMappingURL=demo.js.map