/** * Recursive function to extract properties. * * @param string $uri * URI of schema type. * * @return array|null * Array of properties of the type and all parent types. */ private function getProperties($uri) { $resource = array("type" => "uri", "value" => $uri); $property_list = $this->graph->resourcesMatching("http://schema.org/domainIncludes", $resource); $options = array(); foreach ($property_list as $value) { // Omit deprecated properties. if ($value->get("schema:supersededBy")) { continue; } $options[$value->shorten()] = $value->get("rdfs:label")->getValue(); } $parents = $this->graph->all($uri, "rdfs:subClassOf"); foreach ($parents as $value) { $options += $this->getProperties($value->getUri()); } return $options; }
/** * @param EasyRdf_Graph $po_graph * @param string $ps_base_node * @param string $ps_node_uri * @param int $pn_limit * @param bool $pb_recursive * @return array */ static function getListOfRelatedGraphs($po_graph, $ps_base_node, $ps_node_uri, $pn_limit, $pb_recursive = false) { $vs_cache_key = md5(serialize(func_get_args())); if (CompositeCache::contains($vs_cache_key, 'GettyLinkedDataRelatedGraphs')) { return CompositeCache::fetch($vs_cache_key, 'GettyLinkedDataRelatedGraphs'); } $va_related_nodes = $po_graph->all($ps_base_node, $ps_node_uri); $va_pull_graphs = array(); if (is_array($va_related_nodes)) { $vn_i = 0; foreach ($va_related_nodes as $o_related_node) { $vs_pull_uri = (string) $o_related_node; if (!($o_pull_graph = self::getURIAsRDFGraph($vs_pull_uri))) { return false; } $va_pull_graphs[$vs_pull_uri] = $o_pull_graph; if (++$vn_i >= $pn_limit) { break; } } } if ($pb_recursive) { $va_sub_pull_graphs = array(); foreach ($va_pull_graphs as $vs_pull_uri => $o_pull_graph) { // avoid circular references if (isset($va_pull_graphs[$vs_pull_uri]) || isset($va_sub_pull_graphs[$vs_pull_uri])) { continue; } $va_sub_pull_graphs = array_merge($va_sub_pull_graphs, self::getListOfRelatedGraphs($o_pull_graph, $vs_pull_uri, $ps_node_uri, $pn_limit, true)); } $va_pull_graphs = array_merge($va_pull_graphs, $va_sub_pull_graphs); } CompositeCache::save($vs_cache_key, $va_pull_graphs, 'GettyLinkedDataRelatedGraphs'); return $va_pull_graphs; }