getRDFXMLSerializer() static public method

static public getRDFXMLSerializer ( $a = '' )
 function _run_query($query)
 {
     $response = $this->sparqlservice->graph($query);
     if ($response->is_success()) {
         require_once MORIARTY_ARC_DIR . '/ARC2.php';
         $parser = ARC2::getRDFParser();
         $parser->parse(false, $response->body);
         $changeset = $this->revert_changes($parser->getSimpleIndex(0));
         $ser = ARC2::getRDFXMLSerializer();
         $response->body = $ser->getSerializedIndex($changeset);
     }
     return $response;
 }
Ejemplo n.º 2
0
 function graph($query)
 {
     require_once MORIARTY_ARC_DIR . '/ARC2.php';
     //$parser = ARC2::getRDFParser();
     $ser = ARC2::getRDFXMLSerializer();
     $body = false;
     $response = new HTTPResponse();
     //	if(stristr($query, 'DESCRIBE <#to_changeset>')){
     $r = new RollbackTest();
     $changes = $r->changes;
     $body = $ser->getSerializedIndex($changes);
     //	} else if(stristr($query, 'DESCRIBE ?cs ?statement')){
     // $r = new RollbackTest();
     // $changes  = $r->changes;
     // $body  = $ser->getSerializedIndex($changes);
     //	}
     $response->status_code = '200';
     $response->body = $body;
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * Convert an ARC triples array into RDF/XML
  * @param array $triples
  * @return string $rdfxml
  */
 function triplesToRDFXML($triples)
 {
     $ser = ARC2::getRDFXMLSerializer();
     // TODO: Choose format depending on user choice
     // Serialize into RDF/XML, since it will contain
     // all URIs in un-abbreviated form, so that they
     // can easily be replaced by search-and-replace
     $rdfxml = $ser->getSerializedTriples($triples);
     if ($ser->getErrors()) {
         die("ARC Serializer Error: " . $ser->getErrors());
     }
     return $rdfxml;
 }
Ejemplo n.º 4
0
$hash = sha1($ss . $ts);
$get = file_get_contents('http://www.slideshare.net/api/2/get_slideshow?' . '&slideshow_url=' . rawurlencode($url) . '&api_key=' . rawurlencode($api_key) . '&ts=' . rawurlencode($ts) . '&hash=' . rawurlencode($hash));
// Defns
$x = new SimpleXMLElement($get);
$type = 'avdoc';
$sl = array();
$sl[$url] = array();
$tags = array('id' => 'rdf:about', 'title' => 'dct:title', 'author' => array('name' => 'dct:creator'), 'summary' => 'bibo:abstract', 'link' => 'rdfs:seeAlso');
$types = array(0 => 'bibo:Article', 'bibo:AcademicArticle');
$ns = array('bibo' => 'http://purl.org/ontology/bibo/', 'dc' => 'http://purl.org/dc/elements/1.1/', 'dct' => 'http://purl.org/dc/terms/', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'foaf' => 'http://xmlns.com/foaf/0.1/');
// To add
$res = $x->xpath('/Slideshow/Title');
$sl[$url]['dct:title'] = (string) $res[0][0];
$label = (string) $res[0][0];
$res = $x->xpath('/Slideshow/ThumbnailURL');
$sl[$url]['foaf:img'] = (string) $res[0][0];
$res = $x->xpath('/Slideshow/Descripton');
$sl[$url]['dc:description'] = (string) $res[0][0];
$res = $x->xpath('/Slideshow/DownloadUrl');
$sl[$url]['rdfs:seeAlso'] = (string) $res[0][0];
$otherlinks = array();
$res = $x->xpath('/Slideshow/Username');
foreach ($res as $simpleobj) {
    $otherlinks[] = array('uri' => "bnode", 'rdf' => array(0 => array('pred' => "http://xmlns.com/foaf/0.1/name", 'obj' => (string) $simpleobj[0])), 'type' => 'person', 'rel' => 'http://purl.org/dc/terms/creator', 'inv' => false, 'shim' => "./shims/bnode.php");
}
include_once "../arc/ARC2.php";
$arcSerializerConf = array('ns' => $ns);
$serializer = ARC2::getRDFXMLSerializer($arcSerializerConf);
$si = $serializer->getSerializedIndex($sl);
$output = json_encode(array('label' => $label, 'uri' => $url, 'type' => $type, 'rdf' => array(0 => $si), 'sameas' => array(0 => $url), 'otherlinks' => $otherlinks));
echo $output;
Ejemplo n.º 5
0
 function getRDF($param = array())
 {
     /* { Comments
     		
     		$param format
     			array
     			(
     			'resources'	=> array ( 0 => 
     				array ( 
     					'type'	=> string ∈ taglistlist.keys ,
     					'uri'	=> string	
     					'rdf'	=> rdf to parse
     				)
     			)
     			'relations' => array ( 0 => 'Relation1', 'Relation2'... ) 
     																					
     			);
     			where uri = graphite_resource	
     		
     		}*/
     // Convinience
     $inputRes = $param['resources'];
     // Checks it's non-empty
     if (is_null($inputRes)) {
         die("No URI<br />");
     }
     // Creates Graphite
     $this->g = new Graphite($this->nsArr);
     // Adds RDFXML data to graphite
     foreach ($inputRes as $resource) {
         foreach ($resource['rdf'] as $rdfxml) {
             $this->g->addRDFXML("", $rdfxml);
         }
     }
     // Array that will be in an appropriate format for RDFXML serialization via ARC2
     $serializableList = array();
     // Array treated as a stack of all objects we are interested in.
     $tasks = array();
     // Populates the stack with all the entries fed into the script
     foreach ($inputRes as $inRes) {
         $tasks[] = array('uri' => $inRes['uri'], 'type' => $inRes['type']);
     }
     // Adds all special relations
     foreach ($param['relations'] as $relation) {
         // Adds each relation to the end result - they'll all be significant
         if (is_null($serializableList[$relation['sub']][$relation['pred']])) {
             $serializableList[$relation['sub']][$relation['pred']] = array();
         }
         $serializableList[$relation['sub']][$relation['pred']][] = $relation['obj'];
         // INFO: You have leveled up in skill: Associative arrays!
         // Adds each relationship to graphite, so it can reason over them
         $this->g->addTriple($relation['sub'], $relation['pred'], $relation['obj']);
     }
     // Runs 'till the stack is depleted
     while (($query = array_pop($tasks)) != NULL) {
         // query = current entry being worked on
         // 			$query = array_pop($tasks);
         // Loads the current query as a graphite resource
         $graphuri = $this->g->resource($query['uri']);
         // Loads 1 round of sameAs links
         $graphuri->loadSameAs();
         // Gets all relevant fields
         $ret = $this->getFields(array('uri' => $query['uri'], 'taglist' => $this->taglistlist[$query['type']]));
         //			print_r($ret);
         if (is_null($serializableList[$ret['uri']])) {
             $serializableList[$ret['uri']] = array();
         }
         $serializableList[$ret['uri']] = array_merge_recursive($serializableList[$ret['uri']], $ret['results']);
         //$serializableList = array_unique($serializableList, SORT_REGULAR);
         // Special handling based on type : eg adding all authors of a article to the stack
         switch ($query['type']) {
             case 'person':
                 break;
             case 'article':
                 // Now handled by the shims
                 //				foreach( $graphuri->all( "dct:creator" ) as $creator){
                 //					if (!is_null($creator->uri))
                 //						$tasks[] = array( 'type' => 'person', 'uri' => $creator->uri);
                 //				}
                 break;
             case 'avdoc':
                 break;
             case 'seminar':
                 break;
             case 'conference':
                 break;
             case 'default':
                 break;
         }
     }
     // Recursively calls array_unique on an hashtablearray
     $serializableList = $this->recursiveUnique($serializableList);
     // sets up the rdf serializer and serializes the RO just built.
     $arcSerializerConf = array('ns' => $this->nsArr);
     $serializer = ARC2::getRDFXMLSerializer($arcSerializerConf);
     $si = $serializer->getSerializedIndex($serializableList);
     // writes rdf to a file
     $file = "results.rdf";
     $fh = fopen($file, 'w+') or die("cant open file");
     fwrite($fh, $si);
     fclose($fh);
     // echos raw rdf
     if ($this->verbosity > 1) {
         echo htmlspecialchars($si);
     }
 }
Ejemplo n.º 6
0
 /**
  * getRdf get the full BIBO RDF serialization of the collection of entries
  * @param $format the serialization format
  * @throws Exception if PHP_ZOTERO_ENTRIES_ARC_PATH is not defined
  */
 public function getRdf($format = 'rdf/xml')
 {
     if (!defined('PHP_ZOTERO_ENTRIES_ARC_PATH')) {
         throw new Exception('PHP_ZOTERO_ENTRIES_ARC_PATH must be defined and valid to use RDF methods');
     }
     require_once PHP_ZOTERO_ENTRIES_ARC_PATH;
     switch ($format) {
         case 'rdf/xml':
             $ser = ARC2::getRDFXMLSerializer($this->arcConf);
             break;
         case 'rdf/json':
             $ser = ARC2::getRDFJsonSerializer($this->arcConf);
             break;
         case 'turtle':
             $ser = ARC2::getTurtleSerializer($this->arcConf);
             break;
         case 'ntriples':
             $ser = ARC2::getNTriplesSerializer($this->arcConf);
             break;
     }
     return $ser->getSerializedIndex($this->getArcIndex());
 }
Ejemplo n.º 7
0
<?php

//TODO: Given time, attempt to scrape html with assumption that there is no RDF/other useful metadata
$uri = $_REQUEST['URI'];
$uri = preg_replace("/^(?!http:\\/\\/)/", "http://", $uri);
$name = "Generic Web Resource";
$type = "none";
$sl = array();
$sl[$uri] = array();
include_once "../arc/ARC2.php";
$serializer = ARC2::getRDFXMLSerializer();
$si = $serializer->getSerializedIndex($sl);
$output = json_encode(array('label' => $name, 'uri' => $uri, 'type' => $type, 'rdf' => array(0 => $si), 'sameas' => array(0 => $uri), 'otherlinks' => null));
echo $output;
Ejemplo n.º 8
0
 public static function serializeRdf($data, $extension = 'rdf')
 {
     global $conf;
     global $lodspk;
     $ser;
     $dPointer;
     $docs = Utils::travelTree($data);
     require_once $conf['home'] . 'lib/arc2/ARC2.php';
     $parser = ARC2::getRDFParser();
     $triples = array();
     foreach ($docs as $d) {
         $parser->parse($conf['basedir'], $d);
         $t = $parser->getTriples();
         $triples = array_merge($triples, $t);
     }
     if ($lodspk['mirror_external_uris']) {
         global $uri;
         global $localUri;
         $t = array();
         $t['s'] = $localUri;
         $t['s_type'] = 'uri';
         $t['p'] = "http://www.w3.org/2002/07/owl#sameAs";
         $t['o'] = $uri;
         $t['o_type'] = 'uri';
         array_push($triples, $t);
         $t['p'] = "http://www.w3.org/2000/10/swap/pim/contact#preferredURI";
         array_push($triples, $t);
     }
     switch ($extension) {
         case 'ttl':
             $ser = ARC2::getTurtleSerializer();
             break;
         case 'nt':
             $ser = ARC2::getNTriplesSerializer();
             break;
         case 'json':
             $ser = ARC2::getRDFJSONSerializer();
             break;
         case 'rdf':
             $ser = ARC2::getRDFXMLSerializer();
             break;
         case 'html':
             return array("content" => $triples, "serialized" => false);
             break;
         default:
             $ser = null;
     }
     if ($ser != null) {
         $doc = $ser->getSerializedTriples($triples);
     } else {
         $doc = var_export($data, true);
     }
     return array("content" => $doc, "serialized" => true);
 }
Ejemplo n.º 9
0
    $resource->setProp('dcterms:title', trim($title));
    $meta = get_meta_data($contents);
    if (!empty($meta)) {
        $desc = '';
        foreach ($meta as $row) {
            if (empty($row[1])) {
                continue;
            }
            if ($row[1][0] == 'name' && $row[2][0] == 'description') {
                $desc = $row[3][0];
            }
        }
        if (empty($desc)) {
            //$desc = create_excerpt( strip_tags(getTextBetweenTags($contents, 'body')) );
        }
        $resource->setProp('dcterms:description', trim($desc));
    }
}
switch (strtolower($format)) {
    case 'xml':
        header("content-type: text/xml");
        $conf = array('ns' => $ns, 'serializer_prettyprint_container' => true);
        $ser = @ARC2::getRDFXMLSerializer($conf);
        $doc = @$ser->getSerializedIndex($resource->index);
        break;
    case 'json':
        $parser = @ARC2::getRDFParser();
        $doc = @$parser->toRDFJSON($resource->index);
        break;
}
echo $doc;
Ejemplo n.º 10
0
 public function actionSaveFile($ids = null)
 {
     $ids = explode(',', urldecode(Yii::app()->request->getPost('ids')));
     if ($ids === null) {
         $ids = array();
         for ($i = 0; $i < 20; $i++) {
             $ids[] = rand(0, 80000);
         }
     }
     $nodes = Node::model()->in('id', $ids)->findAll();
     $triples = array();
     foreach ($nodes as $node) {
         $triples[trim($node->title)] = $node->toTriplet();
     }
     require Yii::getPathOfAlias('ext.arc.ARC2') . '.php';
     $ns = array('foaf' => 'http://xmlns.com/foaf/0.1/', 'dc' => 'http://purl.org/dc/elements/1.1/');
     $conf = array('ns' => $ns);
     $ser = ARC2::getRDFXMLSerializer($conf);
     $doc = $ser->getSerializedIndex($triples);
     header("Pragma: no-cache");
     // required
     header('Content-type: application/force-download');
     header('Content-Disposition: attachment; filename="result.rdf"');
     echo $doc;
 }
Ejemplo n.º 11
0
function journo_emitRDFXML(&$j)
{
    global $_conf;
    $ser = ARC2::getRDFXMLSerializer($_conf);
    #    $triples = journo_asARC2Triples($j);
    #    $doc = $ser->getSerializedTriples($triples);
    $idx = journo_asARC2Index($j);
    $doc = $ser->getSerializedIndex($idx);
    print $doc;
}
Ejemplo n.º 12
0
 /**
  * getItemAsRdf returns the BIBO RDF for the entire Zotero Item
  * @param $format default 'rdf/xml' the rdf serialization to use
  * @return string the RDF serialization
  * @throw Exception if PHP_ZOTERO_ENTRIES_ARC_PATH is not defined
  */
 public function getItemAsRdf($format = 'rdf/xml')
 {
     if (!defined('PHP_ZOTERO_ENTRIES_ARC_PATH')) {
         throw new Exception('PHP_ZOTERO_ENTRIES_ARC_PATH must be defined and valid to use RDF methods');
     }
     if (!$this->arcIndex) {
         $this->setRdf();
     }
     switch ($format) {
         case 'rdf/xml':
             $ser = ARC2::getRDFXMLSerializer($this->arcConf);
             break;
         case 'rdf/json':
             $ser = ARC2::getRDFJsonSerializer($this->arcConf);
             break;
         case 'turtle':
             $ser = ARC2::getTurtleSerializer($this->arcConf);
             break;
         case 'ntriples':
             $ser = ARC2::getNTriplesSerializer($this->arcConf);
             break;
     }
     return $ser->getSerializedIndex(array($this->itemUri => $this->arcIndex[$this->itemUri]));
 }
Ejemplo n.º 13
0
 public function get_RDF($print = false)
 {
     $config = array('ns' => $this->namespaces);
     $ser = ARC2::getRDFXMLSerializer($config);
     $result = $this->store->query($this->format_namespaces() . "SELECT ?s ?p ?o WHERE { ?s ?p ?o }");
     $rdf = $ser->getSerializedTriples($result["result"]["rows"]);
     if ($print) {
         header("Content-type: " . $ser->content_header);
         print $rdf;
     } else {
         return $rdf;
     }
 }
Ejemplo n.º 14
0
 /**
  * Serialise the graph to RDF/XML
  * @return string the RDF/XML version of the graph
  */
 public function to_rdfxml()
 {
     /** @var \ARC2_RDFSerializer $serializer */
     $serializer = \ARC2::getRDFXMLSerializer(array('ns' => $this->_labeller->get_ns()));
     return $serializer->getSerializedIndex($this->_to_arc_index($this->_index));
 }
Ejemplo n.º 15
0
 /**
  * Outputs user's FOAF profile
  * @param unknown_type $params
  */
 function content_negociated_user_home(&$params)
 {
     $username = $params['username'];
     $accept = $params['accept'];
     if ($accept == 'application/rdf+xml') {
         $params['content_type'] = 'application/rdf+xml';
         $user_obj = user_get_object_by_name($username);
         $user_real_name = $user_obj->getRealName();
         $user_email = $user_obj->getEmail();
         $mbox = 'mailto:' . $user_email;
         $mbox_sha1sum = sha1($mbox);
         $projects = $user_obj->getGroups();
         sortProjectList($projects);
         $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user_obj);
         sortRoleList($roles);
         // Construct an ARC2_Resource containing the project's RDF (DOAP) description
         $ns = array('rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'foaf' => 'http://xmlns.com/foaf/0.1/', 'sioc' => 'http://rdfs.org/sioc/ns#', 'doap' => 'http://usefulinc.com/ns/doap#', 'dcterms' => 'http://purl.org/dc/terms/', 'planetforge' => 'http://coclico-project.org/ontology/planetforge#');
         $conf = array('ns' => $ns);
         // First, let's deal with the account
         $account_res = ARC2::getResource($conf);
         $account_uri = util_make_url_u($username, $user_obj->getID());
         $account_uri = rtrim($account_uri, '/');
         $person_uri = $account_uri . '#person';
         $account_res->setURI($account_uri);
         // $account_res->setRel('rdf:type', 'foaf:OnlineAccount');
         rdfutils_setPropToUri($account_res, 'rdf:type', 'foaf:OnlineAccount');
         rdfutils_setPropToUri($account_res, 'foaf:accountServiceHomepage', $account_uri . '/');
         $account_res->setProp('foaf:accountName', $username);
         rdfutils_setPropToUri($account_res, 'sioc:account_of', $person_uri);
         rdfutils_setPropToUri($account_res, 'foaf:accountProfilePage', $account_uri);
         $groups_index = array();
         $projects_index = array();
         $roles_index = array();
         $usergroups_uris = array();
         // see if there were any groups
         if (count($projects) >= 1) {
             foreach ($projects as $p) {
                 // TODO : report also private projects if authenticated, for instance through OAuth
                 if ($p->isPublic()) {
                     $project_link = util_make_link_g($p->getUnixName(), $p->getID(), $p->getPublicName());
                     $project_uri = util_make_url_g($p->getUnixName(), $p->getID());
                     // sioc:UserGroups for all members of a project are named after /projects/A_PROJECT/members/
                     $usergroup_uri = $project_uri . 'members/';
                     $role_names = array();
                     $usergroups_uris[] = $usergroup_uri;
                     $usergroup_res = ARC2::getResource($conf);
                     $usergroup_res->setURI($usergroup_uri);
                     rdfutils_setPropToUri($usergroup_res, 'rdf:type', 'sioc:UserGroup');
                     rdfutils_setPropToUri($usergroup_res, 'sioc:usergroup_of', $project_uri);
                     $roles_uris = array();
                     foreach ($roles as $r) {
                         if ($r instanceof RoleExplicit && $r->getHomeProject() != NULL && $r->getHomeProject()->getID() == $p->getID()) {
                             $role_names[$r->getID()] = $r->getName();
                             $role_uri = $project_uri . 'roles/' . $r->getID();
                             $roles_uris[] = $role_uri;
                         }
                     }
                     rdfutils_setPropToUri($usergroup_res, 'planetforge:group_has_function', $roles_uris);
                     $project_res = ARC2::getResource($conf);
                     $project_res->setURI($project_uri);
                     rdfutils_setPropToUri($project_res, 'rdf:type', 'planetforge:ForgeProject');
                     $project_res->setProp('doap:name', $p->getUnixName());
                     $projects_index = ARC2::getMergedIndex($projects_index, $project_res->index);
                     foreach ($role_names as $id => $name) {
                         $role_res = ARC2::getResource($conf);
                         $role_res->setURI($project_uri . 'roles/' . $id);
                         rdfutils_setPropToUri($role_res, 'rdf:type', 'sioc:Role');
                         $role_res->setProp('sioc:name', $name);
                         $roles_index = ARC2::getMergedIndex($roles_index, $role_res->index);
                     }
                     $groups_index = ARC2::getMergedIndex($groups_index, $usergroup_res->index);
                 }
             }
         }
         // end if groups
         rdfutils_setPropToUri($account_res, 'sioc:member_of', $usergroups_uris);
         // next, deal with the person
         $person_res = ARC2::getResource($conf);
         $person_res->setURI($person_uri);
         rdfutils_setPropToUri($person_res, 'rdf:type', 'foaf:Person');
         $person_res->setProp('foaf:name', $user_real_name);
         rdfutils_setPropToUri($person_res, 'foaf:holdsAccount', $account_uri);
         $person_res->setProp('foaf:mbox_sha1sum', $mbox_sha1sum);
         // merge the two sets of triples
         $merged_index = ARC2::getMergedIndex($account_res->index, $person_res->index);
         $merged_index = ARC2::getMergedIndex($merged_index, $groups_index);
         $merged_index = ARC2::getMergedIndex($merged_index, $projects_index);
         $merged_index = ARC2::getMergedIndex($merged_index, $roles_index);
         $conf = array('ns' => $ns, 'serializer_type_nodes' => true);
         $ser = ARC2::getRDFXMLSerializer($conf);
         /* Serialize a resource index */
         $doc = $ser->getSerializedIndex($merged_index);
         $params['content'] = $doc . "\n";
     }
 }
Ejemplo n.º 16
0
 public function printGraph()
 {
     /* Serializer instantiation */
     $ser = \ARC2::getRDFXMLSerializer();
     foreach ($this->objectToPrint as $class => $prop) {
         $triples = $prop->getTriples();
     }
     /* Serialize a triples array */
     echo $ser->getSerializedTriples($triples);
 }
Ejemplo n.º 17
0
 /**
  * Outputs the public projects list as ADMS.SW for /projects
  * @param unknown_type $params
  */
 function content_negociated_projects_list(&$params)
 {
     $accept = $params['accept'];
     if ($accept == 'application/rdf+xml') {
         // We will return RDF+XML
         $params['content_type'] = 'application/rdf+xml';
         // Construct an ARC2_Resource containing the project's RDF (DOAP) description
         $ns = array('rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'doap' => 'http://usefulinc.com/ns/doap#', 'dcterms' => 'http://purl.org/dc/terms/', 'admssw' => 'http://purl.org/adms/sw/', 'adms' => 'http://www.w3.org/ns/adms#');
         $conf = array('ns' => $ns);
         $res = ARC2::getResource($conf);
         $res->setURI(util_make_url("/projects"));
         // $res->setRel('rdf:type', 'doap:Project');
         rdfutils_setPropToUri($res, 'rdf:type', 'admssw:SoftwareRepository');
         //$res->setProp('doap:name', $projectname);
         $res->setProp('adms:accessURL', util_make_url("/softwaremap/"));
         $forge_name = forge_get_config('forge_name');
         $ff = new FusionForge();
         $res->setProp('dcterms:description', 'Public projects in the ' . $ff->software_name . ' Software Map on ' . $forge_name);
         $res->setProp('rdfs:label', $forge_name . ' public projects');
         $res->setProp('adms:supportedSchema', 'ADMS.SW v1.0');
         // same as for trove's full list
         $projects = get_public_active_projects_asc();
         $proj_uris = array();
         foreach ($projects as $row_grp) {
             $proj_uri = util_make_url_g(strtolower($row_grp['unix_group_name']), $row_grp['group_id']);
             $proj_uris[] = $proj_uri;
         }
         if (count($proj_uris)) {
             rdfutils_setPropToUri($res, 'dcterms:hasPart', $proj_uris);
         }
         $conf = array('ns' => $ns, 'serializer_type_nodes' => true);
         $ser = ARC2::getRDFXMLSerializer($conf);
         /* Serialize a resource index */
         $doc = $ser->getSerializedIndex($res->index);
         $params['content'] = $doc . "\n";
     }
 }
Ejemplo n.º 18
0
 function toRDFXML()
 {
     $index = $this->toIndex();
     $ser = ARC2::getRDFXMLSerializer(array('ns' => $this->ns));
     return $ser->getSerializedIndex($index);
 }
Ejemplo n.º 19
0
$triples = array_merge($triples, $newtriples, $log);
if (@$_REQUEST['dummy'] === "true") {
    echo "@prefix nif: <http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#>.\n\t@prefix dbo: <http://dbpedia.org/ontology/>.\n\t@prefix owl: <http://www.w3.org/2002/07/owl#>.\n\t@prefix itsrdf: <http://www.w3.org/2005/11/its/rdf#>.\n\t@prefix prefix: <" . $prefix . "> .\n\t<" . $prefix . "char=0,39> \n\t\ta nif:RFC5147String , nif:Context ;\n\t\tnif:beginIndex \"0\";\n\t\tnif:endIndex \"39\";\n\t\tnif:isString \"\"\"My favorite actress is Natalie Portman.\"\"\" . \n\t\t\n\t<" . $prefix . "char=23,39> \n\t\ta nif:RFC5147String , nif:NamedEntity ;\n\t\tnif:beginIndex \"23\";\n\t\tnif:endIndex \"38\";\n\t\tnif:referenceContext <" . $prefix . "char=0,39>  ;\n\t\titsrdf:taIdentRef <http://dbpedia.org/resource/Natalie_Portman> ;\n\t\titsrdf:taClassRef <http://nerd.eurecom.fr/ontology#Person> , dbo:Actor, dbo:Artist, dbo:Person, dbo:Agent, owl:Thing ;\n\t\tnif:taMsClassRef dbo:Actor .\n\t\t\n\t<http://dbpedia.org/resource/Natalie_Portman> a <http://nerd.eurecom.fr/ontology#Person> , dbo:Actor, dbo:Artist, dbo:Person, dbo:Agent, owl:Thing .\n\t<http://nerd.eurecom.fr/ontology#Person>  <http://nerd.eurecom.fr/ontology#isCoreClass> \"1\" . ";
    die;
}
/****
 * Out
 * ****/
$ns = array('p' => trim($prefix), 'nif' => NIF, 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'owl' => 'http://www.w3.org/2002/07/owl#', 'rlog' => 'http://persistence.uni-leipzig.org/nlp2rdf/ontologies/rlog#', 'dc' => 'http://purl.org/dc/elements/1.1/');
$ser = null;
switch ($outformat) {
    case "turtle":
        $ser = ARC2::getTurtleSerializer(array('ns' => $ns));
        break;
    case "rdfxml":
        $ser = ARC2::getRDFXMLSerializer(array('ns' => $ns));
        break;
    case "json":
        $ser = ARC2::getRDFJSONSerializer(array('ns' => $ns));
        break;
    case "ntriples":
        $ser = ARC2::getNTriplesSerializer(array('ns' => $ns));
        break;
    default:
        $ser = ARC2::getTurtleSerializer(array('ns' => $ns));
        break;
}
$output = "";
if ($outformat == "turtle") {
    $output = $ser->getSerializedTriples($triples);
    header("Content-Type: text/turtle");
Ejemplo n.º 20
0
 /**
  * Serialise the graph to RDF/XML
  * @return string the RDF/XML version of the graph
  */
 function to_rdfxml()
 {
     $this->update_prefix_mappings();
     $serializer = ARC2::getRDFXMLSerializer(array('ns' => $this->_labeller->get_ns()));
     return $serializer->getSerializedIndex($this->_to_arc_index($this->_index));
 }
Ejemplo n.º 21
0
 function getRDFXMLDescribeResultDoc($r)
 {
     $this->setHeader('content-type', 'Content-Type: application/rdf+xml');
     $index = $r['result'];
     $ser = ARC2::getRDFXMLSerializer($this->a);
     $dur = $r['query_time'];
     return $ser->getSerializedIndex($index) . "\n" . '<!-- query time: ' . $dur . ' -->';
 }
Ejemplo n.º 22
0
<?php

$uri = $_REQUEST['URI'];
$BD = $_REQUEST['BD'];
if ($BD == null) {
    die("no data");
}
include_once "../arc/ARC2.php";
$name = "Nameless BNode";
$rdfa = $BD['rdf'];
$sl = array();
$sl[$uri] = array();
foreach ($rdfa as $trip) {
    $sl[$uri][$trip['pred']] = $trip['obj'];
    if ($trip['pred'] = "dct:creator") {
        $name = $trip['obj'];
    }
}
$type = $BD['type'];
$serializer = ARC2::getRDFXMLSerializer(array('ns' => array('foaf' => 'http://xmlns.com/foaf/0.1/')));
$si = $serializer->getSerializedIndex($sl);
$output = json_encode(array('label' => $name, 'uri' => $uri, 'type' => $type, 'rdf' => array(0 => $si), 'sameas' => array(0 => $uri), 'otherlinks' => null));
echo $output;
//	$sl[$uri]['type'] = "bnode";
 /**
  *  method that converts the information into the correct format in rdf
  *
  *  currently only does single export
  *
  *  @dev:
  *    data structure is
  *    array(
  *      array(
  *        url => array(
  *          property => array(
  *            'value' => value,
  *            'type' => 'literal'
  *          )
  *          property_2 => array(
  *            'value' => value,
  *            'type' => 'literal'
  *          )
  *        )
  *      )
  *    );
  *
  *  @see
  *    http://web.archive.org/web/20100801084904/http://n2.talis.com/wiki/RDF_PHP_Specification
  */
 public function convert()
 {
     //variables
     global $base_url;
     $rdf_term_array = $this->get_rdf_list('rdf_term');
     $output = '';
     $available_rdf = $this->get_rdf_list();
     $biblio_list = $this->biblio_node;
     $rdf = array();
     //allow the rdf to use these namespaces
     $ns = $this->_get_namespaces();
     //does for each bibliography within the obj
     foreach ($biblio_list as $nid => $node) {
         $path = url('node/' . $nid);
         foreach ($available_rdf as $node_term => $rdf_term) {
             //breaks the loop if the term is empty or the node field is empty
             if (empty($rdf_term) || empty($node[$node_term])) {
                 continue;
             }
             //ensures that the node field is set
             if (isset($node[$node_term])) {
                 //sanitize the data before it comes out.
                 $value = str_replace(PHP_EOL, '', $node[$node_term]);
                 $processed_value = $this->field_value_handler($value, $node_term);
                 //only continue if the value is processed and not empty
                 if (!empty($processed_value)) {
                     $rdf[$path][$rdf_term] = array(array('value' => $processed_value, 'type' => 'literal'));
                 }
             }
         }
     }
     $conf = array('ns' => $ns);
     $ser = ARC2::getRDFXMLSerializer($conf);
     $doc = $ser->getSerializedIndex($rdf);
     $this->output .= $doc;
 }
Ejemplo n.º 24
0
 function toRDFXML()
 {
     $ser = ARC2::getRDFXMLSerializer();
     return $ser->getSerializedIndex($this->__index);
 }
Ejemplo n.º 25
0
 function exportStoreXml()
 {
     //Récupération des préfixes
     $ns = array();
     $tmpArray = explode("\n", $this->prefix);
     foreach ($tmpArray as $prefix) {
         if (preg_match('`PREFIX (.+): \\<(.+)\\>`', $prefix, $out)) {
             $ns[$out[1]] = $out[2];
         }
     }
     $conf = array('ns' => $ns);
     $ser = ARC2::getRDFXMLSerializer($conf);
     $all = $this->store->query("SELECT ?s ?p ?o WHERE { ?s ?p ?o }");
     $rdfxml2 = $ser->getSerializedTriples($all["result"]['rows']);
     return $rdfxml2;
 }
Ejemplo n.º 26
0
 /**
  * Serialize an index into either RDF-XML or RDF-JSON
  */
 public function serialize($index, $prefix = '', $format = 'xml')
 {
     if (!empty($prefix)) {
         $this->ns['scalar'] = $prefix;
     }
     switch (strtolower($format)) {
         case 'json':
             $parser = @ARC2::getRDFParser();
             $doc = @$parser->toRDFJSON($index);
             break;
         case 'turtle':
             $parser = @ARC2::getRDFParser();
             $doc = @$parser->toTurtle($index, $this->ns);
             break;
         default:
             // xml
             $conf = array('ns' => $this->ns, 'serializer_prettyprint_container' => true);
             // , 'serializer_type_nodes' => true
             $ser = @ARC2::getRDFXMLSerializer($conf);
             $doc = @$ser->getSerializedIndex($index);
     }
     return $doc;
 }
Ejemplo n.º 27
0
 /**
  * @return string
  */
 public function toRDFXML()
 {
     /** @var \ARC2_RDFSerializer $ser */
     $ser = \ARC2::getRDFXMLSerializer();
     return $ser->getSerializedIndex($this->_index);
 }
Ejemplo n.º 28
0
 /**
  * Outputs project's DOAP profile
  * @param unknown_type $params
  */
 function content_negociated_project_home(&$params)
 {
     $projectname = $params['groupname'];
     $accept = $params['accept'];
     $group_id = $params['group_id'];
     if ($accept == 'application/rdf+xml') {
         // connect to FusionForge internals
         $pm = ProjectManager::instance();
         $project = $pm->getProject($group_id);
         $project_shortdesc = $project->getPublicName();
         $project_description = $project->getDescription();
         $tags_list = NULL;
         if (forge_get_config('use_project_tags')) {
             $group = group_get_object($group_id);
             $tags_list = $group->getTags();
         }
         // We will return RDF+XML
         $params['content_type'] = 'application/rdf+xml';
         // Construct an ARC2_Resource containing the project's RDF (DOAP) description
         $ns = array('rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'doap' => 'http://usefulinc.com/ns/doap#', 'dcterms' => 'http://purl.org/dc/terms/', 'schema' => 'http://schema.org/');
         $conf = array('ns' => $ns);
         $res = ARC2::getResource($conf);
         $res->setURI(util_make_url_g($projectname, $group_id));
         // $res->setRel('rdf:type', 'doap:Project');
         rdfutils_setPropToUri($res, 'rdf:type', 'doap:Project');
         $res->setProp('doap:name', $projectname);
         $res->setProp('doap:shortdesc', $project_shortdesc);
         if ($project_description) {
             $res->setProp('doap:description', $project_description);
         }
         $res->setProp('doap:homepage', $project->getHomePage());
         $tags = array();
         if ($tags_list) {
             $tags = split(', ', $tags_list);
             $res->setProp('dcterms:subject', $tags);
         }
         // Now, we need to collect complementary RDF descriptiosn of the project via other plugins
         // invoke the 'project_rdf_metadata' hook so as to complement the RDF description
         $hook_params = array();
         $hook_params['prefixes'] = array();
         foreach ($ns as $prefix => $url) {
             $hook_params['prefixes'][$url] = $prefix;
         }
         $hook_params['group'] = $group_id;
         // pass the resource in case it could be useful (read-only in principle)
         $hook_params['in_Resource'] = $res;
         $hook_params['out_Resources'] = array();
         plugin_hook_by_reference('project_rdf_metadata', $hook_params);
         // add new prefixes to the list
         foreach ($hook_params['prefixes'] as $url => $prefix) {
             if (!isset($ns[$prefix])) {
                 $ns[$prefix] = $url;
             }
         }
         // merge the two sets of triples
         $merged_index = $res->index;
         foreach ($hook_params['out_Resources'] as $out_res) {
             $merged_index = ARC2::getMergedIndex($merged_index, $out_res->index);
         }
         $conf = array('ns' => $ns, 'serializer_type_nodes' => true);
         $ser = ARC2::getRDFXMLSerializer($conf);
         /* Serialize a resource index */
         $doc = $ser->getSerializedIndex($merged_index);
         $params['content'] = $doc . "\n";
     }
 }