In [1]:
"""
We use following lines because we are running on Google Colab
If you are running notebook on a local computer, you don't need these
"""
from google.colab import drive
drive.mount('/content/gdrive')
import os
os.chdir('/content/gdrive/My Drive/finch/tensorflow2/knowledge_graph_completion/wn18/data')
Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount("/content/gdrive", force_remount=True).
In [0]:
from pathlib import Path
In [0]:
"""
Make Vocabulary (Entity and Relation)
"""

Path('../vocab').mkdir(exist_ok=True)

entities, relations = set(), set()

with open('../data/wn18/train.txt') as f:
  for line in f:
    line = line.rstrip()
    s, p, o = line.split()
    entities.add(s)
    relations.add(p)
    entities.add(o)

with open('../vocab/entity.txt', 'w') as f:
  for e in sorted(entities):
    f.write(e+'\n')

with open('../vocab/relation.txt', 'w') as f:
  for r in sorted(relations):
    f.write(r+'\n')
In [0]: