GraphDL semantic parser for converting natural language statements to graph notation.
npm install @graphdl/semantics
# or
pnpm add @graphdl/semanticsimport{GraphDLParser}from'@graphdl/semantics'// Create parser with optional lexiconconstparser=newGraphDLParser({verbs: ['Manage','Develop','Analyze'],nouns: ['Budget','Strategy','Data'],prepositions: ['for','with','using']})// Parse a statementconstresult=parser.parse('Manage budgets for department')console.log(result)// {// subject: undefined,// verb: 'Manage',// object: 'budgets',// preposition: 'for',// prepositionalObject: 'department'// }newGraphDLParser(lexicon?: Lexicon)lexicon.verbs- Array of verb stringslexicon.nouns- Array of noun stringslexicon.prepositions- Array of preposition strings
parse(statement: string): ParsedStatement- Parse a natural language statement into GraphDL notationaddVerb(verb: string)- Add a verb to the lexiconaddNoun(noun: string)- Add a noun to the lexiconaddPreposition(prep: string)- Add a preposition to the lexicon
interfaceParsedStatement{subject?: stringverb?: stringobject?: stringpreposition?: stringprepositionalObject?: stringmodifiers?: string[]}GraphDL uses a dot-notation syntax for expressing semantic relationships:
Subject.verb.Object.preposition.PrepObject
Examples:
Manager.manages.Budget- Simple subject-verb-objectAnalyst.analyzes.Data.using.Tools- With prepositional phrasedevelop.Strategy.for.Organization- Implicit subject
# Install dependencies
pnpm install
# Build
pnpm build
# Run tests
pnpm test# Watch mode
pnpm devMIT