[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ solve the problem with quanted/quantor
Charith Paranaliyanage
paranaliyanage at gmail.com
Wed Aug 27 04:01:07 EDT 2008
Log message for revision 90407:
solve the problem with quanted/quantor
Changed:
U Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt
U Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py
U Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
U Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt
U Sandbox/adamg/ocql/trunk/src/ocql/tests/functions.txt
-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt 2008-08-27 07:54:14 UTC (rev 90406)
+++ Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt 2008-08-27 08:01:07 UTC (rev 90407)
@@ -58,9 +58,9 @@
>>> QueryParser("set [ d in IDepartment; every set [ c in ICourse; some c.runBy == d | c.credits ] == 2 | d.name ]")(None)
Head(Query(<type 'set'>, In(Identifier(d), Identifier(IDepartment));
- Eq((Every, Query(<type 'set'>, In(Identifier(c), Identifier(ICourse));
- Eq((Some, Property(Identifier(c), Identifier(runBy))), Identifier(d)), Property(Identifier(c), Identifier(credits)))),
- Constant(2)), Property(Identifier(d), Identifier(name))))
+ Eq(Quanted((Every, ''), Query(<type 'set'>, In(Identifier(c), Identifier(ICourse));
+ Eq(Quanted((Some, ''), Property(Identifier(c), Identifier(runBy))), Identifier(d)),
+ Property(Identifier(c), Identifier(credits)))), Constant(2)), Property(Identifier(d), Identifier(name))))
>>> QueryParser("set [ c in ICourse; c.credits > 3 | c.code ]")(None)
Head(Query(<type 'set'>, In(Identifier(c), Identifier(ICourse)); Gt(Property(Identifier(c), Identifier(credits)), Constant(3)), Property(Identifier(c), Identifier(code))))
@@ -107,20 +107,26 @@
Head(Query(<type 'set'>, In(Identifier(i), Identifier(IPerson)); Isinstance(Identifier(i), Tutor), Identifier(i)))
>>> QueryParser("set [ s in Staff; set [st in IStudent; some st.takes == atleast 2 s.teaches | st.name] == 'St1' | i.name ]")(None)
- Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff)); Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudent));
- Eq((Some, Property(Identifier(st), Identifier(takes))), (Atleast(2, Property(Identifier(s), Identifier(teaches))))),
+ Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff));
+ Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudent));
+ Eq(Quanted((Some, ''), Property(Identifier(st), Identifier(takes))),
+ Quanted((Atleast, 2), Property(Identifier(s), Identifier(teaches)))),
Property(Identifier(st), Identifier(name))), Constant('St1')), Property(Identifier(i), Identifier(name))))
>>> QueryParser("set [ s in Staff; set [st in IStudent; some st.takes == just 2 s.teaches | st.name] == 'St1' | i.name ]")(None)
- Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff)); Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudent));
- Eq((Some, Property(Identifier(st), Identifier(takes))), (Just(2, Property(Identifier(s), Identifier(teaches))))),
+ Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff));
+ Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudent));
+ Eq(Quanted((Some, ''), Property(Identifier(st), Identifier(takes))),
+ Quanted((Just, 2), Property(Identifier(s), Identifier(teaches)))),
Property(Identifier(st), Identifier(name))), Constant('St1')), Property(Identifier(i), Identifier(name))))
>>> QueryParser("set [ s in Staff; set [st in IStudent; some st.takes == atmost 2 s.teaches | st.name] == 'St1' | i.name ]")(None)
- Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff)); Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudent));
- Eq((Some, Property(Identifier(st), Identifier(takes))), (Atmost(2, Property(Identifier(s), Identifier(teaches))))),
+ Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff));
+ Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudent));
+ Eq(Quanted((Some, ''), Property(Identifier(st), Identifier(takes))),
+ Quanted((Atmost, 2), Property(Identifier(s), Identifier(teaches)))),
Property(Identifier(st), Identifier(name))), Constant('St1')), Property(Identifier(i), Identifier(name))))
-
+
>>> QueryParser("len ( set [ i in IStaff | i ] ) + len ( set [ j in IVisitingStaff | j ] )")(None)
Head(Add(Count(Query(<type 'set'>, In(Identifier(i), Identifier(IStaff)), Identifier(i))),
Count(Query(<type 'set'>, In(Identifier(j), Identifier(IVisitingStaff)), Identifier(j)))))
@@ -148,28 +154,5 @@
Head(Query(<type 'set'>,
In(Identifier(c), Identifier(ICourse));
In(Identifier(d), Identifier(IDepartment));
- Eq(Identifier(d), Quanted(Some, Property(Identifier(c), Identifier(runBy)))),
+ Eq(Identifier(d), Quanted((Some, ''), Property(Identifier(c), Identifier(runBy)))),
Property(Identifier(d), Identifier(name))))
-
- The above should match with:
- Head(Query(
- metadata, symbols,
- set, [
- In(
- metadata, symbols,
- Identifier(metadata, symbols,'c'),
- Identifier(metadata, symbols,'ICourse')),
- In(
- metadata, symbols,
- Identifier(metadata, symbols,'d'),
- Identifier(metadata, symbols,'IDepartment')),
- Eq(
- metadata, symbols,
- Identifier(metadata, symbols,'d'),
- Quanted(metadata, symbols,
- Some(metadata, symbols, ''),
- Property(metadata, symbols,
- Identifier(metadata, symbols, 'c'),
- Identifier(metadata, symbols, 'runBy'))
- )),
- ] ,Identifier(metadata, symbols,'d.name')))
Modified: Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py 2008-08-27 07:54:14 UTC (rev 90406)
+++ Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py 2008-08-27 08:01:07 UTC (rev 90407)
@@ -520,31 +520,31 @@
def p_quantified_some(self, t):
r'''quantified : SOME expression
'''
- t[0] = Some(self.metadata, self.symbols, t[2])
+ t[0] = Quanted(self.metadata, self.symbols, Some(self.metadata, self.symbols, "''"), t[2])
if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
def p_quantified_every(self, t):
r'''quantified : EVERY expression
'''
- t[0] = Every(self.metadata, self.symbols, t[2])
+ t[0] = Quanted(self.metadata, self.symbols, Every(self.metadata, self.symbols, "''"), t[2])
if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
def p_quantified_atleast(self, t):
r'''quantified : ATLEAST CONSTANT expression
'''
- t[0] = Atleast(self.metadata, self.symbols, t[2], t[3])
+ t[0] = Quanted(self.metadata, self.symbols, Atleast(self.metadata, self.symbols, t[2]), t[3])
if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
def p_quantified_almost(self, t):
r'''quantified : ATMOST CONSTANT expression
'''
- t[0] = Atmost(self.metadata, self.symbols, t[2], t[3])
+ t[0] = Quanted(self.metadata, self.symbols, Atmost(self.metadata, self.symbols, t[2]), t[3])
if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
def p_quantified_just(self, t):
r'''quantified : JUST CONSTANT expression
'''
- t[0] = Just(self.metadata, self.symbols, t[2], t[3])
+ t[0] = Quanted(self.metadata, self.symbols, Just(self.metadata, self.symbols, t[2]), t[3])
if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
def p_definition_as(self, t):
Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py 2008-08-27 07:54:14 UTC (rev 90406)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py 2008-08-27 08:01:07 UTC (rev 90407)
@@ -375,22 +375,6 @@
str(self.expr)
)
-class NumericalQuantor(Quantor):
- implements(INumericalQuantor)
- def __init__(self, metadata, symbols, quantity, expr):
- self.metadata = metadata
- self.symbols = symbols
- Child.__init__(self)
- self.setProp('expr', expr)
- self.setProp('quantity', quantity)
-
- def __repr__(self):
- return "(%s(%s, %s))" % (
- self.__class__.__name__,
- str(self.quantity),
- str(self.expr)
- )
-
class Quanted(Child):
implements(IQuanted)
quantor = None
@@ -416,13 +400,13 @@
class Some(Quantor):
implements(ISome)
-class Atmost(NumericalQuantor):
+class Atmost(Quantor):
implements(IAtmost)
-class Atleast(NumericalQuantor):
+class Atleast(Quantor):
implements(IAtleast)
-class Just(NumericalQuantor):
+class Just(Quantor):
implements(IJust)
# Logical operators
Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt 2008-08-27 07:54:14 UTC (rev 90406)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt 2008-08-27 08:01:07 UTC (rev 90407)
@@ -167,11 +167,6 @@
>>> verifyObject(IQuantor, Quantor(metadata, symbols, child))
True
- >>> verifyClass(INumericalQuantor, NumericalQuantor)
- True
- >>> verifyObject(INumericalQuantor, NumericalQuantor(metadata, symbols, 2, child))
- True
-
>>> verifyClass(IQuanted, Quanted)
True
>>> verifyObject(IQuanted, Quanted(metadata, symbols, child, child))
@@ -189,17 +184,17 @@
>>> verifyClass(IAtmost, Atmost)
True
- >>> verifyObject(IAtmost, Atmost(metadata, symbols, 2, child))
+ >>> verifyObject(IAtmost, Atmost(metadata, symbols, child))
True
>>> verifyClass(IAtleast, Atleast)
True
- >>> verifyObject(IAtleast, Atleast(metadata, symbols, 2, child))
+ >>> verifyObject(IAtleast, Atleast(metadata, symbols, child))
True
>>> verifyClass(IJust, Just)
True
- >>> verifyObject(IJust, Just(metadata, symbols, 2, child))
+ >>> verifyObject(IJust, Just(metadata, symbols, child))
True
>>> verifyClass(ICondition, Condition)
Modified: Sandbox/adamg/ocql/trunk/src/ocql/tests/functions.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/tests/functions.txt 2008-08-27 07:54:14 UTC (rev 90406)
+++ Sandbox/adamg/ocql/trunk/src/ocql/tests/functions.txt 2008-08-27 08:01:07 UTC (rev 90407)
@@ -125,6 +125,10 @@
set([Staff <S1>])
Sample from the presentation:
+ >>> engine.compile("set [ c in ICourse; a as c.credits; a < 2 | a ]").execute()
+ set([Course <C2>], Course <C3>])
+
+Sample from the presentation:
>>> engine.compile("set [ c in ICourse; a as c.credits; a > 2 | c ]").execute()
set([Course <C2>], Course <C3>])
More information about the Checkins
mailing list