本文整理汇总了Python中rdflib.ConjunctiveGraph.open方法的典型用法代码示例。如果您正苦于以下问题:Python ConjunctiveGraph.open方法的具体用法?Python ConjunctiveGraph.open怎么用?Python ConjunctiveGraph.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.ConjunctiveGraph
的用法示例。
在下文中一共展示了ConjunctiveGraph.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def open(self):
# XXX: If we have a source that's read only, should we need to set the
# store separately??
g0 = ConjunctiveGraph('SPARQLUpdateStore')
g0.open(tuple(self.conf['rdf.store_conf']))
self.graph = g0
return self.graph
示例2: create
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def create(self, conjunctive=False, gid=None, loader=None, format=None):
self.__lock.acquire()
uuid_lock = None
cached = False
p = r.pipeline(transaction=True)
p.multi()
try:
uuid = shortuuid.uuid()
if conjunctive:
if 'persist' in app.config['STORE']:
g = ConjunctiveGraph('Sleepycat')
g.open('store/resources/{}'.format(uuid), create=True)
else:
g = ConjunctiveGraph()
g.store.graph_aware = False
self.__graph_dict[g] = uuid
self.__uuid_dict[uuid] = g
return g
else:
g = resources_cache.get_context(uuid)
try:
if gid is not None:
st_uuid = r.hget(self.__gids_key, gid)
if st_uuid is not None:
cached = True
uuid = st_uuid
uuid_lock = self.uuid_lock(uuid)
uuid_lock.acquire()
g = self.__uuid_dict[uuid]
uuid_lock.release()
else:
post_ts = dt.now()
elapsed = (post_ts - self.__last_creation_ts).total_seconds()
throttling = (1.0 / GRAPH_THROTTLING) - elapsed
if throttling > 0:
sleep(throttling)
temp_key = '{}:cache:{}'.format(AGENT_ID, uuid)
counter_key = '{}:cnt'.format(temp_key)
ttl = MIN_CACHE_TIME + int(10 * random())
ttl_ts = calendar.timegm((dt.now() + datetime.timedelta(ttl)).timetuple())
if st_uuid is None:
p.delete(counter_key)
p.sadd(self.__cache_key, uuid)
p.hset(self.__gids_key, uuid, gid)
p.hset(self.__gids_key, gid, uuid)
self.__last_creation_ts = dt.now()
p.incr(counter_key)
p.set(temp_key, ttl_ts)
p.expire(temp_key, ttl)
uuid_lock = self.uuid_lock(uuid)
uuid_lock.acquire()
except Exception, e:
log.error(e.message)
traceback.print_exc()
self.__graph_dict[g] = uuid
self.__uuid_dict[uuid] = g
示例3: __init__
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def __init__(self, endpoint):
graph = ConjunctiveGraph('SPARQLStore')
graph.open(endpoint)
graph.namespace_manager = ns_mgr
self.graph = graph
self.default_graph = \
'http://vitro.mannlib.cornell.edu/default/vitro-kb-2'
示例4: initialize
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def initialize(config_file):
print '[%s] Initializing...' % strftime("%a, %d %b %Y %H:%M:%S", localtime())
sys.stdout.flush()
config = __import__(config_file)
try:
g = ConjunctiveGraph(config.graph_store, config.graph_identifier)
g.open(config.db_configstring, create=True)
if config.input_file != None:
print '[%s] Parsing %s...' % (strftime("%a, %d %b %Y %H:%M:%S", localtime()), config.input_file)
sys.stdout.flush()
g.parse(config.input_file, format=config.input_format)
g.commit()
else:
dir_list = os.listdir(config.input_dir)
for file_name in dir_list:
print '[%s] Parsing %s...' % (strftime("%a, %d %b %Y %H:%M:%S", localtime()) ,file_name)
sys.stdout.flush()
g.parse(config.input_dir + '/' + file_name, format=config.input_format)
g.commit()
except Exception as e:
traceback.print_exc()
print e
print '"%s" not found, or incorrect RDF serialization.' % config.input_file
sys.stdout.flush()
exit(-1)
return g, config
示例5: validate_sparql_endpoint
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def validate_sparql_endpoint(form, field):
try:
g = ConjunctiveGraph('SPARQLStore')
g.open(field.data)
g.query('SELECT * WHERE { ?s ?p ?o } LIMIT 1')
except:
raise ValidationError('This is not a valid SPARQL endpoint.')
示例6: open
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def open(self):
import logging
# XXX: If we have a source that's read only, should we need to set the store separately??
g0 = ConjunctiveGraph('Sleepycat')
self.conf['rdf.store'] = 'Sleepycat'
g0.open(self.conf['rdf.store_conf'],create=True)
self.graph = g0
logging.debug("Opened SleepyCatSource")
示例7: get_uri_types
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def get_uri_types(uri, lang):
g = ConjunctiveGraph('SPARQLStore')
g.open(get_dbpedia_endpoint(lang))
#print uri
#print len(list( g.triples(( URIRef(uri), URIRef('http://dbpedia.org/ontology/country'), URIRef('http://es.dbpedia.org/resource/España') )) ))
return [ str(typ) for typ in g.objects(URIRef(uri), RDF.type) ]
示例8: get
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def get(self):
conn = sqlite3.connect(self.conf['sqldb'])
cur = conn.cursor()
#first step, grab all entities and add them to the graph
n = self.conf['rdf.namespace']
cur.execute("SELECT DISTINCT ID, Entity FROM tblentity")
g0 = ConjunctiveGraph(self.conf['rdf.store'])
g0.open(self.conf['rdf.store_conf'], create=True)
for r in cur.fetchall():
#first item is a number -- needs to be converted to a string
first = str(r[0])
#second item is text
second = str(r[1])
# This is the backbone of any RDF graph. The unique
# ID for each entity is encoded as a URI and every other piece of
# knowledge about that entity is connected via triples to that URI
# In this case, we connect the common name of that entity to the
# root URI via the RDFS label property.
g0.add( (n[first], RDFS.label, Literal(second)) )
#second step, get the relationships between them and add them to the graph
cur.execute("SELECT DISTINCT EnID1, Relation, EnID2, Citations FROM tblrelationship")
gi = ''
i = 0
for r in cur.fetchall():
#all items are numbers -- need to be converted to a string
first = str(r[0])
second = str(r[1])
third = str(r[2])
prov = str(r[3])
ui = self.conf['molecule_name'](prov)
gi = Graph(g0.store, ui)
gi.add( (n[first], n[second], n[third]) )
g0.add([ui, RDFS.label, Literal(str(i))])
if (prov != ''):
g0.add([ui, n[u'text_reference'], Literal(prov)])
i = i + 1
cur.close()
conn.close()
return g0
示例9: blogs
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def blogs():
g = ConjunctiveGraph("Sleepycat")
g.open("store")
for person, blog in g.subject_objects(predicate=w.Blog):
name = g.value(subject=person, predicate=w.Name)
for title, feed_url in discover_feeds(blog):
if title:
title = "%s (%s)" % (name, title)
else:
title = name
logging.info("found %s <%s>" % (title, feed_url))
yield title, feed_url
g.close()
示例10: generate_config_file
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def generate_config_file(data_source, rdf_data=None, rdf_format=None, sparql_url=None, sparql_graph=None):
current_task.update_state(state='PROGRESS', meta={'progress_percent': 15, 'progress_msg': 'Reading provided RDF data...'})
try:
if data_source == 'rdf':
data_graph = Graph()
data_graph.parse(format=rdf_format, data=rdf_data)
else:
g = ConjunctiveGraph('SPARQLStore')
g.open(sparql_url)
data_graph = g.get_context(sparql_graph) if sparql_graph else g
except Exception, e:
raise Exception("An error occurred while trying to read provided data source: %s" % str(e))
示例11: ConvertToSQLLITE
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def ConvertToSQLLITE (filename,destinationFileName):
_graph = ConjunctiveGraph()
_graph.parse(filename, format="nt")
sql = ConjunctiveGraph('SQLite')
sql.open(destinationFileName, create=True)
for t in _graph.triples((None,None,None)):
sql.add(t)
sql.commit()
sql.close()
示例12: create
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def create(self, conjunctive=False):
uuid = shortuuid.uuid()
if conjunctive:
if 'persist' in app.config['STORE']:
g = ConjunctiveGraph('Sleepycat')
g.open('store/query/{}'.format(uuid), create=True)
g.store.graph_aware = False
else:
g = ConjunctiveGraph()
g.store.graph_aware = False
else:
g = query.get_context(uuid)
self.__graph_dict[g] = uuid
return g
示例13: post
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def post(g, URLendpoint, graphURI): # eseguo la post del grafo g nel database specificato
output = { 'risposta': [] }
endpoint = ConjunctiveGraph ('SPARQLUpdateStore')
endpoint.open(URLendpoint)
enddata = """INSERT DATA {
GRAPH <"""+graphURI+"""> {
%s
}
}""" % g.serialize(format="nt")
endpoint.update(enddata)
output['risposta'].append(g.serialize(format="turtle"))
示例14: get_dbpedia_resource_triples
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def get_dbpedia_resource_triples(uri, lang):
g = ConjunctiveGraph('SPARQLStore')
g.open(get_dbpedia_endpoint(lang))
triples = []
for p, o in g.predicate_objects(URIRef(uri)):
if isinstance(o, Literal):
triples.append({
'p': unicode(p),
'o': unicode(o),
'lang': o.language
})
return triples
示例15: __init__
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import open [as 别名]
def __init__(self, percolationdir="~/.percolation/"):
percolationdir = os.path.expanduser(percolationdir)
if not os.path.isdir(percolationdir):
os.mkdir(percolationdir)
dbdir = percolationdir+"sleepydb/"
if not os.path.isdir(dbdir):
os.mkdir(dbdir)
percolation_graph = ConjunctiveGraph(store="Sleepycat")
try:
percolation_graph.open(dbdir, create=False)
except: # get exception type (?)
percolation_graph.open(dbdir, create=True)
P.percolation_graph = percolation_graph
self.percolation_graph = percolation_graph
P.percolation_server = self