def get_fragment():
    def get_quads():
        for prefix in prefixes:
            yield '@prefix {}: <{}> .\n'.format(prefix, prefixes[prefix])
        yield '\n'
        for chunk in fragment_gen:
            if chunk is None:
                yield ''
            else:
                headers, (c, s, p, o) = chunk
                yield u'{} {} {} .\n'.format(s.n3(graph.namespace_manager), p.n3(graph.namespace_manager),
                                             o.n3(graph.namespace_manager))

    gp_str = request.args.get('gp', '{}')
    import re

    gp_match = re.search(r'\{(.*)\}', gp_str).groups(0)
    if len(gp_match) != 1:
        raise APIError('Invalid graph pattern')

    tps = re.split('\. ', gp_match[0])
    prefixes, fragment_gen = get_fragment_generator(*tps, monitoring=10, **PROVIDER)
    graph = Graph()
    for prefix in prefixes:
        graph.bind(prefix, prefixes[prefix])

    return Response(stream_with_context(get_quads()), mimetype='text/n3')
Esempio n. 2
0
        http://www.centeropenmiddleware.com/
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  Copyright (C) 2015 Center for Open Middleware.
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
"""

from sdh.curator.client import get_query_generator, get_fragment_generator

__author__ = 'Fernando Serena'

# prefixes, gen = get_query_generator('?s doap:developer ?d', '?d foaf:name ?n',
#                               host='localhost', port=5672)

prefixes, gen = get_fragment_generator('?s doap:developer ?d', '?d foaf:name ?n',
                              host='localhost', port=5672)

for r in gen:
    print r