############################################################################### ## ## ## ALEXANDRIA DIGITAL LIBRARY ## ## University of California at Santa Barbara ## ## ## ## ------------------------------------------------------------------------- ## ## ## ## Copyright (c) 2004 by the Regents of the University of California ## ## All rights reserved ## ## ## ## Redistribution and use in source and binary forms, with or without ## ## modification, are permitted provided that the following conditions are ## ## met: ## ## ## ## 1. Redistributions of source code must retain the above copyright ## ## notice, this list of conditions, and the following disclaimer. ## ## ## ## 2. Redistributions in binary form must reproduce the above copyright ## ## notice, this list of conditions, and the following disclaimer in ## ## the documentation and/or other materials provided with the ## ## distribution. ## ## ## ## 3. All advertising materials mentioning features or use of this ## ## software must display the following acknowledgement: This product ## ## includes software developed by the Alexandria Digital Library, ## ## University of California at Santa Barbara, and its contributors. ## ## ## ## 4. Neither the name of the University nor the names of its ## ## contributors may be used to endorse or promote products derived ## ## from this software without specific prior written permission. ## ## ## ## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY ## ## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ## ## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE ## ## DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ## ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ## ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ## ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ## ## STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ## ## ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ## ## POSSIBILITY OF SUCH DAMAGE. ## ## ## ############################################################################### # $Header: /export/home/gjanee/bucket99/paradigms/RCS/Temporal_Constant.py,v 1.2 2004/02/25 00:17:19 gjanee Exp $ # SYNOPSIS # # Temporal_Constant (table, idColumn, begin, end, cardinality) # # table # A table to query, e.g., "holding". # # idColumn # The table's object identifier column (i.e., the column # to be selected), e.g., "holding_id". # # begin # The begin date of a date range, expressed as an integer # in the encoding YYYYMMDD. # # end # The end date of a date range, expressed as an integer in # the encoding YYYYMMDD. # # cardinality # A Cardinality object representing the cardinality of # 'table'. Should be Cardinality("1") or # Cardinality("1?"). # # DESCRIPTION # # Translates a temporal constraint to a constant TRUE or FALSE # depending on whether the constraint date range matches the # constant date range [begin, end]. A constraint that matches # results in the query # # SELECT idColumn FROM table # WHERE 1 = 1 # # being returned. Otherwise, the query # # SELECT idColumn FROM table # WHERE 1 = 0 # # is returned. # # Exceptions thrown: # # none # # AUTHOR # # Greg Janee # gjanee@alexandria.ucsb.edu # # HISTORY # # $Log: Temporal_Constant.py,v $ # Revision 1.2 2004/02/25 00:17:19 gjanee # Minor documentation fix. # # Revision 1.1 2004/02/10 05:54:07 gjanee # Initial revision # import types import edu.ucsb.adl.middleware M = edu.ucsb.adl.middleware import UniversalTranslator UT = UniversalTranslator class Temporal_Constant (UT.Paradigm): def __init__ (self, table, idColumn, begin, end, cardinality): UT.assertType(table, types.StringType) UT.assertType(idColumn, types.StringType) UT.assertType(begin, types.IntType) assert begin >= 101 and begin <= 99991231,\ "invalid date: " + str(begin) # 101 means '0000-01-01' here UT.assertType(end, types.IntType) assert end >= 101 and end <= 99991231,\ "invalid date: " + str(end) assert begin <= end, "invalid date range: begin > end" UT.assertType(cardinality, UT.Cardinality) self.table = table self.idColumn = idColumn self.begin = begin self.end = end self.cardinality = cardinality.clone() self.cardinality.nullable = 0 def translateBucketAtomic (self, constraint, vocabularies): UT.assertType(constraint, M.Query.TemporalConstraint) assert constraint.getOperator() in UT.standardTemporalOperators,\ "unsupported operator: " + constraint.getOperator() if constraint.getOperator() == "contains": x = self.begin <= constraint.getBegin() and\ self.end >= constraint.getEnd() elif constraint.getOperator() == "is-contained-in": x = self.begin >= constraint.getBegin() and\ self.end <= constraint.getEnd() elif constraint.getOperator() == "overlaps": x = self.end >= constraint.getBegin() and\ self.begin <= constraint.getEnd() else: UT.unhandledCase() if x: return UT.constantTrueQuery(self.table, self.idColumn, "N/A", self.cardinality) else: return UT.constantFalseQuery(self.table, self.idColumn, self.cardinality)