protected void removeDependencyEdge(Node head, Node dependent) throws MaltChainedException { if (head == null || dependent == null || head.getBelongsToGraph() != this || dependent.getBelongsToGraph() != this) { throw new SyntaxGraphException("Head or dependent node is missing."); } else if (!dependent.isRoot()) { Iterator<Edge> ie = dependent.getIncomingEdgeIterator(); while (ie.hasNext()) { Edge e = ie.next(); if (e.getSource() == head) { ie.remove(); graphEdges.remove(e); edgePool.checkIn(e); } } } else { throw new SyntaxGraphException("Head node is not a root node or a terminal node."); } }
public int compareTo(GraphEdge that) { final int BEFORE = -1; final int EQUAL = 0; final int AFTER = 1; if (this == that) return EQUAL; if (this.target.getCompareToIndex() < that.target.getCompareToIndex()) return BEFORE; if (this.target.getCompareToIndex() > that.target.getCompareToIndex()) return AFTER; if (this.source.getCompareToIndex() < that.source.getCompareToIndex()) return BEFORE; if (this.source.getCompareToIndex() > that.source.getCompareToIndex()) return AFTER; if (this.type < that.type) return BEFORE; if (this.type > that.type) return AFTER; return super.compareTo(that); }
public void clear() throws MaltChainedException { super.clear(); if (source != null) { this.source.removeOutgoingEdge(this); } if (target != null) { this.target.removeIncomingEdge(this); } this.source = null; this.target = null; this.type = -1; }
public String toStringNonTerminalNode(NonTerminalNode node) { final StringBuilder sb = new StringBuilder(); sb.append(node.toString().trim()); sb.append('\n'); Iterator<Edge> ie = ((Node)node).getOutgoingEdgeIterator(); while (ie.hasNext()) { Edge e = ie.next(); if (e.getTarget() instanceof TokenNode) { sb.append(" T"); sb.append(e.getTarget().getIndex()); } if (e.getTarget() instanceof NonTerminalNode) { sb.append(" N"); sb.append(e.getTarget().getIndex()); } sb.append('\t'); sb.append(e.toString()); sb.append('\n'); } return sb.toString(); }
/** * Sets the edge with a source node, a target node and a type (DEPENDENCY_EDGE, PHRASE_STRUCTURE_EDGE * or SECONDARY_EDGE). * * @param source a source node * @param target a target node * @param type a type (DEPENDENCY_EDGE, PHRASE_STRUCTURE_EDGE or SECONDARY_EDGE) * @throws MaltChainedException */ public void setEdge(Node source, Node target, int type) throws MaltChainedException { this.source = source; this.target = target; if (type >= Edge.DEPENDENCY_EDGE && type <= Edge.SECONDARY_EDGE ) { this.type = type; } this.source.addOutgoingEdge(this); this.target.addIncomingEdge(this); setChanged(); notifyObservers(this); }
protected void removeDependencyEdge(Node head, Node dependent) throws MaltChainedException { if (head == null || dependent == null) { throw new SyntaxGraphException("Head or dependent node is missing."); } else if (!dependent.isRoot()) { Iterator<Edge> ie = dependent.getIncomingEdgeIterator(); while (ie.hasNext()) { Edge e = ie.next(); if (e.getSource() == head) { graphEdges.remove(e); ie.remove(); edgePool.checkIn(e); } } } else { throw new SyntaxGraphException("Head node is not a root node or a terminal node."); } }
/** * Returns the graph (structure) in which the graph element belongs to. * * @return the graph (structure) in which the graph element belongs to. */ public LabeledStructure getBelongsToGraph() { return target.getBelongsToGraph(); }
public void removeSecondaryEdge(ComparableNode source, ComparableNode target) throws MaltChainedException { if (source == null || target == null) { throw new SyntaxGraphException("Head or dependent node is missing."); } else if (!target.isRoot()) { final Iterator<Edge> ie = ((Node)target).getIncomingEdgeIterator(); while (ie.hasNext()) { Edge e = ie.next(); if (e.getSource() == source) { ie.remove(); graphEdges.remove(e); edgePool.checkIn(e); } } } }
if (e != null && e.hasLabel(deprelTable) && !e.getSource().isRoot()) { if (overSet.size() == 0 || overSet.contains(e.getLabelSymbol(deprelTable))) { DependencyNode to = (DependencyNode)e.getSource();
public String toStringNonTerminalNode(NonTerminalNode node) { final StringBuilder sb = new StringBuilder(); sb.append(node.toString().trim()); sb.append('\n'); Iterator<Edge> ie = ((Node)node).getOutgoingEdgeIterator(); while (ie.hasNext()) { Edge e = ie.next(); if (e.getTarget() instanceof TokenNode) { sb.append(" T"); sb.append(e.getTarget().getIndex()); } if (e.getTarget() instanceof NonTerminalNode) { sb.append(" N"); sb.append(e.getTarget().getIndex()); } sb.append('\t'); sb.append(e.toString()); sb.append('\n'); } return sb.toString(); }
protected LWEdge(Node _source, Node _target) throws MaltChainedException { if (_source.getBelongsToGraph() != _target.getBelongsToGraph()) { throw new LWGraphException("The source node and target node must belong to the same dependency graph."); } this.source = _source; this.target = _target; this.labels = new TreeMap<ColumnDescription, String>(); }
public void removeSecondaryEdge(ComparableNode source, ComparableNode target) throws MaltChainedException { if (source == null || target == null) { throw new SyntaxGraphException("Head or dependent node is missing."); } else if (!target.isRoot()) { Iterator<Edge> ie = ((Node)target).getIncomingEdgeIterator(); while (ie.hasNext()) { Edge e = ie.next(); if (e.getSource() == source) { ie.remove(); graphEdges.remove(e); edgePool.checkIn(e); } } } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; LWEdge other = (LWEdge) obj; if (source.getIndex() != other.source.getIndex()) return false; if (target.getIndex() != other.target.getIndex()) return false; if (labels == null) { if (other.labels != null) return false; } else if (!labels.equals(other.labels)) return false; return true; }
protected LWEdge(Node _source, Node _target, SortedMap<ColumnDescription, String> _labels) throws MaltChainedException { if (_source.getBelongsToGraph() != _target.getBelongsToGraph()) { throw new LWGraphException("The source node and target node must belong to the same dependency graph."); } this.source = _source; this.target = _target; this.labels = _labels; SymbolTableHandler symbolTableHandler = getBelongsToGraph().getSymbolTables(); for (ColumnDescription column : labels.keySet()) { SymbolTable table = symbolTableHandler.addSymbolTable(column.getName()); table.addSymbol(labels.get(column)); } }
public void removeSecondaryEdge(ComparableNode source, ComparableNode target) throws MaltChainedException { if (source == null || target == null || source.getBelongsToGraph() != this || target.getBelongsToGraph() != this) { throw new SyntaxGraphException("Head or dependent node is missing."); } else if (!target.isRoot()) { Iterator<Edge> ie = ((Node)target).getIncomingEdgeIterator(); while (ie.hasNext()) { Edge e = ie.next(); if (e.getSource() == source) { ie.remove(); graphEdges.remove(e); edgePool.checkIn(e); } } } }
public int getHeadIndex() { if (headEdge == null) { return -1; } return headEdge.getSource().getIndex(); }
private static boolean cross ( Edge e1 , Edge e2 ) { int xSource = e1.getSource().getIndex(); int xTarget = e1.getTarget().getIndex(); int ySource = e2.getSource().getIndex(); int yTarget = e2.getTarget().getIndex(); int xMin = Math.min(xSource,xTarget); int xMax = Math.max(xSource,xTarget); int yMin = Math.min(ySource,yTarget); int yMax = Math.max(ySource,yTarget); //System.out.println(xMin+":"+xMax+":"+yMin+":"+yMax); return ( xMin < yMin && yMin < xMax && xMax < yMax ) || ( yMin < xMin && xMin < yMax && yMax < xMax ); }