public function __construct() { $this->mysqli =& $GLOBALS['mysqli_connection']; if ($GLOBALS['ENV_NAME'] == 'production' && environment_defined('slave')) { $this->mysqli_slave = load_mysql_environment('slave'); } else { $this->mysqli_slave =& $this->mysqli; } $this->sparql_client = SparqlClient::connection(); $this->published_id = TranslatedResourceStatus::find_or_create_by_label('Published')->id; $this->trusted_id = Vetted::trusted()->id; $this->unknown_id = Vetted::unknown()->id; $this->untrusted_id = Vetted::untrusted()->id; $this->visible_id = Visibility::visible()->id; $this->invisible_id = Visibility::invisible()->id; $this->master_curator_id = CuratorLevel::master_curator()->id; $this->full_curator_id = CuratorLevel::full_curator()->id; $this->assistant_curator_id = CuratorLevel::assistant_curator()->id; $this->curator_ids = CuratorLevel::curator_ids(); $this->data_object_scope = ChangeableObjectType::data_object_scope(); $this->worms_content_partner_id = ContentPartner::find_or_create_by_full_name('World Register of Marine Species')->id; $this->col_hierarchy_id = Hierarchy::find_or_create_by_label('Species 2000 & ITIS Catalogue of Life: Annual Checklist 2011')->id; $this->latest_harvest_event_ids(); $this->worms_latest_harvest_event_id(); }
private function add_string_types($taxon_id, $label, $value) { $m = new \eol_schema\MeasurementOrFact(); $occurrence = $this->add_occurrence($taxon_id, $label); $m->occurrenceID = $occurrence->occurrenceID; if (in_array($label, array("Prey", "Predator", "Pollen", "Visits", "Distribution"))) { $m->measurementOfTaxon = 'true'; } if ($label == "Occurrence ID") { $m->measurementType = "http://rs.tdwg.org/dwc/terms/occurrenceID"; } elseif ($label == "Distribution") { $m->measurementType = "http://rs.tdwg.org/ontology/voc/SPMInfoItems#Distribution"; } else { $m->measurementType = "http://hymenoptera.org/" . SparqlClient::to_underscore($label); } $m->measurementValue = $value; $m->contributor = 'Catalog of Hymenoptera in America North of Mexico'; $this->archive_builder->write_object_to_file($m); }
private function add_string_types($rec, $label, $value, $measurementType, $family) { $taxon_id = (string) $rec["taxon_id"]; $object_id = (string) $rec["object_id"]; $m = new \eol_schema\MeasurementOrFact(); $occurrence = $this->add_occurrence($taxon_id, $object_id); $m->occurrenceID = $occurrence->occurrenceID; $m->measurementOfTaxon = 'true'; $m->source = @$rec["source"]; if ($val = $measurementType) { $m->measurementType = $val; } else { $m->measurementType = "http://ggbn.org/" . SparqlClient::to_underscore($label); } $m->measurementValue = (string) $value; if (!isset($this->measurement_ids[$m->occurrenceID])) { $this->archive_builder->write_object_to_file($m); $this->measurement_ids[$m->occurrenceID] = ''; } }
private function prepare_turtle($row, $row_class_name, $resource_uri, $entry_uri) { $row_type = $row_class_name::ROW_TYPE; $primary_key = @self::field_decode($row[$row_class_name::PRIMARY_KEY]); $graph_name = $this->harvest_event->resource->virtuoso_graph_name(); // # TODO: taxon id of the partner will not be globally unique // # may this is a reason we will need to do represent the data in a custom way if ($primary_key) { $node_uri = $graph_name . "/" . $row_class_name::GRAPH_NAME . "/" . SparqlClient::to_underscore($primary_key); } else { $node_uri = $graph_name . "/" . $row_class_name::GRAPH_NAME . "/" . md5(serialize($row)); } $turtle = "<{$node_uri}> a <{$row_type}>"; $simple_turtle = ""; foreach ($row as $key => $value) { $value = @self::field_decode($value); if ($value && preg_match("/^http:\\/\\//", $key, $arr)) { if ($key == $row_class_name::PRIMARY_KEY) { continue; } if ($key == "http://rs.tdwg.org/dwc/terms/taxonID") { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($graph_name . "/taxa/" . SparqlClient::to_underscore($value)) . "\n"; if ($row_type == 'http://rs.tdwg.org/dwc/terms/Occurrence') { $this->occurrence_taxon_mapping[$primary_key] = @self::field_decode($value); } } elseif ($key == "http://eol.org/schema/targetTaxonID") { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($graph_name . "/taxa/" . SparqlClient::to_underscore($value)) . "\n"; if ($row_type == 'http://rs.tdwg.org/dwc/terms/targetOccurrenceID') { $this->occurrence_taxon_mapping[$primary_key] = @self::field_decode($value); } } elseif ($key == "http://rs.tdwg.org/dwc/terms/eventID") { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($graph_name . "/events/" . SparqlClient::to_underscore($value)) . "\n"; } elseif ($key == "http://rs.tdwg.org/dwc/terms/occurrenceID" || $key == "http://eol.org/schema/targetOccurrenceID") { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($graph_name . "/occurrences/" . SparqlClient::to_underscore($value)) . "\n"; if ($key == "http://rs.tdwg.org/dwc/terms/occurrenceID" && ($row_type == "http://rs.tdwg.org/dwc/terms/MeasurementOrFact" || $row_type == 'http://eol.org/schema/Association')) { $occurrence_id = $value; } elseif ($row_type == 'http://eol.org/schema/Association' && $key == "http://eol.org/schema/targetOccurrenceID") { $object = $value; } } elseif ($key == "http://eol.org/schema/associationID") { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($graph_name . "/associations/" . SparqlClient::to_underscore($value)) . "\n"; } elseif ($key == "http://eol.org/schema/parentMeasurementID") { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($graph_name . "/measurements/" . SparqlClient::to_underscore($value)) . "\n"; } elseif ($key == "http://eol.org/schema/reference/referenceID") { $reference_ids = self::get_foreign_keys_from_row($row, 'http://eol.org/schema/reference/referenceID'); foreach ($reference_ids as $reference_id) { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($graph_name . "/references/" . SparqlClient::to_underscore($reference_id)) . "\n"; } } elseif ($row_type == "http://rs.tdwg.org/dwc/terms/MeasurementOrFact" && $key == "http://rs.tdwg.org/dwc/terms/measurementType") { $predicate = $value; $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($value) . "\n"; } elseif ($row_type == "http://eol.org/schema/Association" && $key == "http://eol.org/schema/associationType") { $predicate = $value; $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($value) . "\n"; } elseif ($row_type == "http://rs.tdwg.org/dwc/terms/MeasurementOrFact" && $key == "http://rs.tdwg.org/dwc/terms/measurementValue") { $object = $value; $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($value) . "\n"; } elseif ($row_type == "http://rs.tdwg.org/dwc/terms/MeasurementOrFact" && $key == "http://rs.tdwg.org/dwc/terms/measurementUnit") { $unit_of_measure = $value; $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($value) . "\n"; } else { $turtle .= "; " . SparqlClient::enclose_value($key) . " " . SparqlClient::enclose_value($value) . "\n"; } } } if ($row_type == "http://rs.tdwg.org/dwc/terms/MeasurementOrFact" || $row_type == "http://eol.org/schema/Association") { if (isset($predicate) && isset($object)) { $trait_id = md5(serialize($row)); $trait_uri = "{$resource_uri}/traits/{$trait_id}"; $simple_turtle = "{$trait_uri} a eol:trait ;\n"; $simple_turtle .= " eol:predicate {$predicate} ;\n"; $simple_turtle .= " eol:recognized_as {$entry_uri} ;\n"; $simple_turtle .= " eol:value {$object} ;\n"; $simple_turtle .= " eol:source {$resource_uri} .\n"; if (isset($unit_of_measure)) { $simple_turtle .= " eol:units {$unit_of_measure} .\n"; } $simple_turtle .= "{$entry_uri} {$predicate} {$trait_uri} .\n"; } // prepare data point uri attributes $data_point_uri = array("uri" => $node_uri, "created_at" => 'NOW()', "updated_at" => 'NOW()', "resource_id" => $this->harvest_event->resource->id); if (isset($predicate)) { $data_point_uri["predicate"] = $predicate; } if (isset($object)) { $data_point_uri["object"] = $object; } if (isset($unit_of_measure)) { $data_point_uri["unit_of_measure"] = $unit_of_measure; } if (isset($occurrence_id)) { $data_point_uri["occurrence_id"] = $occurrence_id; } } else { $data_point_uri = NULL; } return array($turtle, $data_point_uri, $simple_turtle); }
private function add_string_types($line_data, $taxon) { $string_types = array('Biogeographic Regions', 'Aquatic Biomes', 'Wetlands', 'Other Habitat Features', 'Primary Diet', 'Animal Foods', 'Plant Foods', 'Other Foods'); foreach ($string_types as $label) { if ($v = trim($line_data[$this->column_indices[$label]])) { $values = explode(";", $v); foreach ($values as $value) { $value = trim($value); $this_label = $label; $m = new \eol_schema\MeasurementOrFact(); $m->measurementOfTaxon = 'true'; if ($this_label == 'Biogeographic Regions') { $qualification = null; if (preg_match("/^(.+) :: (.+)\$/", $value, $arr)) { $value = $arr[1]; $qualification = $arr[2]; } $this_label = trim("{$qualification} range"); } elseif ($this_label == 'Primary Diet') { if (preg_match("/ :: (.+)\$/", $value, $arr)) { $value = $arr[1]; } } print_r($taxon); print "\n value = [{$value}]"; exit; // print "\n [$taxon->taxonID] [$value]"; $occurrence = $this->add_occurrence($taxon, $value); $m->occurrenceID = $occurrence->occurrenceID; $m->measurementType = "http://adw.org/" . SparqlClient::to_underscore($this_label); $m->measurementValue = "http://adw.org/" . SparqlClient::to_underscore($value); $this->archive_builder->write_object_to_file($m); } } } }
private function get_distributions($taxon_id, $sciname) { $xml = self::create_cache("distribution", $taxon_id); $xml = simplexml_load_string($xml); $lines = array(); foreach ($xml->Distribution as $rec) { if (!isset($rec->Location->CountryName)) { continue; } $line = trim($rec->Location->CountryName) . trim($rec->Location->RegionName) . trim($rec->Location->UpperName); if (in_array($line, $lines)) { continue; } $lines[] = $line; $citation = trim($rec->Reference->FullCitation); $ref_url = TROPICOS_DOMAIN . "/Reference/" . trim($rec->Reference->ReferenceId); // $agents = array(); // $agents[] = array("role" => "source", "homepage" => "http://www.tropicos.org", "fullName" => "Tropicos"); // $agent_ids = self::create_agents($agents); $text_id = $rec->Location->LocationID; $region = ""; if ($RegionName = trim($rec->Location->RegionName)) { $region .= $RegionName; } if ($CountryName = trim($rec->Location->CountryName)) { $region .= " - " . $CountryName; } if ($UpperName = trim($rec->Location->UpperName)) { $region .= " - " . $UpperName; } self::add_string_types($taxon_id, $text_id, "Distribution", $region, "http://rs.tdwg.org/ontology/voc/SPMInfoItems#Distribution", true); self::add_string_types($taxon_id, $text_id, "Taxon", $sciname, "http://rs.tdwg.org/dwc/terms/scientificName"); self::add_string_types($taxon_id, $text_id, "Country", trim($rec->Location->CountryName), "http://rs.tdwg.org/dwc/terms/country"); self::add_string_types($taxon_id, $text_id, "Continent", trim($rec->Location->RegionName), "http://rs.tdwg.org/dwc/terms/continent"); if ($upper_name = @$rec->Location->UpperName) { self::add_string_types($taxon_id, $text_id, "Upper name", $upper_name, "http://tropicos.org/" . SparqlClient::to_underscore("Upper name")); } } // $title = "Localities documented in Tropicos sources"; // $subject = "http://rs.tdwg.org/ontology/voc/SPMInfoItems#Distribution"; // $license = "http://creativecommons.org/licenses/by-nc-sa/3.0/"; }
private function add_string_types($measurementOfTaxon, $rec, $label, $value, $mtype, $reference_ids = array()) { $taxon_id = $rec["schema_taxon_id"]; $catnum = $rec["catnum"]; $m = new \eol_schema\MeasurementOrFact(); $occurrence = $this->add_occurrence($taxon_id, $catnum); $m->occurrenceID = $occurrence->occurrenceID; if ($mtype) { $m->measurementType = $mtype; } else { $m->measurementType = "http://domain.org/" . SparqlClient::to_underscore($label); } // currently won't pass here $m->measurementValue = $value; if ($val = $measurementOfTaxon) { $m->measurementOfTaxon = $val; $m->source = $rec["source"]; if ($reference_ids) { $m->referenceID = implode("; ", $reference_ids); } // $m->measurementRemarks = ''; $m->contributor = ''; $m->measurementMethod = ''; } $this->archive_builder->write_object_to_file($m); }
private function add_string_types($measurementOfTaxon, $rec, $label, $value, $mtype, $measurementRemarks = null) { $taxon_id = $rec["taxon_id"]; $catnum = $rec["catnum"]; $m = new \eol_schema\MeasurementOrFact(); $occurrence = $this->add_occurrence($taxon_id, $catnum); $m->occurrenceID = $occurrence->occurrenceID; if ($mtype) { $m->measurementType = $mtype; } else { $m->measurementType = "http://feis.org/" . SparqlClient::to_underscore($label); } // currently won't pass here $m->measurementValue = $value; if ($val = $measurementOfTaxon) { $m->measurementOfTaxon = $val; } if ($measurementOfTaxon) { $m->source = $rec["source"]; $m->measurementRemarks = $measurementRemarks; // not used... $m->contributor, $m->measurementMethod } $this->archive_builder->write_object_to_file($m); }
private function add_associations($line_data) { $source_taxon_id = trim($line_data[$this->column_indices['my active taxon id']]); $target_taxon_id = trim($line_data[$this->column_indices['my passive taxon id']]); $relationship = trim($line_data[$this->column_indices['active relation']]); if ($source_taxon_id && $target_taxon_id && $relationship) { $m = new \eol_schema\Association(); if (!$this->taxon_occurrences[$source_taxon_id]) { return; } if (!$this->taxon_occurrences[$target_taxon_id]) { return; } $m->occurrenceID = $this->taxon_occurrences[$source_taxon_id]->occurrenceID; $m->associationType = "http://bioinfo.org/" . SparqlClient::to_underscore($relationship); $m->targetOccurrenceID = $this->taxon_occurrences[$target_taxon_id]->occurrenceID; $this->archive_builder->write_object_to_file($m); } }
private function add_string_types($measurementOfTaxon, $rec, $label, $value, $mtype, $measurementRemarks = null) { echo "\n [{$label}]:[{$value}]\n"; $taxon_id = $rec["taxon_id"]; $catnum = $rec["catnum"]; $m = new \eol_schema\MeasurementOrFact(); $occurrence = $this->add_occurrence($taxon_id, $catnum); $m->occurrenceID = $occurrence->occurrenceID; if ($mtype) { $m->measurementType = $mtype; } else { $m->measurementType = "http://iucn.org/" . SparqlClient::to_underscore($label); } $m->measurementValue = $value; if ($val = $measurementOfTaxon) { $m->measurementOfTaxon = $val; } if ($measurementOfTaxon) { $m->source = $rec["source"]; $m->measurementRemarks = $measurementRemarks; // $m->contributor = ''; // $m->measurementMethod = ''; } $this->archive_builder->write_object_to_file($m); }