是否可以返回type of an entities(例如位置) 就像freebase search的工作方式一样?我正在使用freebase搜索示例代码(我将在下面提供它们)来生成搜索结果,但即使使用通配符,它也不会提取实体类型,这里有一些示例结果。
样本结果
["\/en\/bukit_panjang","Bukit Panjang",284.883636,"\/m\/04fxxf","en"]
["\/en\/bukit_panjang_mrt_station",{"id":"\/metropolitan_transit\/transit_stop","name":"Transit Stop"},"Bukit Panjang LRT\/MRT Station",250.857147,"\/m\/0661mk1","en"]
["\/en\/bukit_panjang_plaza",{"id":"\/business\/shopping_center","name":"Shopping center"},"Bukit Panjang Plaza",229.566818,"\/m\/02q_h6s","en"]
搜索示例代码
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.jayway.jsonpath.JsonPath;
import java.io.FileInputStream;
import java.util.Properties;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class SearchSample {
public static Properties properties = new Properties();
public static void main(String[] args) {
try {
properties.load(new FileInputStream("freebase.properties"));
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
JSONParser parser = new JSONParser();
GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/search");
url.put("query", "Bukit Panjang");
//url.put("filter", "(any type:/people/person domain:location/citytown/)");
url.put("filter", "(any part_of:singapore)");
url.put("limit", "10");
url.put("indent", "true");
url.put("key", properties.get("API_KEY"));
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse httpResponse = request.execute();
JSONObject response = (JSONObject)parser.parse(httpResponse.parseAsString());
JSONArray results = (JSONArray)response.get("result");
for (Object result : results) {
System.out.println(JsonPath.read(result,"$.*").toString());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
答案 0 :(得分:1)
使用output
参数来定制输出,如本页所述:
https://developers.google.com/freebase/v1/search-output
e.g。
(尽管您可能需要考虑使用notable_type
或notable_for
代替原始类型,具体取决于您的目标)