package com.master.thesis;

import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.sail.SailGraph;
import com.tinkerpop.blueprints.oupls.sail.GraphSail;

import info.aduna.iteration.CloseableIteration;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringEscapeUtils;
import org.openrdf.query.BindingSet;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.impl.EmptyBindingSet;
import org.openrdf.query.parser.ParsedQuery;
import org.openrdf.query.parser.sparql.SPARQLParser;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailConnection;

import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.sail.SailGraph;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import junit.framework.Assert;

public class squeryold {

        void runsquery() throws Exception{
           OrientGraph g = new OrientGraph("remote:diufpc307/test2", "admin", "admin");
           g.setUseVertexFieldsForEdgeLabels(false);
           g.setUseClassForEdgeLabel(false);
System.out.println("Before sail");
GraphSail sail = new GraphSail(g);
sail.initialize();
System.out.println("After sail");
             SailConnection conn = sail.getConnection();

       SPARQLParser queryParser = new SPARQLParser();
       
       String queryString = "SELECT ?p ?o WHERE { <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductType1> ?p ?o } ";
       
    		   ParsedQuery query = queryParser.parseQuery(queryString, null);
       System.out.println("\nSPARQL: " + queryString);
       System.out.println("\nPRINTING RESULTS............ ");
       CloseableIteration<? extends BindingSet, QueryEvaluationException> results =
               conn.evaluate(query.getTupleExpr(), query.getDataset(), new EmptyBindingSet(), false);
       
       Assert.assertTrue("Results are expected to be not-empty", results.hasNext());
       System.out.println(results.next().getBinding("p"));
       
       while (results.hasNext()) {
           System.out.println(results.next().getBinding("o"));
       }

       sail.shutDown();
}
}