Exemplo n.º 1
0
 //
 // PRIVATE
 //
 private void assertLegalArguments(Connective connective, params Sentence[] sentences)
 {
     if (connective == null)
     {
         throw new ArgumentException("Connective must be specified.");
     }
     if (sentences == null)
     {
         throw new ArgumentException("> 0 simpler sentences must be specified.");
     }
     if (connective == Connective.NOT)
     {
         if (sentences.Length != 1)
         {
             throw new ArgumentException("A not (~) complex sentence only take 1 simpler sentence not " + sentences.Length);
         }
     }
     else
     {
         if (sentences.Length != 2)
         {
             throw new ArgumentException("Connective is binary (" + connective + ") but only " + sentences.Length + " simpler sentences provided");
         }
     }
 }
Exemplo n.º 2
0
        /**
         * Constructor.
         *
         * @param connective
         *            the complex sentence's connective.
         * @param sentences
         *            the simpler sentences making up the complex sentence.
         */
        public ComplexSentence(Connective connective, params Sentence[] sentences)
        {
            // Assertion checks
            assertLegalArguments(connective, sentences);

            this.connective  = connective;
            simplerSentences = new Sentence[sentences.Length];
            for (int i = 0; i < sentences.Length; i++)
            {
                simplerSentences[i] = sentences[i];
            }
        }
Exemplo n.º 3
0
        /**
         * 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);
        }
Exemplo n.º 4
0
 /**
  * Convenience constructor for binary sentences.
  *
  * @param sentenceL
  *          the left hand sentence.
  * @param binaryConnective
  *          the binary connective.
  * @param sentenceR
  *          the right hand sentence.
  */
 public ComplexSentence(Sentence sentenceL, Connective binaryConnective, Sentence sentenceR) : this(binaryConnective, sentenceL, sentenceR)
 {
 }
Exemplo n.º 5
0
        // PROTECTED

        protected bool hasConnective(Connective connective)
        {
            // Note: can use '==' as Connective is an enum.
            return(getConnective() == connective);
        }