Skip to content

Repository files navigation

@graphdl/semantics

GraphDL semantic parser for converting natural language statements to graph notation.

Installation

npm install @graphdl/semantics
# or
pnpm add @graphdl/semantics

Usage

import{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'// }

API

GraphDLParser

Constructor

newGraphDLParser(lexicon?: Lexicon)
  • lexicon.verbs - Array of verb strings
  • lexicon.nouns - Array of noun strings
  • lexicon.prepositions - Array of preposition strings

Methods

  • parse(statement: string): ParsedStatement - Parse a natural language statement into GraphDL notation
  • addVerb(verb: string) - Add a verb to the lexicon
  • addNoun(noun: string) - Add a noun to the lexicon
  • addPreposition(prep: string) - Add a preposition to the lexicon

ParsedStatement

interfaceParsedStatement{subject?: stringverb?: stringobject?: stringpreposition?: stringprepositionalObject?: stringmodifiers?: string[]}

GraphDL Notation

GraphDL uses a dot-notation syntax for expressing semantic relationships:

Subject.verb.Object.preposition.PrepObject

Examples:

  • Manager.manages.Budget - Simple subject-verb-object
  • Analyst.analyzes.Data.using.Tools - With prepositional phrase
  • develop.Strategy.for.Organization - Implicit subject

Development

# Install dependencies
pnpm install
# Build
pnpm build
# Run tests
pnpm test# Watch mode
pnpm dev

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages