You are here

function ARC_simple_model::init in Taxonomy import/export via XML 5

Same name and namespace in other branches
  1. 5.2 arc/ARC_simple_model.php \ARC_simple_model::init()
  2. 6.2 arc/ARC_simple_model.php \ARC_simple_model::init()
  3. 6 arc/ARC_simple_model.php \ARC_simple_model::init()
1 call to ARC_simple_model::init()
ARC_simple_model::ARC_simple_model in arc/ARC_simple_model.php

File

arc/ARC_simple_model.php, line 83

Class

ARC_simple_model

Code

function init() {
  $triples =& $this->triples;

  /* reference */
  $resources = array();

  /* resources */
  $resource_indices = array();

  /* resource_index */
  $typed_resources = array();

  /* key=class uri */
  for ($i = 0, $i_max = count($triples); $i < $i_max; $i++) {
    $cur_t = $triples[$i];

    /* s,p,o vars */
    $s = $cur_t["s"];
    $s_type = $s["type"];
    $s_val = $s_type == "uri" ? $s["uri"] : $s["bnode_id"];
    $s_val = $s_type == "uri" ? $this
      ->get_abbr_val($s_val) : $s_val;
    $p_full = $cur_t["p"];
    $p = $this
      ->get_abbr_val($p_full);
    $o = $cur_t["o"];
    $o_type = $o["type"];
    $o_val = $o_type == "uri" ? $o["uri"] : $o["bnode_id"];
    $o_val = $o_type == "literal" ? $o["val"] : $o_val;
    $o_val = $o_type == "uri" ? $this
      ->get_abbr_val($o_val) : $o_val;
    $o_val = strpos(utf8_decode(str_replace("?", "", $o_val)), "?") === false ? utf8_decode($o_val) : $o_val;
    $o_dt = $o_type == "literal" && $o["dt"] ? $o["dt"] : "";
    $o_lang = $o_type == "literal" && $o["lang"] ? $o["lang"] : "";

    /* s */
    if (!isset($resource_indices[$s_val])) {

      /* new entry */
      $cur_resource_index = count($resources);
      $resources[$cur_resource_index] = array(
        "val" => $s_val,
        "type" => $s_type,
      );
      $resource_indices[$s_val] = $cur_resource_index;
    }
    else {
      $cur_resource_index = $resource_indices[$s_val];
    }

    /* props */
    if (!isset($resources[$cur_resource_index]["props"])) {
      $resources[$cur_resource_index]["props"] = array();
    }
    $props =& $resources[$cur_resource_index]["props"];

    /* props[$p] */
    if (!isset($props[$p])) {
      $props[$p] = array();
    }
    $props[$p][] = array(
      "val" => $o_val,
      "type" => $o_type,
      "dt" => $o_dt,
      "lang" => $o_lang,
    );

    /* typed r */
    if ($p_full == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") {
      if (!isset($typed_resources[$o_val])) {
        $typed_resources[$o_val] = array();
      }
      $typed_resources[$o_val][] =& $resources[$cur_resource_index];
    }
  }
  $this->resources = $resources;
  $this->resource_indices = $resource_indices;
  $this->typed_resources = $typed_resources;
  return true;
}