2013-08-20 12 views
12

SPARQL 생성 쿼리를 사용하여 기존 명명 된 그래프에서 새 명명 된 그래프를 만들려고합니다. 쿼리하는 데이터베이스에는 기존 명명 된 그래프로 http://graph.com/old이 포함되어 있습니다. 나는 Jena TDB을 데이터베이스로 사용하고 있습니다. Jena Fuseki endpoint를 통해 액세스 할 수 있습니다. 아래 쿼리는 나에게 오류를 제공합니다명명 된 그래프에 연결

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

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

내가 구조물 블록에서 그래프 문을 제거하면 쿼리가 완벽하게 작동,하지만 난 기본 대신 지정하는 명명 된 그래프로 트리플을 배치 할 하나.

내가 알 수있는 한, SPARQL 1.1 section on CONSTRUCT은 명명 된 그래프로 구성하는 것에 대해 아무 것도 말하지 않습니다. 이것을 할 수있는 방법이 있습니까?

답변

14

변수 바인딩을 다시 가져 오는 데 관심이있을 때 SELECT 쿼리가 사용되는 것처럼 CONSTRUCT 쿼리를 사용하면 모델을 다시 가져 오는 데 관심이 있습니다. SELECT 결과 세트에서 바인드 된 변수가 모델이나 영구적 인 바인딩 세트에 들어 가지 않는 것처럼 어디에도 저장된 CONSTRUCT로 작성된 모델도 마찬가지입니다. SPARQL 1.1 INSERT를 사용하고자한다. 업데이트 기능은 3 SPARQL 1.1 Update Language에 설명되어 있습니다. 귀하의 갱신 요청을 따라서 같이 쓸 수있다 :이 특별한 경우를 들어

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

하지만, 당신은 3.2.3 COPY에 설명 복사 작업을 사용할 수 있습니다. COPY는 먼저 대상 그래프에서 모든 데이터를 제거하므로 실제 사례에는 적용되지 않을 수 있습니다 (제공된 코드가 최소한의 예일 수 있으며 실제로 수행하려는 실제 업데이트가 아닐 수도 있음). COPY 정보 표준 말한다 : COPY가 적합하지 않은 경우

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.

, 다음 ADD은 당신이 찾고있는 무엇을 할 수

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

COPY' 물론입니다'에 대한 대안'ADD', 이것은 소스에서 타겟으로 데이터를 복사하고 기존 그래프를 기존 데이터로 보존합니다. – RobV

+0

@RobV 좋은 점! 나는 많은 SPARQL 1.1 Update를하지 않았으며 COPY를 찾은 후에 스펙을 충분히 읽지 못했다고 생각한다. 나는 ADD를 추가 할 것이다. –