Пример #1
0
    def handler_collection_finish(self, data):
        self.add_prod_datum('pattern', data.get('pattern'))

        first = col = data.get('Collection')
        li = flatten(data.get('GraphNode'))
        li = filter(lambda x: x != None, li)
        last = li.pop()
        for r in li:
            self.add_pattern(
                'Collection', {
                    'subject':
                    first,
                    'predicate':
                    URI.intern(
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#first"),
                    'object':
                    r
                })
            rest = self.gen_node()
            self.add_pattern(
                'Collection', {
                    'subject':
                    first,
                    'predicate':
                    URI.intern(
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"),
                    'object':
                    rest
                })
            first = rest

        if last:
            self.add_pattern(
                'Collection', {
                    'subject':
                    first,
                    'predicate':
                    URI.intern(
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#first"),
                    'object':
                    last
                })

            self.add_pattern(
                'Collection', {
                    'subject':
                    first,
                    'predicate':
                    URI.intern(
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"),
                    'object':
                    URI.intern(
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil")
                })
Пример #2
0
	def handler_collection_finish(self, data):
		self.add_prod_datum('pattern', data.get('pattern'))
		
		first = col = data.get('Collection')
		li = flatten(data.get('GraphNode'))
		li = filter(lambda x: x != None, li)
		last = li.pop()
		for r in li:
			self.add_pattern('Collection', { 'subject' : first, 'predicate' : URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"), 'object' : r })
			rest = self.gen_node()
			self.add_pattern('Collection', { 'subject' : first, 'predicate' : URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"), 'object' : rest})
			first = rest
			
		if last:
			self.add_pattern('Collection', { 'subject' : first, 'predicate' : URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"), 'object' : last})
		
			self.add_pattern('Collection', { 'subject' : first, 'predicate' : URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"), 'object' : URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil")})
Пример #3
0
 def uri(self, value, append=None):
     uri = self.options.get('base_uri')
     if uri:
         uri += value
     else:
         uri = URI(value)
     if append:
         uri += append
     return uri
Пример #4
0
 def on_token(self, production, token):
     if len(self.productions) > 0:
         parent_prod = self.productions[-1]
         if parent_prod == '_Add_Sub_MultiplicativeExpression_Star':
             if production in ['+', '-']:
                 self.add_prod_datum('AdditiveExpression', production)
         elif parent_prod == 'UnaryExpression':
             if production in ['!', '+', '-']:
                 self.add_prod_datum('UnaryExpression', production)
         elif parent_prod in [
                 'NumericLiteralPositive', 'NumericLiteralNegative',
                 'NumericLiteral'
         ]:
             if production in ['+', '-']:
                 self.add_prod_datum('NumericLiteral', production)
         else:
             if production == 'a':
                 self.add_prod_datum(
                     'Verb',
                     URI.intern(
                         "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"))
             elif production == 'ANON':
                 self.add_prod_datum('BlankNode', self.gen_node())
             elif production in ['ASC', 'DESC']:
                 self.add_prod_datum('OrderDirection', token.lower())
             elif production == 'BLANK_NODE_LABEL':
                 self.add_prod_datum('BlankNode', self.gen_node(token))
             elif production == 'BoooleanLiteral':
                 self.add_prod_datum(
                     'literal',
                     Literal(token,
                             {'datatype': vocab.XSD.get_prop('boolean')}))
             elif production == 'BOUND':
                 self.add_prod_datum('BOUND', 'bound')
             elif production == 'DATATYPE':
                 self.add_prod_datum('BuiltInCall', 'datatype')
             elif production == 'DECIMAL':
                 self.add_prod_datum(
                     'literal',
                     Literal(token,
                             {'datatype': vocab.XSD.get_prop('decimal')}))
             elif production in ['DISTINCT', 'REDUCED']:
                 self.add_prod_datum('DISTINCT_REDUCED', token.lower())
             elif production == 'DOUBLE':
                 self.add_prod_datum(
                     'literal',
                     Literal(token,
                             {'datatype': vocab.XSD.get_prop('double')}))
             elif production == 'INTEGER':
                 self.add_prod_datum(
                     'literal',
                     Literal(token,
                             {'datatype': vocab.XSD.get_prop('integer')}))
             elif production == 'IRI_REF':
                 self.add_prod_datum('iri', self.uri(token))
             elif production == 'ISBLANK':
                 self.add_prod_datum('BuiltInCall', 'isBLANK')
             elif production == 'ISLITERAL':
                 self.add_prod_datum('BuiltInCall', 'isLITERAL')
             elif production == 'ISIRI':
                 self.add_prod_datum('BuiltInCall', 'isIRI')
             elif production == 'ISURI':
                 self.add_prod_datum('BuiltInCall', 'isURI')
             elif production == 'LANG':
                 self.add_prod_datum('BuiltInCall', 'lang')
             elif production == 'LANGMATCHES':
                 self.add_prod_datum('BuiltInCall', 'langMatches')
             elif production == 'LANGTAG':
                 self.add_prod_datum('language', token)
             elif production == 'NIL':
                 self.add_prod_datum('NIL', RDF["nil"])
             elif production == 'PNAME_LN':
                 self.add_prod_datum('PrefixedName', self.ns(*token))
             elif production == 'PNAME_NS':
                 self.add_prod_datum('PrefixedName', self.ns(token, None))
                 self.prod_data[-1]['prefix'] = token
             elif production == 'STR':
                 self.add_prod_datum('BuiltInCall', 'str')
             elif production == 'SAMETERM':
                 self.add_prod_datum('BuiltInCall', 'sameTerm')
             elif production in [
                     'STRING_LITERAL1', 'STRING_LITERAL2',
                     'STRING_LITERAL_LONG1', 'STRING_LITERAL_LONG2'
             ]:
                 self.add_prod_datum('string', token)
             elif production in ['VAR1', 'VAR2']:
                 new_token = self.get_gen_var(token)
                 self.add_prod_datum('Var', new_token)
             elif production in ['*', '/']:
                 self.add_prod_datum('MultiplicativeExpression', production)
             elif production in ['=', '!=', '<', '>', '<=', '>=']:
                 self.add_prod_datum('RelationalExpression', production)
             elif production == '&&':
                 self.add_prod_datum('ConditionalAndExpression', production)
             elif production == '||':
                 self.add_prod_datum('ConditionalOrExpression', production)
         self.progress("%s<%s(:token)" % (production, parent_prod),
                       "%s: %s" % (token, self.prod_data[-1]),
                       {'depth': (len(self.productions) + 1)})
     else:
         self.error("%s(:token)" % parent_prod,
                    "Token has no parent production",
                    {'production': production})
Пример #5
0
	def on_token(self, production, token):
		if len(self.productions) > 0:
			parent_prod = self.productions[-1]
			if parent_prod == '_Add_Sub_MultiplicativeExpression_Star':
				if production in ['+','-']:
					self.add_prod_datum('AdditiveExpression', production)
			elif parent_prod == 'UnaryExpression':
				if production in ['!','+','-']:
					self.add_prod_datum('UnaryExpression', production)
			elif parent_prod in ['NumericLiteralPositive','NumericLiteralNegative','NumericLiteral']:
				if production in ['+','-']:
					self.add_prod_datum('NumericLiteral', production)
			else:
				if production == 'a':
					self.add_prod_datum('Verb', URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"))
				elif production == 'ANON':
					self.add_prod_datum('BlankNode', self.gen_node())
				elif production in ['ASC','DESC']:
					self.add_prod_datum('OrderDirection', token.lower())
				elif production == 'BLANK_NODE_LABEL':
					self.add_prod_datum('BlankNode', self.gen_node(token))
				elif production == 'BoooleanLiteral':
					self.add_prod_datum('literal', Literal(token, {'datatype' : vocab.XSD.get_prop('boolean')}))
				elif production == 'BOUND':
					self.add_prod_datum('BOUND', 'bound')
				elif production == 'DATATYPE':
					self.add_prod_datum('BuiltInCall', 'datatype')
				elif production == 'DECIMAL':
					self.add_prod_datum('literal', Literal(token, {'datatype' : vocab.XSD.get_prop('decimal')}))
				elif production in ['DISTINCT', 'REDUCED']:
					self.add_prod_datum('DISTINCT_REDUCED', token.lower()) 
				elif production == 'DOUBLE':
					self.add_prod_datum('literal', Literal(token, {'datatype' : vocab.XSD.get_prop('double')}))
				elif production == 'INTEGER':
					self.add_prod_datum('literal', Literal(token, {'datatype' : vocab.XSD.get_prop('integer')}))
				elif production == 'IRI_REF':
					self.add_prod_datum('iri', self.uri(token)) 
				elif production == 'ISBLANK':
					self.add_prod_datum('BuiltInCall', 'isBLANK') 
				elif production == 'ISLITERAL':
					self.add_prod_datum('BuiltInCall', 'isLITERAL') 
				elif production == 'ISIRI':
					self.add_prod_datum('BuiltInCall', 'isIRI')
				elif production == 'ISURI':
					self.add_prod_datum('BuiltInCall', 'isURI')
				elif production == 'LANG':
					self.add_prod_datum('BuiltInCall', 'lang')
				elif production == 'LANGMATCHES':
					self.add_prod_datum('BuiltInCall', 'langMatches')
				elif production == 'LANGTAG':
					self.add_prod_datum('language', token) 
				elif production == 'NIL':
					self.add_prod_datum('NIL', RDF["nil"]) 
				elif production == 'PNAME_LN':
					self.add_prod_datum('PrefixedName', self.ns(*token)) 
				elif production == 'PNAME_NS':
					self.add_prod_datum('PrefixedName', self.ns(token, None))
					self.prod_data[-1]['prefix'] = token
				elif production == 'STR':
					self.add_prod_datum('BuiltInCall', 'str') 
				elif production == 'SAMETERM':
					self.add_prod_datum('BuiltInCall', 'sameTerm') 
				elif production in ['STRING_LITERAL1', 'STRING_LITERAL2', 'STRING_LITERAL_LONG1', 'STRING_LITERAL_LONG2']:
					self.add_prod_datum('string', token) 
				elif production in ['VAR1', 'VAR2']:
					new_token = self.get_gen_var(token)
					self.add_prod_datum('Var', new_token) 
				elif production in ['*', '/']:
					self.add_prod_datum('MultiplicativeExpression', production) 
				elif production in ['=', '!=', '<', '>', '<=', '>=']:
					self.add_prod_datum('RelationalExpression', production) 
				elif production == '&&':
					self.add_prod_datum('ConditionalAndExpression', production) 
				elif production == '||':
					self.add_prod_datum('ConditionalOrExpression', production) 
			self.progress("%s<%s(:token)" % (production, parent_prod), "%s: %s" % (token, self.prod_data[-1]), {'depth' : (len(self.productions) + 1)})
		else:
			self.error("%s(:token)" % parent_prod, "Token has no parent production", { 'production' : production})