00001 /* 00002 * All of the documentation and software included in the 00003 * Alchemy Software is copyrighted by Stanley Kok, Parag 00004 * Singla, Matthew Richardson, Pedro Domingos, Marc 00005 * Sumner and Hoifung Poon. 00006 * 00007 * Copyright [2004-07] Stanley Kok, Parag Singla, Matthew 00008 * Richardson, Pedro Domingos, Marc Sumner and Hoifung 00009 * Poon. All rights reserved. 00010 * 00011 * Contact: Pedro Domingos, University of Washington 00012 * (pedrod@cs.washington.edu). 00013 * 00014 * Redistribution and use in source and binary forms, with 00015 * or without modification, are permitted provided that 00016 * the following conditions are met: 00017 * 00018 * 1. Redistributions of source code must retain the above 00019 * copyright notice, this list of conditions and the 00020 * following disclaimer. 00021 * 00022 * 2. Redistributions in binary form must reproduce the 00023 * above copyright notice, this list of conditions and the 00024 * following disclaimer in the documentation and/or other 00025 * materials provided with the distribution. 00026 * 00027 * 3. All advertising materials mentioning features or use 00028 * of this software must display the following 00029 * acknowledgment: "This product includes software 00030 * developed by Stanley Kok, Parag Singla, Matthew 00031 * Richardson, Pedro Domingos, Marc Sumner and Hoifung 00032 * Poon in the Department of Computer Science and 00033 * Engineering at the University of Washington". 00034 * 00035 * 4. Your publications acknowledge the use or 00036 * contribution made by the Software to your research 00037 * using the following citation(s): 00038 * Stanley Kok, Parag Singla, Matthew Richardson and 00039 * Pedro Domingos (2005). "The Alchemy System for 00040 * Statistical Relational AI", Technical Report, 00041 * Department of Computer Science and Engineering, 00042 * University of Washington, Seattle, WA. 00043 * http://www.cs.washington.edu/ai/alchemy. 00044 * 00045 * 5. Neither the name of the University of Washington nor 00046 * the names of its contributors may be used to endorse or 00047 * promote products derived from this software without 00048 * specific prior written permission. 00049 * 00050 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON 00051 * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00052 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00053 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00054 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY 00055 * OF WASHINGTON OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00056 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00057 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00058 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00059 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00060 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00061 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00062 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00063 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00064 * 00065 */ 00066 #include "predicatetemplate.h" 00067 #include "domain.h" 00068 00069 const char* PredicateTemplate::EMPTY_NAME = "SK_EMPTY"; 00070 const char* PredicateTemplate::EQUAL_NAME = "SK_EQUAL"; 00071 const char* PredicateTemplate::GT_NAME = "greaterThan"; 00072 const char* PredicateTemplate::LT_NAME = "lessThan"; 00073 const char* PredicateTemplate::GTEQ_NAME = "greaterThanEq"; 00074 const char* PredicateTemplate::LTEQ_NAME = "lessThanEq"; 00075 const char* PredicateTemplate::SUBSTR_NAME = "substr"; 00076 const char* PredicateTemplate::ANY_TYPE_NAME = "SK_ANY"; 00077 const char* PredicateTemplate::INT_TYPE_NAME = "int"; 00078 const char* PredicateTemplate::STRING_TYPE_NAME = "string"; 00079 const char* PredicateTemplate::ZZ_RETURN_PREFIX = "isReturnValueOf"; 00080 00081 const char* PredicateTemplate::SUCC_NAME = "succ"; 00082 const char* PredicateTemplate::PLUS_NAME = "plus"; 00083 const char* PredicateTemplate::MINUS_NAME = "minus"; 00084 const char* PredicateTemplate::TIMES_NAME = "times"; 00085 const char* PredicateTemplate::DIVIDEDBY_NAME = "dividedBy"; 00086 const char* PredicateTemplate::MOD_NAME = "mod"; 00087 const char* PredicateTemplate::CONCAT_NAME = "concat"; 00088 00089 // Caller is responsible for deleting typeName if required. 00090 // returns true if termType is successfully added; false otherwise 00091 // isUnique is false by default 00092 bool PredicateTemplate::appendTermType(const char* const & typeName, 00093 const bool& isUnique, 00094 const Domain* const & domain) 00095 { 00096 int id = domain->getTypeId(typeName); 00097 if (id < 0) 00098 { 00099 cout << "Warning: In PredicateTemplate::addTermType(). Type " << typeName 00100 << " has not been declared." << endl; 00101 return false; 00102 } 00103 00104 char* tname = new char[strlen(typeName)+1]; 00105 strcpy(tname, typeName); 00106 termTypesAsStr_->append(tname); 00107 termTypesAsInt_->append(id); 00108 termsUnique_->append(isUnique); 00109 assert(termTypesAsStr_->size() == termTypesAsInt_->size()); 00110 return true; 00111 } 00112 00113 00114 // returns true if termType is successfully added; false otherwise 00115 // isUnique is false by default 00116 bool PredicateTemplate::appendTermType(const int& typeId, const bool& isUnique, 00117 const Domain* const & domain) 00118 { 00119 const char* typeName = domain->getTypeName(typeId); 00120 if (typeName==NULL) 00121 { 00122 cout << "Error: In PredicateTemplate::addTermType(). TypeId " << typeId 00123 << " does not exist." << endl; 00124 return false; 00125 } 00126 00127 char* tname = new char[strlen(typeName)+1]; 00128 strcpy(tname, typeName); 00129 termTypesAsStr_->append(tname); 00130 termTypesAsInt_->append(typeId); 00131 termsUnique_->append(isUnique); 00132 assert(termTypesAsStr_->size() == termTypesAsInt_->size()); 00133 return true; 00134 } 00135 00136