src/java/isac/util/formulae/CalcHead.java
author wneuper
Tue, 14 Jun 2005 17:22:50 +0200
changeset 2391 59a60ef2a2c8
parent 2351 9ea270ae70e4
child 2400 3ba8afe9f5cc
permissions -rw-r--r--
java: minor changes preparing tryMatch
     1 /*
     2  * Created on Sep 11, 2003
     3  */
     4 package isac.util.formulae;
     5 
     6 /**
     7  * Every calculation has a CalcHead, which consists of Model and Specification
     8  * of the calculation. The CalcHead is empty at the beginning of the
     9  * Specifying-phase and has to be filled before one can start the solving phase.
    10  * 
    11  * @author Alan Krempler
    12  */
    13 public class CalcHead extends CalcElement {
    14 
    15 	/**
    16 	 * Labels a model item as "correct" TODO rename CALCHEAD_* to MODEL_ITEM_*
    17 	 */
    18 	public static final int MODEL_ITEM_CORRECT = 1;
    19 
    20 	/**
    21 	 * Labels a model item as "incorrect"
    22 	 */
    23 	public static final int MODEL_ITEM_INCORRECT = 2;
    24 
    25 	/**
    26 	 * Labels a model item as "syntax error"
    27 	 */
    28 	public static final int MODEL_ITEM_SYNTAXERROR = 3;
    29 
    30 	/**
    31 	 * Labels a model item as "incomplete"
    32 	 */
    33 	public static final int MODEL_ITEM_INCOMPLETE = 4;
    34 
    35 	/**
    36 	 * Labels a model item as "false"
    37 	 */
    38 	public static final int MODEL_ITEM_FALSE = 5;
    39 
    40 	/**
    41 	 * Labels a model item as to be filled in by the KI
    42 	 */
    43 	public static final int MODEL_ITEM_HELP_ME = 6;
    44 
    45 	/**
    46 	 * Labels a model item as superfluous
    47 	 */
    48 	public static final int MODEL_ITEM_SUPERFLUOUS = 7;
    49 
    50 	/**
    51 	 * Labels a model item as missing
    52 	 */
    53 	public static final int MODEL_ITEM_MISSING = 8;
    54 
    55 	/**
    56 	 * show all details of a CalcHead in the CalcHeadPanel
    57 	 * 
    58 	 * @deprecated in favour of ICalcElement#VIEWSTYLE_DEFAULT FIXME.WN0504
    59 	 */
    60 	public static final int VIEWSTYLE_FULL = 2;
    61 
    62 	/**
    63 	 * skip to show the CalcHead in the CalcHeadPanel, rather only show the
    64 	 * HeadLine of the CalcHead on the Worksheet
    65 	 * 
    66 	 * @deprecated in favour of ICalcElement#DISPLAY_HIDDEN FIXME.WN0504
    67 	 */
    68 	public static final int VIEWSTYLE_SINGLELINE = 4;
    69 
    70 	/**
    71 	 * @deprecated WN050415 no description available
    72 	 */
    73 	//public static final int VIEWSTYLE_IN_CALC = 5;
    74 	/**
    75 	 * @deprecated WN050415 no description available
    76 	 */
    77 	//public static final int VIEWSTYLE_SIMPLE_SOLVE = 10;
    78 	// TODO: remove testing constant
    79 	private int calcTreeID = -4711;
    80 
    81 	private CalcHeadItemList given_, where_, find_, relate_;
    82 
    83 	private Specification specification;
    84 
    85 	private Position position;
    86 
    87 	private String belongsTo;
    88 
    89 	private String head;//TODO.WN050420 should be type Formula
    90 
    91 	private int calcHeadStatus;//TODO.WN041007 confusion with statusString
    92 
    93 	private String statusString;//TODO.WN041007 confusion with calcHeadStatus
    94 
    95 	// drop THIS one and setStatusString
    96 
    97 	/**
    98 	 * Format the object in a way that the bridge can handle it FIXME.WN041008
    99 	 * this is Formalization.toSMLString, _NOT_ CalcHead.toSMLString !!!
   100 	 * 
   101 	 * @return SML representation
   102 	 */
   103 	public String toSMLString() {
   104 		//this should go to Formalization???WN050420 dont understand
   105 		StringBuffer sb = new StringBuffer();
   106 		sb.append("[([");
   107 		if (getGiven() != null) {
   108 			sb.append(getGiven().toSMLString());
   109 		}
   110 		if (getWhere() != null) {
   111 			sb.append(",");
   112 			sb.append(getWhere().toSMLString());
   113 		}
   114 		if (getFind() != null) {
   115 			sb.append(",");
   116 			sb.append(getFind().toSMLString());
   117 		}
   118 		if (getRelate() != null) {
   119 			sb.append(",");
   120 			sb.append(getRelate().toSMLString());
   121 		}
   122 		sb.append("],(");
   123 		if (getSpecification() != null) {
   124 			sb.append(specification.toSMLString());
   125 		}
   126 		sb.append("))]");
   127 		return sb.toString();
   128 	}
   129 
   130 	/**
   131 	 * Special string format of the calcHead used by modifyCalcHead
   132 	 * TODO.WN041007 ?
   133 	 * 
   134 	 * @return String used by modifyCalcHead
   135 	 */
   136 	public String toModifyCalcHeadString() {
   137 		StringBuffer sb = new StringBuffer();
   138 		try {
   139 			belongsTo = "Pbl";//TODO.WN041007 this is too restrictive: + Met !!
   140 			sb.append("((");
   141 			if (position == null) {
   142 				position = new Position();
   143 				position.setKind("Pbl");
   144 			}
   145 			sb.append(position.toSMLString());
   146 			sb.append("),\"");
   147 			sb.append(head);
   148 			sb.append("\",[Given [");
   149 			sb.append(given_.toSMLString());
   150 			sb.append("],Find [");
   151 			sb.append(find_.toSMLString());
   152 			sb.append("],Relate [");
   153 			sb.append(relate_.toSMLString());
   154 			sb.append("]]," + belongsTo + ",(");
   155 			sb.append(specification.toSMLString());
   156 			sb.append("))");
   157 
   158 		} catch (Exception e) {
   159 			System.out.println("Some Items of Calchead are null!");
   160 		}
   161 		return sb.toString();
   162 	}
   163 
   164 	/**
   165 	 * Copies values form one CalcHead object to another. This is needed,
   166 	 * because the backend produces a new calcHead after each update, but the
   167 	 * dialog holds only one instance of CalcHead all the time.
   168 	 * 
   169 	 * @param other
   170 	 *            the other calcHead object
   171 	 */
   172 	public void fillValuesfrom(CalcHead other) {
   173 		this.belongsTo = other.belongsTo;
   174 		this.calcHeadStatus = other.calcHeadStatus;
   175 		this.calcTreeID = other.calcTreeID;
   176 		this.find_ = other.find_;
   177 		this.given_ = other.given_;
   178 		this.head = other.head;
   179 		this.position = other.position;
   180 		this.relate_ = other.relate_;
   181 		this.specification = other.specification;
   182 		this.where_ = other.where_;
   183 		this.visibility_ = other.visibility_;
   184 		this.view_style_ = other.view_style_;
   185 		this.rating_ = other.rating_;
   186 	}
   187 
   188 	/*
   189 	 * (non-Javadoc)
   190 	 * 
   191 	 * @see isac.util.CalcElement#getMathML()
   192 	 */
   193 	public String getMathML() {
   194 		// TODO Auto-generated method stub
   195 		return null;
   196 	}
   197 
   198 	/*
   199 	 * (non-Javadoc)
   200 	 * 
   201 	 * @see isac.util.CalcElement#getType()
   202 	 */
   203 	public int getType() {
   204 		return CALCEL_CALCHEAD;
   205 	}
   206 
   207 	public CalcHeadItemList getFind() {
   208 		return find_;
   209 	}
   210 
   211 	public CalcHeadItemList getGiven() {
   212 		return given_;
   213 	}
   214 
   215 	public CalcHeadItemList getRelate() {
   216 		return relate_;
   217 	}
   218 
   219 	public CalcHeadItemList getWhere() {
   220 		return where_;
   221 	}
   222 
   223 	public void setFind(CalcHeadItemList el) {
   224 		find_ = el;
   225 	}
   226 
   227 	public void setGiven(CalcHeadItemList el) {
   228 		given_ = el;
   229 	}
   230 
   231 	public void setRelate(CalcHeadItemList el) {
   232 		relate_ = el;
   233 	}
   234 
   235 	public void setWhere(CalcHeadItemList el) {
   236 		where_ = el;
   237 	}
   238 
   239 	public Specification getSpecification() {
   240 		return specification;
   241 	}
   242 
   243 	public void setSpecification(Specification specification) {
   244 		this.specification = specification;
   245 	}
   246 
   247 	public Position getPosition() {
   248 		return position;
   249 	}
   250 
   251 	public void setPosition(Position position) {
   252 		this.position = position;
   253 	}
   254 
   255 	//for XMLParserDigest
   256 	public void setResponse(Position position) {
   257 		this.position = position;
   258 	}
   259 
   260 	public String getBelongsTo() {
   261 		return belongsTo;
   262 	}
   263 
   264 	public void setBelongsTo(String string) {
   265 		belongsTo = string;
   266 	}
   267 
   268 	public String getHead() {
   269 		return head;
   270 	}
   271 
   272 	/**
   273 	 * set the headline in the CalcHead; this is in general e.g.
   274 	 * 'Problem(Reals,[by_calculus,maximum])' or for algebrasystem-like problems
   275 	 * e.g. 'solve(x+1=2,x)'
   276 	 */
   277 	public void setHead(String string) {
   278 		head = string;
   279 	}
   280 
   281 	public int getCalcTreeID() {
   282 		return calcTreeID;
   283 	}
   284 
   285 	public void setCalcTreeID(int id) {
   286 		calcTreeID = id;
   287 	}
   288 
   289 	public int getCalcHeadStatus() {
   290 		return calcHeadStatus;
   291 	}
   292 
   293 	/**
   294 	 * distinguish between (1) the _overall_-status of a CalcHead and (2) e.g.
   295 	 * the MODEL_ITEM_CORRECT for model items as defined above HERE (2) IS MEANT !
   296 	 * 
   297 	 * @see <isac.util.formulae.CalcHead#setStatusString(String)>
   298 	 */
   299 	public void setCalcHeadStatus(int i) {
   300 		calcHeadStatus = i;
   301 	}
   302 
   303 	public void setCalcHeadStatus(String s) {//TOD0.WN041007 drop this NONSENSE
   304 		if (s.compareTo("correct") == 0) {
   305 			calcHeadStatus = (MODEL_ITEM_CORRECT);
   306 		} else if (s.compareTo("incorrect") == 0) {
   307 			calcHeadStatus = (MODEL_ITEM_INCORRECT);
   308 		}
   309 	}
   310 
   311 	public String getStatusString() {
   312 		return statusString;
   313 	}
   314 
   315 	/**
   316 	 * distinguish between (1) the _overall_-status of a CalcHead and (2) e.g.
   317 	 * the MODEL_ITEM_CORRECT for model items as defined above HERE (1) IS MEANT !
   318 	 * 
   319 	 * @see <isac.util.formulae.CalcHead#setCalcHeadStatus(int)>
   320 	 */
   321 	public void setStatusString(String string) {//TOD0.WN041007 rename to
   322 		// setCalcHeadStatus
   323 		statusString = string; //TOD0.WN041007 calcHeadStatus = string;
   324 		setCalcHeadStatus(string);//TOD0.WN041007 drop this !!!
   325 	}
   326 
   327 	public boolean usesTheory(String thyID) {//TODO.WN040930 new type TheoryID
   328 		// ?
   329 		return this.specification.getTheory().equals(thyID);
   330 	}
   331 
   332 	public boolean usesSubTheoryOf(String thyID) {//TODO.WN040930 new type
   333 		// TheoryID ?
   334 		System.err.println("TODO CalcHead.usesSubTheoryOf(" + thyID + ")");
   335 		System.exit(999);
   336 		return false;
   337 	}
   338 
   339 	public boolean usesProblem(ProblemID pid) {
   340 		return this.specification.getProblem().equals(pid);
   341 	}
   342 
   343 	public boolean usesProblemClass(ProblemID pid) {
   344 		CalcHeadCompoundID p = this.specification.getProblem();
   345 		return ((ProblemID) this.specification.getProblem())
   346 				.belongsToClass(pid);
   347 	}
   348 
   349 }