/** * transform * * @param KVDthes_Term $thes * @return EasyRdf_Resource */ public function transform(KVDthes_Term $thes) { if ($thes->isNull()) { throw new InvalidArgumentException('Een nullobject kan niet geserialiseerd worden!'); } if ($thes->getType()->getId() != 'HR') { throw new InvalidArgumentException('Om een thesaurus te kunnen serialiseren hebben we de HR term nodig.'); } $term = $thes; $thes = $term->getThesaurus(); $type = 'skos:ConceptScheme'; try { $uri = $this->genThesaurusUri($thes); $res = $this->graph->resource($uri, $type); } catch (InvalidArgumentException $e) { $res = $this->graph->newBNode($type); } $res->add('skos:prefLabel', $thes->getNaam()); $res->add('dc:title', $thes->getNaam()); $res->add('dc:language', $thes->getLanguage()); if ($term->hasNTRelations()) { $term->sortRelations(KVDthes_TermSorter::SORT_ID); $rels = $term->getNarrowerTerms(); foreach ($rels as $rel) { $tt = $this->graph->resource($this->genTermUri($rel)); $res->add('skos:hasTopConcept', $tt); } } return $res; }
/** * leaveComposite * * @param KVDthes_Term $node * @return true */ public function leaveComposite(KVDthes_Term $node) { $this->visitation[$node->getId()]['right'] = ++$this->count; if ($this->visitation[$node->getId()]['depth'] != $this->depth--) { throw new Exception('Depth should be equal'); } return true; }
/** * visit * * @param KVDthes_Term $node * @return void */ public function visit(KVDthes_Term $node) { $this->term = $this->dom->createElement('term'); $this->term->appendChild($this->createTermId($node->getId())); $this->term->appendChild($this->createTermName($node->getTerm())); $this->term->appendChild($this->createTermType($node->getType()->getId())); $this->term->appendChild($this->createTermLanguage('nl-BE')); return true; }
/** * visit * * @param KVDthes_Term $node * @return void */ public function visit(KVDthes_Term $node) { if ($this->result == null) { if ($node->getTerm() == $this->searchTerm) { $this->result = $node; return false; } } return true; }
/** * visit * * @param KVDthes_Term $node * @return void */ public function visit(KVDthes_Term $node) { if ($node->hasRelations(KVDthes_Relation::REL_NT)) { $this->currItem = new KVDthes_DojoDatastoreComposite($node->getId(), $node->getQualifiedTerm(), $this->depth, $node->getType()->getId()); } else { $this->currItem = new KVDthes_DojoDatastoreTerm($node->getId(), $node->getQualifiedTerm(), $this->depth, $node->getType()->getId()); } $this->result->addItem($this->currItem); return true; }
/** * leaveComposite * * @return boolean */ public function leaveComposite(KVDthes_Term $node) { if ($node->hasNTRelations()) { $this->depth--; $this->result .= $this->pad() . "</ul>\n"; $this->depth--; } $this->result .= $this->pad() . "</li>\n"; return true; }
public function testNotes() { $this->object->setLoadState(KVDthes_Term::LS_NOTES); $this->object->setLoadState(KVDthes_Term::LS_REL); $this->object->setLoadState(KVDthes_Term::LS_MATCH); $this->object->setScopeNote('SN'); $this->object->setHistoryNote('HN'); $this->object->setIndexingNote('IN'); $this->object->setSourceNote('SoN'); $this->assertEquals('SN', $this->object->getScopeNote()); $this->assertEquals('HN', $this->object->getHistoryNote()); $this->assertEquals('IN', $this->object->getIndexingNote()); $this->assertEquals('SoN', $this->object->getSourceNote()); }
/** * renderTerm * * @param KVDthes_Term $term * @return string */ public function renderTerm(KVDthes_Term $term) { return '<p>' . $term->getQualifiedTerm() . '</p>'; }
/** * insertRelations * * @param KVDthes_Term $term * @return void */ private function insertRelations(KVDthes_Term $term) { $sql = sprintf('INSERT INTO %s.relation ( thesaurus_id, id_from, relation_type, id_to) VALUES ( %s, ?, ?, ?)', $this->parameters['schema'], $this->parameters['thesaurus_id']); if (count($term->getRelations()) > 0) { $stmt = $this->conn->prepare($sql); $stmt->bindValue(1, $term->getId(), PDO::PARAM_INT); foreach ($term->getRelations() as $rel) { $stmt->bindValue(2, $rel->getType(), PDO::PARAM_STR); $stmt->bindValue(3, $rel->getTerm()->getId(), PDO::PARAM_INT); $stmt->execute(); } } }
/** * findNodeForTerm * * @param KVDthes_Term $termObj * @return DOMNode */ private function findNodeForTerm(KVDthes_Term $termObj) { $list = $this->xp->query('/Zthes/term[termId="' . $termObj->getId() . '"]'); if ($list->length == 0) { throw new RuntimeException('Unable to find term node with id ' . $termObj->getId() . '!'); } return $list->item(0); }
/** * visit * * @param KVDthes_Term $node * @return void */ public function visit(KVDthes_Term $node) { $this->from = $node->getId(); return true; }
/** * visitRelation * * @param KVDthes_Relation $rel * @return boolean */ public function visitRelation(KVDthes_Relation $rel) { $this->result .= $this->currItem->getId() . ' -> ' . $rel->getTerm()->getId() . ";\n"; return true; }
public function __toString() { return 'Relation ' . $this->type . ' ' . $this->term->getOmschrijving(); }
/** * visit * * @param KVDthes_Term $node * @return void */ public function visit(KVDthes_Term $node) { $this->result .= $this->depth . $this->pad() . $node->getQualifiedTerm() . "\n"; return true; }
/** * setBroaderTerm * * @since 10 apr 2009 * @param KVDthes_Term $term * @return void */ public function setBroaderTerm(KVDthes_Term $term) { if (!$this->isPreferredTerm() && !$term->isNull()) { throw new LogicException('You are trying to set a Broader Term for a term which is not a preferred term.'); } $this->checkRelations(); $it = $this->relations->getBTIterator(); $it->rewind(); if ($it->valid()) { $current = $it->current(); $this->removeRelation($current); } // Indien de term een NullObject is wissen we de bestaande BT relation maar vervangen we die niet door iets nieuws. if (!$term->isNull()) { $this->addRelation(new KVDthes_Relation(KVDthes_Relation::REL_BT, $term)); } $this->markDirty(); }
/** * sortRelations * * @return void */ protected function sortRelations(KVDthes_Term $node) { if ($this->relationsSortOrder > KVDthes_TermSorter::SORT_UNSORTED) { $node->sortRelations($this->relationsSortOrder); } }
/** * leaveComposite * * @return boolean */ public function leaveComposite(KVDthes_Term $node) { if ($node->hasNTRelations()) { $this->depth--; $this->result .= $this->pad() . $this->renderer->getCompositeEnd() . "\n"; $this->depth--; } $this->result .= $this->pad() . $this->renderer->getVisitEnd() . "\n"; return true; }
/** * transform * * @param KVDthes_term $thes * @return EasyRdf_Resource */ public function transform(KVDthes_Term $term) { if (!$term->isPreferredTerm()) { $term = $term->getPreferredTerm(); } if ($term->getType()->getId() == 'NL') { $type = 'skos:Collection'; } else { $type = 'skos:Concept'; } try { $uri = $this->genTermUri($term); $res = $this->graph->resource($uri, $type); } catch (InvalidArgumentException $e) { $res = $this->graph->newBNode($type); } $thes = $term->getThesaurus(); try { $thes_uri = $this->genThesaurusUri($thes); $thres = $this->graph->resource($thes_uri); $res->add('skos:inScheme', $thres); } catch (InvalidArgumentException $e) { // Kennen geen uri voor de thesaurus. } $res->add('skos:prefLabel', $term->getTerm()); if ($term->hasRelations(KVDthes_Relation::REL_UF)) { $rels = $term->getNonPreferredTerms(); foreach ($rels as $rel) { $res->add('skos:altLabel', $rel->getTerm()); } } if ($term->hasRelations(KVDthes_Relation::REL_NT)) { $rels = $term->getNarrowerTerms(); foreach ($rels as $rel) { if ($rel->getType()->getId() == 'NL') { $nts = $rel->getNarrowerTerms(); } else { $nts = new KVDthes_DomainObjectCollection(array($rel)); } foreach ($nts as $nt) { if ($term->getType()->getId() == 'NL') { $rel_uri = 'skos:member'; } else { $rel_uri = 'skos:narrower'; } $uri = $this->genTermUri($nt); $ntres = $this->graph->resource($uri); $res->add($rel_uri, $ntres); } } } if ($term->getType()->getId() != 'NL' && $term->hasRelations(KVDthes_Relation::REL_BT)) { $bt = $term->getBroaderTerm(); while ($bt->getType()->getId() == 'NL') { $bt = $bt->getBroaderTerm(); } $uri = $this->genTermUri($bt); $bt = $this->graph->resource($uri); $res->add('skos:broader', $bt); } if ($term->hasRelations(KVDthes_Relation::REL_RT)) { $rels = $term->getRelatedTerms(); foreach ($rels as $rel) { $uri = $this->genTermUri($rel); $rt = $this->graph->resource($uri); $res->add('skos:related', $rt); } } if ($term->getScopeNote() != '') { $res->add('skos:definition', $term->getScopeNote()); } if ($term->getIndexingNote() != '') { $res->add('skos:scopeNote', $term->getIndexingNote()); } if ($term->getHistoryNote() != '') { $res->add('skos:historyNote', $term->getHistoryNote()); } if ($term->getSourceNote() != '') { $res->add('dc:source', $term->getSourceNote()); } return $res; }