Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aorogat authored Jul 2, 2020
1 parent aab0af2 commit 1f525a3
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 325 deletions.
37 changes: 37 additions & 0 deletions src/DataSet/Benchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package DataSet;

/**
*
* @author aorogat
*/
public class Benchmark {

public final static int QALD_1 = 1;
public final static int QALD_2 = 2;
public final static int QALD_3 = 3;
public final static int QALD_4 = 4;
public final static int QALD_5 = 5;
public final static int QALD_6 = 6;
public final static int QALD_7 = 7;
public final static int QALD_8 = 8;
public final static int QALD_9 = 9;

public final static int QALD_ALL = 100;
public final static int LC_QUAD = 101;
public final static int GraphQuestions = 102;
public final static int WebQuestions = 103;
public final static int SimpleQuestions = 104;
public final static int SimpleDBpediaQA = 105;
public final static int Free917 = 106;
public final static int TempQuestions = 107;
public final static int ComQA = 108;
public final static int ComplexQuestions = 109;



}
241 changes: 66 additions & 175 deletions src/DataSet/DataSetPreprocessing.java

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/ShallowAnalysis/Keywords.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ShallowAnalysis;

import DataSet.Benchmark;
import DataSet.DataSetPreprocessing;
import java.text.DecimalFormat;
import java.text.NumberFormat;
Expand All @@ -16,7 +17,7 @@ public class Keywords

public Keywords()
{
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(-1, false, false, true);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.QALD_1);
}

public static void main(String[] args) {
Expand Down
11 changes: 6 additions & 5 deletions src/ShallowAnalysis/NoOfTriples.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ShallowAnalysis;

import DataSet.Benchmark;
import DataSet.DataSetPreprocessing;
import Graph.Edge;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -34,7 +35,7 @@ public NoOfTriples() {
zero = 0; one = 0; two = 0; three = 0; four = 0; five = 0; six = 0; seven = 0;
eight = 0; nine = 0; ten = 0; elevenOrMore = 0; total = 0;
s = "QALD " + i;
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(i, false, false, false);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(i);
triplesAnalysis();
results.add(s);
qs.clear();
Expand All @@ -43,7 +44,7 @@ public NoOfTriples() {
zero = 0; one = 0; two = 0; three = 0; four = 0; five = 0; six = 0; seven = 0;
eight = 0; nine = 0; ten = 0; elevenOrMore = 0; total = 0;
s = "QALD ALL";
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(100, false, false, false);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.QALD_ALL);
triplesAnalysis();
results.add(s);

Expand All @@ -52,7 +53,7 @@ public NoOfTriples() {
zero = 0; one = 0; two = 0; three = 0; four = 0; five = 0; six = 0; seven = 0;
eight = 0; nine = 0; ten = 0; elevenOrMore = 0; total = 0;
s = "LC-QUAD";
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(-1, true, false, false);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.LC_QUAD);
triplesAnalysis();
results.add(s);

Expand All @@ -61,7 +62,7 @@ public NoOfTriples() {
zero = 0; one = 0; two = 0; three = 0; four = 0; five = 0; six = 0; seven = 0;
eight = 0; nine = 0; ten = 0; elevenOrMore = 0; total = 0;
s = "Graph";
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(-1, false, true, false);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.GraphQuestions);
triplesAnalysis();
results.add(s);
System.out.println("====================================================");
Expand All @@ -76,7 +77,7 @@ public NoOfTriples() {
zero = 0; one = 0; two = 0; three = 0; four = 0; five = 0; six = 0; seven = 0;
eight = 0; nine = 0; ten = 0; elevenOrMore = 0; total = 0;
s = "Web";
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(-1, false, false, true);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.WebQuestions);
triplesAnalysis();
results.add(s);
System.out.println("====================================================");
Expand Down
17 changes: 15 additions & 2 deletions src/ShallowAnalysis/OperatorDistribution.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ShallowAnalysis;

import DataSet.Benchmark;
import DataSet.DataSetPreprocessing;
import java.text.DecimalFormat;
import java.text.NumberFormat;
Expand All @@ -16,10 +17,11 @@ public class OperatorDistribution
public static int none = 0, F = 0, A = 0, AF = 0, CPF = 0,
O = 0, OF = 0, AO = 0, AOF = 0, CPF_O = 0,
G = 0, CPF_G = 0,
U = 0, UF = 0, AU = 0, AUF = 0, CPF_U = 0;
U = 0, UF = 0, AU = 0, AUF = 0, CPF_U = 0,
FGP = 0, FGU = 0, FAG = 0, AOUF = 0, AOUFG = 0;

public OperatorDistribution() {
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(100, false, false, false);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.QALD_1);
}

public static void main(String[] args) {
Expand Down Expand Up @@ -60,6 +62,13 @@ public void analysis() {

if(!FILTER && !AND && !OPT && !GRAPH && !UNION)none++;


if(FILTER && !AND && OPT && GRAPH && !UNION)FGP++;
if(FILTER && !AND && !OPT && GRAPH && UNION)FGU++;
if(FILTER && AND && !OPT && GRAPH && !UNION)FAG++;
if(FILTER && AND && OPT && !GRAPH && UNION)AOUF++;
if(FILTER && AND && OPT && GRAPH && UNION)AOUFG++;

// System.out.println(q.toString());
// System.out.println("==============");
// System.out.println("Filter = "+ FILTER + "AND = "+ AND + "OPT = "+ OPT + "Graph = "+GRAPH +"Union = "+ UNION );
Expand Down Expand Up @@ -124,6 +133,10 @@ public void analysis() {
System.out.println(formatter.format(Double.valueOf(AUF)/qs.size()*100) +"\\%" );
System.out.println("'+"+formatter.format(Double.valueOf(CPF_U)/qs.size()*100) +"\\%" );

System.out.println("FGP = "+FGP);
System.out.println("FGU = "+FGU);
System.out.println("FAG = "+FAG);
System.out.println("AOUF = "+AOUF);
}


Expand Down
3 changes: 2 additions & 1 deletion src/ShapeAnalysis/CategorizedQuestions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package ShapeAnalysis;

import DataSet.Benchmark;
import DataSet.DataSetPreprocessing;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -38,7 +39,7 @@ public class CategorizedQuestions {
ArrayList<Question> flowerSet_Qs = new ArrayList<Question>();

public CategorizedQuestions() {
DataSetPreprocessing.getQueriesWithoutDuplicates(9, false, false, false);
ArrayList qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.QALD_1);
for (Question q : DataSetPreprocessing.questionsWithoutDuplicates) {
String queryString = q.getQuestionQuery();
try {
Expand Down
49 changes: 49 additions & 0 deletions src/ShapeAnalysis/ElementVisitorShapeImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ShapeAnalysis;

import Graph.Edge;
import java.util.Iterator;
import org.apache.jena.query.Query;
import org.apache.jena.sparql.core.TriplePath;
import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.ElementPathBlock;
import org.apache.jena.sparql.syntax.ElementSubQuery;
import org.apache.jena.sparql.syntax.ElementVisitorBase;
import org.apache.jena.sparql.syntax.ElementWalker;

public class ElementVisitorShapeImpl extends ElementVisitorBase {

static boolean subquery = false;

@Override
public void visit(ElementPathBlock el) {
Iterator<TriplePath> triples = el.patternElts();
while (triples.hasNext()) {
TriplePath triple = triples.next();

QueryShapeType.graph.edges.add(new Edge(triple.getSubject().toString(), triple.getObject().toString()));
if (!QueryShapeType.graph.vertices.contains(triple.getSubject().toString())) {
QueryShapeType.graph.vertices.add(triple.getSubject().toString());
}
if (!QueryShapeType.graph.vertices.contains(triple.getObject().toString())) {
QueryShapeType.graph.vertices.add(triple.getObject().toString());
}
}
}

@Override
public void visit(ElementSubQuery el) {
subquery = true;
Query q = el.getQuery();
Element e = q.getQueryPattern();

ElementVisitorBase visitor = new ElementVisitorShapeImpl();
ElementWalker.walk(e, visitor);

}

}
50 changes: 21 additions & 29 deletions src/ShapeAnalysis/QueryShapeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import Graph.Edge;
import Graph.Graph;
import ShallowAnalysis.ElementVistorImpl;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.sparql.core.TriplePath;
import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.ElementPathBlock;
import org.apache.jena.sparql.syntax.ElementSubQuery;
import org.apache.jena.sparql.syntax.ElementVisitorBase;
import org.apache.jena.sparql.syntax.ElementWalker;

Expand Down Expand Up @@ -228,7 +231,7 @@ private static boolean isPetal(String queryString) {
}
return false;
}

private static boolean isPetal(Graph graph) {
ArrayList<Integer> verticesDegrees = graph.getVerticesDegrees();

Expand Down Expand Up @@ -288,9 +291,10 @@ public static boolean isFlower(String queryString) {

public static boolean isFlowerSet(String queryString) {
//if separate graphs are flowers
if(isFlower(queryString))
if (isFlower(queryString)) {
return true;

}

//pruning the graph: remove elements with degree 1
// if the remaining graphs are petals, it is a flowerset
Graph graph = queryToGraph(queryString);
Expand Down Expand Up @@ -324,37 +328,25 @@ public static boolean isFlowerSet(String queryString) {
if (degree_2 > 0 && degree_greater_2 >= 2) {
return true;
}

return false;
}



static public Graph graph = new Graph();
private static Graph queryToGraph(String queryString) {
//Define Graph as a set of edges
final Graph graph = new Graph();
graph = new Graph();
try {
Query query = QueryFactory.create(queryString);
// This will walk through all parts of the query
ElementWalker.walk(query.getQueryPattern(),
// For each element...
new ElementVisitorBase() {
// ...when it's a block of triples...
public void visit(ElementPathBlock el) {
// ...go through all the triples...
Iterator<TriplePath> triples = el.patternElts();
while (triples.hasNext()) {
TriplePath triple = triples.next();

graph.edges.add(new Edge(triple.getSubject().toString(), triple.getObject().toString()));
if (!graph.vertices.contains(triple.getSubject().toString())) {
graph.vertices.add(triple.getSubject().toString());
}
if (!graph.vertices.contains(triple.getObject().toString())) {
graph.vertices.add(triple.getObject().toString());
}
}
}
}
);
Query q = QueryFactory.create(queryString);
Element e = q.getQueryPattern();

System.out.println("===============================");
System.out.println(e.getClass().toString());
System.out.println("===============================");
System.out.println(e.toString());
ElementVisitorBase visitor = new ElementVisitorShapeImpl();
ElementWalker.walk(e, visitor);

} catch (Exception e) {
System.err.println("This Query has a problem in its graph");
Expand Down
5 changes: 3 additions & 2 deletions src/ShapeAnalysis/QuestionByQuestionAnalysis.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ShapeAnalysis;

import DataSet.Benchmark;
import DataSet.DataSetPreprocessing;
import ShallowAnalysis.NoOfTriples;
import java.text.DecimalFormat;
Expand All @@ -20,12 +21,12 @@
*/
public class QuestionByQuestionAnalysis {

static ArrayList<Query> queries;
static ArrayList<Query> qs;
static ArrayList<Question> questions;
static int counter = 0;

public QuestionByQuestionAnalysis() {
queries = DataSetPreprocessing.getQueriesWithoutDuplicates(9, false, false, false);
qs = DataSetPreprocessing.getQueriesWithoutDuplicates(Benchmark.QALD_1);
questions = DataSetPreprocessing.questionsWithoutDuplicates;
}

Expand Down
Loading

0 comments on commit 1f525a3

Please sign in to comment.