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

Improved

parent 1dca6344
No related branches found
No related tags found
No related merge requests found
......@@ -9,25 +9,19 @@ import org.json.JSONObject;
import java.io.IOException;
import java.util.*;
public class Implementation
{
public class Implementation {
public String getURL(String u)
{
public String getURL(String u) {
if (u.length() > 1) {
u = u.replace(" ", "%20");
u = u.substring(0, u.length() - 3);
}
}
String url = "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=" + u + "&rvsection=0";
return url;
}
public String getPageContent(String url) throws IOException
{
public String getPageContent(String url) throws IOException {
String returnValue = "empty";
HttpClient httpclient = HttpClients.createDefault();
......@@ -37,8 +31,7 @@ public class Implementation
BasicStatusLine n = (BasicStatusLine) response.getStatusLine();
String jsonString = EntityUtils.toString(response.getEntity());
JSONObject obj = new JSONObject(jsonString);
if (obj.getJSONObject("query") != null)
{
if (jsonString.contains("query") && obj.getJSONObject("query") != null) {
JSONObject pageNamejjj = obj.getJSONObject("query");
Map<String, Object> ne = new HashMap<>();
......@@ -55,51 +48,20 @@ public class Implementation
Map<String, Object> ne2 = new HashMap<>();
ne2 = (Map<String, Object>) ne1.get(o.substring(1, o.length() - 1));
if (ne2.get("revisions") != null)
{
if (ne2.get("revisions") != null) {
ArrayList<Object> rev = (ArrayList<Object>) ne2.get("revisions");
Map<String, Object> ne3 = new HashMap<>();
if (!rev.isEmpty() && rev.get(0) != null)
{
if (!rev.isEmpty() && rev.get(0) != null) {
ne3 = (Map<String, Object>) rev.get(0);
Object h = ne3.get("*");
if (h != null)
{
if (h != null) {
returnValue = h.toString();
}
else
{
System.out.println("inside 4");
System.out.println("*****");
}
}
else
{
System.out.println("inside 3");
System.out.println("*****");
}
}
else
{
System.out.println("inside 2");
System.out.println("*****");
}
}
else
{
System.out.println("inside 1");
System.out.println("*****");
}
return returnValue;
}
......
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
public class Main {
public static void main(String args[]) throws IOException {
BufferedWriter out;
System.out.println("Hi");
Path currentPath = Paths.get("");
String filepath = currentPath.toAbsolutePath().toString();
filepath = filepath + File.separator + "result.ttl";
File file1 = new File(filepath);
file1.getParentFile().mkdirs();
file1.createNewFile();
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filepath), StandardCharsets.UTF_8));
Annotator at = new Annotator();
//at.getAnnotations();
File file = new File("SNLP2019_test.tsv");
BufferedReader br = new BufferedReader(new FileReader(file));
ArrayList<String> input = new ArrayList<>();
ArrayList<String> id = new ArrayList<>();
String s = "";
......@@ -23,10 +34,28 @@ public class Main {
String inp[] = s.split("\\t+");
input.add(inp[1]);
id.add(inp[0]);
}
for (int i=1; i<input.size(); i++)
{
String res = at.getAnnotations(input.get(i));
System.out.println("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII" +res);
if(res == "true")
{
//writer1.write(id.get(y) + "\t" + input.get(y) + "\t" + 1.0 + "\n");
String str = "<http://swc2017.aksw.org/task2/dataset/"+id.get(i) +"><http://swc2017.aksw.org/hasTruthValue>\"1.0\"^^<http://www.w3.org/2001/XMLSchema#double> ."+ "\n";
writer.write("<http://swc2017.aksw.org/task2/dataset/"+id.get(i) +"><http://swc2017.aksw.org/hasTruthValue>\"1.0\"^^<http://www.w3.org/2001/XMLSchema#double> ."+ "\n");
}
else
{
String str1 = "<http://swc2017.aksw.org/task2/dataset/"+id.get(i) +"><http://swc2017.aksw.org/hasTruthValue>\"1.0\"^^<http://www.w3.org/2001/XMLSchema#double> ."+ "\n";
writer.write("<http://swc2017.aksw.org/task2/dataset/"+id.get(i) +"><http://swc2017.aksw.org/hasTruthValue>\"0.0\"^^<http://www.w3.org/2001/XMLSchema#double> ."+ "\n");
}
}
writer.close();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment