Skip to content

Commit

Permalink
Fixed codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnqu committed Jul 30, 2021
1 parent 8e749dd commit 69aafd4
Show file tree
Hide file tree
Showing 36 changed files with 312,635 additions and 730,776 deletions.
1 change: 0 additions & 1 deletion codes/extra/core/__init__.py

This file was deleted.

Binary file removed codes/extra/core/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed codes/extra/core/__pycache__/base.cpython-38.pyc
Binary file not shown.
Binary file removed codes/extra/data/__pycache__/graph.cpython-38.pyc
Binary file not shown.
4 changes: 0 additions & 4 deletions codes/extra/utils/__init__.py

This file was deleted.

Binary file removed codes/extra/utils/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed codes/extra/utils/__pycache__/file.cpython-38.pyc
Binary file not shown.
Binary file removed codes/extra/utils/__pycache__/io.cpython-38.pyc
Binary file not shown.
Binary file removed codes/extra/utils/__pycache__/pretty.cpython-38.pyc
Binary file not shown.
Binary file removed codes/extra/utils/__pycache__/torch.cpython-38.pyc
Binary file not shown.
10 changes: 8 additions & 2 deletions codes_toy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,28 @@ def __init__(self, data_path):
for line in fi:
h, r, t = line.strip().split('\t')
self.train_triplets.append((self.entity2id[h], self.relation2id[r], self.entity2id[t]))
self.train_triplets.append((self.entity2id[t], self.relation2id[r] + len(self.relation2id), self.entity2id[h]))

with open(os.path.join(data_path, 'valid.txt')) as fi:
for line in fi:
h, r, t = line.strip().split('\t')
self.valid_triplets.append((self.entity2id[h], self.relation2id[r], self.entity2id[t]))
self.valid_triplets.append((self.entity2id[t], self.relation2id[r] + len(self.relation2id), self.entity2id[h]))

with open(os.path.join(data_path, 'test.txt')) as fi:
for line in fi:
h, r, t = line.strip().split('\t')
self.test_triplets.append((self.entity2id[h], self.relation2id[r], self.entity2id[t]))
self.test_triplets.append((self.entity2id[t], self.relation2id[r] + len(self.relation2id), self.entity2id[h]))

self.entity_size = len(self.entity2id)
self.relation_size = len(self.relation2id) * 2

def get_entity_size(self):
return len(self.entity2id)
return self.entity_size

def get_relation_size(self):
return len(self.relation2id)
return self.relation_size

class RuleMiner:
def __init__(self, graph):
Expand Down
17 changes: 17 additions & 0 deletions codes_toy/pyrnnlogiclib/rnnlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,16 @@ void KnowledgeGraph::read_data(char *data_path)
if (ent2id.count(s_head) == 0 || ent2id.count(s_tail) == 0 || rel2id.count(s_rel) == 0) continue;

h = ent2id[s_head]; t = ent2id[s_tail]; r = rel2id[s_rel];

triplet.h = h; triplet.t = t; triplet.r = r;
train_triplets.push_back(triplet);
set_train_triplets.insert(triplet);
set_all_triplets.insert(triplet);

triplet.h = t; triplet.t = h; triplet.r = r + relation_size;
train_triplets.push_back(triplet);
set_train_triplets.insert(triplet);
set_all_triplets.insert(triplet);
}
fclose(fi);

Expand All @@ -276,9 +282,14 @@ void KnowledgeGraph::read_data(char *data_path)
if (ent2id.count(s_head) == 0 || ent2id.count(s_tail) == 0 || rel2id.count(s_rel) == 0) continue;

h = ent2id[s_head]; t = ent2id[s_tail]; r = rel2id[s_rel];

triplet.h = h; triplet.t = t; triplet.r = r;
valid_triplets.push_back(triplet);
set_all_triplets.insert(triplet);

triplet.h = t; triplet.t = h; triplet.r = r + relation_size;
valid_triplets.push_back(triplet);
set_all_triplets.insert(triplet);
}
fclose(fi);
valid_triplet_size = int(valid_triplets.size());
Expand All @@ -297,14 +308,20 @@ void KnowledgeGraph::read_data(char *data_path)
if (ent2id.count(s_head) == 0 || ent2id.count(s_tail) == 0 || rel2id.count(s_rel) == 0) continue;

h = ent2id[s_head]; t = ent2id[s_tail]; r = rel2id[s_rel];

triplet.h = h; triplet.t = t; triplet.r = r;
test_triplets.push_back(triplet);
set_all_triplets.insert(triplet);

triplet.h = t; triplet.t = h; triplet.r = r + relation_size;
test_triplets.push_back(triplet);
set_all_triplets.insert(triplet);
}
fclose(fi);
test_triplet_size = int(test_triplets.size());

all_triplet_size = int(set_all_triplets.size());
relation_size *= 2;

printf("#Entities: %d \n", entity_size);
printf("#Relations: %d \n", relation_size);
Expand Down
Empty file modified data/FB15k-237/entities.dict
100755 → 100644
Empty file.
237 changes: 0 additions & 237 deletions data/FB15k-237/relations.dict
100755 → 100644

Large diffs are not rendered by default.

61,398 changes: 20,466 additions & 40,932 deletions data/FB15k-237/test.txt
100755 → 100644

Large diffs are not rendered by default.

816,345 changes: 272,115 additions & 544,230 deletions data/FB15k-237/train.txt
100755 → 100644

Large diffs are not rendered by default.

Loading

0 comments on commit 69aafd4

Please sign in to comment.