/** * Utility routine that will create a string representation of a given * Sentence and place it inside brackets if it is a complex sentence that * has lower precedence than this complex sentence.<br> * <br> * Note: this is a form of pretty printing, whereby we only add brackets in * the concrete syntax representation as needed to ensure it can be parsed * back again into an equivalent abstract syntax representation used here. * * @param parentConnective * the connective of the parent sentence. * @param childSentence * a simpler child sentence. * @return a string representation of the Sentence, bracketed if the parent * based on its connective has higher precedence. */ public string bracketSentenceIfNecessary(Connective parentConnective, Sentence childSentence) { string result = null; if (childSentence is ComplexSentence) { ComplexSentence cs = (ComplexSentence)childSentence; if (cs.getConnective().getPrecedence() < parentConnective .getPrecedence()) { result = "(" + childSentence + ")"; } } if (result == null) { result = childSentence.ToString(); } return(result); }
public override bool Equals(object o) { if (this == o) { return(true); } if ((o == null) || (this.GetType() != o.GetType())) { return(false); } bool result = false; ComplexSentence other = (ComplexSentence)o; if (other.GetHashCode() == this.GetHashCode()) { if (other.getConnective().Equals(this.getConnective()) && other.getNumberSimplerSentences() == this .getNumberSimplerSentences()) { // connective and # of simpler sentences match // assume match and then test each simpler sentence result = true; for (int i = 0; i < this.getNumberSimplerSentences(); ++i) { if (!other.getSimplerSentence(i).Equals( this.getSimplerSentence(i))) { result = false; break; } } } } return(result); }