/**
  * Create a new store on the platform. This is currently restricted to Talis administrators.
  * @param string name the name of the store
  * @param string template_uri the URI of the store template to use
  * @return HttpRequest
  */
 function create_store($name, $template_uri)
 {
     if (empty($this->request_factory)) {
         $this->request_factory = new HttpRequestFactory();
     }
     $uri = $this->uri;
     $mimetype = MIME_RDFXML;
     $request = $this->request_factory->make('POST', $uri, $this->credentials);
     $request->set_accept("*/*");
     $request->set_content_type($mimetype);
     $sr = new SimpleGraph();
     $sr->add_resource_triple('_:req', BF_STORETEMPLATE, $template_uri);
     $sr->add_literal_triple('_:req', BF_STOREREF, $name);
     $request->set_body($sr->to_rdfxml());
     return $request->execute();
 }
 function test_get_subjects()
 {
     $g = new SimpleGraph();
     $g->add_resource_triple('http://example.org/subj1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_1');
     $g->add_resource_triple('http://example.org/subj2', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_2');
     $g->add_resource_triple('http://example.org/subj3', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_1');
     $g->add_literal_triple('http://example.org/subj4', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_1');
     $subjects = $g->get_subjects();
     $this->assertEquals(4, count($subjects), 'The returned subjects should be exactly 4');
     $this->assertContains('http://example.org/subj1', $subjects, 'subj1 matches and should be returned');
     $this->assertContains('http://example.org/subj2', $subjects, 'subj2 matches and should be returned');
     $this->assertContains('http://example.org/subj3', $subjects, 'subj3 matches and should be returned');
     $this->assertContains('http://example.org/subj4', $subjects, 'subj4 matches and should be returned');
 }
示例#3
0
<?php

define('MORIARTY_ARC_DIR', 'arc/');
require 'inc.php';
require 'credentials.inc.php';
require_once 'moriarty/credentials.class.php';
function report($r)
{
    var_dump($r->status_code);
    if ($r->is_success() === false) {
        var_dump($r);
        die;
    }
}
$void = new SimpleGraph();
$void->add_turtle(file_get_contents('void.ttl'));
$void->add_literal_triple(WHOISWHO, DCT . 'modified', date('c'), false, XSDT . 'dateTime');
$graph = new Graph('http://api.talis.com/stores/euwhoiswho/meta', new Credentials(STORE_USER, STORE_PASS));
$graph->mirror_from_uri(WHOISWHO, $void->to_json());
$graph->submit_ntriples_in_batches_from_file('roles.nt', 500, 'report');
$graph->mirror_from_uri("http://institutions.publicdata.eu/", file_get_contents('institutions.publicdata.eu.ttl'));
$graph->submit_ntriples_in_batches_from_file('all.nt', 500, 'report');
 /**
  * @access private
  */
 function make_job_request($jobtype, $time = null, $label = null)
 {
     $time = $time == null ? gmmktime() : $time;
     $formatted_time = gmdate("Y-m-d\\TH:i:s\\Z", $time);
     $label = $label == null ? 'Job submitted ' . $formatted_time : $label;
     $job = new SimpleGraph();
     $job->add_resource_triple('_:job', BF_JOBTYPE, $jobtype);
     $job->add_resource_triple('_:job', RDF_TYPE, BF_JOBREQUEST);
     $job->add_literal_triple('_:job', BF_STARTTIME, $formatted_time);
     $job->add_literal_triple('_:job', RDFS_LABEL, $label);
     return $job;
 }
 function test_match_compare_string_with_boolean()
 {
     $g = new SimpleGraph();
     $g->set_namespace_mapping('ex', 'http://example.org/');
     $g->add_literal_triple('http://example.org/subj', 'http://example.org/pred', 'obj');
     $g->add_literal_triple('http://example.org/subj2', 'http://example.org/pred', '');
     $gp = new GraphPath('*[literal-value(ex:pred) = true()]');
     $this->assertPathSelects($gp, $g);
 }
 /**
  * Get the changeset that would be applied by the update method.
  *
  * @return ChangeSet
  */
 function get_update_changeset()
 {
     $store = new Store($this->_store_uri, $this->_credentials, $this->_request_factory);
     $query = $this->get_sparql();
     $res = $this->get();
     $cs = new SimpleGraph();
     $diffs = $this->get_differences($res);
     $node_index = 0;
     foreach ($diffs as $s => $diff_info) {
         $removals = $diff_info['removals'];
         $additions = $diff_info['additions'];
         $cs_subj = '_:cs' . $node_index++;
         $cs->add_resource_triple($cs_subj, RDF_TYPE, CS_CHANGESET);
         $cs->add_resource_triple($cs_subj, CS_SUBJECTOFCHANGE, $s);
         $cs->add_literal_triple($cs_subj, CS_CHANGEREASON, "Update from DataTable");
         $cs->add_literal_triple($cs_subj, CS_CREATEDDATE, gmdate(DATE_ATOM));
         $cs->add_literal_triple($cs_subj, CS_CREATORNAME, "Moriarty DataTable");
         if (count($removals) > 0) {
             foreach ($removals as $p => $p_list) {
                 foreach ($p_list as $p_info) {
                     $node = '_:r' . $node_index;
                     $cs->add_resource_triple($cs_subj, CS_REMOVAL, $node);
                     $cs->add_resource_triple($node, RDF_TYPE, RDF_STATEMENT);
                     $cs->add_resource_triple($node, RDF_SUBJECT, $s);
                     $cs->add_resource_triple($node, RDF_PREDICATE, $p);
                     if ($p_info['type'] === 'literal') {
                         $dt = array_key_exists('datatype', $p_info) ? $p_info['datatype'] : null;
                         $lang = array_key_exists('lang', $p_info) ? $p_info['lang'] : null;
                         $cs->add_literal_triple($node, RDF_OBJECT, $p_info['value'], $lang, $dt);
                     } else {
                         $cs->add_resource_triple($node, RDF_OBJECT, $p_info['value']);
                     }
                     $node_index++;
                 }
             }
         }
         if (count($additions) > 0) {
             foreach ($additions as $p => $p_list) {
                 foreach ($p_list as $p_info) {
                     $node = '_:a' . $node_index;
                     $cs->add_resource_triple($cs_subj, CS_ADDITION, $node);
                     $cs->add_resource_triple($node, RDF_TYPE, RDF_STATEMENT);
                     $cs->add_resource_triple($node, RDF_SUBJECT, $s);
                     $cs->add_resource_triple($node, RDF_PREDICATE, $p);
                     if ($p_info['type'] === 'literal') {
                         $dt = array_key_exists('datatype', $p_info) ? $p_info['datatype'] : null;
                         $lang = array_key_exists('lang', $p_info) ? $p_info['lang'] : null;
                         $cs->add_literal_triple($node, RDF_OBJECT, $p_info['value'], $lang, $dt);
                     } else {
                         $cs->add_resource_triple($node, RDF_OBJECT, $p_info['value']);
                     }
                     $node_index++;
                 }
             }
         }
     }
     return $cs;
 }
示例#7
0
$graph = new SimpleGraph();
//$def = new SimpleGraph() ;
$graph->add_turtle(file_get_contents(PROJECT_ROOT . 'defs/eu-dataset-definition.ttl'));
$graph->set_namespace_mapping('eedef', $schema_base_uri);
$graph->set_namespace_mapping('ee', $data_base_uri);
$graph->set_namespace_mapping('qb', 'http://purl.org/linked-data/cube#');
$graph->set_namespace_mapping('dct', 'http://purl.org/dc/terms/');
$electionPercentageData = $ee->getSeatsByPartyByStateTablePercentages();
// seats won counts
foreach ($ee->getSeatsByPartyByStateTableCounts() as $k1 => $v) {
    foreach ($v as $k2 => $val) {
        if ($k2 == 'PoliticalGroupAbbr') {
            // add political groups
            $political_group = $data_base_uri . "political_group/" . $ee->uri_safe($v['PoliticalGroupAbbr']);
            $graph->add_resource_triple($political_group, $graph->qname_to_uri("rdf:type"), $schema_base_uri . "PoliticalGroup");
            $graph->add_literal_triple($political_group, $graph->qname_to_uri("rdfs:label"), html_entity_decode($v['PoliticalGroupName'], ENT_QUOTES));
            $graph->add_literal_triple($political_group, $graph->qname_to_uri("dct:identifier"), html_entity_decode($v['PoliticalGroupAbbr'], ENT_QUOTES));
        }
        if (preg_match("/^[A-Z][A-Z]\$/", $k2)) {
            // add country
            $country_name = $ee->lookupCountry($k2);
            $country_code = $k2;
            $country_uri = $data_base_uri . "country/" . $ee->uri_safe($country_code);
            $graph->add_resource_triple($country_uri, $graph->qname_to_uri("rdf:type"), $schema_base_uri . "Country");
            $graph->add_literal_triple($country_uri, $graph->qname_to_uri("rdfs:label"), $country_name);
            $graph->add_literal_triple($country_uri, $graph->qname_to_uri("dct:identifier"), $country_code);
            // add results per country
            foreach ($val as $party => $count) {
                if ($party == 'seatCount') {
                    // total count for the political group
                    $totalCount = $count;
 }
 $g = new SimpleGraph();
 $g->from_json($response->body);
 if (!$g->has_triples_about($resource_uri)) {
     send_not_found($uri, $template);
 } else {
     $g->remove_property_values($resource_uri, 'http://schemas.talis.com/2005/dir/schema#etag');
     if ($uri != $doc_uri) {
         header("HTTP/1.1 303 See Other");
         header("Location: " . $doc_uri);
         exit;
     } else {
         $g->add_resource_triple($doc_uri, RDF_TYPE, FOAF_DOCUMENT);
         $g->add_resource_triple($doc_uri, RDF_TYPE, 'http://purl.org/dc/dcmitype/Text');
         $g->add_resource_triple($doc_uri, FOAF_PRIMARYTOPIC, $resource_uri);
         $g->add_literal_triple($doc_uri, 'http://purl.org/dc/terms/title', 'Linked Data for ' . $g->get_label($resource_uri, TRUE));
         foreach ($media_types as $extension => $type_info) {
             $alt_uri = $resource_uri . '.' . $extension;
             $g->add_resource_triple($doc_uri, 'http://purl.org/dc/terms/hasFormat', $alt_uri);
             $g->add_resource_triple($alt_uri, 'http://purl.org/dc/terms/isFormatOf', $doc_uri);
             $g->add_resource_triple($alt_uri, RDF_TYPE, 'http://purl.org/dc/dcmitype/Text');
             $g->add_resource_triple($alt_uri, RDF_TYPE, FOAF_DOCUMENT);
             $g->add_resource_triple($alt_uri, FOAF_PRIMARYTOPIC, $resource_uri);
             $g->add_literal_triple($alt_uri, 'http://purl.org/dc/terms/format', $type_info['type']);
             $g->add_literal_triple($alt_uri, 'http://purl.org/dc/terms/title', 'Linked Data in ' . $type_info['label'] . ' format for ' . $g->get_label($resource_uri, TRUE));
         }
         if ($doc_type == 'rdf') {
             send_rdfxml('200 OK', $g->to_rdfxml(), $content_location, $etag);
         } else {
             if ($doc_type == 'ttl') {
                 send_turtle('200 OK', $g->to_turtle(), $content_location, $etag);