def Mythread(rnum, sparql, filename): global correctness # query gc = GstoreConnector.GstoreConnector("172.31.222.94", 9000) # gc.build("test", "data/lubm/lubm.nt", "root", "123456") # gc.load("test", "root", "123456") gc.fquery("root", "123456", "lubm", sparql, filename) # res = gc.query("root", "123456", "test", sparql) # read the file to a str with open(filename, "r") as f: res = f.read() # count the nums m = 0 for i in range(len(sparql)): if (sparql[i] == "?"): m = m + 1 if (sparql[i] == "{"): break n = 0 for i in range(len(res)): if (res[i] == "{"): n = n + 1 Num = (n - 3) / (m + 1) # compare the result if (rnum != Num): correctness = False print("sparql: " + sparql) print("Num: " + str(Num))
def Mythread(rnum, sparql, filename, RequestType): global correctness # query gc = GstoreConnector.GstoreConnector(IP, Port, username, password) res = gc.query("lubm", "json", sparql, RequestType) # fquery #gc = GstoreConnector.GstoreConnector(IP, Port, username, password) #gc.fquery("lubm", "json", sparql, filename, RequestType) #with open(filename, "r") as f: # res = f.read() # count the nums m = 0 for i in range(len(sparql)): if (sparql[i] == "?"): m = m + 1 if (sparql[i] == "{"): break n = 0 for i in range(len(res)): if (res[i] == "{"): n = n + 1 Num = (n - 3) / (m + 1) # compare the result if (rnum != Num): correctness = False print("sparql: " + sparql) print("Num: " + str(Num))
def net(sparql1): """ 实现gStore的API连接,以及进行查询,后续会根据问题的类型进行相应的一些选项修改 :param sparql1: 查询语句1,以后可能会有查询语句2、3、4... """ gc = GstoreConnector.GstoreConnector("pkubase.gstore-pku.com", 80) gc.fquery(username, password, "pkubase", sparql1, filename) print(gc.query(username, password, "pkubase", sparql1))
def __init__(self): self.gc = GstoreConnector.GstoreConnector("127.0.0.1", 9000) self.ret = self.gc.build("weibo", "data/weibo.nt", gStoreusername, gStorepassword) self.ret = self.gc.load("weibo", gStoreusername, gStorepassword) self.all_ids = self.get_all_ids() self.all_ids_num = len(self.all_ids) self.all_weibo_ids = self.get_all_weibo_ids() self.current_uid = "" self.islogin = False
username = "******" password = "******" sparql = "select ?x where \ { \ ?x <rdf:type> <ub:UndergraduateStudent>. \ ?y <ub:name> <Course1>. \ ?x <ub:takesCourse> ?y. \ ?z <ub:teacherOf> ?y. \ ?z <ub:name> <FullProfessor1>. \ ?z <ub:worksFor> ?w. \ ?w <ub:name> <Department0>. \ }" filename = "res.txt" # start a gc with given IP, Port, username and password gc = GstoreConnector.GstoreConnector(IP, Port, username, password) # build a database with a RDF graph res = gc.build("lubm", "data/lubm/lubm.nt", "POST") print(res) # load the database res = gc.load("lubm", "POST") print(res); # to add, delete a user or modify the privilege of a user, operation must be done by the root user #res = gc.user("add_user", "user1", "111111", "POST") #print(res); # show all users res = gc.showUser("POST")
password = "******" sparql = "select ?x where \ { \ ?x <rdf:type> <ub:UndergraduateStudent>. \ ?y <ub:name> <Course1>. \ ?x <ub:takesCourse> ?y. \ ?z <ub:teacherOf> ?y. \ ?z <ub:name> <FullProfessor1>. \ ?z <ub:worksFor> ?w. \ ?w <ub:name> <Department0>. \ }" filename = "res.txt" # start a gc with given IP and Port gc = GstoreConnector.GstoreConnector("172.31.222.94", 9000) # unload the database #ret = gc.unload("test", username, password) # build database with a RDF graph ret = gc.build("lubm", "data/lubm/lubm.nt", username, password) # load the database ret = gc.load("lubm", username, password) # show print(gc.show(username, password)) # show information of all users print(gc.showUser())
import json, datetime, random from django.shortcuts import render, redirect from weibo.models import UserInfo from django.http import HttpResponse, HttpResponseRedirect from django.views.decorators.csrf import csrf_exempt try: from . import GstoreConnector from .config import mysql_conf, gStore_conf, path except: import GstoreConnector from config import mysql_conf, gStore_conf, path # My uid: 3023515021 gc = GstoreConnector.GstoreConnector(gStore_conf['host'], gStore_conf['port']) # 4条边关系 def jrelation(request): # uid = 2773208055 nodes = {} links = set() tuid = request.GET.get("tuid", "") if tuid == "": return HttpResponse("") tuid = int(tuid) uid = int(request.COOKIES.get("uid")) print("jrelation called", uid)
{ \ ?x <rdf:type> <ub:UndergraduateStudent>. \ ?y <ub:name> <Course1>. \ ?x <ub:takesCourse> ?y. \ ?z <ub:teacherOf> ?y. \ ?z <ub:name> <FullProfessor1>. \ ?z <ub:worksFor> ?w. \ ?w <ub:name> <Department0>. \ }" sparql2 = "select * where { ?x ?y ?z }" filename = "res.txt" # start a gc with given IP and Port gc = GstoreConnector.GstoreConnector("10.168.7.245", 9001) # unload the database #ret = gc.unload("test", username, password) # build database with a RDF graph # ret = gc.build("lubm", "data/lubm/lubm.nt", username, password) # load the database # ret = gc.load("lubm", username, password) # # # show # print(gc.show(username, password)) # # # show information of all users # print(gc.showUser())
from structs import * prefix = {'u':'http://example.org/user/', 'w': 'http://example.org/weibo/', 'c': 'http://example.org/comment/', 'ua': 'http://example.org/user_attr/', 'wa': 'http://example.org/weibo_attr/', 'ca': 'http://example.org/comment_attr/', 'r': 'http://example.org/rel/'} database = 'toyweibo' u_len = len(prefix['u']) w_len = len(prefix['w']) c_len = len(prefix['c']) prefix_string = ''.join(['prefix %s:<%s> ' % (k,v) for k,v in prefix.items()]) gc = GstoreConnector.GstoreConnector('localhost', 9000, 'root', '123456') _ = gc.load(database) # def transfer(l): # ls = l.split(' ') # for lls in ls: # for k,v in prefix.items(): # if lls.startswith(k+':'): # llss = lls.split(':') # uri = '<' + v + llss[1] + '>' # l = l.replace(lls, uri) # return l # basic functions def handle_bad(ls):