Remote construct query problem

Hello I published few days ago about to get all data in sparql query

I get it with a construct, so my query looks like :

PREFIX schema: <http://schema.org/> 
CONSTRUCT{
?persona ?tipo ?prefPersona.
?persona ?tipo ?Categoria.
?Categoria ?id ?nombreCategoria. 
?Categoria ?tipo ?prefPuesto.
?persona ?prefExperiencia ?Experiencia. 
?Experiencia ?id ?nombreExperiencia.
?persona ?habilidades ?lenguajeProg. 
?lenguajeProg ?id ?nombreLenguajeProg.
?persona ?prefCertif ?certificacion. 
?certificacion ?id ?nombreCertificacion.
?persona ?prefIdioma ?idioma. 
?idioma ?id ?nombreIdioma.
}
where{ 
GRAPH <http://opendata.eurohelp.es/dataset/recursos-humanos> {
?persona ?tipo ?prefPersona.
?persona ?tipo ?Categoria.
?Categoria ?id ?nombreCategoria.
?Categoria ?tipo ?prefPuesto.
?persona ?prefExperiencia ?Experiencia.
?Experiencia ?id ?nombreExperiencia.
?persona ?habilidades ?lenguajeProg.
?lenguajeProg ?id ?nombreLenguajeProg.
?persona ?prefCertif ?certificacion.
?certificacion ?id ?nombreCertificacion.
?persona ?prefIdioma ?idioma.
?idioma ?id ?nombreIdioma.
FILTER (?nombreCategoria IN ("Jefe de proyecto"))
FILTER (?nombreExperiencia IN ("Eurohelp Consulting"))
FILTER (?nombreLenguajeProg IN ("HTML"))
FILTER (?nombreCertificacion IN ("ISTQB"))
FILTER (?nombreIdioma IN ("Spanish"))
FILTER (?nombreIdioma IN ("Spanish"))
FILTER (?tipo = rdf:type )
FILTER (?id = schema:name )
FILTER (?prefIdioma = <http://opendata.euskadi.eus/idioma> )
FILTER (?habilidades = <http://opendata.euskadi.eus/skill> )
FILTER (?prefExperiencia = <http://opendata.euskadi.eus/experience> )
FILTER (?prefPuesto = <http://opendata.euskadi.eus/puesto> )
FILTER (?prefCertif = <http://opendata.euskadi.eus/certification> )
FILTER (?prefPersona = <http://schema.org/Person>)
}
}

Well, when I execute the query in Stardog manually it works and give me the results like I want, but when I try to do it using Eclipse with a Stardog remote conection I get the following error :

org.openrdf.query.QueryEvaluationException: com.complexible.stardog.security.ResourceExistsException: Not a supported accept type(s): [application/trig]
at com.complexible.stardog.sesame.AbstractQuery.executeQuery(AbstractQuery.java:54)
at com.complexible.stardog.sesame.StardogGraphQuery.evaluate(StardogGraphQuery.java:40)
at stardog.Stardog.getGraphData(Stardog.java:146)
at stardog.main.main(main.java:18)
Caused by: com.complexible.stardog.security.ResourceExistsException: Not a supported accept type(s): [application/trig]
at com.complexible.stardog.protocols.http.client.BaseHttpClient.checkResponseCode(BaseHttpClient.java:426)
at com.complexible.stardog.protocols.http.client.BaseHttpClient.execute(BaseHttpClient.java:304)
at com.complexible.stardog.protocols.http.client.HttpClientImpl.graph(HttpClientImpl.java:413)
at com.complexible.stardog.protocols.http.client.HttpClientImpl.graph(HttpClientImpl.java:93)
at com.complexible.stardog.api.impl.SPECGraphQuery.execute(SPECGraphQuery.java:47)
at com.complexible.stardog.api.impl.SPECGraphQuery.execute(SPECGraphQuery.java:32)
at com.complexible.stardog.sesame.AbstractQuery.executeQuery(AbstractQuery.java:47)
... 3 more

I want to get the results in JSON FORMAT, it is not possible?

My JAVA code:

public File getGraphData(String[] pCategoria, String[] pExperiencia, String[] pHabilidades,
			String[] pCertificaciones, String[] pIdiomas, String[] pUniversidad) {
		String query = "PREFIX schema: <http://schema.org/> " + "CONSTRUCT{"
				+ "?persona ?tipo ?prefPersona.?persona ?tipo ?Categoria."
				+ "?Categoria ?id ?nombreCategoria. ?Categoria ?tipo ?prefPuesto."
				+ "?persona ?prefExperiencia ?Experiencia. " + "?Experiencia ?id ?nombreExperiencia."
				+ "?persona ?habilidades ?lenguajeProg. " + "?lenguajeProg ?id ?nombreLenguajeProg."
				+ "?persona ?prefCertif ?certificacion. " + "?certificacion ?id ?nombreCertificacion."
				+ "?persona ?prefIdioma ?idioma. " + "?idioma ?id ?nombreIdioma." + "}"
				+ "where{ GRAPH <http://opendata.eurohelp.es/dataset/recursos-humanos> {"
				+ "?persona ?tipo ?prefPersona." + "?persona ?tipo ?Categoria." + "?Categoria ?id ?nombreCategoria."
				+ "?Categoria ?tipo ?prefPuesto." + "?persona ?prefExperiencia ?Experiencia."
				+ "?Experiencia ?id ?nombreExperiencia." + "?persona ?habilidades ?lenguajeProg."
				+ "?lenguajeProg ?id ?nombreLenguajeProg." + "?persona ?prefCertif ?certificacion."
				+ "?certificacion ?id ?nombreCertificacion." + "?persona ?prefIdioma ?idioma."
				+ "?idioma ?id ?nombreIdioma." + "FILTER (?nombreCategoria IN ())" + "FILTER (?nombreExperiencia IN ())"
				+ "FILTER (?nombreLenguajeProg IN ())" + "FILTER (?nombreCertificacion IN ())"
				+ "FILTER (?nombreIdioma IN ())" + "FILTER (?nombreIdioma IN ())" + "FILTER (?tipo = rdf:type )"
				+ "FILTER (?id = schema:name )" + "FILTER (?prefIdioma = <http://opendata.euskadi.eus/idioma> )"
				+ "FILTER (?habilidades = <http://opendata.euskadi.eus/skill> )"
				+ "FILTER (?prefExperiencia = <http://opendata.euskadi.eus/experience> )"
				+ "FILTER (?prefPuesto = <http://opendata.euskadi.eus/puesto> )"
				+ "FILTER (?prefCertif = <http://opendata.euskadi.eus/certification> )"
				+ "FILTER (?prefPersona = <http://schema.org/Person> )" + "}" + "}";

		query = completarFila("?nombreCategoria IN (", pCategoria, query);
		query = completarFila("?nombreExperiencia IN (", pExperiencia, query);
		query = completarFila("?nombreLenguajeProg IN (", pHabilidades, query);
		query = completarFila("?nombreCertificacion IN (", pCertificaciones, query);
		query = completarFila("?nombreIdioma IN (", pIdiomas, query);
		System.out.println(query);
		File file = null;
		try {
			file = new File("./JSON/archivoJSON.json");
			OutputStream os = new FileOutputStream(file);
			GraphQuery tupleQuery = repository.prepareGraphQuery(QueryLanguage.SPARQL, query);
			GraphQueryResult results = tupleQuery.evaluate();
			QueryResultIO.createWriter(TupleQueryResultFormat.JSON, os);

			results.close();
			file.deleteOnExit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return file;
	}

	public String completarFila(String pPatron, String[] pConjunto, String pQuery) {
		for (int i = 0; i < pConjunto.length; i++) {
			if (i + 1 >= pConjunto.length) {
				pQuery = pQuery.replace(pPatron, pPatron + "\"" + pConjunto[i] + "\"");
			} else {
				pQuery = pQuery.replace(pPatron, pPatron + "\"" + pConjunto[i] + "\"" + ",");
			}
		}
		return pQuery;
	}

Thanks for your attention.

Regards

Hi,

Your problem here is that you are trying to use a TupleQueryResultWriter to write GraphQueryResults. The result of a CONSTRUCT query is (essentially) an RDF document, and TupleQueryResultWriters write SPARQL results, not RDF.

What you want here is a Sesame Rio JSONLDWriter:

GraphQueryResult results = tupleQuery.evaluate();
JSONLDWriter aWriter = new JSONLDWriter(file);
aWriter.startRDF();
while (results.hasNext()) {
	aWriter.handleStatement(results.next());
}
aWriter.endRDF();

results.close();
file.deleteOnExit();

Thank you so much, it works.

Regards

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.