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 lexicon
const parser = new GraphDLParser({
verbs: ['Manage', 'Develop', 'Analyze'],
nouns: ['Budget', 'Strategy', 'Data'],
prepositions: ['for', 'with', 'using']
})
// Parse a statement
const result = parser.parse('Manage budgets for department')
console.log(result)
// {
// subject: undefined,
// verb: 'Manage',
// object: 'budgets',
// preposition: 'for',
// prepositionalObject: 'department'
// }new GraphDLParser(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
interface ParsedStatement {
subject?: string
verb?: string
object?: string
preposition?: string
prepositionalObject?: string
modifiers?: 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