Exemple #1
0
 function parseDataRDF()
 {
     $items = array();
     if (!isset($this->data['@graph'])) {
         return $items;
     }
     foreach ($this->data['@graph'] as $item) {
         $obj = new SKOSConcept($item['@id']);
         foreach ($item as $key => $value) {
             if (!$this->isRelation($key)) {
                 $obj->addProperty($key, $value);
             }
         }
         $items[$item['@id']] = $obj;
     }
     foreach ($this->data['@graph'] as $item) {
         $obj = $items[$item['@id']];
         foreach ($item as $key => $value) {
             if ($this->isRelation($key)) {
                 if (is_array($value)) {
                     foreach ($value as $relation) {
                         if (array_key_exists($relation, $items)) {
                             $obj->addRelation($key, $items[$relation]);
                         }
                     }
                 } else {
                     if (array_key_exists($value, $items)) {
                         $obj->addRelation($key, $items[$value]);
                     }
                 }
             }
         }
     }
     return $items;
 }
 function visit(SKOSConcept $concept)
 {
     $relations = $concept->getRelations();
     if (count($relations) != 0) {
         $arr = array();
         foreach ($relations as $key => $relation) {
             foreach ($relation as $object) {
                 $item = array();
                 $item["type"] = $key;
                 switch (true) {
                     case strpos($key, "broader"):
                         $item["urlsource"] = $concept->getProperty("page");
                         $item["urltarget"] = $object->getProperty("page");
                         $item["source"] = ucfirst(str_replace("uri:TZW-3A", "", $concept->getName()));
                         $item["target"] = ucfirst(str_replace("uri:TZW-3A", "", $object->getName()));
                         break;
                     case strpos($key, "narrower"):
                         $item["urlsource"] = $object->getProperty("page");
                         $item["urltarget"] = $concept->getProperty("page");
                         $item["source"] = ucfirst(str_replace("uri:TZW-3A", "", $object->getName()));
                         $item["target"] = ucfirst(str_replace("uri:TZW-3A", "", $concept->getName()));
                         break;
                     default:
                         return;
                         break;
                 }
                 array_push($arr, $item);
             }
         }
         $this->data = array_merge($this->data, $arr);
     }
 }
 function parseDataRDF()
 {
     $items = array();
     if (!isset($this->data['@graph'])) {
         return $items;
     }
     //first create all objects; without relations
     //these items are described in the array of the result-set
     foreach ($this->data['@graph'] as $item) {
         $obj = new SKOSConcept($item['@id']);
         foreach ($item as $key => $value) {
             if (!$this->isRelation($key)) {
                 $obj->addProperty($key, $value);
             }
         }
         $items[$item['@id']] = $obj;
     }
     //now add relations. Only add relation if item is created by previous loop
     foreach ($this->data['@graph'] as $item) {
         $obj = $items[$item['@id']];
         foreach ($item as $key => $value) {
             if ($this->isRelation($key)) {
                 if (is_array($value)) {
                     foreach ($value as $relation) {
                         if (array_key_exists($relation, $items)) {
                             //object is created
                             $obj->addRelation($key, $items[$relation]);
                         }
                     }
                 } else {
                     if (array_key_exists($value, $items)) {
                         $obj->addRelation($key, $items[$value]);
                     }
                 }
             }
         }
     }
     return $items;
 }
Exemple #4
0
 public function testVisit()
 {
     // Arrange
     $a = new NodeMapVisitor();
     $b = new SKOSConcept("TestConcept");
     $b->addRelation("Eigenschap-3ASkosem-3Abroader", new SKOSConcept("TestConceptA"));
     $b->addRelation("Eigenschap-3ASkosem-3Abroader", new SKOSConcept("TestConceptB"));
     $b->addRelation("Eigenschap-3ASkosem-3Anarrower", new SKOSConcept("TestConceptC"));
     $b->addRelation("Eigenschap-3ASkosem-3Abroader", new SKOSConcept("TestConceptD"));
     $b->addRelation("Eigenschap-3ASkosem-3Anarrower", new SKOSConcept("TestConceptE"));
     // Assert
     // There are 5 relations added.
     $this->assertEquals(5, count($a->visit($b)));
 }
 function visit(SKOSConcept $concept)
 {
     //first add node-info to nodedata
     $arr = array();
     $item = array();
     //$item["type"] = "node";
     $item["name"] = ucfirst(str_replace("uri:TZW:", "", $concept->getName()));
     $item["distance"] = $concept->distance;
     foreach ($concept->getProperties() as $key => $property) {
         $item[$key] = $property;
     }
     $item["url"] = $concept->getProperty("page");
     $source = $item["name"];
     $this->nodedata[$source] = $item;
     //now add relation-info to data
     $relations = $concept->getRelations();
     if (count($relations) != 0) {
         foreach ($relations as $key => $relation) {
             foreach ($relation as $object) {
                 if (!strpos($key, "narrower")) {
                     //omit narrower because always broader equivalnet present
                     $item = array();
                     $item["type"] = $key;
                     switch (true) {
                         case strpos($key, "broader"):
                             $item["urlsource"] = $concept->getProperty("page");
                             $item["urltarget"] = $object->getProperty("page");
                             $item["source"] = ucfirst(str_replace("uri:TZW:", "", $concept->getName()));
                             $item["target"] = ucfirst(str_replace("uri:TZW:", "", $object->getName()));
                             break;
                         case strpos($key, "narrower"):
                             //TODO omit next lines; never reached, because narrower relations are omitted
                             $item["urlsource"] = $object->getProperty("page");
                             $item["urltarget"] = $concept->getProperty("page");
                             $item["source"] = ucfirst(str_replace("uri:TZW:", "", $object->getName()));
                             $item["target"] = ucfirst(str_replace("uri:TZW:", "", $concept->getName()));
                             break;
                         case strpos($key, "related"):
                             $item["urlsource"] = $object->getProperty("page");
                             $item["urltarget"] = $concept->getProperty("page");
                             $item["source"] = ucfirst(str_replace("uri:TZW:", "", $object->getName()));
                             $item["target"] = ucfirst(str_replace("uri:TZW:", "", $concept->getName()));
                             break;
                             //narrower is toegevoegd maar functioneert niet;Anton: volgens mij nu wel!
                         //narrower is toegevoegd maar functioneert niet;Anton: volgens mij nu wel!
                         default:
                             return;
                             break;
                     }
                     array_push($arr, $item);
                 }
             }
         }
         $this->data = array_merge($this->data, $arr);
     }
 }