Example #1
0
 /**
  * Add $triples about a given $subject to Mongo. Only $triples with subject matching $subject will be added, others will be ignored.
  * Make them quads with a $context
  * @param $subject
  * @param array $triples
  * @param string $storeName
  * @param string $podName
  * @param null $context
  * @param null $allowableTypes
  */
 public function loadTriplesAbout($subject, array $triples, $storeName, $podName, $context = null, $allowableTypes = null)
 {
     $context = $context == null ? Config::getInstance()->getDefaultContextAlias() : $this->labeller->uri_to_alias($context);
     if (array_key_exists($podName, $this->collections)) {
         $collection = $this->collections[$podName];
     } else {
         $m = new Client(Config::getInstance()->getConnStr($storeName), [], ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']]);
         $collection = $m->selectDatabase($storeName)->selectCollection($podName);
     }
     $graph = new MongoGraph();
     foreach ($triples as $triple) {
         $triple = rtrim($triple);
         $parts = preg_split("/\\s/", $triple);
         $subject = trim($parts[0], '><');
         $predicate = trim($parts[1], '><');
         $object = $this->extract_object($parts);
         if ($this->isUri($object)) {
             $graph->add_resource_triple($subject, $predicate, $object);
         } else {
             $graph->add_literal_triple($subject, $predicate, $object);
         }
     }
     if ($allowableTypes != null && is_array($allowableTypes)) {
         $types = $graph->get_resource_triple_values($subject, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
         if ($types == null || empty($types)) {
             return;
         } else {
             foreach ($types as $type) {
                 if (in_array($type, $allowableTypes)) {
                     $this->saveCBD($subject, $graph, $collection, $context);
                     return;
                 }
             }
             return;
         }
     }
     $this->saveCBD($subject, $graph, $collection, $context);
 }