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