class FreebaseHelper {

	public FreebaseRelation getTypesForRelationFromFreebase(String r) throws IOException {

		final String relation = r.replaceFirst("ns:", "");

		String toAsk = relation;
		String left = null;

		boolean direct = true;

		// check if we have a compound type
		if (relation.contains("..")) {
			// examples
			// ns:location.location.adjoin_s..location.adjoining_relationship.adjoins	29587812
			// ns:organization.organization.headquarters..location.mailing_address.state_province_region	2506163
			// ns:organization.organization_member.member_of..organization.organization_membership.organization	2048109
			toAsk = relation.substring(0, relation.indexOf(".."));
			left = relation.substring(relation.indexOf("..") + 2);
			direct = false;
		}

		JsonNode property;

		try {
			property = getFreebaseTopicForID(toAsk);
		} catch (FileNotFoundException e) {
			LOG.warn("Error", e);
			return null;
		}

		String one;
		String two;

		if (direct) {

			one = property.has("/type/property/schema") ?
				property.get("/type/property/schema").get("values").get(0).get("id").asText() :
				property.get("/type/object/type").get("values").get(0).get("id").asText();

			two = property.has("/type/property/expected_type") ?
				property.get("/type/property/expected_type").get("values").get(0).get("id").asText() :
				property.get("/type/object/type").get("values").get(0).get("id").asText();


		} else if (!property.has("/type/property/expected_type")) {

			one = property.has("/type/property/schema") ?
				property.get("/type/property/schema").get("values").get(0).get("id").asText() :
				property.get("/type/object/type").get("values").get(0).get("id").asText();


			// Property 2
			final JsonNode second = getFreebaseTopicForID(left);

			two = second.has("/type/property/expected_type") ?
				second.get("/type/property/expected_type").get("values").get(0).get("id").asText() :
				second.get("/type/object/type").get("values").get(0).get("id").asText();


		} else {

			// Property 1
			one = property.get("/type/property/schema").get("values").get(0).get("id").asText();

			// Property 2
			JsonNode second = getFreebaseTopicForID(left);

			two = second.has("/type/property/expected_type") ?
				second.get("/type/property/expected_type").get("values").get(0).get("id").asText() :
				second.get("/type/object/type").get("values").get(0).get("id").asText();


			// Description


		}
		one = one.replaceFirst("/", "ns:").replaceAll("/", ".");
		two = two.replaceFirst("/", "ns:").replaceAll("/", ".");
		FreebaseRelation relDescription = new FreebaseRelation(one, two, null, null);
		LOG.info(relDescription.toString());


		return relDescription;

	}

}