本文整理匯總了Python中rdflib.Graph.ConjunctiveGraph.close方法的典型用法代碼示例。如果您正苦於以下問題:Python ConjunctiveGraph.close方法的具體用法?Python ConjunctiveGraph.close怎麽用?Python ConjunctiveGraph.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rdflib.Graph.ConjunctiveGraph
的用法示例。
在下文中一共展示了ConjunctiveGraph.close方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testModel
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import close [as 別名]
def testModel(self):
g = ConjunctiveGraph()
g.parse(StringInputSource(input), format="n3")
i = 0
for s, p, o in g:
if isinstance(s, Graph):
i += 1
self.assertEquals(i, 3)
self.assertEquals(len(list(g.contexts())), 13)
g.close()
示例2: load_store
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import close [as 別名]
def load_store(files):
"""
Takes a directory of RDf files and loads them into the store.
"""
try:
store = plugin.get("MySQL", Store)("rdflib_db")
store.open(config["rdflib.config"])
graph = ConjunctiveGraph(store)
# iterate through files and load them into the graph
for fpath in fl:
graph.parse(fpath, format=get_format(fpath), publicID=context_uri(fpath))
print fpath + " loaded."
# save triples to store
graph.commit()
graph.close()
except:
print "=== error opening RDF store ==="
exit
示例3: Namespace
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import close [as 別名]
from __future__ import division
import sys, time
sys.path.append('pytc-0.7/build/lib.linux-x86_64-2.5')
sys.path.insert(0, 'rdflib/build/lib.linux-x86_64-2.5')
from rdflib.Graph import ConjunctiveGraph
from rdflib import Namespace, Literal
EX = Namespace("http://example.com/")
graph = ConjunctiveGraph('TokyoCabinet')
graph.open("tcgraph", create=True)
graph.add((EX['hello'], EX['world'], Literal("lit")))
print list(graph.triples((None, None, None)))
graph.close()
示例4: createMediaGraphs
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import close [as 別名]
def createMediaGraphs(rows):
albums = {}
artists = {
'Madonna': mb_artist['79239441-bfd5-4981-a70c-55c3f15c1287'],
'John Coltrane': mb_artist['b625448e-bf4a-41c3-a421-72ad46cdb831'],
'Miles Davis' : mb_artist['561d854a-6a28-4aa7-8c99-323e6ce46c2a']}
counter = 1
for row in rows:
graph = Graph(identifier = URIRef(graph_uri))
# Create all the relevant nodes (with the correct IDs)
work = getNewNode('work')
composition = getNewNode('composition')
track = getNewNode('track')
record = getNewNode('record')
performance = getNewNode('performance')
signal = Namespace(graph_uri+"/"+row['uid'])
# If we don't have an artist url, make a foaf Agent instead.
if row['artist']:
try:
artist = artists[row['artist']]
except KeyError:
artist = getNewNode('artist')
graph.add((artist, RDF.type, foaf['Agent']))
graph.add((artist, foaf['name'], Literal(row['artist'].strip())))
artists[row['artist']] = artist;
if row['composer']:
try:
composer = artists[row['composer']]
except KeyError:
composer = getNewNode('artist')
graph.add((composer, RDF.type, foaf['Agent']))
graph.add((composer, foaf['name'], Literal(row['composer'].strip())))
artists[row['composer']] = composer;
else:
composer = artist
# Work
graph.add((work, RDF.type, mo['MusicalWork']))
# Composition
graph.add((composition, RDF.type, mo['Composition']))
if composer:
graph.add((composition, mo['composer'], composer))
graph.add((composition, mo['produced_work'], work))
# Track
graph.add((track, RDF.type, mo['Track']))
if row['artist']:
graph.add((track, foaf['maker'], artist))
if row['tracknum']:
graph.add((track, mo['track_number'], Literal(row['tracknum'])))
if row['album']:
# Album
try:
album = albums[row['album']]
except KeyError:
album = getNewNode('album')
graph.add((album, RDF.type, mo['Record']))
graph.add((album, dc['title'], Literal(row['album'].strip())))
graph.add((album, mo['release_type'], mo['album']))
albums[row['album']] = album
graph.add((album, mo['track'], track))
# Signal
graph.add((signal, RDF.type, mo['Signal']))
graph.add((signal, mo['published_as'], record))
if row['track']:
graph.add((signal, dc['title'], Literal(row['track'].strip())))
if row['isrc']:
graph.add((signal, mo['isrc'], Literal(row['isrc'].strip())))
# Add to the various databases
dbs = databases[catalogueID]
for db in dbs:
graph.add((db, audiodb["has-signal"], signal))
# Record
graph.add((record, RDF.type, mo['Record']))
graph.add((record, mo['publication_of'], signal))
graph.add((record, mo['track'], track))
# Performance
graph.add((performance, RDF.type, mo['Performance']))
graph.add((performance, mo['performance_of'], work))
if row['artist']:
graph.add((performance, mo['performer'], artist))
graph.add((performance, mo['recorded_as'], signal))
graph.close()
graph.serialize(format='xml',destination="output/"+catalogueID.lower()+"/media_"+str(counter)+".rdf")
counter += 1