-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathop.sql
69 lines (59 loc) · 2.29 KB
/
op.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
\set schema_file /path/to/Ontological-Pathfinding/data/YAGOData/YAGOSchema.csv
\set rules_file /path/to/Ontological-Pathfinding/data/YAGOData/YAGORules.csv
\set rules_file_1 :rules_file '-1'
\set rules_file_2 :rules_file '-2'
\set rules_file_3 :rules_file '-3'
\set rules_file_4 :rules_file '-4'
\set rules_file_5 :rules_file '-5'
\set rules_file_6 :rules_file '-6'
CREATE SCHEMA op;
CREATE TABLE op.Kbschema(predicate TEXT, domain TEXT, range TEXT);
COPY op.Kbschema FROM :'schema_file' DELIMITER ' ' QUOTE E'\b' CSV;
-- Type I
-- p(x, y) <- q(x, y)
COPY (SELECT DISTINCT h.predicate AS h, b.predicate AS b
FROM op.Kbschema h
JOIN op.Kbschema b
ON h.domain = b.domain AND h.range = b.range
WHERE h.predicate <> b.predicate)
TO :'rules_file_1' DELIMITER ' ';
-- Type II
-- p(x, y) <- q(y, x)
COPY (SELECT DISTINCT h.predicate AS h, b.predicate AS b
FROM op.Kbschema h
JOIN op.Kbschema b
ON h.domain = b.range AND h.range = b.domain)
TO :'rules_file_2' DELIMITER ' ';
-- Type III
-- p(x, y) <- q(z, x), r(z, y)
COPY (SELECT DISTINCT h.predicate AS h, b1.predicate AS b1, b2.predicate AS b2
FROM op.Kbschema h
JOIN op.Kbschema b1 ON h.domain = b1.range
JOIN op.Kbschema b2 ON h.range = b2.range
WHERE b1.domain = b2.domain)
TO :'rules_file_3' DELIMITER ' ';
-- Type IV
-- p(x, y) <- q(x, z), r(z, y)
COPY (SELECT DISTINCT h.predicate AS h, b1.predicate AS b1, b2.predicate AS b2
FROM op.Kbschema h
JOIN op.Kbschema b1 ON h.domain = b1.domain
JOIN op.Kbschema b2 ON h.range = b2.range
WHERE b1.range = b2.domain)
TO :'rules_file_4' DELIMITER ' ';
-- Type V
-- p(x, y) <- q(z, x), r(y, z)
COPY (SELECT DISTINCT h.predicate AS h, b1.predicate AS b1, b2.predicate AS b2
FROM op.Kbschema h
JOIN op.Kbschema b1 ON h.domain = b1.range
JOIN op.Kbschema b2 ON h.range = b2.domain
WHERE b1.domain = b2.range)
TO :'rules_file_5' DELIMITER ' ';
-- Type VI
-- p(x, y) <- q(x, z), r(y, z)
COPY (SELECT DISTINCT h.predicate AS h, b1.predicate AS b1, b2.predicate AS b2
FROM op.Kbschema h
JOIN op.Kbschema b1 ON h.domain = b1.domain
JOIN op.Kbschema b2 ON h.range = b2.domain
WHERE b1.range = b2.range)
TO :'rules_file_6' DELIMITER ' ';
DROP SCHEMA op CASCADE;