Skip to content

Commit

Permalink
Add LC-QuAD_2 to the analysis part.
Browse files Browse the repository at this point in the history
  • Loading branch information
aorogat authored Sep 15, 2021
1 parent b7d7297 commit ceb693c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/DataSet/Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Benchmark {

public final static int QALD_ALL = 100;
public final static int LC_QUAD = 101;
public final static int LC_QUAD_2 = 111;
public final static int GraphQuestions = 102;
public final static int WebQuestions = 103;
public final static int SimpleQuestions = 104;
Expand Down
11 changes: 11 additions & 0 deletions src/DataSet/DataSetPreprocessing.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Scanner;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.sys.JenaSystem;
import qa.dataStructures.Question;
import qa.parsers.JSONParser;
import qa.parsers.Parser;
Expand Down Expand Up @@ -107,6 +108,14 @@ public static ArrayList getQueriesWithoutDuplicates(int benchmark) {
questions.addAll(JSONParser.parseNo(currentDirectory+"/data/DBpedia/No_SPARQL/V1/test.json", "QUAD", "dbpedia"));
questions.addAll(JSONParser.parseNo(currentDirectory+"/data/DBpedia/No_SPARQL/V1/valid.json", "QUAD", "dbpedia"));
}

if (benchmark == Benchmark.LC_QUAD_2 || benchmark == Benchmark.PropertiesDefined) {
//questions.addAll(JSONParser.parseQuAD2File(currentDirectory + "/data/DBpedia/SPARQL/LC-QuAD2-data/test.json", "QUAD2", "wikidata"));
//questions.addAll(JSONParser.parseQuAD2File(currentDirectory + "/data/DBpedia/SPARQL/LC-QuAD2-data/train.json", "QUAD2", "wikidata"));
questions.addAll(JSONParser.parseQuAD2File(currentDirectory + "/data/DBpedia/SPARQL/LC-QuAD2-data/lcquad_2_0.json", "QUAD2", "wikidata"));

}

if (benchmark == Benchmark.GraphQuestions || benchmark == Benchmark.PropertiesDefined) {
questions.addAll(JSONParser.parseGra(currentDirectory + "/data/Freebase/SPARQL/GraphQuestions-master/freebase13/graphquestions.testing.json", "Freebase_Graph", "freebase"));
questions.addAll(JSONParser.parseGra(currentDirectory + "/data/Freebase/SPARQL/GraphQuestions-master/freebase13/graphquestions.training.json", "Freebase_Graph", "freebase"));
Expand Down Expand Up @@ -219,6 +228,8 @@ public static ArrayList getQueriesWithoutDuplicates(int benchmark) {
Note that even with this turned on there are still lots of non-standard SPARQL syntactic
constructs that Virtuoso supports that ARQ will still reject.
*/
JenaSystem.init();
org.apache.jena.query.ARQ.init();
for (int i = 0; i < questions.size(); i++) {
String queryString = questions.get(i).getQuestionQuery();
try {
Expand Down
31 changes: 16 additions & 15 deletions src/mainClass/BenchmarkAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void analyze()
System.out.println(" 11- LC-QUAD, \t\t12- WebQuestions, \t\t13- GraphQuestions, ");
System.out.println(" 14- ComplexQuestions, \t15- ComQA, \t\t\t16- TempQuestions, ");
System.out.println(" 17- SimpleDBpediaQA, \t18- SimpleQuestions, ");
System.out.println(" 19- User Defined]");
System.out.println(" 19- User Defined, \t20- LC-QuAD_2]");
System.out.print(" Benchmark is: ");

benchmark = in.nextInt();
Expand All @@ -53,6 +53,7 @@ public static void analyze()
case 17: benchmark = Benchmark.SimpleDBpediaQA; break;
case 18: benchmark = Benchmark.SimpleQuestions; break;
case 19: benchmark = Benchmark.UserDefined; break;
case 20: benchmark = Benchmark.LC_QUAD_2; break;
default: analyze();
}

Expand All @@ -62,20 +63,20 @@ public static void analyze()
//Shallow Anlysis
//===============
//1- Keyword Analysis
Keywords k = new Keywords(qs);
k.keywordsAnalysis();

//2- Number of triples analysis
NoOfTriples triples = new NoOfTriples(qs);
triples.triplesAnalysis();

//3- Operator Distribution
OperatorDistribution distribution = new OperatorDistribution(qs);
distribution.analysis();

//Shape Analysis
ShapeAnalysis shapes = new ShapeAnalysis(qs);
shapes.analysis();
// Keywords k = new Keywords(qs);
// k.keywordsAnalysis();
//
// //2- Number of triples analysis
// NoOfTriples triples = new NoOfTriples(qs);
// triples.triplesAnalysis();
//
// //3- Operator Distribution
// OperatorDistribution distribution = new OperatorDistribution(qs);
// distribution.analysis();
//
// //Shape Analysis
// ShapeAnalysis shapes = new ShapeAnalysis(qs);
// shapes.analysis();

//NLQ Analysis
QABenchmark.NLQAnalyze();
Expand Down
24 changes: 24 additions & 0 deletions src/qa/parsers/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,30 @@ public static ArrayList<Question> parseQuADFile(String fileDirectory, String sou
}
return questionsList;
}

public static ArrayList<Question> parseQuAD2File(String fileDirectory, String sourceString, String endpoint) throws JSONException {
ArrayList<Question> questionsList = new ArrayList<Question>();
String fileContents = FileManager.readWholeFile(fileDirectory);
JSONArray arr = new JSONArray(fileContents);
for (int i = 0; i < arr.length(); i++) {

Question question = new Question();
question.setDatabase(endpoint);
question.setFilepath(fileDirectory);
// The source is predefined
question.setQuestionSource(sourceString);

JSONObject currentQuestionObject = arr.getJSONObject(i);
question.setQuestionString(currentQuestionObject.get("paraphrased_question").toString().replace("\n", ""));

// The question's SPARQL Query
question.setQuestionQuery(currentQuestionObject.get("sparql_wikidata").toString());
if (question.getQuestionQuery() != null || question.getQuestionString()!=null && !question.getQuestionString().equals("")) {
questionsList.add(question);
}
}
return questionsList;
}

public static ArrayList<Question> parseNo(String fileDirectory, String sourceString, String endpoint) throws JSONException {
ArrayList<Question> questionsList = new ArrayList<Question>();
Expand Down

0 comments on commit ceb693c

Please sign in to comment.