server/src/app/Libraries/Mergers/CocoonAbstractRdfMerger.php
changeset 19 eadaf0b8f02e
parent 18 f2a40bbc27f6
child 169 8fddc113095e
equal deleted inserted replaced
18:f2a40bbc27f6 19:eadaf0b8f02e
    24      * @param EasyRdf\Graph $baseGraph The graph used as base for the merge
    24      * @param EasyRdf\Graph $baseGraph The graph used as base for the merge
    25      * @param EasyRdf\Graph $srcGraph The source graph with the new triples to add
    25      * @param EasyRdf\Graph $srcGraph The source graph with the new triples to add
    26      *
    26      *
    27      * @return EasyRdf\Graph The new merged graph
    27      * @return EasyRdf\Graph The new merged graph
    28      */
    28      */
    29     function mergeGraph($baseGraph, $srcGraph) {
    29     function mergeGraph($baseGraph, $srcGraph, $uri = null) {
    30 
    30 
       
    31         $uri = is_null($uri)?$baseGraph->getUri():$uri;
    31         $this->mergedArray = [];
    32         $this->mergedArray = [];
    32         $this->resGraph = new Graph($baseGraph->getUri());
    33         $this->resGraph = new Graph($uri);
    33         $this->bnodeMerge = [];
    34         $this->bnodeMerge = [];
    34         $this->baseGraph = $baseGraph;
    35         $this->baseGraph = $baseGraph;
    35         $this->srcGraph = $srcGraph;
    36         $this->srcGraph = $srcGraph;
    36 
    37 
    37 
    38 
    76             elseif (!is_null($baseUrl) && !is_null($srcUrl)) {
    77             elseif (!is_null($baseUrl) && !is_null($srcUrl)) {
    77 
    78 
    78                 $baseResource = $baseGraph->resource($baseUrl);
    79                 $baseResource = $baseGraph->resource($baseUrl);
    79                 $srcResource = $srcGraph->resource($srcUrl);
    80                 $srcResource = $srcGraph->resource($srcUrl);
    80 
    81 
    81                 $mergeMethod = $typeMergeMethodMap[$baseResource->typeAsResource()->getUri()];
    82                 if(!is_null($baseResource->typeAsResource()) && array_key_exists($baseResource->typeAsResource()->getUri(), $typeMergeMethodMap)) {
    82                 $this->mergedArray[$bnodeId] = [];
    83 
    83 
    84                     $mergeMethod = $typeMergeMethodMap[$baseResource->typeAsResource()->getUri()];
    84                 call_user_func(array($this, $mergeMethod), $baseResource, $srcResource, $bnodeId);
    85                     $this->mergedArray[$bnodeId] = [];
    85 
    86 
       
    87                     call_user_func(array($this, $mergeMethod), $baseResource, $srcResource, $bnodeId);
       
    88                 }
    86             }
    89             }
    87 
    90 
    88         }
    91         }
    89 
    92 
    90         //echo "MERGED ARRAY:\n";
    93         //echo "MERGED ARRAY:\n";
   181 
   184 
   182     }
   185     }
   183 
   186 
   184 
   187 
   185     protected function mergeProperties($singleBNodeProperties, $singleProperties, &$targetArray, $baseRes, $srcRes) {
   188     protected function mergeProperties($singleBNodeProperties, $singleProperties, &$targetArray, $baseRes, $srcRes) {
   186         $srcArray = $this->srcGraph->toRdfPhp()[$srcRes->getUri()];
   189         $srcRdfPhp = $this->srcGraph->toRdfPhp();
   187         $baseArray = $this->baseGraph->toRdfPhp()[$baseRes->getUri()];
   190         $srcArray = array_key_exists($srcRes->getUri(), $srcRdfPhp)?$srcRdfPhp[$srcRes->getUri()]:[];
       
   191         $baseRdfPhp = $this->baseGraph->toRdfPhp();
       
   192         $baseArray = array_key_exists($baseRes->getUri(), $baseRdfPhp)?$baseRdfPhp[$baseRes->getUri()]:[];
   188         foreach($srcRes->propertyUris() as $prop) {
   193         foreach($srcRes->propertyUris() as $prop) {
   189             if(in_array($prop, $singleBNodeProperties)) {
   194             if(in_array($prop, $singleBNodeProperties)) {
   190                 $this->mergePropertySingleBNode($prop, $targetArray, $baseArray, $srcArray);
   195                 $this->mergePropertySingleBNode($prop, $targetArray, $baseArray, $srcArray);
   191             }
   196             }
   192             elseif(in_array($prop, $singleProperties)) {
   197             elseif(in_array($prop, $singleProperties)) {