コード例 #1
0
 //
 // PRIVATE
 //
 private void assertLegalArguments(Connective connective, params Sentence[] sentences)
 {
     if (connective == null)
     {
         throw new IllegalArgumentException("Connective must be specified.");
     }
     if (sentences == null)
     {
         throw new IllegalArgumentException("> 0 simpler sentences must be specified.");
     }
     if (connective == Connective.NOT)
     {
         if (sentences.Length != 1)
         {
             throw new IllegalArgumentException("A not (~) complex sentence only take 1 simpler sentence not " + sentences.Length);
         }
     }
     else
     {
         if (sentences.Length != 2)
         {
             throw new IllegalArgumentException("Connective is binary (" + connective + ") but only " + sentences.Length + " simpler sentences provided");
         }
     }
 }
コード例 #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];
            System.Array.Copy(sentences, 0, simplerSentences, 0, sentences.Length);
        }
コード例 #3
0
ファイル: Sentence.cs プロジェクト: tvn-cosine/aima.net
        /**
         * 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);
        }
コード例 #4
0
ファイル: Sentence.cs プロジェクト: tvn-cosine/aima.net
 protected bool hasConnective(Connective connective)
 {
     // Note: can use '==' as Connective is an enum.
     return(getConnective() == connective);
 }
コード例 #5
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)
 {
 }