FreebaseHelper { public Entity getNameForID(String id) throws IOException { String trimmedID = id.replaceAll("\\.", "/"); if (!trimmedID.startsWith("/")) { trimmedID = "/" + trimmedID; } String metaURL = FREEBASE_SEARCH_API.replace("{id}", trimmedID); JsonNode jsonNode = getURL(metaURL); LOG.trace(metaURL); if (jsonNode.get("result").size() < 1) { LOG.error("No results for mid {}", id); return null; } JsonNode result = jsonNode.get("result").get(0); String name = result.has("name") ? result.get("name").asText() : ""; Entity person = new Entity(id, name); final JsonNode output = result.get("output"); if (output.has("type")) { final JsonNode types = output.get("type").get("/type/object/type"); person.types = Lists.newArrayList(Iterables.transform(types, new Function<JsonNode, String>() { @Nullable @Override public String apply(@Nullable JsonNode type) { return type.get("id").asText(); } })); } if (output.has("/common/topic/alias")) { final JsonNode alias = output.get("/common/topic/alias").get("/common/topic/alias"); if (alias != null) { person.alias = Lists.newArrayList(Iterables.transform(alias, new Function<JsonNode, String>() { @Nullable @Override public String apply(@Nullable JsonNode alias) { return alias.asText(); } })); } } return person; }  static String transformOldToNewId(String old); static String transformNewToOldId(String newId); Entity getNameForID(String id); Entity getNameForIDs(String id); boolean checkIfCompoundRelationHolds(String id1, String id2, String[] relation); FreebaseRelation getTypesForRelationFromFreebase(String r); void readAllInverseRelations(); static void main(String[] args);  }
@Test public void testGetTopicForID() throws Exception { FreebaseHelper freebaseHelper = new FreebaseHelper(); FreebaseHelper.Entity subject = freebaseHelper.getNameForID("/m/0g6g2m"); System.out.println(subject); subject = freebaseHelper.getNameForID("/m/047rcpg"); System.out.println(subject); FreebaseHelper.Entity object = freebaseHelper.getNameForID("/m/02h4rq6"); System.out.println(object); }
@Test public void testReplacedTopic() throws Exception { FreebaseHelper freebaseHelper = new FreebaseHelper(); final FreebaseHelper.Entity nameForID = freebaseHelper.getNameForID("/m/07mt8q3"); System.out.println(nameForID); }
@Test public void testErrorID() throws Exception { FreebaseHelper freebaseHelper = new FreebaseHelper(); final FreebaseHelper.Entity nameForID = freebaseHelper.getNameForID("/m/0h6rm"); System.out.println(nameForID); }