예제 #1
0
파일: RuleSizeSurvey.py 프로젝트: xzlyu/RQE
def get_graph(e2idx_file, r2idx_file, triple2idx_file):
    graph = Graph()
    graph.e2idx_file = e2idx_file
    graph.r2idx_file = r2idx_file
    graph.triple2idx_file = triple2idx_file
    graph.load_data()
    return graph
예제 #2
0
import random

from Empty_Answer_Query import eaqs
from RuleBased.Graph import Graph
from RuleBased.Params import pca_or_cwa
from RuleBased.SparqlParser import SparqlParser
from Util import Util

util = Util()

search_folder = "../../MyData/DBO/All/"

graph = Graph()
graph.e2idx_file = search_folder + "entity2id.txt"
graph.r2idx_file = search_folder + "relation2id.txt"
graph.triple2idx_file = search_folder + "triple2id.txt"

graph.load_data()

r_name_list = []
r_idx_list = []

for sparql in eaqs:
    sp = SparqlParser(sparql=sparql)
    sp.parse_sparql()
    for relation in sp.r_name_list:
        r_name_list.append(relation)
    r_name_list = list(set(r_name_list))
r_idx_list = [graph.r_id_by_name(r_name) for r_name in r_name_list]

for r_name in r_name_list:
예제 #3
0
                f.write("{}\t{}\n".format(res[1][0], res[1][1]))
                # print("Answer:", end="\t")
                for answer_name in res[2]:
                    # print("{}".format(answer_name), end="\t")
                    f.write("{}\t".format(answer_name))
                if res_idx != len(res_list) - 1:
                    f.write("\n")
                # print("\n")


if __name__ == "__main__":

    e2idx_file = "../../../MyData/DBO/All/entity2id.txt"
    r2idx_file = "../../../MyData/DBO/All/relation2id.txt"
    triple2idx_file = "../../../MyData/DBO/All/triple2id.txt"
    graph = Graph()
    graph.e2idx_file = e2idx_file
    graph.r2idx_file = r2idx_file
    graph.triple2idx_file = triple2idx_file
    graph.load_data()

    r_name_list_left = [["dbo:owner", "dbo:foundationPlace"],
                        ["dbo:regionServed", "dbo:product"],
                        ["dbo:locationCountry", "dbo:foundationPlace"],
                        ["dbo:regionServed", "dbo:owner"]]
    for r_name in r_name_list_left:
        tcs = TwoConsSampler(graph)
        tcs.set_relation(r_name[0], r_name[1])
        tcs.sample_data()
        tcs.record_test_sample()