2013-08-20 20 views
12

Sto tentando di utilizzare una query Construct SPARQL per creare un nuovo grafo con nome da uno esistente. Il database che sto interrogando contiene http://graph.com/old come un grafico con nome esistente. Sto usando Jena TDB come database, a cui si accede tramite un punto vendita Jena Fuseki. La query di seguito mi dà un errore:COSTRUIRE in un grafico con nome

CONSTRUCT 
{ 
    GRAPH <http://graph.com/new> { 
     ?s ?p ?o 
    } 
} 

WHERE 
{ 
    GRAPH <http://graph.com/old> { 
     ?s ?p ?o 
    } 
} 

Se rimuovo la dichiarazione del grafico dal blocco costruire, la query funziona perfettamente, ma vorrei mettere le triple in un grafico di nome che ho specificato invece di quello predefinito uno.

Per quanto ho potuto trovare, il SPARQL 1.1 section on CONSTRUCT non dice nulla sulla costruzione di grafici con nome. C'è un modo per fare questo?

risposta

14

Proprio come le query SELECT vengono utilizzate quando si è interessati a ottenere un set di associazioni di variabili, le query CONSTRUCT vengono utilizzate per ottenere un modello indietro. Proprio come le variabili legate in un set di risultati SELECT non sono inserite in alcun modello o set persistente di associazioni, né il modello costruito da un CONSTRUCT è memorizzato ovunque. Vuoi usare SPARQL 1.1 INSERT. Le funzioni di aggiornamento sono descritte in 3 SPARQL 1.1 Update Language. La vostra richiesta di aggiornamento può quindi essere scritta come:

INSERT { 
    GRAPH <http://graph.com/new> { 
    ?s ?p ?o 
    } 
} 
WHERE { 
    GRAPH <http://graph.com/old> { 
    ?s ?p ?o 
    } 
} 

Per questo caso particolare, però, si potrebbe essere in grado di utilizzare l'operazione di copia descritto in 3.2.3 COPY. COPY rimuove prima tutti i dati dal grafico di destinazione, quindi potrebbe non essere applicabile al tuo caso reale (comprendendo che il codice che hai fornito potrebbe essere un esempio minimo e non necessariamente l'aggiornamento che stai tentando di eseguire). A proposito COPIA lo standard dice:

The COPY operation is a shortcut for inserting all data from an input graph into a destination graph. Data from the input graph is not affected, but data from the destination graph, if any, is removed before insertion.

COPY (SILENT)? ((GRAPH)? IRIref_from | DEFAULT) TO ((GRAPH)? IRIref_to | DEFAULT) 

is similar in operation to:

DROP SILENT (GRAPH IRIref_to | DEFAULT); 
     INSERT { (GRAPH IRIref_to)? { ?s ?p ?o } } WHERE { (GRAPH IRIref_from)? { ?s ?p ?o } } 

The difference between COPY and the DROP/INSERT combination is that if COPY is used to copy a graph onto itself then no operation will be performed and the data will be left as it was. Using DROP/INSERT in this situation would result in an empty graph.

If the destination graph does not exist, it will be created. By default, the service may return failure if the input graph does not exist. If SILENT is present, the result of the operation will always be success.

Se COPIA non è adatto, quindi ADD può essere quello che stai cercando:

3.2.5 ADD

The ADD operation is a shortcut for inserting all data from an input graph into a destination graph. Data from the input graph is not affected, and initial data from the destination graph, if any, is kept intact.

ADD (SILENT)? ((GRAPH)? IRIref_from | DEFAULT) TO ((GRAPH)? IRIref_to | DEFAULT) 

is equivalent to:

INSERT { (GRAPH IRIref_to)? { ?s ?p ?o } } WHERE { (GRAPH IRIref_from)? { ?s ?p ?o } } 

If the destination graph does not exist, it will be created. By default, the service may return failure if the input graph does not exist. If SILENT is present, the result of the operation will always be success.

+2

L'alternativa a 'COPY' è naturalmente' add', questo copia i dati dalla sorgente alla destinazione e conserva i dati esistenti dei grafici di destinazione – RobV

+0

@RobV Buon punto! Non ho fatto molto l'aggiornamento di SPARQL 1.1, e credo di non aver letto abbastanza nella specifica dopo aver trovato COPY. Aggiungerò ADD. –