[pypy-svn] r33911 - pypy/dist/pypy/lib/pyontology

ale at codespeak.net ale at codespeak.net
Mon Oct 30 17:14:07 CET 2006


Author: ale
Date: Mon Oct 30 17:14:05 2006
New Revision: 33911

Modified:
   pypy/dist/pypy/lib/pyontology/pyontology.py
   pypy/dist/pypy/lib/pyontology/sparql_grammar.py
Log:
Fix to the grammar to put prefixes in a dictionary


Modified: pypy/dist/pypy/lib/pyontology/pyontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/pyontology.py	(original)
+++ pypy/dist/pypy/lib/pyontology/pyontology.py	Mon Oct 30 17:14:05 2006
@@ -509,9 +509,9 @@
                     print "FAilure", e
 
     def _sparql(self, query):
-        qe = SP.Query.parseString(query)[0]
+        qe = SP.Query.parseString(query)
 
-        prefixes = qe.PrefixDecl[0]
+        prefixes = qe.Prefix[0]
 
         resvars = []
         for v in qe.SelectQuery[0].VARNAME:
@@ -958,7 +958,7 @@
         def minCard(cls , prop, val):
             var = "%s_%s_card" %(cls, prop.name)
             con = Expression([var], "%s >= %i" % (var, val))
-            return {},[con, CardinalityConstraint(prop.name, cls, val , '>')]
+            return {},[ CardinalityConstraint(prop.name, cls, val , '>')]
         self.cardinality_helper(s, int(var), minCard)
     
     def cardinality(self, s, var):

Modified: pypy/dist/pypy/lib/pyontology/sparql_grammar.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/sparql_grammar.py	(original)
+++ pypy/dist/pypy/lib/pyontology/sparql_grammar.py	Mon Oct 30 17:14:05 2006
@@ -208,12 +208,12 @@
     # Query ::= Prolog
     #      ( SelectQuery | ConstructQuery | DescribeQuery | AskQuery )
 
-    Query << Group(Prolog + (SelectQuery | ConstructQuery | DescribeQuery | AskQuery)).ignore(_comment)
+    Query << (Prolog + (SelectQuery | ConstructQuery | DescribeQuery | AskQuery)).ignore(_comment)
 
 
     # Prolog ::= BaseDecl? PrefixDecl*
 
-    Prolog << ( Optional(BaseDecl) + ZeroOrMore(PrefixDecl))
+    Prolog << ( Optional(BaseDecl) + Dict(ZeroOrMore(PrefixDecl)).setResultsName('Prefix'))
 
     # BaseDecl ::= 'BASE' QuotedIRIref
 
@@ -223,7 +223,7 @@
     member << Group(Optional(NCNAME_PREFIX) + Suppress(':') + QuotedIRIref)
     # PrefixDecl ::= 'PREFIX' QNAME_NS QuotedIRIref
 
-    PrefixDecl <<  (_prefix.suppress() + Dict(delimitedList(member,':'))).setResultsName('PrefixDecl')
+    PrefixDecl <<  Group(_prefix.suppress() +Optional(NCNAME_PREFIX) + Suppress(':') + QuotedIRIref ).setResultsName('PrefixDecl')
 
     # SelectQuery ::= 'SELECT' 'DISTINCT'? ( Var+ | '*' ) DatasetClause* WhereClause SolutionModifier
 
@@ -231,6 +231,8 @@
                     (OneOrMore(Var) | star) + ZeroOrMore(DatasetClause) + 
                     WhereClause + Optional(SolutionModifier))
 
+    # ConstructQuery ::= 'CONSTRUCT' ConstructTemplate DatasetClause* WhereClause SolutionModifier
+
     ConstructQuery << _construct + ConstructTemplate + ZeroOrMore(DatasetClause) + WhereClause + SolutionModifier
 
     # DescribeQuery ::= 'DESCRIBE' ( VarOrIRIref+ | '*' ) DatasetClause* WhereClause? SolutionModifier
@@ -572,7 +574,7 @@
     #      | [#xFDF0-#xFFFD]
     #      | [#x10000-#xEFFFF]
 
-    NCCHAR1 << Word(alphas)
+    NCCHAR1 << Word(alphas+"_")
 
     # VARNAME ::= ( NCCHAR1 | [0-9] ) ( NCCHAR1 | "_" | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*
 



More information about the Pypy-commit mailing list