public String sparql(String sparqlQuery, String wikiURL) { StringMatrix result = new StringMatrix(); String resultString = null; RDFManager myRdfManager = new RDFManager(); wikiURL = ensureTrailingSlash(wikiURL); // Make some configurations String serviceURL = wikiURL + "Special:SPARQLEndpoint"; if (sparqlQuery.contains("INSERT INTO <")) { String sparqlQueryUrlEnc = urlencode(sparqlQuery); String getURL = serviceURL + "?query=" + sparqlQueryUrlEnc; resultString = downloadURL(getURL); } else { result = myRdfManager.sparqlRemote(serviceURL, sparqlQuery, null); resultString = result.toString(); } // Convert and return results return resultString; }
/** * Get * * @param wikiURL * @param limit * @return resultRDF */ public IRDFStore getRDF(String wikiURL, int limit) { String sparqlQuery = null; RDFManager myRdfManager = new RDFManager(); IRDFStore resultRDF = null; if (limit == 0) { sparqlQuery = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }"; } else { sparqlQuery = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }" + "LIMIT " + Integer.toString(limit); } // Make some configurations String serviceURL = wikiURL + "Special:SPARQLEndpoint"; try { resultRDF = myRdfManager.sparqlConstructRemote(serviceURL, sparqlQuery, null); } catch (BioclipseException e) { e.printStackTrace(); } return resultRDF; }
public void putRDF(IRDFStore rdfData, String wikiURL) { // Create a Manager for SPARQLing the rdfData RDFManager myRdfManager = new RDFManager(); String sparqlInsertTriple; String sparqlGetAllTriples = "SELECT ?s ?p ?o WHERE { ?s ?p ?o }"; try { StringMatrix rdfDataMatrix = myRdfManager.sparql(rdfData, sparqlGetAllTriples); int mxRowsCnt = rdfDataMatrix.getRowCount(); System.out.println("mxRowsCnt: " + mxRowsCnt); // We skip the first row which just contains column names for (int i = 1; i < mxRowsCnt; i++) { sparqlInsertTriple = "INSERT INTO <> {\n"; sparqlInsertTriple += "<" + rdfDataMatrix.get(i, 1) + "> <" + rdfDataMatrix.get(i, 2) + "> <" + rdfDataMatrix.get(i, 3) + "> .\n"; sparqlInsertTriple += "}\n"; System.out.println( "SPARQL INSERT CODE:\n---------------------------------\n" + sparqlInsertTriple); sparql(sparqlInsertTriple, wikiURL); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BioclipseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }