guid = $guid; $this->type = $type; } function add_term($guid, $subject, $relevance = 0.0) { $this->terms[$guid] = new CalaisTerm($guid, $subject, $relevance); } function add_relevance($guid, $relevance) { if ($this->has_guid($guid)) { $this->terms[$guid]->relevance = $relevance; } } function add_geo($guid, $resolvedName, $lat, $lon) { if ($this->has_guid($guid)) { $term = &$this->terms[$guid]; $term->resolvedName = $resolvedName; $term->lat = $lat; $term->lon = $lon; } } /** * Set the resolved (normalized) name for the guid. * * @param $guid * The global identifier of a term * @param $resolvedName * The normalized value of a term */ function set_resolved_name($guid, $resolvedName) { $term = &$this->terms[$guid]; if(isset($term)) { $term->resolvedName = $resolvedName; } } function has_guid($guid) { return array_key_exists($guid, $this->terms); } function get_term_by_value($value) { foreach ($this->terms as $term) { if ($term->value == $value) { return $term; } } return FALSE; } function has_term_value($value) { return $this->get_term_by_value($value) !== FALSE; } function remove_term_by_name($name) { $filter = new TermFilter($name); $this->terms = array_filter($this->terms, array($filter, 'filter')); } function readable_type() { return calais_api_make_readable($this->type); } } class TermFilter { public $filter; function __construct($filter) { $this->filter = $filter; } function filter($term) { return $term->value != $this->filter; } } /** * This class represents a specific term result from the Calais Web Service. */ class CalaisTerm { public $guid; public $value; public $relevance; // Extra data use for geo terms public $resolvedName; public $lat; public $lon; /** * */ function __construct($guid, $value, $relevance = 0.0) { $this->guid = $guid; $this->value = $value; $this->relevance = $relevance; } }