public abstract class GrammaticalStructure
extends java.lang.Object
implements java.io.Serializable
GrammaticalStructure
stores dependency relations between
nodes in a tree. A new GrammaticalStructure
is constructed
from an existing parse tree with the help of {@code GrammaticalRelation}
, which
defines a hierarchy of grammatical relations, along with
patterns for identifying them in parse trees. The constructor for
GrammaticalStructure
uses these definitions to
populate the new GrammaticalStructure
with as many
labeled grammatical relations as it can. Once constructed, the new
GrammaticalStructure
can be printed in various
formats, or interrogated using the interface methods in this
class. Internally, this uses a representation via a TreeGraphNode
,
that is, a tree with additional labeled
arcs between nodes, for representing the grammatical relations in a
parse tree.EnglishGrammaticalRelations
,
GrammaticalRelation
,
EnglishGrammaticalStructure
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
GrammaticalStructure.Extras
A specification for the types of extra edges to add to the dependency tree.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.List<TypedDependency> |
allTypedDependencies |
static int |
CoNLLX_FieldCount |
static int |
CoNLLX_GovField |
static int |
CoNLLX_POSField |
static int |
CoNLLX_RelnField |
static int |
CoNLLX_WordField |
protected java.util.function.Predicate<java.lang.String> |
puncFilter |
protected java.util.function.Predicate<java.lang.String> |
tagFilter |
protected java.util.List<TypedDependency> |
typedDependencies |
Constructor and Description |
---|
GrammaticalStructure(java.util.List<TypedDependency> projectiveDependencies,
TreeGraphNode root) |
GrammaticalStructure(Tree t,
java.util.Collection<GrammaticalRelation> relations,
java.util.concurrent.locks.Lock relationsLock,
TreeTransformer transformer,
HeadFinder hf,
java.util.function.Predicate<java.lang.String> puncFilter,
java.util.function.Predicate<java.lang.String> tagFilter)
Create a new GrammaticalStructure, analyzing the parse tree and
populate the GrammaticalStructure with as many labeled
grammatical relation arcs as possible.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addEnhancements(java.util.List<TypedDependency> list,
EnhancementOptions options)
Destructively applies different enhancements to the dependency graph.
|
java.util.Collection<TypedDependency> |
allTypedDependencies()
Returns all the typed dependencies of this grammatical structure.
|
static GrammaticalStructure |
buildCoNLLXGrammaticalStructure(java.util.List<java.util.List<java.lang.String>> tokenFields,
java.util.Map<java.lang.String,GrammaticalRelation> shortNameToGRel,
GrammaticalStructureFromDependenciesFactory factory) |
protected void |
collapseDependencies(java.util.List<TypedDependency> list,
boolean CCprocess,
GrammaticalStructure.Extras includeExtras)
Destructively modify the
Collection<TypedDependency> to collapse
language-dependent transitive dependencies. |
protected void |
collapseDependenciesTree(java.util.List<TypedDependency> list)
Destructively modify the
Collection<TypedDependency> to collapse
language-dependent transitive dependencies but keeping a tree structure. |
protected void |
correctDependencies(java.util.List<TypedDependency> list)
Destructively modify the
TypedDependencyGraph to correct
language-dependent dependencies. |
protected java.util.function.Predicate<TypedDependency> |
extraTreeDepFilter()
Returns a Filter which checks dependencies for usefulness as
extra tree-based dependencies.
|
static GrammaticalStructure |
fromStringReps(java.util.List<java.lang.String> tokens,
java.util.List<java.lang.String> posTags,
java.util.List<java.lang.String> deps)
Create a grammatical structure from its string representation.
|
protected void |
getExtras(java.util.List<TypedDependency> basicDep)
Get extra dependencies that do not depend on the tree structure,
but rather only depend on the existing dependency structure.
|
GrammaticalRelation |
getGrammaticalRelation(IndexedWord gov,
IndexedWord dep)
Get GrammaticalRelation between gov and dep, and null if gov is not the
governor of dep.
|
GrammaticalRelation |
getGrammaticalRelation(int govIndex,
int depIndex)
Get GrammaticalRelation between gov and dep, and null if gov is not the
governor of dep.
|
static java.util.Collection<TypedDependency> |
getRoots(java.util.Collection<TypedDependency> list)
Return a list of TypedDependencies which are not dependent on any node from the list.
|
protected void |
getTreeDeps(java.util.List<TypedDependency> deps,
DirectedMultiGraph<TreeGraphNode,GrammaticalRelation> completeGraph,
java.util.function.Predicate<TypedDependency> puncTypedDepFilter,
java.util.function.Predicate<TypedDependency> extraTreeDepFilter)
Look through the tree t and adds to the List basicDep
additional dependencies which aren't
in the List but which satisfy the filter puncTypedDepFilter.
|
static boolean |
isConnected(java.util.Collection<TypedDependency> list)
Checks if all the typeDependencies are connected
|
static void |
main(java.lang.String[] args) |
protected void |
postProcessDependencies(java.util.List<TypedDependency> basicDep)
Post process the dependencies in whatever way this language
requires.
|
static java.util.List<GrammaticalStructure> |
readCoNLLXGrammaticalStructureCollection(java.lang.String fileName,
java.util.Map<java.lang.String,GrammaticalRelation> shortNameToGRel,
GrammaticalStructureFromDependenciesFactory factory)
Read in a file containing a CoNLL-X dependency treebank and return a
corresponding list of GrammaticalStructures.
|
TreeGraphNode |
root()
Return the root Tree of this GrammaticalStructure.
|
java.lang.String |
toString() |
java.util.Collection<TypedDependency> |
typedDependencies()
Returns the typed dependencies of this grammatical structure.
|
java.util.List<TypedDependency> |
typedDependencies(boolean includeExtras)
Deprecated.
|
java.util.List<TypedDependency> |
typedDependencies(GrammaticalStructure.Extras includeExtras)
Returns the typed dependencies of this grammatical structure.
|
java.util.List<TypedDependency> |
typedDependenciesCCprocessed()
Get a list of the typed dependencies, including extras like control
dependencies, collapsing them and distributing relations across
coordination.
|
java.util.List<TypedDependency> |
typedDependenciesCCprocessed(boolean includeExtras)
Deprecated.
|
java.util.List<TypedDependency> |
typedDependenciesCCprocessed(GrammaticalStructure.Extras includeExtras)
Get the typed dependencies after collapsing them and processing eventual
CC complements.
|
java.util.Collection<TypedDependency> |
typedDependenciesCollapsed()
Get the typed dependencies after collapsing them.
|
java.util.List<TypedDependency> |
typedDependenciesCollapsed(boolean includeExtras)
Deprecated.
|
java.util.List<TypedDependency> |
typedDependenciesCollapsed(GrammaticalStructure.Extras includeExtras)
Get the typed dependencies after collapsing them.
|
java.util.Collection<TypedDependency> |
typedDependenciesCollapsedTree()
Get the typed dependencies after mostly collapsing them, but keep a tree
structure.
|
java.util.List<TypedDependency> |
typedDependenciesEnhanced() |
java.util.List<TypedDependency> |
typedDependenciesEnhancedPlusPlus() |
protected final java.util.List<TypedDependency> typedDependencies
protected final java.util.List<TypedDependency> allTypedDependencies
protected final java.util.function.Predicate<java.lang.String> puncFilter
protected final java.util.function.Predicate<java.lang.String> tagFilter
public static final int CoNLLX_WordField
public static final int CoNLLX_POSField
public static final int CoNLLX_GovField
public static final int CoNLLX_RelnField
public static final int CoNLLX_FieldCount
public GrammaticalStructure(Tree t, java.util.Collection<GrammaticalRelation> relations, java.util.concurrent.locks.Lock relationsLock, TreeTransformer transformer, HeadFinder hf, java.util.function.Predicate<java.lang.String> puncFilter, java.util.function.Predicate<java.lang.String> tagFilter)
t
- A Tree to analyzerelations
- A set of GrammaticalRelations to considerrelationsLock
- Something needed to make this thread-safe when iterating over relationstransformer
- A tree transformer to apply to the tree before converting (this argument
may be null if no transformer is required)hf
- A HeadFinder for analysispuncFilter
- A Filter to reject punctuation. To delete punctuation
dependencies, this filter should return false on
punctuation word strings, and true otherwise.
If punctuation dependencies should be kept, you
should pass in a Filters.<String>acceptFilter()
.tagFilter
- Appears to be unused (filters out tags??)public GrammaticalStructure(java.util.List<TypedDependency> projectiveDependencies, TreeGraphNode root)
public TreeGraphNode root()
public static GrammaticalStructure fromStringReps(java.util.List<java.lang.String> tokens, java.util.List<java.lang.String> posTags, java.util.List<java.lang.String> deps)
tokens
- posTags
- deps
- public java.lang.String toString()
toString
in class java.lang.Object
protected java.util.function.Predicate<TypedDependency> extraTreeDepFilter()
protected void postProcessDependencies(java.util.List<TypedDependency> basicDep)
protected void getExtras(java.util.List<TypedDependency> basicDep)
protected void getTreeDeps(java.util.List<TypedDependency> deps, DirectedMultiGraph<TreeGraphNode,GrammaticalRelation> completeGraph, java.util.function.Predicate<TypedDependency> puncTypedDepFilter, java.util.function.Predicate<TypedDependency> extraTreeDepFilter)
deps
- The list of dependencies which may be augmentedcompleteGraph
- a graph of all the tree dependencies found earlierpuncTypedDepFilter
- The filter that may skip punctuation dependenciesextraTreeDepFilter
- Additional dependencies are added only if they pass this filterpublic GrammaticalRelation getGrammaticalRelation(int govIndex, int depIndex)
public GrammaticalRelation getGrammaticalRelation(IndexedWord gov, IndexedWord dep)
public java.util.Collection<TypedDependency> typedDependencies()
public java.util.Collection<TypedDependency> allTypedDependencies()
public java.util.List<TypedDependency> typedDependencies(GrammaticalStructure.Extras includeExtras)
includeExtras
- If true, the list of typed dependencies
returned may include "extras", and does not follow a tree structure.@Deprecated public java.util.List<TypedDependency> typedDependencies(boolean includeExtras)
public java.util.Collection<TypedDependency> typedDependenciesCollapsed()
public java.util.Collection<TypedDependency> typedDependenciesCollapsedTree()
public java.util.List<TypedDependency> typedDependenciesCollapsed(GrammaticalStructure.Extras includeExtras)
true
.includeExtras
- If true, the list of typed dependencies
returned may include "extras", like controlling subjects@Deprecated public java.util.List<TypedDependency> typedDependenciesCollapsed(boolean includeExtras)
public java.util.List<TypedDependency> typedDependenciesCCprocessed(GrammaticalStructure.Extras includeExtras)
true
.
The "CCPropagated" option corresponds to calling this method with an
argument of true
.includeExtras
- If true, the list of typed dependencies
returned may include "extras", such as controlled subject links.@Deprecated public java.util.List<TypedDependency> typedDependenciesCCprocessed(boolean includeExtras)
public java.util.List<TypedDependency> typedDependenciesEnhanced()
public java.util.List<TypedDependency> typedDependenciesEnhancedPlusPlus()
public java.util.List<TypedDependency> typedDependenciesCCprocessed()
protected void collapseDependencies(java.util.List<TypedDependency> list, boolean CCprocess, GrammaticalStructure.Extras includeExtras)
Collection<TypedDependency>
to collapse
language-dependent transitive dependencies.
list
- A list of dependencies to process for possible collapsingCCprocess
- apply CC process?protected void addEnhancements(java.util.List<TypedDependency> list, EnhancementOptions options)
list
- A list of dependenciesoptions
- Options that determine which enhancements are applied to the dependency graph.protected void collapseDependenciesTree(java.util.List<TypedDependency> list)
Collection<TypedDependency>
to collapse
language-dependent transitive dependencies but keeping a tree structure.
list
- A list of dependencies to process for possible collapsingprotected void correctDependencies(java.util.List<TypedDependency> list)
TypedDependencyGraph
to correct
language-dependent dependencies. (e.g., nsubjpass in a relative clause)
public static boolean isConnected(java.util.Collection<TypedDependency> list)
list
- a list of typedDependenciespublic static java.util.Collection<TypedDependency> getRoots(java.util.Collection<TypedDependency> list)
list
- The list of TypedDependencies to checkpublic static java.util.List<GrammaticalStructure> readCoNLLXGrammaticalStructureCollection(java.lang.String fileName, java.util.Map<java.lang.String,GrammaticalRelation> shortNameToGRel, GrammaticalStructureFromDependenciesFactory factory) throws java.io.IOException
java.io.IOException
public static GrammaticalStructure buildCoNLLXGrammaticalStructure(java.util.List<java.util.List<java.lang.String>> tokenFields, java.util.Map<java.lang.String,GrammaticalRelation> shortNameToGRel, GrammaticalStructureFromDependenciesFactory factory)
public static void main(java.lang.String[] args)