home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / rdflib / sparql / bison / GraphPattern.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  7.8 KB  |  156 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """
  5. See: http://www.w3.org/TR/rdf-sparql-query/#GraphPattern
  6. [20] GraphPattern ::=  FilteredBasicGraphPattern ( GraphPatternNotTriples '.'? GraphPattern )?
  7. [21] FilteredBasicGraphPattern ::= BlockOfTriples? ( Constraint '.'? FilteredBasicGraphPattern )?
  8. [23] GraphPatternNotTriples  ::=  OptionalGraphPattern | GroupOrUnionGraphPattern | GraphGraphPattern
  9. [24] OptionalGraphPattern  ::=  'OPTIONAL' GroupGraphPattern
  10. [25] GraphGraphPattern  ::=  'GRAPH' VarOrBlankNodeOrIRIref GroupGraphPattern
  11. [26] GroupOrUnionGraphPattern ::=  GroupGraphPattern ( 'UNION' GroupGraphPattern )*
  12. [27] Constraint ::= 'FILTER' ( BrackettedExpression | BuiltInCall | FunctionCall )
  13. """
  14.  
  15. class ParsedGroupGraphPattern(object):
  16.     '''
  17.     See: http://www.w3.org/TR/rdf-sparql-query/#GroupPatterns
  18.     A group graph pattern GP is a set of graph patterns, GPi.
  19.     This class is defined to behave (literally) like a set of GraphPattern instances.
  20.     '''
  21.     
  22.     def __init__(self, graphPatterns):
  23.         self.graphPatterns = graphPatterns
  24.  
  25.     
  26.     def __iter__(self):
  27.         for g in self.graphPatterns:
  28.             if not (g.triples) and g.nonTripleGraphPattern is None:
  29.                 continue
  30.                 continue
  31.             yield g
  32.         
  33.  
  34.     
  35.     def __len__(self):
  36.         return [](_[1])
  37.  
  38.     
  39.     def __getitem__(self, k):
  40.         return list(self.graphPatterns)[k]
  41.  
  42.     
  43.     def __repr__(self):
  44.         return '{ %s }' % repr(list(self))
  45.  
  46.  
  47.  
  48. class BlockOfTriples(object):
  49.     '''
  50.     A Basic Graph Pattern is a set of Triple Patterns.
  51.     '''
  52.     
  53.     def __init__(self, statementList):
  54.         self.statementList = statementList
  55.  
  56.     
  57.     def __getattr__(self, attr):
  58.         if hasattr(self.statementList, attr):
  59.             return getattr(self.statementList, attr)
  60.         raise AttributeError, '%s has no such attribute %s' % (repr(self), attr)
  61.  
  62.     
  63.     def __repr__(self):
  64.         return '<SPARQLParser.BasicGraphPattern: %s>' % repr(self.statementList)
  65.  
  66.  
  67.  
  68. class GraphPattern(object):
  69.     '''
  70.     Complex graph patterns can be made by combining simpler graph patterns. The ways of creating graph patterns are:
  71.     * Basic Graph Patterns, where a set of triple patterns must match
  72.     * Group Graph Pattern, where a set of graph patterns must all match using the same variable substitution
  73.     * Value constraints, which restrict RDF terms in a solution
  74.     * Optional Graph patterns, where additional patterns may extend the solution
  75.     * Alternative Graph Pattern, where two or more possible patterns are tried
  76.     * Patterns on Named Graphs, where patterns are matched against named graphs
  77.  
  78.     This class is defined as a direct analogy of Grammar rule [20]:
  79. s    '''
  80.     
  81.     def __init__(self, triples, nonTripleGraphPattern = None):
  82.         if not triples or triples:
  83.             pass
  84.         triples = []
  85.         self.triples = triples
  86.         self.nonTripleGraphPattern = nonTripleGraphPattern
  87.  
  88.     
  89.     def __repr__(self):
  90.         if not (self.triples) and self.nonTripleGraphPattern is None:
  91.             return '<SPARQLParser.EmptyGraphPattern>'
  92.         if not self.triples is not None or self.triples:
  93.             pass
  94.         if not self.nonTripleGraphPattern is not None or ' %s' % self.nonTripleGraphPattern:
  95.             pass
  96.         return '<SPARQLParser.GraphPattern: %s%s>' % ('', '')
  97.  
  98.  
  99.  
  100. class ParsedOptionalGraphPattern(ParsedGroupGraphPattern):
  101.     '''
  102.     An optional graph pattern is a combination of a pair of graph patterns.
  103.     The second pattern modifies pattern solutions of the first pattern but
  104.     does not fail matching of the overall optional graph pattern.
  105.     '''
  106.     
  107.     def __init__(self, groupGraphPattern):
  108.         super(ParsedOptionalGraphPattern, self).__init__(groupGraphPattern.graphPatterns)
  109.  
  110.     
  111.     def __repr__(self):
  112.         return 'OPTIONAL {%s}' % self.graphPatterns
  113.  
  114.  
  115.  
  116. class ParsedAlternativeGraphPattern(object):
  117.     '''
  118.     A union graph pattern is a set of group graph patterns GPi.
  119.     A union graph pattern matches a graph G with solution S
  120.     if there is some GPi such that GPi matches G with solution S.
  121.     '''
  122.     
  123.     def __init__(self, alternativePatterns):
  124.         self.alternativePatterns = alternativePatterns
  125.  
  126.     
  127.     def __repr__(self):
  128.         return []([ '{%s}' % g for g in self.alternativePatterns ])
  129.  
  130.     
  131.     def __iter__(self):
  132.         for g in self.alternativePatterns:
  133.             yield g
  134.         
  135.  
  136.     
  137.     def __len__(self):
  138.         return len(self.alternativePatterns)
  139.  
  140.  
  141.  
  142. class ParsedGraphGraphPattern(ParsedGroupGraphPattern):
  143.     '''
  144.     Patterns on Named Graphs, where patterns are matched against named graphs
  145.     '''
  146.     
  147.     def __init__(self, graphName, groupGraphPattern):
  148.         self.name = graphName
  149.         super(ParsedGraphGraphPattern, self).__init__(groupGraphPattern.graphPatterns)
  150.  
  151.     
  152.     def __repr__(self):
  153.         return 'GRAPH %s { %s }' % (self.name, self.graphPatterns)
  154.  
  155.  
  156.