dependencyParse
Parse tokens into dependency tree structure.Parameters
Array of tokens to parse. Tokens are normalized to lowercase.
Optional POS tags for tokens. If not provided, tags are automatically generated using the built-in POS tagger.
Returns
Dependency parse structure with:tokens: string[] - Normalized token listposTags: string[] - POS tags for each tokenroot: number - Index of root token (usually main verb)arcs: DependencyArc[] - Array of dependency arcs, each with:head: number - Index of head tokendep: number - Index of dependent tokenrelation: string - Dependency relation type
Relations
Supported dependency relations:nsubj- Nominal subject (pre-verbal nouns)obj- Object (post-verbal nouns)amod- Adjectival modifieradvmod- Adverbial modifierprep- Prepositional modifierpunct- Punctuationdep- Generic dependent
Example
With POS Tags
dependencyParseText
Parse natural language text into dependency structure.Parameters
Natural language text to parse
Convert tokens to lowercase before parsing
Returns
Dependency parse structure. SeedependencyParse for structure details.
Example
Processing
- Tokenizes text using word tokenizer
- Filters to alphanumeric tokens (removes punctuation)
- Normalizes to lowercase (if enabled)
- Generates POS tags automatically
- Builds dependency parse
Root Selection
The root is selected as:- First verb-like token (VB* tags or auxiliary verbs)
- Falls back to first token if no verb found
Parse Algorithm
Uses rule-based heuristics:- Identifies main verb as root
- Attaches pre-verbal nouns as subjects
- Attaches post-verbal nouns as objects
- Attaches adjectives to nearest following noun
- Attaches adverbs to root verb
- Attaches prepositions to root
- Attaches punctuation to root
Visualizing Dependencies
Limitations
This is a rule-based parser with limitations:- Simple heuristics, not statistical
- Limited relation types
- Best for simple English sentences
- No handling of complex clauses
- No prepositional phrase attachment
- spaCy’s dependency parser
- Stanford CoreNLP
- Neural dependency parsers