Reputation: 302
I am attempting to use Freebase to find all the alternative names of a specified company. I currently have the following code, which works when you specify the languages you want the name to be in. I would like it to return all alias, regardless of the language. However, if I do not specify the languages, no results are returned. Also, if I include all languages in the query as one long list, it returns results for the wrong company. When I did this in the below code, it returned results for Bank of America. Is there a way of specifying all languages? The main purpose of the code is to find common acronyms of companies, though select full names are useful too.
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", "Royal Bank of Scotland");
url.put("filter", "(all type:/organization/organization )");
url.put("limit", "1");
url.put("output", "( /common/topic/alias )");
url.put("lang", "cs");//Specify Laungauges
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");
System.out.println(results);
Upvotes: 0
Views: 274
Reputation: 10540
The lang
parameter takes a comma separated list of languages. If you really want all, you can just use the entire list which currently is:
"en,es,fr,de,it,pt,zh,ja,ko,ru,sv,fi,da,nl,el,ro,tr,hu,th,pl,cs,id,bg,uk,ca,eu,no,sl,sk,hr,sr,ar,hi,vi,fa,ga,iw,lv,lt,gl,is,hy,lo,km,sq,fil,zxx"
From https://www.googleapis.com/freebase/v1/search?help=langs&indent=true as documented on https://developers.google.com/freebase/v1/search-cookbook#language-constraints
This query works for me:
https://www.googleapis.com/freebase/v1/search?query="Royal%20Bank%20of%20Scotland"&filter=(all%20type:/organization/organization%20)&limit=1&output=(/common/topic/alias%20)&lang=en,es,fr,de,it,pt,zh,ja,ko,ru,sv,fi,da,nl,el,ro,tr,hu,th,pl,cs,id,bg,uk,ca,eu,no,sl,sk,hr,sr,ar,hi,vi,fa,ga,iw,lv,lt,gl,is,hy,lo,km,sq,fil,zxx
Upvotes: 1