// Path: core/src/main/java/edu/tuberlin/dima/textmining/jedi/core/model/FreebaseRelation.java
// public class FreebaseRelation {
// 
//         String domain;
//         String range;
// 
//         List<String> domainTypes;
//         List<String> rangeTypes;
// 
//         public FreebaseRelation(String domain, String range, List<String> rangeTypes, List<String> domainTypes) {
//             this.domain = domain;
//             this.range = range;
//             this.rangeTypes = rangeTypes;
//             this.domainTypes = domainTypes;
//         }
// 
//         public String getRange() {
//             return range;
//         }
// 
//         public String getDomain() {
//             return domain;
//         }
// 
//         public List<String> getRangeTypes() {
//             return rangeTypes;
//         }
// 
//         public List<String> getDomainTypes() {
//             return domainTypes;
//         }
// 
//     @Override
//     public String toString() {
//         return "FreebaseRelation{" +
//                 "domain='" + domain + '\'' +
//                 ", range='" + range + '\'' +
//                 ", domainTypes=" + domainTypes +
//                 ", rangeTypes=" + rangeTypes +
//                 '}';
//     }
// }


import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import edu.tuberlin.dima.textmining.jedi.core.model.FreebaseRelation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.List;

		JsonNode jsonNode = getURL(metaURL);


		if (jsonNode.has("property")) {
			final JsonNode property = jsonNode.get("property");
			if (property.has("/type/property/reverse_property")) {
				return property.get("/type/property/reverse_property").get("values").get(0).get("id").asText();
			}
		}

		return null;
	}

	private JsonNode getFreebaseTopicForID(String freebaseID) throws IOException {
		String ask = "https://www.googleapis.com/freebase/v1/topic/{freebaseID}?key=AIzaSyCyloa8DMxhKvBVdqdk_Drf900rAeeA7QA";

		String trimmedR = freebaseID.replaceAll("\\.", "/");
		String metaURL = ask.replace("{freebaseID}", trimmedR);

		LOG.info("Asking " + trimmedR);

		JsonNode parse = getURL(metaURL);

		return parse.get("property");


	}


// Path: core/src/main/java/edu/tuberlin/dima/textmining/jedi/core/model/FreebaseRelation.java
// public class FreebaseRelation {
// 
//         String domain;
//         String range;
// 
//         List<String> domainTypes;
//         List<String> rangeTypes;
// 
//         public FreebaseRelation(String domain, String range, List<String> rangeTypes, List<String> domainTypes) {
//             this.domain = domain;
//             this.range = range;
//             this.rangeTypes = rangeTypes;
//             this.domainTypes = domainTypes;
//         }
// 
//         public String getRange() {
//             return range;
//         }
// 
//         public String getDomain() {
//             return domain;
//         }
// 
//         public List<String> getRangeTypes() {
//             return rangeTypes;
//         }
// 
//         public List<String> getDomainTypes() {
//             return domainTypes;
//         }
// 
//     @Override
//     public String toString() {
//         return "FreebaseRelation{" +
//                 "domain='" + domain + '\'' +
//                 ", range='" + range + '\'' +
//                 ", domainTypes=" + domainTypes +
//                 ", rangeTypes=" + rangeTypes +
//                 '}';
//     }
// }


// Path: core/src/main/java/edu/tuberlin/dima/textmining/jedi/core/freebase/FreebaseHelper.java
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import edu.tuberlin.dima.textmining.jedi.core.model.FreebaseRelation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.List;


		JsonNode jsonNode = getURL(metaURL);


		if (jsonNode.has("property")) {
			final JsonNode property = jsonNode.get("property");
			if (property.has("/type/property/reverse_property")) {
				return property.get("/type/property/reverse_property").get("values").get(0).get("id").asText();
			}
		}

		return null;
	}

	private JsonNode getFreebaseTopicForID(String freebaseID) throws IOException {
		String ask = "https://www.googleapis.com/freebase/v1/topic/{freebaseID}?key=AIzaSyCyloa8DMxhKvBVdqdk_Drf900rAeeA7QA";

		String trimmedR = freebaseID.replaceAll("\\.", "/");
		String metaURL = ask.replace("{freebaseID}", trimmedR);

		LOG.info("Asking " + trimmedR);

		JsonNode parse = getURL(metaURL);

		return parse.get("property");


	}


	public FreebaseRelation getTypesForRelationFromFreebase(String r) throws IOException {