@@ -0,0 +1,1607 @@
+# split the YAGOFact data set into training set, validation set and test set%0A# sparse: train:valid:test = 80%25:10%25:10%25%0Aimport sys%0Aimport numpy as np%0A%0A# split the YAGOFact data into training set, validation set and testing set%0Adef split():%0A    left_dict = %7B%7D%0A    rel_dict = %7B%7D%0A    right_dict = %7B%7D%0A    f = open('/remote/curtis/wcohen/data/ontological-pathfinding/YAGOFacts.csv', 'r')%0A    dat = f.readlines()%0A    subsample_fraction = 0.01%0A    train_pr = 0.8%0A    valid_pr = 0.1%0A    f.close()%0A    f_train = open('data/yago-sparse-train.txt', 'w')%0A    f_test = open('data/yago-sparse-test.txt', 'w')%0A    f_valid = open('data/yago-sparse-valid.txt', 'w')%0A    train_set = %5B%5D%0A    valid_set = %5B%5D%0A    test_set = %5B%5D%0A    for i in dat:%0A        rel, left, right = i.upper().strip().split('%5Ct')%0A        left_dict%5Bleft%5D = 1%0A        rel_dict%5Brel%5D = 1%0A        right_dict%5Bright%5D = 1%0A        words = left + '%5Ct' + rel + '%5Ct' + right + '%5Cn'%0A        if len(words) != 3:%0A            continue%0A        r = np.random.rand()%0A%0A        # subsample the data%0A        if r %3E subsample_fraction:%0A            continue%0A%0A        r = np.random.rand()%0A        if r %3C train_pr:%0A            train_set += %5Bwords%5D%0A        elif r %3C (train_pr + valid_pr):%0A            valid_set += %5Bwords%5D%0A        else:%0A            test_set += %5Bwords%5D%0A    f_train.writelines(train_set)%0A    f_valid.writelines(valid_set)%0A    f_test.writelines(test_set)%0A    f_train.close()%0A    f_test.close()%0A    f_valid.close()%0A    print 'Left entities: %7B%7D, relations: %7B%7D, right entities: %7B%7D'.format(len(left_dict), len(rel_dict), len(right_dict))%0Aif __name__ == %22__main__%22:%0A    split()%0A

add yago