Exemplo n.º 1
0
 public function visitTerm(DOMElement $element)
 {
     $raw_value = $element->getAttribute(self::TERM_VALUE_ATTR);
     $object = Term::parse($raw_value);
     $term = ['raw_value' => $raw_value, 'value' => $object->getValue(), 'context' => $object->getContext(), 'path' => $this->getCurrentPathAsString(), 'lang' => $element->getAttribute(self::TERM_LANG_ATTR), 'id' => $element->getAttribute(self::TERM_ID_ATTR)];
     call_user_func($this->termCallback, $term);
 }
Exemplo n.º 2
0
 public function save()
 {
     $this->ensureDocumentLoaded();
     foreach ($this->new_candidates as $raw_value => $field) {
         $term = Term::parse($raw_value);
         $norm_value = StringUtils::asciiLowerFold($term->getValue());
         $norm_context = StringUtils::asciiLowerFold($term->getContext());
         $element = $this->createElement($raw_value, $norm_value, $norm_context);
         $container = $this->findOrCreateFieldNode($field);
         $this->insertElement($container, $element);
     }
     $this->databox->saveCterms($this->document);
 }
Exemplo n.º 3
0
 private function hydrate(array &$record, array $fields, array $index_fields)
 {
     if (!isset($record['databox_id'])) {
         throw new Exception('Expected a record with the "databox_id" key set.');
     }
     $values = array();
     $terms = array();
     $filters = array();
     $field_names = array();
     foreach ($fields as $name => $root_concepts) {
         // Loop through all values to prepare bulk query
         $field_values = \igorw\get_in($record, explode('.', $index_fields[$name]));
         if ($field_values !== null) {
             // Concepts are databox's specific, but when no root concepts are
             // given we need to make sure we only match in the right databox.
             $filter = $root_concepts ? Filter::childOfConcepts($record['databox_id'], $root_concepts) : Filter::byDatabox($record['databox_id']);
             foreach ($field_values as $value) {
                 $values[] = $value;
                 $terms[] = Term::parse($value);
                 $filters[] = $filter;
                 $field_names[] = $name;
             }
         }
     }
     $bulk = $this->thesaurus->findConceptsBulk($terms, null, $filters, true);
     foreach ($bulk as $offset => $item_concepts) {
         if ($item_concepts && is_array($item_concepts) && count($item_concepts) > 0) {
             $name = $field_names[$offset];
             foreach ($item_concepts as $concept) {
                 $record['concept_path'][$name][] = $concept->getPath();
             }
         } else {
             $this->candidate_terms->insert($field_names[$offset], $values[$offset]);
         }
     }
 }
Exemplo n.º 4
0
 public function __toString()
 {
     return sprintf('<term:%s>', Term::dump($this));
 }