[Mapbender-commits] r10235 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Sep 3 04:02:23 PDT 2019


Author: armin11
Date: 2019-09-03 04:02:23 -0700 (Tue, 03 Sep 2019)
New Revision: 10235

Modified:
   trunk/mapbender/http/php/mod_linkedDataProxy.php
Log:
First draft to integrate json-schema and json-ld into linkedDataProxy

Modified: trunk/mapbender/http/php/mod_linkedDataProxy.php
===================================================================
--- trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-08-30 12:35:29 UTC (rev 10234)
+++ trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-09-03 11:02:23 UTC (rev 10235)
@@ -106,6 +106,45 @@
 	$urlNew = $query[0]."?".http_build_query($vars);
 	return $urlNew;
 }
+function getJsonSchemaObject($feature) {
+    $returnObject = new stdClass();
+    $returnObject->success = false;
+    $url = $feature->properties->{'json-schema_0.7_id'};
+    if (isset($url)) {
+        $schemaContextConnector = new Connector();
+	$file = $schemaContextConnector->load($url);
+        $returnObject->schema = json_decode($file);
+	if ($returnObject->schema == false) {
+	    $returnObject->success = false;
+	} else {
+	    $returnObject->success = true;
+	}
+        $returnObject->url = $url;
+	return $returnObject;
+    } else {
+        return $returnObject;
+    }
+}
+function getJsonLdObject($feature) {
+    $returnObject = new stdClass();
+    $returnObject->success = false;
+    $url = $feature->properties->{'json-ld_1.1_context'};
+    if (isset($url)) {
+        $schemaContextConnector = new Connector();
+	$file = $schemaContextConnector->load($url);
+        $returnObject->schema = json_decode($file);
+	if ($returnObject->schema == false) {
+	    $returnObject->success = false;
+	} else {
+	    $returnObject->success = true;
+	}
+        $returnObject->url = $url;
+	return $returnObject;
+    } else {
+        return $returnObject;
+    } 
+    
+}
 //handle http request parameters
 //parse request parameters
 if (isset($_REQUEST["wfsid"]) & $_REQUEST["wfsid"] != "") {
@@ -793,7 +832,6 @@
 			    $geoJsonVariable .= "var feature_".$geomType."=".json_encode($geojsonList).";";
 			    $geoJsonVariable .= $newline."</script>".$newline;
 			}
-//$e = new mb_exception($geoJsonVariable);
 
 			$usedProxyTime = microtime_float() - $proxyStartTime;
 			$returnObject->numberMatched = $numberOfObjects;
@@ -801,8 +839,25 @@
 			$date = new DateTime();
 			$returnObject->timeStamp = date('Y-m-d\TH:i:s.Z\Z', $date->getTimestamp());
 			$returnObject->genTime = $usedProxyTime;
+			//resolve json-schema *********************************************************
+		        $resolveJsonSchema = getJsonSchemaObject($geojsonList->features[0]);
+		        $schemaObject = $resolveJsonSchema->schema;
+		        //json-ld
+		        $resolveJsonLd = getJsonLdObject($geojsonList->features[0]);
+		        $ldObject = $resolveJsonLd->schema;
+		        //add url to 
+		        foreach ($geojsonList->features as $feature) {	
+			    if ($resolveJsonSchema->success = true) {
+		                $feature->{'$schema'} = $resolveJsonSchema->url;
+                            }
+			    if ($resolveJsonLd->success = true) {
+		                $feature->{'$context'} = $resolveJsonLd->url;
+                            }
+		        }
+			//*****************************************************************************
 			$returnObject->features = $geojsonList->features;
 		    } 
+
 //$e = new mb_exception("wfsid: ".$wfsid." - collection: ".$collection." - item: ".$item);
 		} else {
 //$e = new mb_exception("wfsid: ".$wfsid." - collection: ".$collection." - item: ".$item);	            
@@ -810,7 +865,6 @@
 	            //item part 
 	            //************************************************************************************************************************************
 //$e = new mb_exception("wfsid: ".$wfsid." - collection: ".$collection." - item: ".$item);
-
 		   if (in_array('application/json; subtype=geojson', explode(',', $ftOutputFormats)) && $nativeJson == true) {
 			$features = $wfs->getFeatureById($collection, 'application/json; subtype=geojson', $item, "2.0.0", "EPSG:4326");
 			$geojsonList = json_decode($features);
@@ -959,6 +1013,22 @@
 				$geojsonIndex++;
 			    }
 			}//end if of supported and requested json format
+			//resolve json-schema *********************************************************
+		        $resolveJsonSchema = getJsonSchemaObject($geojsonList->features[0]);
+		        $schemaObject = $resolveJsonSchema->schema;
+		        //json-ld
+		        $resolveJsonLd = getJsonLdObject($geojsonList->features[0]);
+		        $ldObject = $resolveJsonLd->schema;
+		        //add url to 
+		        foreach ($geojsonList->features as $feature) {	
+			    if ($resolveJsonSchema->success = true) {
+		                $feature->{'$schema'} = $resolveJsonSchema->url;
+                            }
+			    if ($resolveJsonLd->success = true) {
+		                $feature->{'$context'} = $resolveJsonLd->url;
+                            }
+		        }
+			//*****************************************************************************
 			if ($f == 'html'){
 			    $geoJsonVariable .= "var feature_".$geomType."=".json_encode($geojsonList).";";
 			    $geoJsonVariable .= $newline."</script>".$newline;
@@ -965,6 +1035,7 @@
 		        }
 			$usedProxyTime = microtime_float() - $proxyStartTime;
 			$returnObject = $geojsonList->features[0];
+
 			//integrate json-ld @context if it is resovable!*******************************************************************************
 			/*$ldContextConnector = new Connector();
 			$url = "http://localhost/mapbender/geoportal/".str_replace(":","__",$ftName).".jsonld";
@@ -974,6 +1045,14 @@
 //$e = new mb_exception(json_encode($contextObject));
 			$returnObject->properties->{'@context'} = $contextObject->{'@context'};*/
 			//integrate json-ld @context if it is resovable!*******************************************************************************
+			//integrate json-schema @id if it is resolvable! - {json-schema_0.7_id} attribute to avoid problems with gml encoding and @ in element name! *******************************************************************************
+			//$schemaObject = 
+
+			
+//$e = new mb_exception(json_encode($contextObject));
+			//$returnObject->properties->{'@context'} = $contextObject->{'@context'};
+			//integrate json-ld @context if it is resovable!*******************************************************************************
+
 			//add service title and collection title for navigation
 			//for rlp
 			$returnObject->serviceTitle = $wfs->title;
@@ -1004,6 +1083,7 @@
     }
 }
 
+
 //************************************************************************************************************************************
 //item part 
 //************************************************************************************************************************************
@@ -1492,12 +1572,35 @@
 				$html .= '                        <span class="d-none" itemprop="sameAs">https://www.ldproxy.nrw.de/topographie/collections/ax_bergbaubetrieb/items/DENWAT01D000CcF0</span>'.$newline;
 				//foreach attribute
 				foreach($feature->properties as $key=>$value) {
+				    if (isset ($schemaObject->properties->{$key}->title)){
+					$attributeTitle = $schemaObject->properties->{$key}->title;
+				    } else {
+					$attributeTitle = $key;
+				    }
+				    if (isset ($schemaObject->properties->{$key}->description)){
+					$attributeDescription = $schemaObject->properties->{$key}->description;
+				    } else {
+					$attributeDescription = $attributeTitle;
+				    }
+				    //inject semantic context if ldObject given
+
 				    $html .= '                        <div class="row my-1">'.$newline;
-				    $html .= '                            <div class="col-md-6 font-weight-bold text-truncate" title="'.$key.'">'.$key.'</div>'.$newline;
+				    $html .= '                            <div class="col-md-6 font-weight-bold text-truncate" title="'.$attributeDescription.'">'.$attributeTitle.'</div>'.$newline;
+				    //semantic annotations
+				    if (isset ($ldObject->{'@context'}->{$key})){
+					$uri = $ldObject->{'@context'}->{$key};
+					$schemaOrgArray = explode("/",str_replace("https://", "", $uri));
+					$schemaOrgObject = $schemaOrgArray[1];
+					$schemaOrgAttribute = $schemaOrgArray[2];
+					//$semAttribution = "vocab=\"https://schema.org/\" typeof=\"$schemaOrgObject\" property=\"$schemaOrgAttribute\"";
+				    	//TODO - check semantics !!!! $semAttribution = "itemscope=\"\" itemtype=\"http://schema.org/".$schemaOrgObject."\" itemprop=\"$schemaOrgAttribute\"";
+				    } else {
+					$semAttribution = "";
+				    }
 				    if (gettype($value) == "string") {
-				        $html .= '                            <div class="col-md-6" >'.string2html($value).'</div>'.$newline;
+				        $html .= '                            <div class="col-md-6" '.$semAttribution.'>'.string2html($value).'</div>'.$newline;
 				    } else {
-					$html .= '                            <div class="col-md-6" >'.json_encode($value).'</div>'.$newline;
+					$html .= '                            <div class="col-md-6" '.$semAttribution.'>'.json_encode($value).'</div>'.$newline;
 				    }
 				    $html .= '                        </div>'.$newline;
 				}
@@ -1518,12 +1621,33 @@
 			$html .= '                        <span class="d-none" itemprop="url">'.$_SERVER['REQUEST_URI'].'</span>'.$newline;
 			//foreach attribute
 			foreach($feature->properties as $key=>$value) {
+			    if (isset ($schemaObject->properties->{$key}->title)){
+				$attributeTitle = $schemaObject->properties->{$key}->title;
+			    } else {
+				$attributeTitle = $key;
+			    }
+			    if (isset ($schemaObject->properties->{$key}->description)){
+				$attributeDescription = $schemaObject->properties->{$key}->description;
+			    } else {
+				$attributeDescription = $attributeTitle;
+			    }
 			    $html .= '                        <div class="row my-1">'.$newline;
-			    $html .= '                            <div class="col-md-6 font-weight-bold text-truncate" title="'.$key.'">'.$key.'</div>'.$newline;
+			    $html .= '                            <div class="col-md-6 font-weight-bold text-truncate" title="'.$attributeDescription.'">'.$attributeTitle.'</div>'.$newline;
+			    //semantic annotations
+			    if (isset ($ldObject->{'@context'}->{$key})){
+				$uri = $ldObject->{'@context'}->{$key};
+				$schemaOrgArray = explode("/",str_replace("https://", "", $uri));
+				$schemaOrgObject = $schemaOrgArray[1];
+				$schemaOrgAttribute = $schemaOrgArray[2];
+				//$semAttribution = "vocab=\"https://schema.org/\" typeof=\"$schemaOrgObject\" property=\"$schemaOrgAttribute\"";
+				//TODO - check semantics !!!! $semAttribution = "itemscope=\"\" itemtype=\"http://schema.org/".$schemaOrgObject."\" itemprop=\"$schemaOrgAttribute\"";
+			    } else {
+				$semAttribution = "";
+			    }
 		            if (gettype($value) == "string") {
-			        $html .= '                            <div class="col-md-6" >'.string2html($value).'</div>'.$newline;
+			        $html .= '                            <div class="col-md-6" '.$semAttribution.'>'.string2html($value).'</div>'.$newline;
                             } else {
-				$html .= '                            <div class="col-md-6" >'.json_encode($value).'</div>'.$newline;
+				$html .= '                            <div class="col-md-6" '.$semAttribution.'>'.json_encode($value).'</div>'.$newline;
 		            }
 			    $html .= '                        </div>'.$newline;
 			}



More information about the Mapbender_commits mailing list