001package org.maltparser.core.flow.item; 002 003import org.maltparser.core.exception.MaltChainedException; 004import org.maltparser.core.flow.FlowChartInstance; 005import org.maltparser.core.flow.spec.ChartItemSpecification; 006import org.maltparser.core.flow.system.elem.ChartElement; 007/** 008* 009* 010* @author Johan Hall 011*/ 012public abstract class ChartItem { 013 protected FlowChartInstance flowChartinstance; 014 protected ChartItemSpecification chartItemSpecification; 015 016 // Signals 017 public final static int CONTINUE = 1; 018 public final static int TERMINATE = 2; 019 public final static int NEWITERATION = 3; 020 021 public ChartItem() { } 022 023 /** 024 * Initialize the chart item 025 * 026 * @param flowChartinstance the flow chart instance that the chart item belongs to 027 * @param chartItemSpecification a specification of the chart item 028 * @throws MaltChainedException 029 */ 030 public void initialize(FlowChartInstance flowChartinstance, ChartItemSpecification chartItemSpecification) throws MaltChainedException { 031 setFlowChartInstance(flowChartinstance); 032 setChartItemSpecification(chartItemSpecification); 033 } 034 035 /** 036 * Cause the chart item to perform the preprocess tasks 037 * 038 * @param signal returned by the previous chart item 039 * @return true if every thing is ok, otherwise false 040 * @throws MaltChainedException 041 */ 042 public abstract int preprocess(int signal) throws MaltChainedException; 043 044 /** 045 * Cause the chart item to perform the process task (for every sentence) 046 * 047 * @param signal returned by the previous chart item 048 * @return true if it is ready to perform the next sentence, otherwise false 049 * @throws MaltChainedException 050 */ 051 public abstract int process(int signal) throws MaltChainedException; 052 053 /** 054 * Cause the chart item to perform the postprocess tasks 055 * 056 * @param signal returned by the previous chart item 057 * @return true if every thing is ok, otherwise false 058 * @throws MaltChainedException 059 */ 060 public abstract int postprocess(int signal) throws MaltChainedException; 061 062 /** 063 * Terminates and cleans up the chart item 064 * 065 * @throws MaltChainedException 066 */ 067 public abstract void terminate() throws MaltChainedException; 068 069 /** 070 * Returns the flow chart instance that the chart item belongs to 071 * 072 * @return the flow chart instance that the chart item belongs to 073 */ 074 public FlowChartInstance getFlowChartInstance() { 075 return flowChartinstance; 076 } 077 078 /** 079 * Sets the flow chart instance that the chart item belongs to 080 * 081 * @param flowChartinstance a flow chart instance 082 */ 083 protected void setFlowChartInstance(FlowChartInstance flowChartinstance) { 084 this.flowChartinstance = flowChartinstance; 085 } 086 087 /** 088 * Returns the option container index 089 * 090 * @return the option container index 091 */ 092 public int getOptionContainerIndex() { 093 return flowChartinstance.getOptionContainerIndex(); 094 } 095 096 /** 097 * Returns the chart element in the flow chart system description 098 * 099 * @param key a chart element key 100 * @return the chart element in the flow chart system description 101 */ 102 public ChartElement getChartElement(String key) { 103 return flowChartinstance.getFlowChartManager().getFlowChartSystem().getChartElement(key); 104 } 105 106 /** 107 * Returns a chart item specification 108 * 109 * @return a chart item specification 110 */ 111 public ChartItemSpecification getChartItemSpecification() { 112 return chartItemSpecification; 113 } 114 115 /** 116 * Sets the specification of the chart item 117 * 118 * @param chartItemSpecification a chart item specification 119 */ 120 public void setChartItemSpecification(ChartItemSpecification chartItemSpecification) { 121 this.chartItemSpecification = chartItemSpecification; 122 } 123}