/** * Warning - this method is incomplete * @param SimpleGraph $graph an RDF graph that should be augmented * @return HttpResponse */ function augment_graph($graph) { if (empty($this->request_factory)) { $this->request_factory = new HttpRequestFactory(); } $request = $this->request_factory->make('POST', $this->uri, $this->credentials); $request->set_accept(MIME_RSS); $request->set_content_type(MIME_RSS); $request->set_body($graph->to_rdfxml()); return $request->execute(); }
function test_get_access_status() { $accessStatusUri = 'http://example.org/store/config/access-status'; $dummyGraph = new SimpleGraph(); $dummyGraph->add_resource_triple($accessStatusUri, 'http://schemas.talis.com/2006/bigfoot/configuration#accessMode', 'http://expected'); $response = new HttpResponse(200); $response->body = $dummyGraph->to_rdfxml(); $mockRequest = $this->getMock('HttpRequest', array('set_accept', 'execute'), array('GET', $accessStatusUri)); $mockRequest->expects($this->once())->method('set_accept')->with(MIME_RDFXML); $mockRequest->expects($this->once())->method('execute')->will($this->returnValue($response)); $mockRequestFactory = $this->getMock('HttpRequestFactory', array('make')); $mockRequestFactory->expects($this->once())->method('make')->will($this->returnValue($mockRequest)); $config = new Config("http://example.org/store/config", null, $mockRequestFactory); $actual = $config->get_access_status(); $this->assertEquals('http://expected', $actual, 'Access status should be correct'); }
/** * Create a new instance of this class * @param string uri URI of the resource * @param Credentials credentials the credentials to use for authenticated requests (optional) */ function __construct($uri, $credentials = null, $request_factory = null) { $this->uri = $uri; $this->credentials = $credentials; $this->request_factory = $request_factory; parent::__construct(); }
function translateLabelsOnPage($xpath_query) { global $nameTranslations; foreach ($this->translate_langs as $lang) { $doc = $this->fetchDocFromUrl($this->translatePageUrlTo($lang)); $xpath = new DomXpath($doc); $graph = new SimpleGraph(); foreach ($xpath->query($xpath_query) as $a) { $nodeId = $this->getNodeIdFromUrl($a->getAttribute('href')); $uri = INST . 'institutions/' . $nodeId; $this->graph->add_literal_triple($uri, RDFS_LABEL, $a->textContent, $lang); $nameTranslations[$uri][$lang] = $a->textContent; } echo trim($graph->to_ntriples()); } }
/** * 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 get_label($uri, $capitalize = false, $use_qnames = FALSE) { if ($label = $this->get_first_literal($uri, RDFS_LABEL)) { return $label; } if ($label = $this->get_first_literal($uri, API . 'name')) { return $label; } if ($label = $this->get_first_literal($uri, API . 'label')) { return $label; } else { return parent::get_label($uri, $capitalize, $use_qnames); } }
function loadDataFromItem() { $uri = $this->ConfigGraph->getCompletedItemTemplate(); $this->list_of_item_uris = array($uri); $viewerUri = $this->getViewer(); $this->viewQuery = $this->SparqlWriter->getViewQueryForUri($uri, $viewerUri); if (LOG_VIEW_QUERIES) { logViewQuery($this->Request, $this->viewQuery); } $response = $this->SparqlEndpoint->graph($this->viewQuery, PUELIA_RDF_ACCEPT_MIMES); $pageUri = $this->Request->getUriWithoutPageParam(); if ($response->is_success()) { $rdf = $response->body; $this->DataGraph->add_rdf($rdf); $this->DataGraph->add_resource_triple($pageUri, FOAF . 'primaryTopic', $uri); $label = $this->DataGraph->get_first_literal($uri, SKOS . 'prefLabel'); if (!empty($label) || ($label = $this->DataGraph->get_label($uri))) { $this->DataGraph->add_literal_triple($pageUri, RDFS_LABEL, $label); } $this->DataGraph->add_resource_triple($uri, FOAF . 'isPrimaryTopicOf', $pageUri); $this->DataGraph->add_resource_triple($this->Request->getUri(), API . 'definition', $this->endpointUrl); if ($datasetUri = $this->ConfigGraph->getDatasetUri()) { $this->DataGraph->add_resource_triple($pageUri, VOID . 'inDataset', $datasetUri); $voidRequest = $this->HttpRequestFactory->make('GET', $datasetUri); $voidRequest->set_accept(PUELIA_RDF_ACCEPT_MIMES); $voidResponse = $voidRequest->execute(); if ($voidResponse->is_success()) { $voidGraph = new SimpleGraph(); $base = array_shift(explode('#', $datasetUri)); $voidGraph->add_rdf($voidResponse->body, $base); if ($licenseUri = $voidGraph->get_first_resource($datasetUri, DCT . 'license')) { $this->DataGraph->add_resource_triple($this->Request->getUri(), DCT . 'license', $licenseUri); } else { logDebug($datasetUri . ' has no dct:license'); } } else { logDebug("VoID document could not be fetched from {$datasetUri}"); } } } else { logError("Endpoint returned {$response->status_code} {$response->body} View Query <<<{$this->viewQuery}>>> failed against {$this->SparqlEndpoint->uri}"); $this->setStatusCode(HTTP_Internal_Server_Error); $this->errorMessages[] = "The SPARQL endpoint used by this URI configuration did not return a successful response."; } $this->pageUri = $pageUri; }
<?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');
/** * Execute a graph type sparql query and obtain the result as a SimpleGraph. An empty SimpleGraph is returned if any HTTP errors occur. * @param string query the describe or construct query to execute * @return SimpleGraph */ function graph_to_simple_graph($query) { $graph = new SimpleGraph(); $response = $this->graph($query); if ($response->is_success()) { $graph->from_rdfxml($response->body); } return $graph; }
public function __construct() { parent::__construct(); $this->aTempImages = array(); $this->aSourceObjects = array(); $this->aSinkObjects = array(); }
/** * Return the current access status for the store. */ function get_access_status() { $accessStatusUri = $this->uri . '/access-status'; if (empty($this->request_factory)) { $this->request_factory = new HttpRequestFactory(); } $request = $this->request_factory->make('GET', $accessStatusUri, $this->credentials); $request->set_accept(MIME_RDFXML); $response = $request->execute(); if ($response->is_success()) { $graph = new SimpleGraph($response->body); $accessMode = $graph->get_first_resource($accessStatusUri, 'http://schemas.talis.com/2006/bigfoot/configuration#accessMode'); return $accessMode; } else { throw new Exception('Error determining access status: ' . $response->to_string()); } }
/** * mirror_from_uri: * * @return array of responses from http requests, and overall success status * @author Keith Alexander * * **/ function mirror_from_uri($url, $rdf_content = false) { $return = array('get_page' => false, 'get_copy' => false, 'update_data' => false, 'success' => false); if (empty($this->request_factory)) { $this->request_factory = new HttpRequestFactory(); } if (!$rdf_content) { $web_page_request = $this->request_factory->make('GET', $url); $web_page_request->set_accept('application/rdf+xml;q=0.8,text/turtle;q=0.9,*/*;q=0.1'); $web_page_response = $web_page_request->execute(); $return['get_page'] = $web_page_response; $web_page_content = $web_page_response->body; } else { $web_page_content = $rdf_content; $return['rdf_content'] = $rdf_content; } if ($rdf_content or $web_page_response->is_success()) { $newGraph = new SimpleGraph(); $newGraph->add_rdf($web_page_content, $url); $jsonGraphContent = $newGraph->to_json(); $newGraph->add_resource_triple($url, OPEN_JSON, $jsonGraphContent); $newGraph->skolemise_bnodes(trim($url, '#') . '#'); $after = $newGraph->get_index(); # get previous copy if it exists $cached_page_response = $this->describe($url, 'json'); $return['get_copy'] = $cached_page_response; if ($cached_page_response->status_code == '200') { $description_index = json_decode($cached_page_response->body, true); if (isset($description_index[$url]) and isset($description_index[$url][OPEN_JSON])) { $before = json_decode($description_index[$url][OPEN_JSON][0]['value'], 1); } else { $before = false; } } else { if ($cached_page_response->status_code == '404') { $before = false; } else { return $return; } } # build new changeset $Changeset = new ChangeSet(array('before' => $before, 'after' => $after, 'creatorName' => 'Graph::mirror_from_uri', 'changeReason' => 'mirroring from ' . $url)); if ($Changeset->has_changes()) { $return['update_data'] = $this->apply_changeset($Changeset); if ($return['update_data']->is_success()) { $return['success'] = true; } else { if ($return['update_data']->status_code == '409') { # Conflict. some statements already removed. $before_graph = new SimpleGraph($before); $return['reapply_before_triples'] = $this->get_metabox()->submit_turtle($before_graph->to_turtle()); if ($return['reapply_before_triples']->status_code == '204') { #Succeeded. No content $return['update_data'] = $this->get_metabox()->apply_changeset($Changeset); $return['success'] = $return['update_data']->is_success(); } } else { return $return; } } return $return; } else { $return['success'] = true; return $return; } } else { return $return; } }
function test_get_resource_property_values() { $ex = "http://example.com/"; $turtle = <<<_TTL_ @base <{$ex}> . <s> <has> <a> , <b> , <c> , <d> , <e> . <a> <p> 2 . <b> <p> 3 . <c> <p> 1 . <e> <p> "!" , "_" . _TTL_; $graph = new SimpleGraph(); $graph->from_turtle($turtle); $expected = array($ex . 'd', $ex . 'e', $ex . 'c', $ex . 'a', $ex . 'b'); $actual = $graph->get_resource_triple_values($ex . 's', $ex . 'has', $ex . 'p'); $actual_r = $graph->get_resource_triple_values($ex . 's', $ex . 'has', $ex . 'p', true); $actual_unsorted = $graph->get_resource_triple_values($ex . 's', $ex . 'has'); $this->assertEquals($expected, $actual, "should return the resource values of one property, ordered by a property of those resources"); $this->assertEquals(array_reverse($expected), $actual_r, "should return the resource values of one property, ordered by a property of those resources, sorted in descending order"); $this->assertEquals(count($actual), count($actual_unsorted), "number of results should be the same whether sorted or not"); }
function __init() { $csIndex = array(); $CSNS = 'http://purl.org/vocab/changeset/schema#'; // Get the triples to be added if (empty($this->before)) { $additions = $this->after; } else { $additions = SimpleGraph::diff($this->after, $this->before); } //Get the triples to be removed if (empty($this->after)) { $removals = $this->before; } else { $removals = SimpleGraph::diff($this->before, $this->after); } // $removals = !empty($this->after)? SimpleGraph::diff($this->before, $this->after) : $this->before; //remove etag triples foreach (array('removals' => $removals, 'additions' => $additions) as $name => $graph) { foreach ($graph as $uri => $properties) { if (isset($properties["http://schemas.talis.com/2005/dir/schema#etag"])) { unset(${$name}[$uri]["http://schemas.talis.com/2005/dir/schema#etag"]); if (count(${$name}[$uri]) == 0) { unset(${$name}[$uri]); } } } } // print_r(array_keys($additions)); // print_r(array_keys($removals)); // print_r(array_merge(array_keys($additions), array_keys($removals))); // Get an array of all the subject uris $subjectIndex = !empty($this->a['subjectOfChange']) ? array($this->a['subjectOfChange']) : array_unique(array_merge(array_keys($additions), array_keys($removals))); // print_r($subjectIndex); // Get the metadata for all the changesets $date = !empty($this->a['createdDate']) ? $this->a['createdDate'] : date(DATE_ATOM); $creator = !empty($this->a['creatorName']) ? $this->a['creatorName'] : 'Moriarty ChangeSet Builder'; $reason = !empty($this->a['changeReason']) ? $this->a['changeReason'] : 'Change using Moriarty ChangeSet Builder'; $csCount = 0; foreach ($subjectIndex as $subjectOfChange) { $csID = '_:cs' . $csCount; $csIndex[$subjectOfChange] = $csID; $this->addT($csID, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $CSNS . 'ChangeSet', 'uri'); $subjectType = strpos($subjectOfChange, '_:') === 0 ? 'bnode' : 'uri'; $this->addT($csID, $CSNS . 'subjectOfChange', $subjectOfChange, $subjectType); $this->addT($csID, $CSNS . 'createdDate', $date, 'literal'); $this->addT($csID, $CSNS . 'creatorName', $creator, 'literal'); $this->addT($csID, $CSNS . 'changeReason', $reason, 'literal'); /* add extra user-given properties to each changeset*/ if (!empty($this->a['properties'])) { foreach ($this->a['properties'] as $p => $objs) { $this->addT($csID, $p, $objs); } } $csCount++; } /*iterate through the triples to be added, reifying them, and linking to the Statements from the appropriate changeset */ $reifiedAdditions = SimpleGraph::reify($additions, 'Add'); if (!empty($reifiedAdditions)) { foreach ($reifiedAdditions as $nodeID => $props) { $subject = $props['http://www.w3.org/1999/02/22-rdf-syntax-ns#subject'][0]['value']; if (in_array($subject, $subjectIndex)) { $csID = $csIndex[$subject]; $this->addT($csID, $CSNS . 'addition', $nodeID, 'bnode'); } // if dc:source is given in the instantiating arguments, add it to the statement as provenance if (isset($this->a['http://purl.org/dc/terms/source'])) { $this->addT($nodeID, 'http://purl.org/dc/terms/source', $this->a['http://purl.org/dc/terms/source'], 'uri'); } } } /*iterate through the triples to be removed, reifying them, and linking to the Statements from the appropriate changeset */ $reifiedRemovals = SimpleGraph::reify($removals, 'Remove'); foreach ($reifiedRemovals as $nodeID => $props) { $subject = $props['http://www.w3.org/1999/02/22-rdf-syntax-ns#subject'][0]['value']; if (in_array($subject, $subjectIndex)) { $csID = $csIndex[$subject]; $this->addT($csID, $CSNS . 'removal', $nodeID, 'bnode'); } } // foreach($this->_index as $uri => $props){ // if( // !isset($props[$CSNS.'removal']) // AND // !isset($props[$CSNS.'addition']) // ){ // unset($this->_index[$uri]); // } // // } $this->_index = SimpleGraph::merge($this->_index, $reifiedAdditions, $reifiedRemovals); }
/** * 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; }
public function __construct() { parent::__construct(); $this->aSourceNodes = array(); $this->aSinkNodes = array(); $this->aRedundancySettings = array(); $this->aContextSearches = array(); }
require_once MORIARTY_DIR . 'simplegraph.class.php'; if ($describer_class) { $describer = new $describer_class(); } else { require_once MORIARTY_DIR . 'store.class.php'; $describer = new Store($store_uri); } $response = $describer->describe($resource_uri, 'cbd', 'json'); $body = ''; $content_location = ''; $etag = ''; if ($response->is_success()) { if (array_key_exists('etag', $response->headers)) { $etag = $response->headers['etag']; } $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) {
$val = strtolower($val); return $val; } function writeLog($msg) { echo $msg . "\n"; } } $ee = new Election_Results("http://www.europarl.europa.eu/parliament/archive/elections2009/en/national_parties_en_txt.html"); $ee->parseSeatsByPartyByStateTables(); print_r($electionCountData); //echo $ee->lookupCountry("BE"); $data_base_uri = "http://data.kasabi.com/dataset/european-election-results/"; $schema_base_uri = "http://data.kasabi.com/dataset/european-election-results/def/"; # build a graph $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));
function test_store_data_sends_simple_graph_as_turtle() { $fake_request_factory = new FakeRequestFactory(); $fake_request = new FakeHttpRequest(new HttpResponse()); $fake_request_factory->register('POST', "http://example.org/store/meta", $fake_request); $g = new SimpleGraph(); $g->from_rdfxml($this->_rdfxml_doc); $store = new Store("http://example.org/store", new FakeCredentials(), $fake_request_factory); $response = $store->store_data($g); $this->assertTrue(in_array('Content-Type: text/turtle', $fake_request->get_headers())); }
/** * mirror_from_url * * @return array of responses from http requests, and overall success status * @author Keith Alexander * * **/ function mirror_from_url($url, $rdf_content = false) { $return = array('get_page' => false, 'get_copy' => false, 'put_page' => false, 'update_data' => false, 'success' => false); if (empty($this->request_factory)) { $this->request_factory = new HttpRequestFactory(); } $last_cached_page_uri = $this->get_contentbox()->uri . '/mirrors/' . $url; if (!$rdf_content) { $web_page_request = $this->request_factory->make('GET', $url); $web_page_request->set_accept('application/rdf+xml;q=0.8,text/turtle;q=0.9,*/*;q=0.1'); $web_page_response = $web_page_request->execute(); $return['get_page'] = $web_page_response; $web_page_content = $web_page_response->body; } else { $web_page_content = $rdf_content; $return['rdf_content'] = $rdf_content; } if ($rdf_content or $web_page_response->is_success()) { $newGraph = new SimpleGraph(); $newGraph->add_rdf($web_page_content, $url); $newGraph->add_resource_triple($url, OPEN_LASTCACHEDPAGE, $last_cached_page_uri); $newGraph->skolemise_bnodes($last_cached_page_uri . '/'); $after = $newGraph->get_index(); # get previous copy if it exists $cached_page_request = $this->request_factory->make('GET', $last_cached_page_uri, $this->credentials); $cached_page_response = $cached_page_request->execute(); $return['get_copy'] = $cached_page_response; if ($cached_page_response->status_code == '200') { $before = json_decode($cached_page_response->body, true); } else { if ($cached_page_response->status_code == '404') { $before = false; } else { return $return; } } # build new changeset $Changeset = new ChangeSet(array('before' => $before, 'after' => $after, 'creatorName' => 'Store::mirror_from_url', 'changeReason' => 'mirroring from ' . $url)); if ($Changeset->has_changes()) { $return['update_data'] = $this->get_metabox()->apply_changeset($Changeset); if ($return['update_data']->is_success()) { $return['success'] = true; } else { if ($return['update_data']->status_code == '409') { # Conflict. some statements already removed. $before_graph = new SimpleGraph($before); $return['reapply_before_triples'] = $this->get_metabox()->submit_turtle($before_graph->to_turtle()); if ($return['reapply_before_triples']->status_code == '204') { #Succeeded. No content $return['update_data'] = $this->get_metabox()->apply_changeset($Changeset); $return['success'] = $return['update_data']->is_success(); } } else { return $return; } } $put_page_request = $this->request_factory->make('PUT', $last_cached_page_uri, $this->credentials); $put_page_request->set_body($newGraph->to_json()); $put_page_request->set_content_type('application/json'); $put_page_response = $put_page_request->execute(); $return['put_page'] = $put_page_response; $return['success'] = $put_page_response->is_success(); return $return; } else { $return['success'] = true; return $return; } } else { return $return; } }
/** * @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; }
/** * Constructor * @param SimpleGraph $oGraph The graph to browse * @param string $sType "Node", "Edge" or null */ public function __construct(SimpleGraph $oGraph, $sType = null) { $this->iCurrentIdx = -1; $this->aList = array(); switch ($sType) { case 'Node': foreach ($oGraph->_GetNodes() as $oNode) { $this->aList[] = $oNode; } break; case 'Edge': foreach ($oGraph->_GetEdges() as $oEdge) { $this->aList[] = $oEdge; } break; default: foreach ($oGraph->_GetNodes() as $oNode) { $this->aList[] = $oNode; } foreach ($oGraph->_GetEdges() as $oEdge) { $this->aList[] = $oEdge; } } }
/** * Obtain the graph's bounded description of a given resource. This is designed to be fast since it uses RDF/JSON which requires no parsing by the SimpleGraph class. This method always returns a SimpleGraph, which will be empty if any HTTP errors occured. * @see http://n2.talis.com/wiki/Metabox#Describing_a_Resource * @param string uri the URI of the resource to be described * @return SimpleGraph */ function describe_to_simple_graph($uri) { $graph = new SimpleGraph(); $response = $this->describe($uri, OUTPUT_TYPE_JSON); if ($response->is_success()) { $graph->from_json($response->body); } return $graph; }
public function testGetParserErrors() { $graph = new SimpleGraph(); $graph->add_rdf($this->_single_triple_turtle); $errors = $graph->get_parser_errors(); $this->assertTrue(empty($errors), "Errors should be empty"); $graph->add_rdf($this->_single_triple_invalid_rdf); $errors = $graph->get_parser_errors(); $this->assertFalse(empty($errors), "Errors should not be empty"); $this->assertTrue(!empty($errors[0]), "Errors first item should not be empty"); }
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); }
function test_to_html_renders_bnodes_as_anchors() { $g = new SimpleGraph(); $g->from_rdfxml($this->_single_triple); $g->add_resource_triple('http://example.org/subj', 'http://example.org/pred', '_:bn123'); $g->add_resource_triple('_:bn123', 'http://example.org/pred', 'http://example.org/obj'); $html = $g->to_html(); $this->assertContains('<a href="http://example.org/subj">subj</a>', $html, "html should contain links to bnode anchors"); $this->assertContains('<a href="#bn123">_:bn123</a>', $html, "html should contain links to bnode anchors"); $this->assertContains('<a id="bn123" href="#bn123">_:bn123</a>', $html, "html should contain anchors for bnodes"); }
function test_update_adds_bnode() { $fake_request_factory = new FakeRequestFactory(); $fake_response = new HttpResponse(); $fake_response->status_code = 200; $fake_response->body = $this->_select_result2; $query = "select ?_uri ?name where { optional {?_uri <http://example.org/name> ?name. } }"; $fake_request = new FakeHttpRequest($fake_response); $fake_request_factory->register('GET', "http://example.org/store/services/sparql?query=" . urlencode($query) . '&output=json', $fake_request); $fake_request_cs = new FakeHttpRequest(new HttpResponse()); $fake_request_factory->register('POST', "http://example.org/store/meta", $fake_request_cs); $dt = new DataTable("http://example.org/store", null, $fake_request_factory); $dt->map('http://example.org/name', 'name'); $dt->set('name', 'foo', 'bnode'); $dt->update(); $cs = new SimpleGraph(); $cs->from_rdfxml($fake_request_cs->get_body()); $changesets = $cs->get_subjects_of_type(CS_CHANGESET); $this->assertEquals(1, count($changesets)); $additions = $cs->get_resource_triple_values($changesets[0], CS_ADDITION); $this->assertEquals(1, count($additions)); $this->assertTrue($cs->has_resource_triple($additions[0], RDF_OBJECT, "_:foo")); }