本文整理汇总了Python中connection.Connection.use_repository方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.use_repository方法的具体用法?Python Connection.use_repository怎么用?Python Connection.use_repository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.use_repository方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: implements
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import use_repository [as 别名]
def implements(self):
"""
Inspects the wiki triples for "implements" links and returns them with their namespace removed.
@return: the list of features
@rtype list of str
"""
if not '_Member__implements' in self.__dict__:
self.__implements = []
connection = Connection('http://triples.101companies.org/openrdf-sesame/')
connection.use_repository('Testing_2')
connection.addnamespace('onto', 'http://101companies.org/ontology#')
connection.addnamespace('res', 'http://101companies.org/resources#')
res = connection.query('SELECT DISTINCT ?feature WHERE { <http://101companies.org/resources#'+self.name+'> <http://101companies.org/ontology#implements> ?feature }')
for feature in res:
val = feature['feature']['value'].replace('http://101companies.org/resources#','').replace('_',' ')
self.__implements.append(val)
return self.__implements
示例2: checkHirerarchy
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import use_repository [as 别名]
def checkHirerarchy():
env = Environment(loader=FileSystemLoader('tmpl'))
connection = Connection('http://triples.101companies.org:8080/openrdf-sesame/')
connection.use_repository('sandbox')
connection.addnamespace('onto', 'http://101companies.org/ontology#')
connection.addnamespace('res', 'http://101companies.org/resources#')
template = env.get_template('subtypeCheck')
print "Subtyping check"
query = template.render()
res = connection.query(query)
x = list()
for r in res:
print r
if not r.has_key('c'):
t = ("Base: " + r['a']['value'], "First Child: " + r['b']['value'])
else:
t = ("Base: " + r['a']['value'], "First Child: " + r['b']['value'], "Second Child: " + r['c']['value'])
if not t in x:
x.append(t)
print x
with open('subtyping_errors.json', 'w') as outfile:
json.dump(x, outfile)
示例3: open
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import use_repository [as 别名]
res = c.query(query)
print "Wrong types:"
for r in res:
print ">>", r['y']['value'], "detected in", r['x']['value']
if __name__=='__main__':
with open("models", "r") as ins:
modelsPath = ins.read().splitlines()[0]
included_extenstions = ['json']
file_names = [fn for fn in os.listdir(modelsPath) if any([fn.endswith(ext) for ext in included_extenstions])]
for file in file_names:
entity = Entity(os.path.abspath(os.path.join(modelsPath, file).replace("\\","/")))
#The check below is a special case of the cardinality check, so it's not needed
#entity.checkRelationsExistance()
entity.checkCardinality()
entity.checkHirerarchy()
env = Environment(loader=FileSystemLoader('tmpl'))
c = Connection('http://triples.101companies.org:8080/openrdf-sesame/')
c.use_repository('sandbox')
c.addnamespace('onto', 'http://101companies.org/ontology#')
c.addnamespace('res', 'http://101companies.org/resources#')
#existanceCheck(env, 'Contribution', 'implements')
#cardinalityCheck(env, 'Contribution', 'implements')
typeCheck(env, 'Contribution', 'Feature', 'implements')
示例4: __init__
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import use_repository [as 别名]
class Entity:
def __init__(self, fn):
json_data = open(fn)
data = json.load(json_data)
#self.context = data['@context']
if 'properties' in data:
self.properties = data['properties']
else:
self.properties = None
self.id = data['@id']
self.type = data['@type']
self.env = Environment(loader=FileSystemLoader('tmpl'))
self.connection = Connection('http://triples.101companies.org:8080/openrdf-sesame/')
self.connection.use_repository('sandbox')
self.connection.addnamespace('onto', 'http://101companies.org/ontology#')
self.connection.addnamespace('res', 'http://101companies.org/resources#')
def checkCardinality(self):
template = self.env.get_template('cardinalityCheck')
type = self.id
if self.properties is None:
return
for prop in self.properties:
p = prop['property']
c = int(prop['minCardinality'])
print "Cardinality check for class: %s and relationship: %s" % (type, p)
query = template.render(ontoClass=type, relationship=p)
res2 = self.connection.query(query)
for r in res2:
#print ">># of relationships declared: %s" % r['count']['value']
if int(r['count']['value']) >= 0:
#print r
#print r['count']['value']
v = int(r['count']['value'])
if v < c:
print "ERROR"
def checkRelationsExistance(self):
print "Existence check"
template = self.env.get_template('existenceCheck')
if self.properties is None:
return
for prop in self.properties:
p = prop['property']
query = template.render(ontoClass=self.id, relationship=p)
res1 = self.connection.query(query)
for r in res1:
print ">>", r
@staticmethod
def checkHirerarchy():
env = Environment(loader=FileSystemLoader('tmpl'))
connection = Connection('http://triples.101companies.org:8080/openrdf-sesame/')
connection.use_repository('sandbox')
connection.addnamespace('onto', 'http://101companies.org/ontology#')
connection.addnamespace('res', 'http://101companies.org/resources#')
template = env.get_template('subtypeCheck')
print "Subtyping check"
query = template.render()
res = connection.query(query)
x = list()
for r in res:
print r
if not r.has_key('c'):
t = ("Base: " + r['a']['value'], "First Child: " + r['b']['value'])
else:
t = ("Base: " + r['a']['value'], "First Child: " + r['b']['value'], "Second Child: " + r['c']['value'])
if not t in x:
x.append(t)
print x
with open('subtyping_errors.json', 'w') as outfile:
json.dump(x, outfile)
示例5: prefixy
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import use_repository [as 别名]
try:
output = template.render(data=res, prefixy=lambda x: prefixy(x), unqualify=lambda x: unqualify(x), escape=lambda x: escape(x))
except:
output = ""
#print output
with open(os.path.join(os.path.dirname(__file__), 'output', file_to_save.replace('.tmpl', '.txt')), "w") as output_file:
output_file.write(output)
#print res
if __name__=='__main__':
env = Environment(loader=FileSystemLoader('templates'))
connection = Connection('http://triples.101companies.org:8080/openrdf-sesame/')
connection.use_repository('sandbox')
with open('../onto2ttl/config.json') as json_data:
m = load(json_data)
for x in m['@context']:
connection.addnamespace(x, m['@context'][x])
req = urllib2.Request('http://triples.101companies.org:8080/openrdf-workbench/repositories/sandbox/namespaces')
req.add_header('Accept', 'application/sparql-results+json')
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
sock = urllib2.urlopen(req)
#print "INFO", sock.info()
data = sock.read()
#print "DATA", data
sock.close()
prefixes = dict()