Trees
Dependency structure in natural language consists of directed relations between words in a sentence.
Simple API for building dependency trees:
DependencyTrees.DependencyTree — Type
DependencyTreeA rooted tree of dependency relations among the tokens of a sentence.
DependencyTree functions
DependencyTrees.arcs — Function
arcs(tree::DependencyTree)Return a vector of (src, dst) tuples, representing all dependency arcs in tree.
Projectivity
"Projectivity" is a characteristic of dependency trees.
An arc from a head to a dependent is said to be projective if there is a path from the head to every word that lies between the headprojective and the dependent in the sentence. A dependency tree is then said to be projective if all the arcs that make it up are projective. [1]
Drawing the trees will show that non-projective trees have crossing arcs, and projective trees do not.
DependencyTrees.isprojective — Function
isprojective(tree::DependencyTree)True when a tree is projective, false when non-projective.
julia> tree = DependencyTree([("john", 2), ("saw", 0), ("a", 4), ("dog", 2), ("yesterday", 2), ("which", 7), ("was", 4), ("a", 9), ("yorkshire", 10), ("terrier", 7)])
┌─────────── 0 ROOT
│ ┌─► 1 john
└─►┌──┌──└── 2 saw
│ │ ┌─► 3 a
┌──│ └─►└── 4 dog
│ └───────► 5 yesterday
│ ┌─► 6 which
┌──└───────►└── 7 was
│ ┌─► 8 a
│ ┌─►└── 9 yorkshire
└───────►└───── 10 terrier
julia> isprojective(tree)
false
julia> tree2 = DependencyTree([("john", 2), ("saw", 0), ("a", 4), ("dog", 2), ("which", 6), ("was", 4), ("a", 8), ("yorkshire", 9), ("terrier", 6), ("yesterday", 2)])
┌───────────────── 0 ROOT
│ ┌─► 1 john
└─►┌────────┌──└── 2 saw
│ │ ┌─► 3 a
│ ┌──└─►└── 4 dog
│ │ ┌─► 5 which
│ ┌──└────►└── 6 was
│ │ ┌─► 7 a
│ │ ┌─►└── 8 yorkshire
│ └────►└───── 9 terrier
└─────────────► 10 yesterday
julia> isprojective(tree2)
true
Tokens
DependencyTrees.Token — Type
Token(form, head=-1, label=nothing)A token in a dependency tree.
Visualizing Trees
DependencyTrees.jl by default displays DependencyTrees by drawing arrows representing the dependency arcs. For example,