use of eu.etaxonomy.cdm.model.description.TaxonInteraction in project cdmlib by cybertaxonomy.
the class ReferencingObjectFormatter method getCache.
// from taxeditor DescriptionHelper
private static String getCache(DescriptionElementBase element, Language defaultLanguage) {
String mainElementLabel = null;
DescriptionBase<?> descr = element.getInDescription();
descr = CdmBase.deproxy(descr);
if (descr != null) {
if (descr.isInstanceOf(TaxonDescription.class)) {
Taxon taxon = CdmBase.deproxy(descr, TaxonDescription.class).getTaxon();
if (taxon != null) {
mainElementLabel = taxon.getTitleCache();
}
} else if (descr.isInstanceOf(SpecimenDescription.class)) {
SpecimenOrObservationBase<?> specimen = CdmBase.deproxy(descr, SpecimenDescription.class).getDescribedSpecimenOrObservation();
if (specimen != null) {
mainElementLabel = specimen.getTitleCache();
}
} else if (descr.isInstanceOf(TaxonNameDescription.class)) {
TaxonName name = CdmBase.deproxy(descr, TaxonNameDescription.class).getTaxonName();
if (name != null) {
mainElementLabel = name.getTitleCache();
}
}
}
String cache = null;
if (element instanceof TextData) {
// cache = ((TextData) element).getText(language);
cache = "Text Data";
}
if (element instanceof CommonTaxonName) {
cache = ((CommonTaxonName) element).getName();
}
if (element instanceof TaxonInteraction) {
Taxon taxon2 = ((TaxonInteraction) element).getTaxon2();
if (taxon2 != null && taxon2.getName() != null) {
cache = taxon2.getName().getTitleCache();
} else {
cache = "No taxon chosen";
}
}
if (element instanceof Distribution) {
Distribution distribution = (Distribution) element;
NamedArea area = distribution.getArea();
if (area != null) {
cache = area.getLabel();
PresenceAbsenceTerm status = distribution.getStatus();
if (status == null) {
cache += ", no status";
} else {
cache += ", " + status.getLabel();
}
}
}
String result = cache == null ? "" : cache;
if (isNotBlank(mainElementLabel)) {
result = CdmUtils.concat(" ", result, "(" + mainElementLabel + ")");
}
return result;
}
use of eu.etaxonomy.cdm.model.description.TaxonInteraction in project cdmlib by cybertaxonomy.
the class FullCoverageDataGenerator method createDescriptions.
private void createDescriptions(List<CdmBase> cdmBases) {
TermVocabulary<AnnotationType> voc = TermVocabulary.NewInstance(TermType.AnnotationType, AnnotationType.class, "my termVoc desc", "myTerm voc", "mtv", URI.create("http://www.abc.de"));
handleIdentifiableEntity(voc);
cdmBases.add(voc);
Representation rep = voc.getRepresentations().iterator().next();
handleAnnotatableEntity(rep);
// Representation engRep = Language.ENGLISH().getRepresentations().iterator().next();
// handleAnnotatableEntity(engRep);
// cdmBases.add(engRep); //needed?
// Categorical data
State state = State.NewInstance("Test state", "state", "st.");
state.addMedia(Media.NewInstance());
cdmBases.add(state);
CategoricalData categoricalData = CategoricalData.NewInstance(state, Feature.CONSERVATION());
StateData stateData = categoricalData.getStateData().get(0);
stateData.addModifier(DefinedTerm.SEX_FEMALE());
handleAnnotatableEntity(categoricalData);
State nextState = State.NewInstance();
cdmBases.add(nextState);
StateData stateData2 = StateData.NewInstance(nextState);
stateData2.setCount(3);
stateData2.putModifyingText(Language.ENGLISH(), "State2 modifying text");
categoricalData.addStateData(stateData2);
categoricalData.setOrderRelevant(true);
// Quantitative data
Feature leaveLength = Feature.NewInstance("Leave length description", "leave length", "l.l.");
cdmBases.add(leaveLength);
leaveLength.setSupportsQuantitativeData(true);
QuantitativeData quantitativeData = QuantitativeData.NewInstance(leaveLength);
MeasurementUnit measurementUnit = MeasurementUnit.NewInstance("Measurement Unit", "munit", null);
cdmBases.add(measurementUnit);
quantitativeData.setUnit(measurementUnit);
quantitativeData.setUuid(UUID.fromString("920fce5e-4913-4a3f-89bf-1611f5081869"));
StatisticalMeasurementValue statisticalMeasurementValue = quantitativeData.setAverage(new BigDecimal("22.9215"), null);
handleAnnotatableEntity(quantitativeData);
handleIdentifiableEntity(measurementUnit);
DefinedTerm valueModifier = DefinedTerm.NewModifierInstance("about", "about", null);
statisticalMeasurementValue.addModifier(valueModifier);
cdmBases.add(valueModifier);
// Feature
TermVocabulary<DefinedTerm> recommendedModifierEnumeration = TermVocabulary.NewInstance(TermType.Modifier, DefinedTerm.class);
leaveLength.addRecommendedModifierEnumeration(recommendedModifierEnumeration);
cdmBases.add(recommendedModifierEnumeration);
TermVocabulary<State> supportedCategoricalEnumeration = TermVocabulary.NewInstance(TermType.State, State.class);
leaveLength.addSupportedCategoricalEnumeration(supportedCategoricalEnumeration);
cdmBases.add(supportedCategoricalEnumeration);
leaveLength.addRecommendedMeasurementUnit(measurementUnit);
leaveLength.addRecommendedStatisticalMeasure(StatisticalMeasure.AVERAGE());
// CommonTaxonName
CommonTaxonName commonTaxonName = CommonTaxonName.NewInstance("common name", Language.ENGLISH(), Country.UNITEDSTATESOFAMERICA());
handleAnnotatableEntity(commonTaxonName);
// TextData
TextData textData = TextData.NewInstance(Feature.DIAGNOSIS());
Language eng = Language.ENGLISH();
textData.putText(eng, "My text data");
LanguageString languageString = textData.getLanguageText(eng);
Taxon referencedTaxon = getTaxon();
cdmBases.add(referencedTaxon);
languageString.addIntextReference(IntextReference.NewInstance(referencedTaxon, languageString, 2, 5));
textData.putModifyingText(eng, "nice diagnosis");
handleAnnotatableEntity(textData);
handleAnnotatableEntity(languageString);
TextFormat format = TextFormat.NewInstance("format", "format", null);
textData.setFormat(format);
cdmBases.add(format);
handleAnnotatableEntity(format);
// IndividualsAssociation
DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
IndividualsAssociation indAssoc = IndividualsAssociation.NewInstance(specimen);
indAssoc.putDescription(Language.ENGLISH(), "description for individuals association");
handleAnnotatableEntity(indAssoc);
// TaxonInteraction
TaxonInteraction taxonInteraction = TaxonInteraction.NewInstance(Feature.HOSTPLANT());
taxonInteraction.putDescription(Language.ENGLISH(), "interaction description");
handleAnnotatableEntity(taxonInteraction);
// Distribution
NamedArea inCountryArea = NamedArea.NewInstance("My area in a country", "my area", "ma");
inCountryArea.addCountry(Country.TURKEYREPUBLICOF());
cdmBases.add(inCountryArea);
Distribution distribution = Distribution.NewInstance(inCountryArea, PresenceAbsenceTerm.CULTIVATED());
handleAnnotatableEntity(distribution);
// TemporalData
Feature floweringSeason = Feature.FLOWERING_PERIOD();
TemporalData temporalData = TemporalData.NewInstance(ExtendedTimePeriod.NewExtendedMonthInstance(5, 8, 4, 9));
temporalData.setFeature(floweringSeason);
temporalData.getPeriod().setFreeText("My temporal text");
handleAnnotatableEntity(temporalData);
temporalData.setUuid(UUID.fromString("9a1c91c0-fc58-4310-94cb-8c26115985d3"));
Taxon taxon = getTaxon();
TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon);
taxonDescription.addElements(categoricalData, quantitativeData, textData, commonTaxonName, taxonInteraction, indAssoc, distribution, temporalData);
DerivedUnit describedSpecimenOrObservation = DerivedUnit.NewInstance(SpecimenOrObservationType.DerivedUnit);
taxonDescription.setDescribedSpecimenOrObservation(describedSpecimenOrObservation);
taxonDescription.addScope(DefinedTerm.SEX_FEMALE());
taxonDescription.addGeoScope(Country.GERMANY());
handleIdentifiableEntity(taxonDescription);
taxon.addAggregationSource(taxonDescription);
cdmBases.add(taxon);
// DescriptionElmenetBase + source
textData.addMedia(Media.NewInstance());
textData.addModifier(DefinedTerm.SEX_HERMAPHRODITE());
textData.putModifyingText(Language.ENGLISH(), "no modification");
textData.setTimeperiod(TimePeriodParser.parseString("1970-1980"));
Reference ref = ReferenceFactory.newArticle();
DescriptionElementSource source = textData.addSource(OriginalSourceType.Import, "22", "taxon description table", ref, "detail");
source.setNameUsedInSource(TaxonNameFactory.NewBotanicalInstance(Rank.GENUS()));
ExternalLink link = ExternalLink.NewInstance(ExternalLinkType.WebSite, URI.create("http://wwww.abd.de"), "Somehow useful link", 445);
source.addLink(link);
handleAnnotatableEntity(source);
// as long as it still exists
taxonDescription.addDescriptionSource(ref);
// Specimen description
SpecimenOrObservationBase<?> describedSpecimen = getSpecimen();
SpecimenDescription specDesc = SpecimenDescription.NewInstance(specimen);
cdmBases.add(describedSpecimen);
handleAnnotatableEntity(specDesc);
// Name description
TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
TaxonNameDescription nameDesc = TaxonNameDescription.NewInstance(name);
cdmBases.add(name);
handleAnnotatableEntity(nameDesc);
// Feature Tree
TermTree<Feature> featureTree = TermTree.NewFeatureInstance();
// featureTree
TermNode<Feature> descriptionTermNode = featureTree.getRoot().addChild(Feature.DESCRIPTION());
TermNode<Feature> leaveLengthNode = descriptionTermNode.addChild(leaveLength);
handleIdentifiableEntity(featureTree);
State inapplicableState = State.NewInstance("inapplicableState", "inapplicableState", null);
State applicableState = State.NewInstance("only applicable state", "only applicable state", null);
cdmBases.add(applicableState);
cdmBases.add(inapplicableState);
// this is semantically not correct, should be a parent feature
leaveLengthNode.addInapplicableState(leaveLength, inapplicableState);
leaveLengthNode.addApplicableState(leaveLength, applicableState);
cdmBases.add(featureTree);
cdmBases.add(leaveLengthNode);
// DescriptiveDataSet
DescriptiveDataSet descriptiveDataSet = DescriptiveDataSet.NewInstance();
descriptiveDataSet.addDescription(taxonDescription);
descriptiveDataSet.setLabel("My Descriptive Dataset");
descriptiveDataSet.getDescriptiveSystem();
handleAnnotatableEntity(descriptiveDataSet);
descriptiveDataSet.addGeoFilterArea(Country.GERMANY());
Classification classification = Classification.NewInstance("DescriptiveDataSet subtree classification");
Taxon subTreeTaxon = getTaxon();
TaxonNode subtree = classification.addChildTaxon(subTreeTaxon, null, null);
descriptiveDataSet.addTaxonSubtree(subtree);
cdmBases.add(classification);
cdmBases.add(subtree);
// polytomous keys
Taxon coveredTaxon = Taxon.NewInstance(name, null);
PolytomousKey key = PolytomousKey.NewTitledInstance("My Polykey");
handleIdentificationKey(key, taxon, coveredTaxon);
key.setStartNumber(10);
PolytomousKeyNode firstChildNode = PolytomousKeyNode.NewInstance("Green", "What is the leave length?", coveredTaxon, leaveLength);
key.getRoot().addChild(firstChildNode);
PolytomousKeyNode secondChildNode = PolytomousKeyNode.NewInstance("234");
firstChildNode.addChild(secondChildNode);
PolytomousKey subkey = PolytomousKey.NewTitledInstance("Sub-key");
firstChildNode.setSubkey(subkey);
PolytomousKeyNode subKeyNode = PolytomousKeyNode.NewInstance("sub key couplet");
subkey.getRoot().addChild(subKeyNode);
secondChildNode.setOtherNode(subKeyNode);
secondChildNode.putModifyingText(Language.GERMAN(), "manchmal");
cdmBases.add(key);
cdmBases.add(subkey);
MediaKey mediaKey = MediaKey.NewInstance();
mediaKey.addKeyRepresentation(Representation.NewInstance("Media Key Representation", "media key", null, Language.ENGLISH()));
handleIdentificationKey(mediaKey, taxon, coveredTaxon);
MultiAccessKey multiAccessKey = MultiAccessKey.NewInstance();
handleIdentificationKey(multiAccessKey, taxon, coveredTaxon);
cdmBases.add(mediaKey);
cdmBases.add(multiAccessKey);
}
use of eu.etaxonomy.cdm.model.description.TaxonInteraction in project cdmlib by cybertaxonomy.
the class DescriptionElementFormatter method format.
public static String format(DescriptionElementBase element, Language defaultLanguage) {
// String mainElementLabel= null;
// DescriptionBase<?> descr = element.getInDescription();
// descr = CdmBase.deproxy(descr);
//
// if (descr != null){
// IDescribable<?> target = CdmBase.deproxy(descr.describedEntity());
// if (target != null){
// mainElementLabel = target.getTitleCache();
// }else{
// return descr.getTitleCache();
// }
// }
String cache = null;
if (element instanceof TextData) {
// cache = ((TextData) element).getText(language);
cache = "Text Data";
}
if (element instanceof CommonTaxonName) {
cache = ((CommonTaxonName) element).getName();
}
if (element instanceof TaxonInteraction) {
Taxon taxon2 = ((TaxonInteraction) element).getTaxon2();
if (taxon2 != null && taxon2.getName() != null) {
cache = taxon2.getName().getTitleCache();
} else {
cache = "No taxon chosen";
}
}
if (element instanceof Distribution) {
Distribution distribution = (Distribution) element;
NamedArea area = distribution.getArea();
if (area != null) {
cache = area.getLabel();
PresenceAbsenceTerm status = distribution.getStatus();
if (status == null) {
cache += ", no status";
} else {
cache += ", " + status.getLabel();
}
}
}
String result = cache == null ? "" : cache;
// }
return result;
}
use of eu.etaxonomy.cdm.model.description.TaxonInteraction in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method handleTaxonInteractionsFacts.
private void handleTaxonInteractionsFacts(CdmLightExportState state, CdmBase cdmBase, List<DescriptionElementBase> taxonInteractionsFacts) {
CdmLightExportTable table = CdmLightExportTable.TAXON_INTERACTION_FACT;
String titleCache = null;
if (cdmBase instanceof TaxonBase) {
titleCache = ((TaxonBase) cdmBase).getTitleCache();
}
for (DescriptionElementBase element : taxonInteractionsFacts) {
try {
String[] csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FACT_ID)] = getId(state, element);
handleSource(state, element, table);
csvLine[table.getIndex(CdmLightExportTable.TAXON_FK)] = getId(state, cdmBase);
csvLine[table.getIndex(CdmLightExportTable.TAXON2_FK)] = getId(state, ((TaxonInteraction) element).getTaxon2());
csvLine[table.getIndex(CdmLightExportTable.DESCRIPTION)] = createMultilanguageString(((TaxonInteraction) element).getDescription());
state.getProcessor().put(table, element, csvLine);
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when handling taxon interaction" + cdmBaseStr(element) + (titleCache != null ? (" " + titleCache) : "") + ": " + e.getMessage());
}
}
}
use of eu.etaxonomy.cdm.model.description.TaxonInteraction in project cdmlib by cybertaxonomy.
the class DwcaResourceRelationExport method handleTaxonNode.
@Override
protected void handleTaxonNode(DwcaTaxExportState state, TaxonNode node) throws FileNotFoundException, UnsupportedEncodingException, IOException {
try {
DwcaTaxExportConfigurator config = state.getConfig();
Taxon taxon = CdmBase.deproxy(node.getTaxon());
// taxon interactions
Set<TaxonDescription> descriptions = taxon.getDescriptions();
for (TaxonDescription description : descriptions) {
for (DescriptionElementBase el : description.getElements()) {
if (el.isInstanceOf(TaxonInteraction.class)) {
DwcaResourceRelationRecord record = new DwcaResourceRelationRecord(metaRecord, config);
TaxonInteraction taxonInteraction = CdmBase.deproxy(el, TaxonInteraction.class);
if (!state.recordExistsUuid(taxonInteraction)) {
handleInteraction(state, record, taxon, taxonInteraction);
PrintWriter writer = createPrintWriter(state, file);
record.write(state, writer);
state.addExistingRecordUuid(taxonInteraction);
}
}
}
}
// concept relationships
for (TaxonRelationship rel : taxon.getTaxonRelations()) {
DwcaResourceRelationRecord record = new DwcaResourceRelationRecord(metaRecord, config);
IdentifiableEntity<?> subject = rel.getFromTaxon();
IdentifiableEntity<?> object = rel.getToTaxon();
if (rel.getType().isAnyMisappliedName()) {
// misapplied names are handled in core (tax)
continue;
}
if (!state.recordExistsUuid(rel)) {
handleRelationship(record, subject, object, rel, false);
PrintWriter writer = createPrintWriter(state, file);
record.write(state, writer);
state.addExistingRecordUuid(rel);
}
}
// Name relationship
// TODO
INonViralName name = taxon.getName();
if (name == null) {
String message = "There is a taxon node without name: " + node.getId();
state.getResult().addError(message, "DwcaResourceRelationExport.makeSingleTaxonNode");
return;
}
Set<NameRelationship> rels = name.getNameRelations();
for (NameRelationship rel : rels) {
DwcaResourceRelationRecord record = new DwcaResourceRelationRecord(metaRecord, config);
IdentifiableEntity<?> subject = CdmBase.deproxy(rel.getFromName());
IdentifiableEntity<?> object = CdmBase.deproxy(rel.getToName());
name = CdmBase.deproxy(name);
boolean isInverse = false;
if (subject == name) {
subject = taxon;
} else if (object == name) {
object = subject;
subject = taxon;
isInverse = true;
} else {
String message = "Both, subject and object, are not part of the relationship for " + name.getTitleCache();
state.getResult().addWarning(message);
}
if (!state.recordExistsUuid(rel)) {
// ????
handleRelationship(record, subject, object, rel, isInverse);
PrintWriter writer = createPrintWriter(state, file);
record.write(state, writer);
state.addExistingRecordUuid(rel);
}
}
} catch (Exception e) {
String message = "Unexpected exception: " + e.getMessage();
state.getResult().addException(e, message);
} finally {
flushWriter(state, file);
}
return;
}
Aggregations