001 package org.maltparser.core.syntaxgraph; 002 003 import java.util.SortedMap; 004 import java.util.SortedSet; 005 006 import org.maltparser.core.exception.MaltChainedException; 007 import org.maltparser.core.symbol.SymbolTable; 008 import org.maltparser.core.syntaxgraph.edge.Edge; 009 import org.maltparser.core.syntaxgraph.node.DependencyNode; 010 /** 011 * 012 * 013 * @author Johan Hall 014 */ 015 public interface DependencyStructure extends TokenStructure, SecEdgeStructure { 016 public DependencyNode addDependencyNode() throws MaltChainedException; 017 public DependencyNode addDependencyNode(int index) throws MaltChainedException; 018 /** 019 * Returns the dependency node identified by <i>index</i> if it exists, otherwise <i>null</i>. 020 * 021 * @param index the index of the dependency node 022 * @return the dependency node identified by <i>index</i> if it exists, otherwise <i>null</i>. 023 * @throws MaltChainedException 024 */ 025 public DependencyNode getDependencyNode(int index) throws MaltChainedException; 026 public int nDependencyNode(); 027 028 029 public int getHighestDependencyNodeIndex(); 030 /** 031 * Adds an edge from the head to the dependent identified by the indices of the dependency nodes. 032 * 033 * @param headIndex the index of the head dependency node 034 * @param dependentIndex the index of the dependent dependency node 035 * @return the edge that have been added. 036 * @throws MaltChainedException 037 */ 038 public Edge addDependencyEdge(int headIndex, int dependentIndex) throws MaltChainedException; 039 /** 040 * Replace the head of the dependent with a new head. The labels are not affected. 041 * 042 * @param newHeadIndex the index of the new head dependency node 043 * @param dependentIndex the index of the dependent dependency node 044 * @return the edge that have been moved. 045 * @throws MaltChainedException 046 */ 047 public Edge moveDependencyEdge(int newHeadIndex, int dependentIndex) throws MaltChainedException; 048 /** 049 * Remove an edge from the head to the dependent identified by the indices of the dependency nodes. 050 * @param headIndex the index of the head dependency node 051 * @param dependentIndex the index of the dependent dependency node 052 * @throws MaltChainedException 053 */ 054 public void removeDependencyEdge(int headIndex, int dependentIndex) throws MaltChainedException; 055 /** 056 * Returns the number of edges 057 * 058 * @return the number of edges 059 */ 060 public int nEdges(); 061 /** 062 * Returns a sorted set of integers {0,s,..n} , where each index i identifies a dependency node. Index 0 063 * should always be the root dependency node and index s is the first terminal node and index n is the 064 * last terminal node. 065 * 066 * @return a sorted set of integers 067 */ 068 public SortedSet<Integer> getDependencyIndices(); 069 /** 070 * Returns the root of the dependency structure. 071 * 072 * @return the root of the dependency structure. 073 */ 074 public DependencyNode getDependencyRoot(); 075 /** 076 * Returns <i>true</i> if the head edge of the dependency node with <i>index</i> is labeled, otherwise <i>false</i>. 077 * 078 * @param index the index of the dependency node 079 * @return <i>true</i> if the head edge of the dependency node with <i>index</i> is labeled, otherwise <i>false</i>. 080 * @throws MaltChainedException 081 */ 082 public boolean hasLabeledDependency(int index) throws MaltChainedException; 083 /** 084 * Returns <i>true</i> if all nodes in the dependency structure are connected, otherwise <i>false</i>. 085 * 086 * @return <i>true</i> if all nodes in the dependency structure are connected, otherwise <i>false</i>. 087 */ 088 public boolean isConnected(); 089 /** 090 * Returns <i>true</i> if all edges in the dependency structure are projective, otherwise <i>false</i>. 091 * 092 * @return <i>true</i> if all edges in the dependency structure are projective, otherwise <i>false</i>. 093 * @throws MaltChainedException 094 */ 095 public boolean isProjective() throws MaltChainedException; 096 /** 097 * Returns <i>true</i> if all dependency nodes have at most one incoming edge, otherwise <i>false</i>. 098 * 099 * @return <i>true</i> if all dependency nodes have at most one incoming edge, otherwise <i>false</i>. 100 */ 101 public boolean isSingleHeaded(); 102 /** 103 * Returns <i>true</i> if the dependency structure are a tree (isConnected() && isSingleHeaded()), otherwise <i>false</i>. 104 * 105 * @return <i>true</i> if the dependency structure are a tree (isConnected() && isSingleHeaded()), otherwise <i>false</i>. 106 */ 107 public boolean isTree(); 108 /** 109 * Returns the number of non-projective edges in the dependency structure. 110 * 111 * @return the number of non-projective edges in the dependency structure. 112 * @throws MaltChainedException 113 */ 114 public int nNonProjectiveEdges() throws MaltChainedException; 115 /** 116 * Links all subtrees to the root of the dependency structure. 117 * 118 * @throws MaltChainedException 119 */ 120 public void linkAllTreesToRoot() throws MaltChainedException; 121 /** 122 * Returns the default edge label of the root as a string value. 123 * 124 * @param table the symbol table that identifies the label type. 125 * @return the default edge label of the root. 126 * @throws MaltChainedException 127 */ 128 public String getDefaultRootEdgeLabelSymbol(SymbolTable table) throws MaltChainedException; 129 /** 130 * Returns the default edge label of the root as an integer value. 131 * 132 * @param table the symbol table that identifies the label type. 133 * @return the default edge label of the root as an integer value. 134 * @throws MaltChainedException 135 */ 136 public int getDefaultRootEdgeLabelCode(SymbolTable table) throws MaltChainedException; 137 /** 138 * Sets the default edge label of the root. 139 * 140 * @param table the symbol table that identifies the label type. 141 * @param defaultRootSymbol the default root edge label 142 * @throws MaltChainedException 143 */ 144 public void setDefaultRootEdgeLabel(SymbolTable table, String defaultRootSymbol) throws MaltChainedException; 145 /** 146 * Sets the default edge label of the root according to the default root label option 147 * 148 * @param rootLabelOption the default root label option 149 * @param edgeSymbolTables a sorted map that maps the symbol table name to the symbol table object. 150 * @throws MaltChainedException 151 */ 152 public void setDefaultRootEdgeLabels(String rootLabelOption, SortedMap<String, SymbolTable> edgeSymbolTables) throws MaltChainedException; 153 }