You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/02/27 14:01:11 UTC
[9/12] MARMOTTA-108: marmotta-client-php
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/model/rdf/URI.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/model/rdf/URI.php b/client/marmotta-client-php/src/main/php/model/rdf/URI.php
new file mode 100644
index 0000000..ae15caa
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/model/rdf/URI.php
@@ -0,0 +1,53 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+namespace MarmottaClient\Model\RDF;
+
+require_once 'RDFNode.php';
+use MarmottaClient\Model\RDF\RDFNode;
+
+/**
+ * Represents a RDF URI Resource in PHP.
+ *
+ * User: sschaffe
+ * Date: 25.01.12
+ * Time: 10:13
+ * To change this template use File | Settings | File Templates.
+ */
+class URI extends RDFNode
+{
+ /** @var URI of the URI Resource (string) */
+ private $uri;
+
+ function __construct($uri)
+ {
+ $this->uri = $uri;
+ }
+
+
+
+ function __toString()
+ {
+ return $this->uri;
+ }
+
+ public function getUri()
+ {
+ return $this->uri;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/test_configuration.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/test_configuration.php b/client/marmotta-client-php/src/main/php/test_configuration.php
new file mode 100644
index 0000000..6710e42
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/test_configuration.php
@@ -0,0 +1,50 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: sschaffe
+ * Date: 25.01.12
+ * Time: 15:49
+ * To change this template use File | Settings | File Templates.
+ */
+require_once 'autoload.php';
+
+use MarmottaClient\ClientConfiguration;
+use MarmottaClient\Clients\ConfigurationClient;
+
+$config = new ClientConfiguration("http://localhost:8080/mtta");
+
+$client = new ConfigurationClient($config);
+
+//var_dump($client->listConfigurationKeys());
+
+//var_dump($client->listConfigurations("solr"));
+
+$client->setConfiguration("client.php.test1","1234");
+$client->setConfiguration("client.php.test2",array("1234","abc"));
+
+var_dump($client->getConfiguration("client.php.test1"));
+var_dump($client->getConfiguration("client.php.test2"));
+
+$client->deleteConfiguration("client.php.test1");
+$client->deleteConfiguration("client.php.test2");
+
+
+var_dump($client->getConfiguration("client.php.test1"));
+var_dump($client->getConfiguration("client.php.test2"));
+
+?>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/test_import.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/test_import.php b/client/marmotta-client-php/src/main/php/test_import.php
new file mode 100644
index 0000000..b49742d
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/test_import.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: sschaffe
+ * Date: 27.01.12
+ * Time: 14:13
+ * To change this template use File | Settings | File Templates.
+ */
+
+require_once 'autoload.php';
+
+use MarmottaClient\ClientConfiguration;
+use MarmottaClient\Clients\ImportClient;
+use MarmottaClient\Clients\ResourceClient;
+
+$config = new ClientConfiguration("http://localhost:8080/mtta");
+
+$client = new ImportClient($config);
+
+// list supported types
+echo "Supported Types: ";
+foreach($client->getSupportedTypes() as $type) {
+ echo $type . ",";
+}
+echo "\n";
+
+
+// import a simple data set
+$data = "<http://example.com/resource/r1> <http://example.com/resource/p1> \"Test Data\".";
+$client->uploadDataset($data,"text/rdf+n3");
+
+
+// wait a bit for import to finish
+sleep(1);
+
+
+$rclient = new ResourceClient($config);
+
+foreach($rclient->getResourceMetadata("http://example.com/resource/r1") as $property => $value) {
+ echo $property . " = " . $value[0] . "\n";
+}
+
+
+
+
+?>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/test_ldpath.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/test_ldpath.php b/client/marmotta-client-php/src/main/php/test_ldpath.php
new file mode 100644
index 0000000..1c0bf8d
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/test_ldpath.php
@@ -0,0 +1,48 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: sschaffe
+ * Date: 27.01.12
+ * Time: 17:21
+ * To change this template use File | Settings | File Templates.
+ */
+require_once 'autoload.php';
+
+use MarmottaClient\ClientConfiguration;
+use MarmottaClient\Clients\LDPathClient;
+
+$config = new ClientConfiguration("http://localhost:8080/mtta");
+
+$client = new LDPathClient($config);
+
+// list friends of hans meier
+foreach($client->evaluatePath("http://localhost:8080/mtta/resource/hans_meier", "foaf:knows / foaf:name") as $friend) {
+ echo "Friend: $friend\n";
+}
+
+// list profile of hans meier
+foreach($client->evaluateProgram("http://localhost:8080/mtta/resource/hans_meier", "friend = foaf:knows / foaf:name :: xsd:string; name = foaf:name :: xsd:string; interest = foaf:interest / (rdfs:label[@en] | rdfs:label[@none] | <http://rdf.freebase.com/ns/type.object.name>[@en]) :: xsd:string;") as $field => $values) {
+ echo "$field: ";
+ foreach($values as $value) {
+ echo $value . ",";
+ }
+ echo "\n";
+}
+
+
+?>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/test_private.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/test_private.php b/client/marmotta-client-php/src/main/php/test_private.php
new file mode 100644
index 0000000..779b4c5
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/test_private.php
@@ -0,0 +1,38 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: sschaffe
+ * Date: 30.01.12
+ * Time: 17:00
+ * To change this template use File | Settings | File Templates.
+ */
+require_once 'autoload.php';
+
+use MarmottaClient\ClientConfiguration;
+use MarmottaClient\Clients\LDPathClient;
+
+$config = new ClientConfiguration("http://localhost:8080/mtta");
+
+$client = new LDPathClient($config);
+
+// list friends of hans meier
+foreach($client->evaluatePath("https://www.youtube.com/profile?user=wastl76", "(<http://gdata.youtube.com/schemas/2007#playlist> | <http://gdata.youtube.com/schemas/2007#favorite> ) / <http://gdata.youtube.com/schemas/2007#video> / <http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag> / <http://www.holygoat.co.uk/owl/redwood/0.1/tags/name>") as $field) {
+ echo "Tag: $field\n";
+}
+
+?>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/test_resource.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/test_resource.php b/client/marmotta-client-php/src/main/php/test_resource.php
new file mode 100644
index 0000000..78d7710
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/test_resource.php
@@ -0,0 +1,63 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: sschaffe
+ * Date: 25.01.12
+ * Time: 10:38
+ * To change this template use File | Settings | File Templates.
+ */
+
+
+require_once 'autoload.php';
+
+use MarmottaClient\ClientConfiguration;
+use MarmottaClient\Clients\ResourceClient;
+
+$config = new ClientConfiguration("http://localhost:8080/mtta");
+
+$client = new ResourceClient($config);
+
+/*
+echo $client->getResourceContent("http://localhost:8080/mtta/resource/Chess","application/xhtml+xml")->getData();
+*/
+
+/*
+echo "should be false: " . $client->existsResource("http://brzlbrnft.com/123") . "\n";
+echo "should be true: " . $client->existsResource("http://localhost:8080/mtta/resource/Chess") . "\n";
+*/
+
+
+$client->createResource("http://localhost:8080/mtta/resource/1234");
+
+$metadata = array(
+ "http://xmlns.com/foaf/0.1/name" => array(new \MarmottaClient\Model\RDF\Literal("Hans Mustermann"))
+);
+
+$client->updateResourceMetadata("http://localhost:8080/mtta/resource/1234",$metadata);
+
+$client->deleteResource("http://localhost:8080/mtta/resource/1234");
+
+
+/*
+$metadata = $client->getResourceMetadata("http://localhost:8080/mtta/resource/hans_meier");
+
+var_dump($metadata);
+
+echo encode_metadata("http://localhost:8080/mtta/resource/hans_meier",$metadata);
+*/
+?>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/test_sparql.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/test_sparql.php b/client/marmotta-client-php/src/main/php/test_sparql.php
new file mode 100644
index 0000000..c049b65
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/test_sparql.php
@@ -0,0 +1,44 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: sschaffe
+ * Date: 27.01.12
+ * Time: 10:48
+ * To change this template use File | Settings | File Templates.
+ */
+require_once 'autoload.php';
+
+use MarmottaClient\ClientConfiguration;
+use MarmottaClient\Clients\SPARQLClient;
+
+$config = new ClientConfiguration("http://localhost:8080/mtta");
+
+$client = new SPARQLClient($config);
+
+echo "TEST SPARQL SELECT:\n";
+foreach($client->select("SELECT ?r ?n WHERE { ?r <http://xmlns.com/foaf/0.1/name> ?n }") as $row) {
+ echo $row["r"] . " has name " . $row["n"] . "\n";
+}
+
+
+echo "TEST SPARQL ASK:\n";
+echo "should be true: " . $client->ask("ASK { ?r <http://xmlns.com/foaf/0.1/name> ?n }") . "\n";
+echo "should be false: " . $client->ask("ASK { ?r <http://xmlns.com/foaf/0.1/brzlbrnft> ?n }") . "\n";
+
+
+?>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/marmotta-client-php/src/main/php/util/rdfjson.php
----------------------------------------------------------------------
diff --git a/client/marmotta-client-php/src/main/php/util/rdfjson.php b/client/marmotta-client-php/src/main/php/util/rdfjson.php
new file mode 100644
index 0000000..aa93143
--- /dev/null
+++ b/client/marmotta-client-php/src/main/php/util/rdfjson.php
@@ -0,0 +1,132 @@
+<?php
+/*
+ * Copyright (C) 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Created by IntelliJ IDEA.
+ * User: sschaffe
+ * Date: 25.01.12
+ * Time: 11:08
+ * To change this template use File | Settings | File Templates.
+ */
+
+require_once 'model/rdf/Literal.php';
+require_once 'model/rdf/URI.php';
+require_once 'model/rdf/BNode.php';
+
+use MarmottaClient\Model\RDF\Literal;
+use MarmottaClient\Model\RDF\URI;
+use MarmottaClient\Model\RDF\BNode;
+
+/**
+ * Convert an RDF/JSON string into the MarmottaClient metadata representation. Returns an array of the form
+ *
+ * array(
+ * "http://xmlns.com/foaf/0.1/name" => array(new Literal("Sepp Huber"))
+ * )
+ *
+ * @param $rdfjson_string
+ */
+function decode_metadata($uri,$rdfjson_string) {
+ $result = array();
+
+ $json_array = json_decode($rdfjson_string,true);
+ foreach($json_array as $subject => $properties) {
+ if($uri == $subject) {
+ foreach($properties as $property => $objects) {
+ $result[$property] = array();
+ foreach($objects as $object) {
+ $result[$property][] = decode_node($object);
+ }
+ }
+ }
+ }
+ return $result;
+}
+
+
+function decode_node($object) {
+ if($object["type"] == "literal") {
+ return new Literal(
+ $object["value"],
+ isset($object["lang"]) ? $object["lang"] : null,
+ isset($object["datatype"]) ? $object["datatype"] : null
+ );
+ } else if($object["type"] == "uri") {
+ return new URI($object["value"]);
+ } else if($object["type"] == "bnode") {
+ return new BNode($object["value"]);
+ } else {
+ return null;
+ }
+}
+
+/**
+ * Transform a metadata array into an RDF/JSON representation suitable for sending to the Marmotta Server.
+ *
+ * @param $uri
+ * @param $metadata_array
+ */
+function encode_metadata($uri, $metadata_array) {
+ $result = array();
+ $result[$uri] = array();
+
+ foreach($metadata_array as $property => $values) {
+ $result[$uri][$property] = array();
+ foreach($values as $value) {
+ if($value instanceof \MarmottaClient\Model\RDF\Literal) {
+ $object = array (
+ "type" => "literal",
+ "value" => $value->getContent()
+ );
+ if(!is_null($value->getLanguage())) {
+ $object["lang"] = $value->getLanguage();
+ }
+ if(!is_null($value->getDatatype())) {
+ $object["datatype"] = $value->getDatatype();
+ }
+ $result[$uri][$property][] = $object;
+ } else if($value instanceof \MarmottaClient\Model\RDF\URI) {
+ $result[$uri][$property][] = array(
+ "type" => "uri",
+ "value" => $value->getUri()
+ );
+ } else if($value instanceof \MarmottaClient\Model\RDF\BNode) {
+ $result[$uri][$property][] = array(
+ "type" => "bnode",
+ "value" => $value->getAnonId()
+ );
+ } else {
+ // try figuring out whether it is literal or uri based on the string value
+ if(preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $value)) {
+ $result[$uri][$property][] = array(
+ "type" => "uri",
+ "value" => $value
+ );
+ } else {
+ $object = array (
+ "type" => "literal",
+ "value" => $value
+ );
+ }
+ }
+ }
+ }
+ return json_encode($result);
+}
+
+
+
+?>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/34193131/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 9a3fdc2..9702715 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -39,7 +39,7 @@
<profile>
<id>all</id>
<modules>
- <module>lmf-client-php</module>
+ <module>marmotta-client-php</module>
<module>marmotta-client-js</module>
<module>marmotta-client-js-sample-webapp</module>
</modules>