initial commit

This commit is contained in:
Chegele 2023-09-05 20:30:37 -04:00
commit a4daf1c3e0
20 changed files with 718 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.vscode
node_modules
dist

65
README.md Normal file
View File

@ -0,0 +1,65 @@
# DGraph Compiler
This project involves a NodeJS Command Line Interface (CLI) designed to parse and process files generated by Obsidian Discourse Graphs. The primary goal is to create a text-based markdown artifact that represents the entire graph in a comprehensible format.
The CLI consumes graph files and produces an "artifact" which is a text-based representation of the graph's structure, relationships, and contained data. This process is referred to as compiling and includes updates for the user while parsing components, displaying specific errors and warnings as needed. Compilation relies on configurable parameters which define how the graph should be processed, allowing for customization and adaptability.
The project's future roadmap includes incorporating Git for version control of graph elements, configuration parameters, and compiled artifacts. This addition aims to enhance collaboration and tracking of changes in the graph.
Additionally, the project aims to integrate the DGF (DAO Governance Framework) to facilitate decentralized governance over the compilation script, configuration parameters, and other components. This step empowers communities to collectively manage the evolution of the project.
*The current version of the project operates only on a local directory and lacks any governance mechanisms defined by DGF. This simplification serves to assist with the prototyping process as we work towards a MVP for proof of concept.*
## Contributing
To contribute to the project, please follow these steps:
1. Fork the repository
2. Create a new branch for your changes
3. Make your changes and commit them
4. Push your changes to your fork
5. Submit a pull request
## Scripts
- `build:once` - Compiles the TypeScript code once.
- `build:watch` - Compiles the TypeScript code and watches for changes.
- `start` - Starts the application.
- `start:debug` - Starts the application with debugging enabled on port `9229`.
## Setting up for Development
To set up the project for development, follow these steps:
1. Clone the repository to your local machine.
2. Install the project dependencies by running `npm install`.
3. Transpile the TypeScript into JavaScript using one of the following options.
- Run `npm run build:once` to compile the TypeScript code once.
- Run `npm run build:watch` to compile the TypeScript code and watch for changes.
4. Develop and debug the project using either the npm script or the launch configuration in VSCode.
#### Developing the Application with Nodemon
- `npm run start:debug`
- *Note: If using build:watch you will need to run this command in a second terminal*
#### Developing the application with VSCode Debugger
1. Copy the below code into `.vscode/launch.json` at the root directory of the project.
2. Launch the VScode debugger by
- Pressing the F5 shortcut key
- From the toolbar, select Run > Start Debugging
- From the Debugging sidebar, select the green play button
```jsonc
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Debug with nodemon",
"request": "launch",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--inspect=9229",
"--watch",
"dist",
"dist/index.js"
]
}
]
}
```

View File

@ -0,0 +1,4 @@
Here is more detail about the claim
- informs [[{QUE} Example Question]]
- generates [[{QUE} Example Question 2]]

View File

@ -0,0 +1,3 @@
Here is more detail about the claim
- informs [[{QUE} Example Question]]

View File

@ -0,0 +1 @@
- opposes [[{CLM} Example Claim]]

View File

@ -0,0 +1 @@
- supports [[{CLM} Example Claim]]

View File

@ -0,0 +1 @@
Add question details

View File

@ -0,0 +1 @@
Add question details

View File

@ -0,0 +1 @@
[[{EVD} Example Evidence]]

417
package-lock.json generated Normal file
View File

@ -0,0 +1,417 @@
{
"name": "dgraph-compiler",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "dgraph-compiler",
"version": "1.0.0",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.5.8",
"nodemon": "^3.0.1",
"typescript": "^5.2.2"
}
},
"node_modules/@types/node": {
"version": "20.5.8",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.8.tgz",
"integrity": "sha512-eajsR9aeljqNhK028VG0Wuw+OaY5LLxYmxeoXynIoE6jannr9/Ucd1LL0hSSoafk5LTYG+FfqsyGt81Q6Zkybw==",
"dev": true
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
"dev": true
},
"node_modules/anymatch": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
"dev": true,
"dependencies": {
"normalize-path": "^3.0.0",
"picomatch": "^2.0.4"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
},
"node_modules/binary-extensions": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"node_modules/braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"dev": true,
"dependencies": {
"fill-range": "^7.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/chokidar": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz",
"integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==",
"dev": true,
"funding": [
{
"type": "individual",
"url": "https://paulmillr.com/funding/"
}
],
"dependencies": {
"anymatch": "~3.1.2",
"braces": "~3.0.2",
"glob-parent": "~5.1.2",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
"normalize-path": "~3.0.0",
"readdirp": "~3.6.0"
},
"engines": {
"node": ">= 8.10.0"
},
"optionalDependencies": {
"fsevents": "~2.3.2"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"dev": true
},
"node_modules/debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dev": true,
"dependencies": {
"ms": "^2.1.1"
}
},
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"dev": true,
"dependencies": {
"to-regex-range": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
"dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/glob-parent": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
"dev": true,
"dependencies": {
"is-glob": "^4.0.1"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/ignore-by-default": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
"dev": true
},
"node_modules/is-binary-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
"dev": true,
"dependencies": {
"binary-extensions": "^2.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/is-extglob": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-glob": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
"dev": true,
"dependencies": {
"is-extglob": "^2.1.1"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-number": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
"dev": true,
"engines": {
"node": ">=0.12.0"
}
},
"node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"dev": true
},
"node_modules/nodemon": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz",
"integrity": "sha512-g9AZ7HmkhQkqXkRc20w+ZfQ73cHLbE8hnPbtaFbFtCumZsjyMhKk9LajQ07U5Ux28lvFjZ5X7HvWR1xzU8jHVw==",
"dev": true,
"dependencies": {
"chokidar": "^3.5.2",
"debug": "^3.2.7",
"ignore-by-default": "^1.0.1",
"minimatch": "^3.1.2",
"pstree.remy": "^1.1.8",
"semver": "^7.5.3",
"simple-update-notifier": "^2.0.0",
"supports-color": "^5.5.0",
"touch": "^3.1.0",
"undefsafe": "^2.0.5"
},
"bin": {
"nodemon": "bin/nodemon.js"
},
"engines": {
"node": ">=10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/nodemon"
}
},
"node_modules/nopt": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
"integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==",
"dev": true,
"dependencies": {
"abbrev": "1"
},
"bin": {
"nopt": "bin/nopt.js"
},
"engines": {
"node": "*"
}
},
"node_modules/normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/picomatch": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true,
"engines": {
"node": ">=8.6"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
"integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==",
"dev": true
},
"node_modules/readdirp": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
"dev": true,
"dependencies": {
"picomatch": "^2.2.1"
},
"engines": {
"node": ">=8.10.0"
}
},
"node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/simple-update-notifier": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
"integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==",
"dev": true,
"dependencies": {
"semver": "^7.5.3"
},
"engines": {
"node": ">=10"
}
},
"node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
"dev": true,
"dependencies": {
"is-number": "^7.0.0"
},
"engines": {
"node": ">=8.0"
}
},
"node_modules/touch": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
"integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==",
"dev": true,
"dependencies": {
"nopt": "~1.0.10"
},
"bin": {
"nodetouch": "bin/nodetouch.js"
}
},
"node_modules/typescript": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/undefsafe": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==",
"dev": true
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
}
}

19
package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "dgraph-compiler",
"version": "1.0.0",
"description": "Compile Obsidian discurce graphs into text-based artifacts",
"main": "index.js",
"scripts": {
"build:once": "tsc",
"build:watch": "tsc -w",
"start": "node dist/index.js",
"start:debug": "nodemon --inspect=9229 --watch dist dist/index.js"
},
"author": "Chegele",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.5.8",
"nodemon": "^3.0.1",
"typescript": "^5.2.2"
}
}

View File

@ -0,0 +1,28 @@
import { Node } from "../node-types/abstract-node";
export abstract class EDGE {
public static readonly EDGE_TYPE: string;
public static readonly SOURCE_TYPES: string[];
public static readonly REFERENCE_TYPES: string[];
public readonly source: Node;
public readonly reference: Node;
public constructor(source: Node, reference: Node) {
this.source = source;
this.reference = reference;
}
public static nodesCompatible(source: Node, reference: Node): boolean {
if (!this.SOURCE_TYPES.includes(source.TYPE)) return false;
if (!this.REFERENCE_TYPES.includes(reference.TYPE)) return false;
return true;
}
public static createEdge(source: Node, reference: Node): EDGE {
throw new Error('You must override the static createEdge method in specific edge implementations');
}
}

18
src/edge-types/inform.ts Normal file
View File

@ -0,0 +1,18 @@
import { Node } from "../node-types/abstract-node";
import { EDGE } from "./abstract-edge";
export class InformEdge extends EDGE {
public static readonly EDGE_TYPE = "inform";
public static readonly SOURCE_TYPES = ["claim", "evidence"];
public static readonly REFERENCE_TYPES = ['question'];
constructor(source: Node, reference: Node) {
super(source, reference);
}
public static createEdge(source: Node, reference: Node): InformEdge {
return new InformEdge(source, reference);
}
}

45
src/index.ts Normal file
View File

@ -0,0 +1,45 @@
import * as fs from 'fs/promises';
import { QuestionNode } from "./node-types/question";
import { ClaimNode } from './node-types/claim';
import { EvidenceNode } from './node-types/evidence';
import { SourceNode } from './node-types/source';
export class Compiler {
public static nodes = [
ClaimNode,
EvidenceNode,
QuestionNode,
SourceNode
];
public static getNodeType(name: string) {
for (const nodeType of Compiler.nodes) {
if (nodeType.TYPE_PATTERN.test(name)) return nodeType;
}
throw new Error(`File name does not match any known node type \n - ${name}`);
}
static async loadNodes(directory: string) {
console.log('Loading nodes...');
const nodes = [];
const files = await fs.readdir(directory);
for (const file of files) try {
const NodeType = Compiler.getNodeType(file);
const node = NodeType.load(file, "");
nodes.push(node);
console.log(`Loaded ${NodeType.TYPE} node "${node.name}"`);
} catch (err) {
console.error(err.message);
}
return nodes;
}
}
const graphPath = "./example_graph";
Compiler.loadNodes(graphPath);

View File

@ -0,0 +1,19 @@
export abstract class Node {
public static readonly TYPE: string;
public static readonly TYPE_PATTERN: RegExp;
public readonly name: string;
public readonly data: string;
public constructor(name: string, data: string) {
this.name = name;
this.data = data;
}
public static load(fileName: string, fileData: string): Node {
throw new Error('You must override the static parse method in specific node implementations');
}
}

20
src/node-types/claim.ts Normal file
View File

@ -0,0 +1,20 @@
import { Node } from "./abstract-node";
export class ClaimNode extends Node{
public static readonly TYPE = 'claim';
public static readonly TYPE_PATTERN = /^\{CLM\}/;
public constructor(name: string, data: string) {
super(name, data);
}
public static load(fileName: string, fileData: string) {
const name = fileName.replace(ClaimNode.TYPE_PATTERN, '')
.replace('.md', '')
.trim();
return new ClaimNode(name, fileData);
}
}

View File

@ -0,0 +1,20 @@
import { Node } from "./abstract-node";
export class EvidenceNode extends Node{
public static readonly TYPE = 'evidence';
public static readonly TYPE_PATTERN = /^\{EVD\}/;
public constructor(name: string, data: string) {
super(name, data);
}
public static load(fileName: string, fileData: string) {
const name = fileName.replace(EvidenceNode.TYPE_PATTERN, '')
.replace('.md', '')
.trim();
return new EvidenceNode(name, fileData);
}
}

View File

@ -0,0 +1,20 @@
import { Node } from "./abstract-node";
export class QuestionNode extends Node{
public static readonly TYPE = 'question';
public static readonly TYPE_PATTERN = /^\{QUE\}/;
public constructor(name: string, data: string) {
super(name, data);
}
public static load(fileName: string, fileData: string) {
const name = fileName.replace(QuestionNode.TYPE_PATTERN, '')
.replace('.md', '')
.trim();
return new QuestionNode(name, fileData);
}
}

20
src/node-types/source.ts Normal file
View File

@ -0,0 +1,20 @@
import { Node } from "./abstract-node";
export class SourceNode extends Node{
public static readonly TYPE = 'source';
public static readonly TYPE_PATTERN = /^\{SRC\}/;
public constructor(name: string, data: string) {
super(name, data);
}
public static load(fileName: string, fileData: string) {
const name = fileName.replace(SourceNode.TYPE_PATTERN, '')
.replace('.md', '')
.trim();
return new SourceNode(name, fileData);
}
}

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"sourceMap": true,
"outDir": "dist"
},
"include": [
"src/**/*"
]
}