001 package org.maltparser.core.syntaxgraph; 002 003 import java.util.Observer; 004 005 import org.maltparser.core.exception.MaltChainedException; 006 import org.maltparser.core.pool.ObjectPoolList; 007 import org.maltparser.core.symbol.SymbolTableHandler; 008 /** 009 * 010 * 011 * @author Johan Hall 012 */ 013 public abstract class SyntaxGraph implements LabeledStructure, Structure, Observer { 014 protected SymbolTableHandler symbolTables; 015 protected ObjectPoolList<LabelSet> labelSetPool; 016 protected int numberOfComponents; 017 018 public SyntaxGraph(SymbolTableHandler symbolTables) throws MaltChainedException { 019 setSymbolTables(symbolTables); 020 labelSetPool = new ObjectPoolList<LabelSet>() { 021 protected LabelSet create() { return new LabelSet(6); } 022 public void resetObject(LabelSet o) throws MaltChainedException { o.clear(); } 023 }; 024 } 025 026 public SymbolTableHandler getSymbolTables() { 027 return symbolTables; 028 } 029 030 public void setSymbolTables(SymbolTableHandler symbolTables) { 031 this.symbolTables = symbolTables; 032 } 033 034 public void addLabel(Element element, String labelFunction, String label) throws MaltChainedException { 035 element.addLabel(symbolTables.addSymbolTable(labelFunction), label); 036 } 037 038 public LabelSet checkOutNewLabelSet() throws MaltChainedException { 039 return labelSetPool.checkOut(); 040 } 041 042 public void checkInLabelSet(LabelSet labelSet) throws MaltChainedException { 043 labelSetPool.checkIn(labelSet); 044 } 045 046 public void clear() throws MaltChainedException { 047 numberOfComponents = 0; 048 labelSetPool.checkInAll(); 049 } 050 }