Sono state necessarie alcune operazioni di copia e incolla per vedere cosa stava succedendo esattamente. Ti suggerirei di mettere i newline nella tua query per una leggibilità più semplice. La query che si sta utilizzando è:
PREFIX dbres: <http://dbpedia.org/resource/>
SELECT * WHERE
{
dbres:??? <http://www.w3.org/2000/01/rdf-schema#label> ?o
FILTER (langMatches(lang(?o),"en"))
}
dove ???
che viene sostituito dal contenuto della stringa entity
. . Si sta facendo assolutamente alcuna convalida dell'input qui per garantire che il valore di entity
sarà legale per incollare in base alla tua domanda, suona come entity
contiene William_H._Miller_(writer)
, in modo che stai ricevendo il query:
PREFIX dbres: <http://dbpedia.org/resource/>
SELECT * WHERE
{
dbres:William_H._Miller_(writer) <http://www.w3.org/2000/01/rdf-schema#label> ?o
FILTER (langMatches(lang(?o),"en"))
}
È possibile incollare che nella public DBpedia endpoint, e si otterrà un simile messaggio di errore di analisi:
Virtuoso 37000 Error SP030: SPARQL compiler, line 6: syntax error at 'writer' before ')'
SPARQL query:
define sql:big-data-const 0
#output-format:text/html
define sql:signal-void-variables 1 define input:default-graph-uri <http://dbpedia.org> PREFIX dbres: <http://dbpedia.org/resource/>
SELECT * WHERE
{
dbres:William_H._Miller_(writer) <http://www.w3.org/2000/01/rdf-schema#label> ?o
FILTER (langMatches(lang(?o),"en"))
}
Meglio di colpire endpoint di DBpedia con le query cattivi, si può anche utilizzare the SPARQL query validator, che riporta per quella query:
Syntax error: Lexical error at line 4, column 34. Encountered: ")" (41), after : "writer"
In Jena, è possibile utilizzare ParameterizedSparqlString per evitare questo tipo di problemi. Ecco il tuo esempio, rielaborato ad utilizzare una stringa con parametri:
import com.hp.hpl.jena.query.ParameterizedSparqlString;
public class PSSExample {
public static void main(String[] args) {
// Create a parameterized SPARQL string for the particular query, and add the
// dbres prefix to it, for later use.
final ParameterizedSparqlString queryString = new ParameterizedSparqlString(
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"SELECT * WHERE\n" +
"{\n" +
" ?entity rdfs:label ?o\n" +
" FILTER (langMatches(lang(?o),\"en\"))\n" +
"}\n"
) {{
setNsPrefix("dbres", "http://dbpedia.org/resource/");
}};
// Entity is the same.
final String entity = "William_H._Miller_(writer)";
// Now retrieve the URI for dbres, concatentate it with entity, and use
// it as the value of ?entity in the query.
queryString.setIri("?entity", queryString.getNsPrefixURI("dbres")+entity);
// Show the query.
System.out.println(queryString.toString());
}
}
L'output è:
PREFIX dbres: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE
{
<http://dbpedia.org/resource/William_H._Miller_(writer)> rdfs:label ?o
FILTER (langMatches(lang(?o),"en"))
}
È possibile eseguire questa query a livello di endpoint pubblico e ottenere the expected results. Si noti che se si utilizza un entity
che non ha bisogno fuga speciale, ad esempio,
final String entity = "George_Washington";
allora l'uscita query di utilizzare il modulo prefissato:
PREFIX dbres: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE
{
dbres:George_Washington rdfs:label ?o
FILTER (langMatches(lang(?o),"en"))
}
Questo è molto conveniente, perché si don' t deve fare qualsiasi verificando se il suffisso, ad es., entity
, ha caratteri che devono essere sfuggiti; Jena si prende cura di questo per te.
puoi fornire il contenuto della riga 86? Inoltre sembra un errore di sintassi per me. – Framester
Le parentesi tonde (o parentesi, nel mio dialetto locale) sono usate per circondare gli argomenti delle funzioni in SPARQL, ad esempio, in 'concat ('[',? X, ']')', quindi mi aspetterei che questa sia una sintassi errore. Probabilmente dovrai utilizzare l'intero URI, circondato da "<' and '>". –