Skip to content
Snippets Groups Projects
Commit 5378c9fe authored by RahulSherikar's avatar RahulSherikar
Browse files

changes

parent ac3ee963
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="12" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
......@@ -26,12 +26,6 @@
<version>4.3.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bytedeco.javacpp-presets/cpython-platform -->
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>cpython-platform</artifactId>
<version>3.6-1.4.3</version>
</dependency>
......
......@@ -5,207 +5,7 @@ public class Annotator {
Implementation impl = new Implementation();
/*
public String getAnnotations(String input) throws IOException {
String endpoint = "https://labs.tib.eu/falcon/api?mode=long";
String endpoint1 = "https://labs.tib.eu/falcon/falcon2/api?mode=long";
ArrayList<String> realArr = new ArrayList<>();
String res = "";
Implementation impl = new Implementation();
// 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\"" + ":" +
"\"" + input + "\"" + "}", 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());
JSONArray relations = null;
JSONArray relsrrsy = null;
String y = "";
relations = jsonObject.getJSONArray("relations_wikidata");
if(relations.length() != 0)
{
relsrrsy = relations.getJSONArray(0);
int i = 0;
//rrayList<String> rel = (ArrayList<String>) relations.get(0);
String x = relsrrsy.get(1).toString();
JSONObject jsonObject1 = new JSONObject(builder.toString());
JSONArray relations1 = jsonObject.getJSONArray("entities_wikidata");
for(int j=1; j<relations1.length(); j++)
{
JSONArray relsrrsy1 = relations1.getJSONArray(j);
String strrel = relsrrsy1.get(1).toString();
realArr.add(strrel);
}
//int i = 0;
JSONArray relsrrsy1 = relations1.getJSONArray(0);
//rrayList<String> rel = (ArrayList<String>) relations.get(0);
y = relsrrsy1.get(1).toString();
}
//String c = jsonObject.getString("")
if(!y.equals(""))
{
String[] arrStr = y.split(" ");
String newStr = "";
final StringBuilder ret = new StringBuilder(y.length());
for (final String word : y.split(" ")) {
if (!word.isEmpty()) {
ret.append(Character.toUpperCase(word.charAt(0)));
ret.append(word.substring(1).toLowerCase());
}
if (!(ret.length() == y.length()))
ret.append(" ");
}
y = ret.toString();
String url = impl.getURL(y);
String content = impl.getPageContent(url);
if(content.equals(""))
{
System.out.println("Content is empty");
}
if(realArr.size() == 0)
{
if(content.contains(relations.toString()))
{
res = "true";
//
}
else {
res = "false";
//
}
}
for(int a=0; a<realArr.size(); a++)
{
if(content.contains(realArr.get(a)))
{
res = "true";
//
}
else {
res = "false";
//
}
}
}
else if(y.equals("") && relations.length() == 0)
{
System.out.println("String y is empty and relation is empty false returned");
}
else if(y.equals("") && relations.length() != 0)
{
System.out.println("String y is empty and relation is not empty false returned");
}
if (res.equals(""))
{
res = "false";
System.out.println("Input is" +input);
}
// jsonObject.
} catch (IOException e) {
System.out.print("error");
e.printStackTrace();
}
return res;
}
private String ifKeyword(String[] out, String toString) {
String x[] = toString.split(",");
String in = x[1].replaceAll("[^aA-zZ]" , "");
if(in.contains("]"))
{
in = in.replace("]", "");
}
String rtr = "";
for(int i = 0; i< out.length; i++)
{
if(out[i].contains(in))
{
rtr = rtr + out[i];
}
}
return rtr;
}
// 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;
// }
*/
public String getAnnotations(String input) throws IOException {
input = input.replace(":", "");
......@@ -218,8 +18,8 @@ public class Annotator {
if(input.contains("death") )
{
String[] spl = input.split("death place is");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
String find = spl[1].replace(".", "");
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -239,8 +39,8 @@ public class Annotator {
{
String[] spl = input.split("birth place is");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
String find = spl[1].replace(".", "");
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -258,8 +58,8 @@ public class Annotator {
{
String[] spl = input.split("last place is");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
String find = spl[1].replace(".", "");
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -277,8 +77,8 @@ public class Annotator {
{
String[] spl = input.split("foundation place is");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
String find = spl[1].replace(".", "");
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -296,8 +96,8 @@ public class Annotator {
{
String[] spl = input.split("innovation place is");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
String find = spl[1].replace(".", "");
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -315,8 +115,8 @@ public class Annotator {
{
String[] spl = input.split("nascence place is");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
String find = spl[1].replace(".", "");
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -340,8 +140,8 @@ public class Annotator {
{
input = input.replace("death place.","");
String[] spl = input.split(" is ");
String rtr = impl.getURL(spl[1]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[1]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
content = content.replace("]" , "");
......@@ -360,8 +160,8 @@ public class Annotator {
input = input.replace(" birth place.","");
String[] spl = input.split(" is ");
String rtr = impl.getURL(spl[1]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[1]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
content = content.replace("]" , "");
......@@ -379,8 +179,8 @@ public class Annotator {
input = input.replace(" last place.","");
String[] spl = input.split(" is ");
String rtr = impl.getURL(spl[1]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[1]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
content = content.replace("]" , "");
......@@ -398,8 +198,8 @@ public class Annotator {
input = input.replace(" foundation place.","");
String[] spl = input.split(" is ");
String rtr = impl.getURL(spl[1]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[1]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
content = content.replace("]" , "");
......@@ -417,8 +217,8 @@ public class Annotator {
input = input.replace(" innovation place.","");
String[] spl = input.split(" is ");
String rtr = impl.getURL(spl[1]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[1]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
content = content.replace("]" , "");
......@@ -436,8 +236,8 @@ public class Annotator {
input = input.replace(" nascence place.","");
String[] spl = input.split(" is ");
String rtr = impl.getURL(spl[1]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[1]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
content = content.replace("]" , "");
......@@ -457,8 +257,8 @@ public class Annotator {
{
input = input.replace(".", "");
String[] spl = input.split(" stars ");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -478,8 +278,8 @@ public class Annotator {
{
input = input.replace(".", "");
String[] spl = input.split(" team is ");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -499,8 +299,8 @@ public class Annotator {
{
input = input.replace(".", "");
String[] spl = input.split(" award is ");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -519,8 +319,8 @@ public class Annotator {
{
input = input.replace(".", "");
String[] spl = input.split(" subsidiary is ");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......@@ -539,8 +339,8 @@ public class Annotator {
{
input = input.replace(".", "");
String[] spl = input.split(" spouse is ");
String rtr = impl.getURL(spl[0]);
String content = impl.getPageContent(rtr);
String rtr = impl.wiki(spl[0]);
String content = impl.contentOfInfobox(rtr);
content = content.replaceAll("[^aA-zZ\\s]" , "");
content = content.replace("[" , "");
......
......@@ -12,58 +12,59 @@ import java.util.*;
public class Implementation {
public String getURL(String u) {
if (u.length() > 1) {
u = u.replace(" ", "%20");
}
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();
public String contentOfInfobox(String url) throws IOException {
HttpPost httpPost = new HttpPost(url);
HttpPost post = new HttpPost(url);
HttpClient client = HttpClients.createDefault();
HttpResponse response = client.execute(post);
String jsonForm = EntityUtils.toString(response.getEntity());
JSONObject jsonobject = new JSONObject(jsonForm);
String predict = "empty";
HttpResponse response = httpclient.execute(httpPost);
BasicStatusLine n = (BasicStatusLine) response.getStatusLine();
String jsonString = EntityUtils.toString(response.getEntity());
JSONObject obj = new JSONObject(jsonString);
if (jsonString.contains("query") && 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");
if ((jsonobject.getJSONObject("query") != null) && (jsonForm.contains("query")) ) {
Set<Object> x = Collections.singleton(ne1.keySet());
Map<String, Object> pagesMap = new HashMap<>();
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> revisionsMap = new HashMap<>();
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));
JSONObject value = jsonobject.getJSONObject("query");
queryMap = value.toMap();
if (ne2.get("revisions") != null) {
ArrayList<Object> rev = (ArrayList<Object>) ne2.get("revisions");
Map<String, Object> ne3 = new HashMap<>();
pagesMap = (Map<String, Object>) queryMap.get("pages");
Set<Object> pagesSet = Collections.singleton(pagesMap.keySet());
String convertString = pagesSet.iterator().next().toString();
revisionsMap = (Map<String, Object>) pagesMap.get(convertString.substring(1, convertString.length() - 1));
if (!rev.isEmpty() && rev.get(0) != null) {
ne3 = (Map<String, Object>) rev.get(0);
Object h = ne3.get("*");
if (revisionsMap.get("revisions") != null) {
ArrayList<Object> checkRevisions = (ArrayList<Object>) revisionsMap.get("revisions");
Map<String, Object> mapIt = new HashMap<>();
if (h != null) {
returnValue = h.toString();
if (!checkRevisions.isEmpty() && checkRevisions.get(0) != null) {
mapIt = (Map<String, Object>) checkRevisions.get(0);
Object checkNull = mapIt.get("*");
if (checkNull != null) {
predict = checkNull.toString();
}
}
}
}
return predict;
}
return returnValue;
public String wiki(String section) {
int len = section.length();
if (len > 1) {
section = section.replace(" ", "%20");
}
String url = "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=" + section + "&rvsection=0";
return url;
}
}
......
......@@ -11,49 +11,51 @@ public class Main {
BufferedWriter out;
String s = "";
System.out.println("Hi");
Path currentPath = Paths.get("");
String filepath = currentPath.toAbsolutePath().toString();
filepath = filepath + File.separator + "result6.ttl";
Path relPath = Paths.get("");
String filepath = relPath.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));
Writer logs = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filepath), StandardCharsets.UTF_8));
Annotator at = new Annotator();
File file = new File("SNLP2019_test.tsv");
BufferedReader br = new BufferedReader(new FileReader(file));
ArrayList<String> input = new ArrayList<>();
ArrayList<String> statement = new ArrayList<>();
ArrayList<String> id = new ArrayList<>();
String s = "";
while ((s = br.readLine()) != null) {
String inp[] = s.split("\\t+");
input.add(inp[1]);
id.add(inp[0]);
String splitIt[] = s.split("\\t+");
id.add(splitIt[0]);
statement.add(splitIt[1]);
}
for (int i = 1; i < input.size(); i++) {
String res = at.getAnnotations(input.get(i));
System.out.println("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII" + res);
for (int i = 1; i < statement.size(); i++) {
String res = at.getAnnotations(statement.get(i));
System.out.println("-------------------" + res);
if (res == "true") {
//writer1.write(id.get(y) + "\t" + input.get(y) + "\t" + 1.0 + "\n");
//writer1.write(id.get(y) + "\t" + statement.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");
logs.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>\"0.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");
logs.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();
logs.close();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment