001package org.gbif.dwc.terms;
002
003import java.util.ArrayList;
004import java.util.List;
005
006/**
007 * All Darwin Core terms with namespace http://rs.tdwg.org/dwc/terms/ as an 
008 * enumeration with alternative term names found sometimes in data.
009 * Old, deprecated terms are kept but marked as such.
010 */
011public enum DwcTerm implements Term, AlternativeNames {
012
013  /**
014   * CLASS TERMS
015   * Listed in the order given on the Darwin Core Quick Reference Guide.
016   * @see <a href="http://rs.tdwg.org/dwc/terms/index.htm#theterms">DwC Quick Reference Guide</a>
017   * Location is not on this list because it is a term in the dcterm namespace.
018   */
019  Occurrence(DwcTerm.GROUP_OCCURRENCE, "DarwinCore", "SimpleDarwinCore"),
020  Organism(DwcTerm.GROUP_ORGANISM),
021  MaterialSample(DwcTerm.GROUP_MATERIAL_SAMPLE),
022  Event(DwcTerm.GROUP_EVENT),
023  GeologicalContext(DwcTerm.GROUP_GEOLOGICALCONTEXT),
024  Identification(DwcTerm.GROUP_IDENTIFICATION),
025  Taxon(DwcTerm.GROUP_TAXON),
026  MeasurementOrFact(DwcTerm.GROUP_MEASUREMENTORFACT),
027  ResourceRelationship(DwcTerm.GROUP_RESOURCERELATIONSHIP),
028
029  /**
030   * PROPERTY TERMS
031   * Listed in the order given on the Darwin Core Quick Reference Guide.
032   * @see <a href="http://rs.tdwg.org/dwc/terms/index.htm#theterms">DwC Quick Reference Guide</a>
033   */
034  institutionID(DwcTerm.GROUP_RECORD),
035  collectionID(DwcTerm.GROUP_RECORD),
036  datasetID(DwcTerm.GROUP_RECORD),
037  institutionCode(DwcTerm.GROUP_RECORD),
038  collectionCode(DwcTerm.GROUP_RECORD),
039  datasetName(DwcTerm.GROUP_RECORD),
040  ownerInstitutionCode(DwcTerm.GROUP_RECORD),
041  basisOfRecord(DwcTerm.GROUP_RECORD),
042  informationWithheld(DwcTerm.GROUP_RECORD),
043  dataGeneralizations(DwcTerm.GROUP_RECORD),
044  dynamicProperties(DwcTerm.GROUP_RECORD),
045
046  occurrenceID(DwcTerm.GROUP_OCCURRENCE),
047  catalogNumber(DwcTerm.GROUP_OCCURRENCE, "catalogNumberNumeric"),
048  recordNumber(DwcTerm.GROUP_OCCURRENCE, "collectorNumber"),
049  recordedBy(DwcTerm.GROUP_OCCURRENCE, "collector"),
050  individualCount(DwcTerm.GROUP_OCCURRENCE),
051  organismQuantity(DwcTerm.GROUP_OCCURRENCE),
052  organismQuantityType(DwcTerm.GROUP_OCCURRENCE),
053  sex(DwcTerm.GROUP_OCCURRENCE),
054  lifeStage(DwcTerm.GROUP_OCCURRENCE),
055  reproductiveCondition(DwcTerm.GROUP_OCCURRENCE),
056  behavior(DwcTerm.GROUP_OCCURRENCE),
057  establishmentMeans(DwcTerm.GROUP_OCCURRENCE),
058  occurrenceStatus(DwcTerm.GROUP_OCCURRENCE),
059  preparations(DwcTerm.GROUP_OCCURRENCE),
060  disposition(DwcTerm.GROUP_OCCURRENCE),
061  associatedMedia(DwcTerm.GROUP_OCCURRENCE),
062  associatedReferences(DwcTerm.GROUP_OCCURRENCE),
063  associatedSequences(DwcTerm.GROUP_OCCURRENCE),
064  associatedTaxa(DwcTerm.GROUP_OCCURRENCE),
065  otherCatalogNumbers(DwcTerm.GROUP_OCCURRENCE),
066  occurrenceRemarks(DwcTerm.GROUP_OCCURRENCE),
067
068  organismID(DwcTerm.GROUP_ORGANISM, "individualID"),
069  organismName(DwcTerm.GROUP_ORGANISM),
070  organismScope(DwcTerm.GROUP_ORGANISM),
071  associatedOccurrences(DwcTerm.GROUP_ORGANISM),
072  associatedOrganisms(DwcTerm.GROUP_ORGANISM),
073  previousIdentifications(DwcTerm.GROUP_ORGANISM),
074  organismRemarks(DwcTerm.GROUP_ORGANISM),
075
076  materialSampleID(DwcTerm.GROUP_MATERIAL_SAMPLE),
077
078  eventID(DwcTerm.GROUP_EVENT),
079  parentEventID(DwcTerm.GROUP_EVENT),
080  fieldNumber(DwcTerm.GROUP_EVENT),
081  eventDate(DwcTerm.GROUP_EVENT, "earliestDateCollected", "latestDateCollected"),
082  eventTime(DwcTerm.GROUP_EVENT),
083  startDayOfYear(DwcTerm.GROUP_EVENT),
084  endDayOfYear(DwcTerm.GROUP_EVENT),
085  year(DwcTerm.GROUP_EVENT),
086  month(DwcTerm.GROUP_EVENT),
087  day(DwcTerm.GROUP_EVENT),
088  verbatimEventDate(DwcTerm.GROUP_EVENT),
089  habitat(DwcTerm.GROUP_EVENT),
090  samplingProtocol(DwcTerm.GROUP_EVENT),
091  samplingEffort(DwcTerm.GROUP_EVENT),
092  sampleSizeValue(DwcTerm.GROUP_EVENT),
093  sampleSizeUnit(DwcTerm.GROUP_EVENT),
094  fieldNotes(DwcTerm.GROUP_EVENT),
095  eventRemarks(DwcTerm.GROUP_EVENT),
096
097  locationID(DwcTerm.GROUP_LOCATION),
098  higherGeographyID(DwcTerm.GROUP_LOCATION),
099  higherGeography(DwcTerm.GROUP_LOCATION),
100  continent(DwcTerm.GROUP_LOCATION),
101  waterBody(DwcTerm.GROUP_LOCATION),
102  islandGroup(DwcTerm.GROUP_LOCATION),
103  island(DwcTerm.GROUP_LOCATION),
104  country(DwcTerm.GROUP_LOCATION),
105  countryCode(DwcTerm.GROUP_LOCATION),
106  stateProvince(DwcTerm.GROUP_LOCATION, "state", "province"),
107  county(DwcTerm.GROUP_LOCATION),
108  municipality(DwcTerm.GROUP_LOCATION, "city"),
109  locality(DwcTerm.GROUP_LOCATION),
110  verbatimLocality(DwcTerm.GROUP_LOCATION),
111  minimumElevationInMeters(DwcTerm.GROUP_LOCATION),
112  maximumElevationInMeters(DwcTerm.GROUP_LOCATION),
113  verbatimElevation(DwcTerm.GROUP_LOCATION),
114  minimumDepthInMeters(DwcTerm.GROUP_LOCATION),
115  maximumDepthInMeters(DwcTerm.GROUP_LOCATION),
116  verbatimDepth(DwcTerm.GROUP_LOCATION),
117  minimumDistanceAboveSurfaceInMeters(DwcTerm.GROUP_LOCATION),
118  maximumDistanceAboveSurfaceInMeters(DwcTerm.GROUP_LOCATION),
119  locationAccordingTo(DwcTerm.GROUP_LOCATION),
120  locationRemarks(DwcTerm.GROUP_LOCATION),
121  decimalLatitude(DwcTerm.GROUP_LOCATION, "latitude"),
122  decimalLongitude(DwcTerm.GROUP_LOCATION, "longitude"),
123  geodeticDatum(DwcTerm.GROUP_LOCATION, "datum", "horizontaldatum"),
124  coordinateUncertaintyInMeters(DwcTerm.GROUP_LOCATION),
125  coordinatePrecision(DwcTerm.GROUP_LOCATION),
126  pointRadiusSpatialFit(DwcTerm.GROUP_LOCATION),
127  verbatimCoordinates(DwcTerm.GROUP_LOCATION),
128  verbatimLatitude(DwcTerm.GROUP_LOCATION),
129  verbatimLongitude(DwcTerm.GROUP_LOCATION),
130  verbatimCoordinateSystem(DwcTerm.GROUP_LOCATION),
131  verbatimSRS(DwcTerm.GROUP_LOCATION),
132  footprintWKT(DwcTerm.GROUP_LOCATION),
133  footprintSRS(DwcTerm.GROUP_LOCATION),
134  footprintSpatialFit(DwcTerm.GROUP_LOCATION),
135  georeferencedBy(DwcTerm.GROUP_LOCATION),
136  georeferencedDate(DwcTerm.GROUP_LOCATION),
137  georeferenceProtocol(DwcTerm.GROUP_LOCATION),
138  georeferenceSources(DwcTerm.GROUP_LOCATION),
139  georeferenceVerificationStatus(DwcTerm.GROUP_LOCATION),
140  georeferenceRemarks(DwcTerm.GROUP_LOCATION),
141
142  geologicalContextID(DwcTerm.GROUP_GEOLOGICALCONTEXT),
143  earliestEonOrLowestEonothem(DwcTerm.GROUP_GEOLOGICALCONTEXT),
144  latestEonOrHighestEonothem(DwcTerm.GROUP_GEOLOGICALCONTEXT),
145  earliestEraOrLowestErathem(DwcTerm.GROUP_GEOLOGICALCONTEXT),
146  latestEraOrHighestErathem(DwcTerm.GROUP_GEOLOGICALCONTEXT),
147  earliestPeriodOrLowestSystem(DwcTerm.GROUP_GEOLOGICALCONTEXT),
148  latestPeriodOrHighestSystem(DwcTerm.GROUP_GEOLOGICALCONTEXT),
149  earliestEpochOrLowestSeries(DwcTerm.GROUP_GEOLOGICALCONTEXT),
150  latestEpochOrHighestSeries(DwcTerm.GROUP_GEOLOGICALCONTEXT),
151  earliestAgeOrLowestStage(DwcTerm.GROUP_GEOLOGICALCONTEXT),
152  latestAgeOrHighestStage(DwcTerm.GROUP_GEOLOGICALCONTEXT),
153  lowestBiostratigraphicZone(DwcTerm.GROUP_GEOLOGICALCONTEXT),
154  highestBiostratigraphicZone(DwcTerm.GROUP_GEOLOGICALCONTEXT),
155  lithostratigraphicTerms(DwcTerm.GROUP_GEOLOGICALCONTEXT),
156  group(DwcTerm.GROUP_GEOLOGICALCONTEXT),
157  formation(DwcTerm.GROUP_GEOLOGICALCONTEXT),
158  member(DwcTerm.GROUP_GEOLOGICALCONTEXT),
159  bed(DwcTerm.GROUP_GEOLOGICALCONTEXT),
160
161  identificationID(DwcTerm.GROUP_IDENTIFICATION),
162  identificationQualifier(DwcTerm.GROUP_IDENTIFICATION),
163  typeStatus(DwcTerm.GROUP_IDENTIFICATION),
164  identifiedBy(DwcTerm.GROUP_IDENTIFICATION),
165  dateIdentified(DwcTerm.GROUP_IDENTIFICATION),
166  identificationReferences(DwcTerm.GROUP_IDENTIFICATION),
167  identificationVerificationStatus(DwcTerm.GROUP_IDENTIFICATION),
168  identificationRemarks(DwcTerm.GROUP_IDENTIFICATION),
169
170  taxonID(DwcTerm.GROUP_TAXON, "nameUsageID"),
171  scientificNameID(DwcTerm.GROUP_TAXON, "nameID"),
172  acceptedNameUsageID(DwcTerm.GROUP_TAXON, "acceptedTaxonID"),
173  parentNameUsageID(DwcTerm.GROUP_TAXON, "parentTaxonID", "higherTaxonID", "higherNameUsageID"),
174  originalNameUsageID(DwcTerm.GROUP_TAXON, "originalNameID", "originalTaxonID", "basionymID"),
175  nameAccordingToID(DwcTerm.GROUP_TAXON, "taxonAccordingToID"),
176  namePublishedInID(DwcTerm.GROUP_TAXON),
177  taxonConceptID(DwcTerm.GROUP_TAXON),
178  scientificName(DwcTerm.GROUP_TAXON),
179  acceptedNameUsage(DwcTerm.GROUP_TAXON, "acceptedTaxon"),
180  parentNameUsage(DwcTerm.GROUP_TAXON, "parentTaxon", "higherTaxon", "higherNameUsage"),
181  originalNameUsage(DwcTerm.GROUP_TAXON, "originalName", "originalTaxon", "basionym"),
182  nameAccordingTo(DwcTerm.GROUP_TAXON, "taxonAccordingTo"),
183  namePublishedIn(DwcTerm.GROUP_TAXON),
184  namePublishedInYear(DwcTerm.GROUP_TAXON),
185  higherClassification(DwcTerm.GROUP_TAXON),
186  kingdom(DwcTerm.GROUP_TAXON),
187  phylum(DwcTerm.GROUP_TAXON),
188  /**
189   * The taxonomic class.
190   * The real Darwin Core term is class, but as java does not allow this name we use a variation instead.
191   */
192  class_(DwcTerm.GROUP_TAXON, "class"),
193  order(DwcTerm.GROUP_TAXON),
194  family(DwcTerm.GROUP_TAXON),
195  genus(DwcTerm.GROUP_TAXON),
196  subgenus(DwcTerm.GROUP_TAXON),
197  specificEpithet(DwcTerm.GROUP_TAXON),
198  infraspecificEpithet(DwcTerm.GROUP_TAXON),
199  taxonRank(DwcTerm.GROUP_TAXON, "rank"),
200  verbatimTaxonRank(DwcTerm.GROUP_TAXON),
201  scientificNameAuthorship(DwcTerm.GROUP_TAXON),
202  vernacularName(DwcTerm.GROUP_TAXON),
203  nomenclaturalCode(DwcTerm.GROUP_TAXON),
204  taxonomicStatus(DwcTerm.GROUP_TAXON),
205  nomenclaturalStatus(DwcTerm.GROUP_TAXON),
206  taxonRemarks(DwcTerm.GROUP_TAXON, "taxonRemark"),
207
208  measurementID(DwcTerm.GROUP_MEASUREMENTORFACT),
209  measurementType(DwcTerm.GROUP_MEASUREMENTORFACT),
210  measurementValue(DwcTerm.GROUP_MEASUREMENTORFACT),
211  measurementAccuracy(DwcTerm.GROUP_MEASUREMENTORFACT),
212  measurementUnit(DwcTerm.GROUP_MEASUREMENTORFACT),
213  measurementDeterminedBy(DwcTerm.GROUP_MEASUREMENTORFACT),
214  measurementDeterminedDate(DwcTerm.GROUP_MEASUREMENTORFACT),
215  measurementMethod(DwcTerm.GROUP_MEASUREMENTORFACT),
216  measurementRemarks(DwcTerm.GROUP_MEASUREMENTORFACT),
217
218  resourceRelationshipID(DwcTerm.GROUP_RESOURCERELATIONSHIP),
219  resourceID(DwcTerm.GROUP_RESOURCERELATIONSHIP),
220  relatedResourceID(DwcTerm.GROUP_RESOURCERELATIONSHIP),
221  relationshipOfResource(DwcTerm.GROUP_RESOURCERELATIONSHIP),
222  relationshipAccordingTo(DwcTerm.GROUP_RESOURCERELATIONSHIP),
223  relationshipEstablishedDate(DwcTerm.GROUP_RESOURCERELATIONSHIP),
224  relationshipRemarks(DwcTerm.GROUP_RESOURCERELATIONSHIP);
225
226  public static final String NS = "http://rs.tdwg.org/dwc/terms/";
227  public static final String PREFIX = "dwc";
228  static final String[] PREFIXES = {NS, PREFIX + ":", "darwin:", "darwincore:", "dw:"};
229  public static final String GROUP_RECORD = "Record";
230  public static final String GROUP_OCCURRENCE = "Occurrence";
231  public static final String GROUP_ORGANISM = "Organism";
232  public static final String GROUP_MATERIAL_SAMPLE = "MaterialSample";
233  public static final String GROUP_EVENT = "Event";
234  public static final String GROUP_LOCATION = "Location";
235  public static final String GROUP_GEOLOGICALCONTEXT = "GeologicalContext";
236  public static final String GROUP_IDENTIFICATION = "Identification";
237  public static final String GROUP_TAXON = "Taxon";
238  public static final String GROUP_MEASUREMENTORFACT = "MeasurementOrFact";
239  public static final String GROUP_RESOURCERELATIONSHIP = "ResourceRelationship";
240
241  /**
242   * Lists all term groups in the order given on the Darwin Core Quick Reference Guide.
243   * @see <a href="http://rs.tdwg.org/dwc/terms/index.htm#theterms">DwC Quick Reference Guide</a>
244   */
245  public static final String[] GROUPS =
246    {GROUP_RECORD, GROUP_OCCURRENCE, GROUP_ORGANISM, GROUP_EVENT, GROUP_LOCATION, 
247          GROUP_GEOLOGICALCONTEXT, GROUP_IDENTIFICATION, GROUP_TAXON, 
248          GROUP_MEASUREMENTORFACT, GROUP_RESOURCERELATIONSHIP};
249
250  public static final DwcTerm[] TAXONOMIC_TERMS =
251    {DwcTerm.taxonID, DwcTerm.scientificNameID, DwcTerm.acceptedNameUsageID, 
252          DwcTerm.parentNameUsageID, DwcTerm.originalNameUsageID, 
253          DwcTerm.nameAccordingToID, DwcTerm.namePublishedInID, DwcTerm.taxonConceptID,
254      DwcTerm.scientificName, DwcTerm.acceptedNameUsage, DwcTerm.parentNameUsage, 
255          DwcTerm.originalNameUsage, DwcTerm.nameAccordingTo, DwcTerm.namePublishedIn, 
256          DwcTerm.namePublishedInYear, DwcTerm.higherClassification, DwcTerm.kingdom, 
257          DwcTerm.phylum, DwcTerm.class_, DwcTerm.order, DwcTerm.family, DwcTerm.genus, 
258          DwcTerm.subgenus, DwcTerm.specificEpithet, DwcTerm.infraspecificEpithet, 
259          DwcTerm.taxonRank, DwcTerm.verbatimTaxonRank, DwcTerm.scientificNameAuthorship, 
260          DwcTerm.vernacularName, DwcTerm.nomenclaturalCode, DwcTerm.taxonomicStatus,
261      DwcTerm.nomenclaturalStatus, DwcTerm.taxonRemarks};
262
263  /**
264   * List of all higher rank terms in dwc, ordered by rank and starting with kingdom.
265   */
266  public static final DwcTerm[] HIGHER_RANKS =
267    {DwcTerm.kingdom, DwcTerm.phylum, DwcTerm.class_, DwcTerm.order, DwcTerm.family, 
268          DwcTerm.genus, DwcTerm.subgenus};
269
270  /**
271   * List of all class terms in dwc.
272   */
273  //TODO: create dynamically via method!
274  // Location is not in this list because it is in the dcterms namespace.
275  public static final DwcTerm[] CLASS_TERMS =
276    {DwcTerm.Occurrence, DwcTerm.Organism, DwcTerm.MaterialSample, DwcTerm.Event, 
277          DwcTerm.GeologicalContext, DwcTerm.Identification, DwcTerm.Taxon, 
278          DwcTerm.MeasurementOrFact, DwcTerm.ResourceRelationship};
279
280  private final String groupName;
281  public final String normQName;
282  public final String[] normAlts;
283
284  private DwcTerm(String groupName, String... alternatives) {
285    normQName = TermFactory.normaliseTerm(qualifiedName());
286    for (int i = 0; i < alternatives.length; i++) {
287      alternatives[i] = TermFactory.normaliseTerm(alternatives[i]);
288    }
289    normAlts = alternatives;
290    this.groupName = groupName;
291  }
292
293
294  /**
295   * The full qualified term uri including the namespace.
296   * For example http://rs.tdwg.org/dwc/terms/scientificName.
297   * @return full qualified term uri
298   */
299  @Override
300  public String qualifiedName() {
301    return NS + simpleName();
302  }
303
304  /**
305   * The simple term name without a namespace.
306   * For example scientificName.
307   * @return simple term name
308   */
309  @Override
310  public String simpleName() {
311    if (this == class_) {
312      return "class";
313    }
314    return name();
315  }
316
317  /**
318   * Array of alternative simple names in use for the term.
319   * Often based on older dwc versions.
320   * @return simple term name
321   */
322  @Override
323  public String[] alternativeNames() {
324    return normAlts;
325  }
326
327  /**
328   * The optional group the term is grouped in.
329   * For example Taxon, Identification, etc.
330   */
331  public String getGroup() {
332    return groupName;
333  }
334
335  /**
336   * @return true if the dwc term is defining a class instead of a property, e.g. Taxon
337   */
338  public boolean isClass() {
339    return Character.isUpperCase(simpleName().charAt(0));
340  }
341
342  /**
343   * List all terms that belong to a given group.
344   *
345   * @param group the group to list terms for
346   *
347   * @return the list of dwc terms in the given group
348   */
349  public static List<DwcTerm> listByGroup(String group) {
350    List<DwcTerm> terms = new ArrayList<DwcTerm>();
351    for (DwcTerm t : DwcTerm.values()) {
352      if (t.getGroup().equalsIgnoreCase(group)) {
353        terms.add(t);
354      }
355    }
356    return terms;
357  }
358
359  @Override
360  public String toString() {
361    return PREFIX + ":" + name();
362  }
363
364}