AGDISTIS { public HashMap<String, String> runDisambiguation(String inputText) throws ParseException, IOException { String urlParameters = "text=" + URLEncoder.encode(inputText, "UTF-8"); urlParameters += "&type=agdistis"; URL url = new URL("https: HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", String.valueOf(urlParameters.length())); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); InputStream inputStream = connection.getInputStream(); InputStreamReader in = new InputStreamReader(inputStream); BufferedReader reader = new BufferedReader(in); StringBuilder sb = new StringBuilder(); while (reader.ready()) { sb.append(reader.readLine()); } wr.close(); reader.close(); connection.disconnect(); String agdistis = sb.toString(); JSONParser parser = new JSONParser(); JSONArray resources = (JSONArray) parser.parse(agdistis); HashMap<String, String> tmp = new HashMap<String, String>(); for (Object res : resources.toArray()) { JSONObject next = (JSONObject) res; String namedEntity = (String) next.get("namedEntity"); String disambiguatedURL = (String) next.get("disambiguatedURL"); tmp.put(namedEntity, disambiguatedURL); } return tmp; }  HashMap<String, String> runDisambiguation(String inputText);  }
@Test public void testDisambiguation() throws ParseException, IOException { AGDISTIS post = new AGDISTIS(); String subjectString = "Tom Cruise"; String objectString = "Katie Holmes"; String preAnnotatedText = "<entity>" + subjectString + "</entity><entity>" + objectString + "</entity>"; log.debug("Disambiguation for: " + preAnnotatedText); HashMap<String, String> realResults = new LinkedHashMap<String,String>(); realResults.put("Katie Holmes", "http: realResults.put("Tom Cruise", "http: HashMap<String, String> results = post.runDisambiguation(preAnnotatedText); for (String namedEntity : results.keySet()) { Assert.assertTrue(results.get(namedEntity).equals(realResults.get(namedEntity))); log.debug("named entity: " + namedEntity + " -> " + results.get(namedEntity)); } }