Example #1
0
def read_graph(*rdfs):
    """
    Read multiple RDF-files and combine them into one graph.
    """
    g = rdflib.Graph()
    namespaces.init_bindings(g)

    for rdf in rdfs:
        log.info("Reading graph %s", rdf)
        g.parse(rdf)

    log.info("Read %d tuples", len(g))
    return g
Example #2
0
def write_resource(graph, dataset_uri, out, include_backlinks=True,
                    format='xml'):
    """
    Writes a single dataset
    """
    subgraph = Graph()
    namespaces.init_bindings(subgraph)

    for p, o in graph.predicate_objects(dataset_uri):
        subgraph.add((dataset_uri, p, o))

    if include_backlinks:
        for s, p in graph.subject_predicates(dateset_uri):
            subgraph.add((s, p, dataset_uri))

    subgraph.serialize(destination=out, format=format)
Example #3
0
def create_subgraph(graph, item):
    g = rdflib.Graph()
    namespaces.init_bindings(g)

    for triple in graph.triples((item, None, None)):
        g.add(triple)

    for triple in graph.triples((URIRef(item + '#facebook'), None, None)):
        g.add(triple)

    for triple in graph.triples((URIRef(item + '#twitter'), None, None)):
        g.add(triple)

    for triple in graph.triples((None, None, item)):
        g.add(triple)

    return g
Example #4
0
def main(output):
    db.init_store("data/db")

    zoochat = db.get_zoochat_graph()
    print "Loaded zoochat graph", zoochat, "containing", len(zoochat), "triples"

    zoowizard = Graph(identifier=namespaces.ZOO_GRAPH)
    namespaces.init_bindings(zoowizard)

    create_resources(zoochat, zoowizard)
    copy_simple_facts(zoochat, zoowizard)
    derive_dbpedia(zoochat, zoowizard)
    
#    geonames = db.get_geonames_graph()
#    print "Loaded geonames graph", geonames, "containing", len(geonames), "triples"
#    find_country_references(zoochat, zoowizard, geonames)

    zoowizard.serialize(destination=output)
Example #5
0
def _get_graph(uri):
    if store is None:
        raise RuntimeError("Don't forget to call init_graph ")
    graph = Graph(store=store, identifier=URIRef(uri))
    namespaces.init_bindings(graph)
    return graph
Example #6
0
def init_graph():
    g = rdflib.Graph()
    namespaces.init_bindings(g)

    return g