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

Merge remote-tracking branch 'origin/master'

parents c3abc0e3 1dca6344
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,20 @@
<groupId>snlp</groupId>
<artifactId>factchecker</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicStatusLine;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import java.io.IOException;
import java.util.*;
public class Implementation
{
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
{
String returnValue = "empty";
HttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpclient.execute(httpPost);
BasicStatusLine n = (BasicStatusLine) response.getStatusLine();
String jsonString = EntityUtils.toString(response.getEntity());
JSONObject obj = new JSONObject(jsonString);
if (obj.getJSONObject("query") != null)
{
JSONObject pageNamejjj = obj.getJSONObject("query");
Map<String, Object> ne = new HashMap<>();
ne = pageNamejjj.toMap();
Map<String, Object> ne1 = new HashMap<>();
ne1 = (Map<String, Object>) ne.get("pages");
Set<Object> x = Collections.singleton(ne1.keySet());
Object f = x.iterator().next();
String o = f.toString();
String k = o.substring(1, o.length() - 1);
Map<String, Object> ne2 = new HashMap<>();
ne2 = (Map<String, Object>) ne1.get(o.substring(1, o.length() - 1));
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)
{
ne3 = (Map<String, Object>) rev.get(0);
Object h = ne3.get("*");
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.util.ArrayList;
public class Main {
......@@ -19,8 +18,7 @@ public class Main {
ArrayList<String> input = new ArrayList<>();
ArrayList<String> id = new ArrayList<>();
String s = "";
while ((s = br.readLine()) != null)
{
while ((s = br.readLine()) != null) {
String inp[] = s.split("\\t+");
input.add(inp[1]);
......@@ -29,9 +27,6 @@ public class Main {
}
int i = 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment