示例#1
0
def create_TD_from(td_uri, node_map):
    td_uri = URIRef(td_uri)

    if td_uri in node_map:
        return node_map[td_uri]

    log.debug('Creating TD for {}...'.format(td_uri))
    th_uri = get_td_thing(td_uri)
    g = R.pull(th_uri, cache=True, infer=False, expire=300)
    g.__iadd__(R.pull(td_uri, cache=True, infer=False, expire=300))
    return TD.from_graph(g, node=URIRef(td_uri), node_map=node_map)
示例#2
0
def build_component(id, node_map=None):
    if node_map is None:
        node_map = {}
    uri = URIRef(id)
    suc_tds = []

    try:
        matching_td = get_matching_TD(uri, node_map)
        network = VTED.network
        if not is_root(id):
            roots = filter(lambda (th, td): th and td, VTED.roots)
            for th_uri, td_uri in roots:
                root = create_TD_from(td_uri, node_map=node_map)
                try:
                    root_paths = nx.all_simple_paths(network, root.id,
                                                     matching_td.id)
                    for root_path in root_paths:
                        root_path = root_path[1:]
                        suc_tds = []
                        for suc_td_id in root_path:
                            suc_td = create_TD_from(get_td_node(suc_td_id),
                                                    node_map=node_map)
                            if suc_td not in suc_tds:
                                suc_tds.append(suc_td)
                        yield root, suc_tds
                except nx.NetworkXNoPath:
                    pass
                except nx.NodeNotFound:
                    pass
        else:
            yield matching_td, suc_tds
    except IndexError:
        graph = R.pull(uri)
        resource = Resource.from_graph(graph, uri, node_map=node_map)
        yield resource, []
示例#3
0
文件: api.py 项目: oeg-upm/agora-gw
def get_thing(id):
    try:
        th_node = get_th_node(id)
        g = R.pull(th_node, cache=True, infer=False, expire=300)

        for prefix, ns in R.fountain.prefixes.items():
            g.bind(prefix, ns)

        if not list(g.objects(th_node, CORE.describedBy)):
            td_node = get_td_node(id)
            g.add((th_node, CORE.describedBy, td_node))

        th_types = list(g.objects(URIRef(th_node), RDF.type))
        th_type = th_types.pop() if th_types else None

        format = TURTLE if request_wants_turtle() else JSONLD
        ttl = serialize_graph(g, format, frame=th_type)

        own_base = unicode(request.url_root)
        ttl = ttl.decode('utf-8').replace(REPOSITORY_BASE + u'/', own_base)
        response = make_response(ttl)
        response.headers['Content-Type'] = 'text/turtle'
        return response
    except IndexError:
        pass

    response = make_response()
    response.status_code = 404

    return response
示例#4
0
文件: api.py 项目: oeg-upm/agora-gw
def get_td(id):
    try:
        td_node = get_td_node(id)
        g = R.pull(td_node, cache=True, infer=False, expire=300)
        for ns, uri in R.fountain.prefixes.items():
            g.bind(ns, uri)

        format = TURTLE if request_wants_turtle() else JSONLD
        ttl = serialize_graph(g, format, frame=CORE.ThingDescription)

        own_base = unicode(request.url_root)
        ttl = ttl.decode('utf-8').replace(REPOSITORY_BASE + u'/', own_base)
        response = make_response(ttl)
        response.headers['Content-Type'] = 'text/turtle'
        return response
    except IndexError:
        pass

    response = make_response()
    response.status_code = 404

    return response
示例#5
0
 def wrapper(uri):
     g = R.pull(uri, cache=True, infer=False, expire=300)
     if not g:
         g = request_loader(uri)
     return g