本文整理匯總了Python中rdflib.Graph.ConjunctiveGraph.commit方法的典型用法代碼示例。如果您正苦於以下問題:Python ConjunctiveGraph.commit方法的具體用法?Python ConjunctiveGraph.commit怎麽用?Python ConjunctiveGraph.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rdflib.Graph.ConjunctiveGraph
的用法示例。
在下文中一共展示了ConjunctiveGraph.commit方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import commit [as 別名]
def main():
"""Main Function
Simple command-line procedure for web2rdf."""
if len(sys.argv) != 2:
print "Must call with a URI parameter."
print "Usage: %s uriSrc" % sys.argv[0]
return
uri = sys.argv[1]
# Get the RDF
wrdf = Web2Rdf(uri)
rdf = wrdf.getRdf()
if not rdf:
print "No RDF returned!"
return False
print "Got RDF..."
rdf = rdfString(rdf)
# Open Storage
print "Opening store..."
db = "./testdb.sqlite"
rstore = RdfStore('sqlite', db)
rstore.open()
print "Storing..."
graph = Graph(rstore.get(), identifier = URIRef("http://slashdot/Test2"))
#graph.parse("example.rdf")
graph.parse(rdf, publicID=uri)
graph.commit()
示例2: commitData
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import commit [as 別名]
def commitData(triples):
"""
Commits triples to RDF store
"""
report("INFO: rdflibWrapper.commitData")
# default_graph_uri = "http://rdflib.net/rdfstore"
graph = Graph(store) # Other optional argument: identifier = rdflib.URIRef(default_graph_uri)
triples = list(set(triples)) # Deduplication of triples
report("INFO: adding %d triples" % (len(triples)))
for triple in triples:
report("S:%s, P:%s, O:%s" % (str(triple[0]), str(triple[1]), str(triple[2])))
map(lambda triple: graph.add(triple), triples) # Add triples to the graph
graph.commit() # Commit newly added triples
示例3: load_store
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import commit [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
示例4: Graph
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import commit [as 別名]
# Get the sqlite plugin. You may have to install the python sqlite libraries
store = plugin.get('SQLite', Store)('rdfstore.db')
# Open previously created store, or create it if it doesn't exist yet
try:
rt = store.open(configString,create=False)
except OperationalError, e:
try:
# There is no underlying sqlite infrastructure, create it
rt = store.open(configString,create=True)
assert rt == VALID_STORE
except OperationalError, e:
raise
import sys, pdb; pdb.post_mortem(sys.exc_info()[2])
# There is a store, use it
graph = Graph(store, identifier = URIRef(default_graph_uri))
print "Triples in graph before add: ", len(graph)
# Now we'll add some triples to the graph & commit the changes
rdflibNS = Namespace('http://rdflib.net/test/')
graph.add((rdflibNS['pic:1'], rdflibNS['name'], Literal('Jane & Bob')))
graph.add((rdflibNS['pic:2'], rdflibNS['name'], Literal('Squirrel in Tree')))
graph.commit()
print "Triples in graph after add: ", len(graph)
# display the graph in RDF/XML
print graph.serialize()
示例5: main
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import commit [as 別名]
def main():
"""Uploads many RDF graphs into storage."""
uris = [
'http://tech.slashdot.org/story/09/11/02/0734253/Transpacific-Unity-Fiber-Optic-Cable-Leaves-Japan',
'http://games.slashdot.org/story/09/10/29/2026217/Nintendo-Announces-DSi-XL',
'http://games.slashdot.org/story/09/10/28/1634218/Leaked-Modern-Warfare-2-Footage-Causes-Outrage',
'http://games.slashdot.org/story/09/11/01/1421253/Scams-and-Social-Gaming',
'http://apple.slashdot.org/story/09/10/26/2256212/Psystars-Rebel-EFI-Hackintosh-Tool-Reviewed-Found-Wanting',
'http://yro.slashdot.org/story/09/11/03/0331227/Feds-Bust-Cable-Modem-Hacker',
'http://hardware.slashdot.org/story/09/11/02/2048234/Europe-Launches-Flood-Predicting-Satellite-and-Test-Probe',
'http://yro.slashdot.org/story/09/11/02/1411252/An-Inbox-Is-Not-a-Glove-Compartment',
'http://science.slashdot.org/story/09/11/03/1554207/2-Companies-Win-NASAs-Moon-Landing-Prize-Money',
'http://news.slashdot.org/story/09/11/03/1751232/Rise-of-the-Robot-Squadrons',
'http://it.slashdot.org/story/09/10/21/2120251/Some-Users-Say-Win7-Wants-To-Remove-iTunes-Google-Toolbar',
'http://apple.slashdot.org/story/09/10/23/1456221/Apple-Seeks-Patent-On-Operating-System-Advertising',
'http://games.slashdot.org/story/09/10/29/0225250/Physics-Rebel-Aims-To-Shake-Up-the-Video-Game-World',
'http://games.slashdot.org/story/09/10/28/030237/2D-Boy-Posts-Pay-What-You-Want-Final-Wrap-up',
'http://it.slashdot.org/story/09/11/02/1622218/IT-Snake-Oil-mdash-Six-Tech-Cure-Alls-That-Went-Bunk',
'http://apple.slashdot.org/story/09/10/20/1833228/Apple-Blurs-the-Server-Line-With-Mac-Mini-Server',
'http://games.slashdot.org/story/09/11/02/1530221/Free-3G-Wireless-For-Nintendos-Next-Handheld',
'http://hardware.slashdot.org/story/09/11/03/1530258/Dell-Rugged-Laptops-Not-Quite-Tough-Enough',
'http://linux.slashdot.org/story/09/11/03/2211231/Some-Early-Adopters-Stung-By-Ubuntus-Karmic-Koala',
'http://hardware.slashdot.org/story/09/10/31/0120223/Contest-To-Hack-Brazilian-Voting-Machines',
'http://ask.slashdot.org/story/09/10/25/1615203/Low-Power-Home-Linux-Server',
'http://games.slashdot.org/story/09/10/30/0149253/FCC-Mulling-More-Control-For-Electronic-Media',
'http://mobile.slashdot.org/story/09/11/03/1649246/Unfinished-Windows-7-Hotspot-Feature-Exploited',
'http://games.slashdot.org/story/09/10/30/2040230/Nokias-N-Gage-Service-To-End-After-2010',
'http://linux.slashdot.org/story/09/10/29/128205/Ubuntu-910-Officially-Released',
'http://ask.slashdot.org/story/09/10/30/2126252/Installing-Linux-On-Old-Hardware',
'http://games.slashdot.org/story/09/10/31/1428225/Controlling-Games-and-Apps-Through-Muscle-Sensors',
'http://tech.slashdot.org/story/09/11/01/2131249/uTorrent-To-Build-In-Transfer-Throttling-Ability',
'http://news.slashdot.org/story/09/11/02/2342258/Microsoft-Links-Malware-Rates-To-Pirated-Windows',
'http://apple.slashdot.org/story/09/10/29/0311214/Speech-to-Speech-Translator-Developed-For-iPhone',
'http://games.slashdot.org/story/09/10/30/022242/DampD-On-Google-Wave',
'http://science.slashdot.org/story/09/11/02/1435227/Bacteria-Could-Survive-In-Martian-Soil',
'http://apple.slashdot.org/story/09/11/02/0853219/For-September-Book-Related-Apps-Overtook-Games-On-iPhone',
'http://hardware.slashdot.org/story/09/11/03/1427210/Negroponte-Hints-At-Paper-Like-Design-For-XO-3',
'http://science.slashdot.org/story/09/11/03/0313242/Giant-Rift-In-Africa-Will-Create-a-New-Ocean',
'http://yro.slashdot.org/story/09/11/02/132211/Attorney-General-Says-Wiretap-Lawsuit-Must-Be-Thrown-Out',
'http://linux.slashdot.org/story/09/10/25/0450232/Ryan-Gordon-Wants-To-Bring-Universal-Binaries-To-Linux',
'http://science.slashdot.org/story/09/11/01/2145208/Computer-Activities-for-Those-With-Speech-and-Language-Difficulties',
'http://science.slashdot.org/story/09/11/03/1842247/The-Tech-Aboard-the-International-Space-Station',
'http://science.slashdot.org/story/09/11/03/1450211/Scientists-Build-a-Smarter-Rat',
'http://yro.slashdot.org/story/09/11/03/2023209/Spring-Design-Sues-Barnes-amp-Noble-Over-Nook-IP',
'http://apple.slashdot.org/story/09/11/01/195232/Apple-Says-Booting-OS-X-Makes-an-Unauthorized-Copy',
'http://yro.slashdot.org/story/09/10/22/1541220/Nokia-Sues-Apple-For-Patent-Infringement-In-iPhone',
'http://linux.slashdot.org/story/09/10/23/1639234/Ubuntu-Karmic-Koala-RC-Hits-the-Streets-With-Windows-7',
'http://linux.slashdot.org/story/09/10/27/1335227/Comparing-the-Freedoms-Offered-By-Maemo-and-Android'
]
i = 0
for uri in uris:
# Get the RDF
wrdf = Web2Rdf(uri)
rdf = wrdf.getRdf()
if not rdf:
print "No RDF returned!"
return False
print "Got RDF..."
rdf = rdfString(rdf)
# Open Storage
print "Opening store..."
#params = "./newdatabase.sqlite" # SQLITE
params = ('localhost', 'tuser', 'tuser', 'rdf') # MYSQL
rstore = RdfStore(params)
rstore.open()
print "Storing..."
graph = Graph(rstore.get(), identifier = URIRef("http://slashdot/"))
#graph.parse("example.rdf")
graph.parse(rdf, publicID=uri)
graph.commit()
i+=1
print "%d of %d uris complete." % (i, len(uris))
示例6: ConjunctiveGraph
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import commit [as 別名]
###################
# a ConjunctiveGraph
###################
conjgraph = ConjunctiveGraph(store=store,identifier=URIRef('http://purl.org/linguistics/gold'))
data = Namespace('http://purl.org/linguistics/data/')
conjgraph.bind('data',data)
#probably no triples should be added the conjgraph
#conjgraph.add((data['lingsign123'], data['orthographicRep'], Literal('dog')))
#conjgraph.add((data['lingsign456'], data['orthographicRep'], Literal('cat')))
#conjgraph.add((data['lingsign789'], data['orthographicRep'], Literal('fish')))
#print conjgraph.default_context
conjgraph.commit()
"""
##############
# Plain Graph1
################
"""
graph1 = Graph(store, identifier = URIRef('http://purl.org/linguistics/e-linguistics/signs'))
graph1.add((URIRef('myname'), RDFS.label, Literal('blah')))
graph1.commit()
"""