getMergedIndex() 정적인 공개 메소드

static public getMergedIndex ( )
예제 #1
0
 /**
  * toIndex
  * @return array
  */
 public function toIndex()
 {
     $index = array();
     foreach ($this->resources as $res) {
         $index = ARC2::getMergedIndex($index, $res->index);
     }
     return $index;
 }
예제 #2
0
 /**
  * function  mergeResource
  * @param PMJ_ResourcePlus $res
  */
 public function mergeResource($res)
 {
     if ($res - uri != $this->uri) {
         $this->addError('Resource uris must match');
         return false;
     }
     $this->index = ARC2::getMergedIndex($res->index, $this->index);
 }
예제 #3
0
 /**
  * mergeResource
  * @param PMJ_ResourcePlus $res
  */
 public function mergeResource($res)
 {
     if ($res->uri != $this->uri) {
         $this->addError('Resource uris must match');
         return false;
     }
     $this->index = ARC2::getMergedIndex($res->index, $this->index);
     foreach ($res->ns as $prefix => $uri) {
         $this->addPrefix($prefix, $uri);
     }
 }
예제 #4
0
 function fetchData($uri = '')
 {
     if (!$uri) {
         $uri = $this->uri;
     }
     if (!$uri) {
         return 0;
     }
     if (in_array($uri, $this->fetched)) {
         return 0;
     }
     $this->index[$uri] = array();
     if ($this->store) {
         $index = $this->store->query('DESCRIBE <' . $uri . '>', 'raw');
     } else {
         $index = $this->toIndex($uri);
     }
     $this->index = ARC2::getMergedIndex($this->index, $index);
     $this->fetched[] = $uri;
 }
예제 #5
0
 function addIndex($index)
 {
     $this->index = ARC2::getMergedIndex($this->index, $index);
     return $this;
 }
예제 #6
0
 function insert($doc, $g = 'http://localhost/')
 {
     $index = $this->v($g, array(), $this->data);
     $this->data[$g] = ARC2::getMergedIndex($index, $this->toIndex($doc));
 }
예제 #7
0
 function extractItem($els)
 {
     list($props, $sub_index) = $this->extractProps($els, 'item');
     $uri = $props[$this->rss . 'link'][0]['value'];
     return ARC2::getMergedIndex(array($uri => $props), $sub_index);
 }
 function getUpdatedIndex($old_index, $q)
 {
     if (!preg_match('/^\\s*(INSERT|DELETE)\\s*(INTO|FROM)?\\s*(.*)$/is', $q, $m)) {
         return 0;
     }
     $qt = strtolower($m[1]);
     $g = $this->getTargetGraph();
     /* inject a target graph, if necessary */
     if (!$m[2]) {
         $q = strtoupper($qt) . ($qt == 'insert' ? ' INTO ' : ' FROM') . ' <' . $g . '> ' . $m[3];
     }
     /* parse the query */
     $this->writeLog($q);
     ARC2::inc('SPARQLPlusParser');
     $p =& new ARC2_SPARQLPlusParser($this->a, $this);
     $p->parse($q);
     $infos = $p->getQueryInfos();
     /* errors? */
     if ($errors = $this->getErrors()) {
         $this->setHeader('http', 'HTTP/1.1 400 Bad Request');
         $this->setHeader('content-type', 'Content-type: text/plain; charset=utf-8');
         $this->result = join("\n", $errors);
         return 0;
     }
     $q_index = ARC2::getSimpleIndex($infos['query']['construct_triples'], 0);
     if ($qt == 'insert') {
         return ARC2::getMergedIndex($old_index, $q_index);
     } elseif ($qt == 'delete') {
         return ARC2::getCleanedIndex($old_index, $q_index);
     }
 }
예제 #9
0
 public function getLinkedData($uri, $alias = null)
 {
     // $testuri = ''; // may defined by sub class for debug checks
     $this->addLogMessage('  --> request data: ' . $uri . ' (' . $alias . ')');
     $indexedData = null;
     // must be an uri b/c blanknode without data makes no sense
     // but better to check
     if (substr($uri, 0, 1) != '_' && array_search($uri, $this->ignoreUris) === false && array_search($uri, $this->requestsUris) === false) {
         $this->requestsUris[] = $uri;
         // test cache for indexed data of uri
         if (false === ($indexedData = $this->getCache(array('name' => $uri, 'space' => $this->cache_space_prefix . 'Data')))) {
             // no data cached - request data from uri
             // use uri without local anchors (they should be included)
             $uriAbs = $uri;
             if (strpos($uri, '#') !== false) {
                 $uriAbs = substr($uri, 0, strpos($uri, '#'));
             }
             // try to get linked data, only if max LinkedData level
             // and requests not reached
             $linkedData = null;
             // check cache for data
             if (false === ($linkedData = $this->getCache(array('name' => $uriAbs, 'space' => $this->cache_space_prefix . 'DataAbs')))) {
                 // if (is_array($linkedData) && count($linkedData) == 0) die($uriAbs);
                 if ($this->level < $this->levelMax && $this->requests < $this->requestsMax) {
                     // parse feed
                     $dataParser = ARC2::getRDFParser(array('reader_timeout' => $this->requestsTimeout, 'http_user_agent_header' => $this->user_agent_string, 'keep_time_limit' => true));
                     /*
                                             if (!isset($dataParser->reader)) {
                                               ARC2::inc('Reader');
                                               $dataParser->reader = & new ARC2_Reader($dataParser->a, $dataParser);
                                             }
                                             $dataParser->reader->timeout = $this->requestsTimeout;
                                             //*/
                     //$dataParser->parse($uriAbs, null, 0, $this->requestsTimeout);
                     $dataParser->parse($uriAbs, null);
                     //print_r(array($uriAbs=>$dataParser->reader->getResponseHeaders()));
                     $this->requests++;
                     if (is_object($dataParser)) {
                         $linkedData = $dataParser->getSimpleIndex(0);
                         // save cache
                         $this->addLogMessage('  --> save to cache: ' . $uriAbs);
                         $this->saveCache(array('data' => $linkedData, 'name' => $uriAbs, 'space' => $this->cache_space_prefix . 'DataAbs', 'time' => true));
                     }
                     unset($dataParser);
                 }
                 $this->addLogMessage('  --> read: ' . $uriAbs . ' (' . count($linkedData) . ' elements)');
             } else {
                 $this->addLogMessage('  --> read from cache: ' . $uriAbs . ' (' . count($linkedData) . ' elements)');
             }
             // check outdated cache as fallback
             // better old data than no data :)
             if (!$linkedData) {
                 if ($linkedData = $this->getCache(array('name' => $uriAbs, 'space' => $this->cache_space_prefix . 'DataAbs', 'time' => -1))) {
                     $this->addLogMessage('  --> read from OUTDATED cache: ' . $uriAbs . ' (' . count($linkedData) . ' elements)');
                 }
             }
             if (isset($testuri) && $uriAbs == $testuri) {
                 die('<pre>' . print_r($linkedData, true) . '</pre>');
             }
             if ($linkedData) {
                 // check linkedData, only keep uri and blanknodes which are referenced by resource
                 if (isset($linkedData[$uri])) {
                     //$indexedData[$uri] = $linkedData[$uri];
                     $indexedData = $linkedData;
                     if (isset($testuri) && $uri == $testuri) {
                         die('<pre>' . print_r($indexedData, true) . '</pre>');
                     }
                     /* TODO: reduceMemoryUsage()
                        $indexedData[$uri] = $linkedData[$uri];
                        if ($this->environment['FP_config']['LinkedData']['useBnodes'] === true)
                        {
                            // keep bnodes in results
                            $bnodes = $this->listBnodes($indexedData[$uri]);
                            foreach ($bnodes as $key)
                            {
                                $indexedData[$key] = $linkedData[$key];
                            }
                        }
                        else
                        {
                            // let bnodes out of result set
                            $indexedData[$uri] = $this->deleteBnodes($indexedData[$uri]);
                        }
                        // TODO: get all other relevant resources (referenced in any way over x steps)
                        unset($bnodes);
                        */
                     $this->addLogMessage('  --> use: ' . $uri . ' (' . count($indexedData[$uri]) . ' elements)');
                     if (isset($testuri) && $uri == $testuri) {
                         die('<pre>' . print_r($indexedData, true) . '</pre>');
                     }
                     unset($linkedData);
                     // save cache for indexed data of uri
                     $this->saveCache(array('data' => $indexedData, 'name' => $uri, 'space' => $this->cache_space_prefix . 'Data', 'time' => true));
                 }
             }
         } else {
             $this->addLogMessage('  --> read from cache: ' . $uri . ' (' . count($indexedData[$uri]) . ' elements)');
         }
     }
     // end of if (substr($uri, 0 , 1) != '_')
     if (isset($testuri) && $uri == $testuri) {
         die('<pre>' . print_r($indexedData, true) . '</pre>');
     }
     if ($indexedData) {
         // return Foafpress_resource
         $ARC2TO = clone $this;
         // check alias (e.g. for owl:sameAs)
         if ($alias) {
             $indexedData[$alias] = $indexedData[$uri];
             unset($indexedData[$uri]);
         }
         if (isset($testuri) && $uri == $testuri) {
             die('<pre>' . print_r($indexedData, true) . '</pre>');
         }
         // merge data
         $this->resource->index = ARC2::getMergedIndex($this->resource->index, $indexedData);
         if (isset($testuri) && $uri == $testuri) {
             die('<pre>' . print_r($this->resource->index, true) . '</pre>');
         }
         unset($indexedData);
         $ARC2TO->uri = $uri;
         $ARC2TO->updateNamespacePrefix();
         if ($alias) {
             //TODO: $ARC2TO->includeSameAs($alias);
             $ARC2TO->uri = $alias;
         } else {
             $ARC2TO->level++;
         }
         $this->addLogMessage('now: count ' . count($this->resource->index) . ' -- memory ' . intval(memory_get_usage(true) / 1024) . 'kb');
         return $ARC2TO;
     } else {
         $this->addLogMessage('now: count ' . count($this->resource->index) . ' -- memory ' . intval(memory_get_usage(true) / 1024) . 'kb');
         // no data or error, only return requested uri
         return $uri;
     }
 }
 /**
  * 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";
     }
 }
예제 #11
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";
     }
 }