/** * Here we set up the PraConfig items that have to do with the input KB files. In particular, that * means deciding which relations are known to be inverses of each other, which edges should be * ignored because using them to predict new relations instances would consitute cheating, and * setting the range and domain of a relation to restrict new predictions. * * <p>Also, if the relations have been embedded into a latent space, we perform a mapping here * when deciding which edges to ignore. This means that each embedding of a KB graph has to have a * different directory. */ public void parseKbFiles( String directory, String relation, PraConfig.Builder builder, String outputBase, FileUtil fileUtil) throws IOException { // TODO(matt): allow this to be left unspecified. Map<Integer, Integer> inverses = createInverses(directory + "inverses.tsv", builder.edgeDict); builder.setRelationInverses(inverses); Map<String, List<String>> embeddings = null; if (fileUtil.fileExists(directory + "embeddings.tsv")) { embeddings = fileUtil.readMapListFromTsvFile(directory + "embeddings.tsv"); } List<Integer> unallowedEdges = createUnallowedEdges(relation, inverses, embeddings, builder.edgeDict); builder.setUnallowedEdges(unallowedEdges); if (fileUtil.fileExists(directory + "ranges.tsv")) { Map<String, String> ranges = fileUtil.readMapFromTsvFile(directory + "ranges.tsv"); String range = ranges.get(relation); String fixed = range.replace("/", "_"); String cat_file = directory + "category_instances" + File.separator + fixed; // Bhushan cat_file = cat_file.replace(":", "_"); Set<Integer> allowedTargets = fileUtil.readIntegerSetFromFile(cat_file, builder.nodeDict); builder.setAllowedTargets(allowedTargets); } else { FileWriter writer = fileUtil.getFileWriter(outputBase + "settings.txt", true); // true -> append writer.write("No range file found! I hope your accept policy is as you want it...\n"); System.out.println("No range file found!"); writer.close(); } }