Skip to content
Snippets Groups Projects
Commit c3abc0e3 authored by anirudhash's avatar anirudhash
Browse files

Annotator

parent bfacc436
No related branches found
No related tags found
No related merge requests found
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
//import net.guides.springboot.springbootasyncexample.model.User;
public class Annotator {
public void getAnnotations() throws IOException {
String endpoint = "https://labs.tib.eu/falcon/api?mode=long";
String endpoint1 = "https://labs.tib.eu/falcon/falcon2/api?mode=long";
// curl --header "Content-Type: application/json" \
// --request POST \
// --data '{"text":"Who painted The Storm on the Sea of Galilee?"}' \
//Curl to array
String[] command = {"curl", "--header", "Content-Type:application/json", "--request", "POST", "--data", "{" + "\"text\"" + ":" +
"\"" + "Who painted The Storm on the Sea of Galilee?" + "\"" + "}", endpoint1};
Process p;
try {
p = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
// String result = builder.toString();
JSONObject jsonObject = new JSONObject(builder.toString());
Object relations = jsonObject.get("relations_wikidata");
Object entities = jsonObject.get("entities_wikidata");
// jsonObject.
System.out.println(relations);
System.out.println(jsonObject.get("entities_wikidata"));
System.out.print(jsonObject);
} catch (IOException e) {
System.out.print("error");
e.printStackTrace();
}
// URL urlForGetRequest = new URL(falcon);
// HttpURLConnection conection = (HttpURLConnection) urlForGetRequest.openConnection();
// int responseCode = conection.getResponseCode();
// System.out.println(responseCode);
// String command = "curl \\t --header \\t \"Content-Type: application/json\" --request POST --data '{\"text\":\"Who painted The Storm on the Sea of Galilee?\"}' https://labs.tib.eu/falcon/api?mode=long";
// Process process = Runtime.getRuntime().exec(command);
// JSONObject job = new JSONObject(process.getInputStream());
// System.out.println(job.length());
//// String responseString = readInputStream(process.getInputStream());
// //Read
// BufferedReader in = new BufferedReader(
// new InputStreamReader(process.getInputStream()));
// StringBuffer response = new StringBuffer();
// String readLine = null;
//
// while ((readLine = in.readLine()) != null) {
// response.append(readLine);
// }
// System.out.println("JSON String Result " + response.toString());
// in.close();
// String parameters = URLEncoder.encode(search, charset);
// URL urlForGetRequest = new URL(falcon);
// String readLine = null;
//
// HttpURLConnection conection = (HttpURLConnection) urlForGetRequest.openConnection();
// conection.setRequestMethod("GET");
// conection.setRequestProperty("data", "HI");
// conection.setRequestProperty(search, String.valueOf(this.getClass())); // set userId its a sample here
//
// int responseCode = conection.getResponseCode();
////
// if (responseCode == HttpURLConnection.HTTP_OK) {
// BufferedReader in = new BufferedReader(
// new InputStreamReader(conection.getInputStream()));
// StringBuffer response = new StringBuffer();
//
//// JSONArray myArray = new JSONArray(conection.getInputStream()
//
//// System.out.println(myArray);
// while ((readLine = in.readLine()) != null) {
// response.append(readLine);
// }
// in.close();
//
// // print result
// System.out.println(response.getClass().getName());
// System.out.println(response.length());
// System.out.println("JSON String Result " + response.toString());
// //GetAndPost.POSTRequest(response.toString());
//
// } else {
// System.out.println("GET NOT WORKED");
//
// }
}
// private List<String> parseJsonStream(InputStream in) throws IOException, ParseException {
// List<String> annotations = new ArrayList<>();
// JSONArray namedEntities = (JSONArray) this.jsonParser.parse(new InputStreamReader(in, "UTF-8"));
// JSONObject namedEntity;
// String url;
// long start, length;
// for (Object obj : namedEntities) {
// namedEntity = (JSONObject) obj;
// start = (long) namedEntity.get("start");
// length = (long) namedEntity.get("offset");
// url = (String) namedEntity.get("disambiguatedURL");
// }
// return annotations;
// }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment