1 package eu
.etaxonomy
.cdm
.api
.service
;
6 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
7 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
8 import eu
.etaxonomy
.cdm
.model
.description
.NaturalLanguageTerm
;
9 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
10 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
11 import eu
.etaxonomy
.cdm
.model
.description
.TextFormat
;
17 public class DefaultQuantitativeDescriptionBuilder
extends AbstractQuantitativeDescriptionBuilder
{
22 protected TextData
doBuild(Map
<StatisticalMeasure
,Float
> measures
, MeasurementUnit mUnit
, List
<Language
> languages
){
23 StringBuilder QuantitativeDescription
= new StringBuilder(); // this StringBuilder is used to concatenate the different words of the description before saving it in the TextData
24 TextData textData
= TextData
.NewInstance(); // TextData that will contain the description and the language corresponding
25 // booleans indicating whether a kind of value is present or not and the float that will eventually hold the value
28 if ((mUnit
!=null)&&(mUnit
.getLabel()!=null)){
29 unit
= mUnit
.getLabel();
32 // the different linking words are taken from NaturalLanguageTerm.class (should this be changed ?)
33 NaturalLanguageTerm nltFrom
= NaturalLanguageTerm
.FROM();
34 String from
= nltFrom
.getPreferredRepresentation(languages
).getLabel();
35 NaturalLanguageTerm nltTo
= NaturalLanguageTerm
.TO();
36 String to
= nltTo
.getPreferredRepresentation(languages
).getLabel();
37 NaturalLanguageTerm nltUp_To
= NaturalLanguageTerm
.UP_TO();
38 String up_To
= nltUp_To
.getPreferredRepresentation(languages
).getLabel();
39 NaturalLanguageTerm nltMost_Frequently
= NaturalLanguageTerm
.MOST_FREQUENTLY();
40 String most_Frequently
= nltMost_Frequently
.getPreferredRepresentation(languages
).getLabel();
41 NaturalLanguageTerm nltOn_Average
= NaturalLanguageTerm
.ON_AVERAGE();
42 String on_Average
= nltOn_Average
.getPreferredRepresentation(languages
).getLabel();
43 NaturalLanguageTerm nltMore_Or_Less
= NaturalLanguageTerm
.MORE_OR_LESS();
44 String more_Or_Less
= nltMore_Or_Less
.getPreferredRepresentation(languages
).getLabel();
47 // the booleans and floats are updated according to the presence or absence of values
49 Boolean max
, min
, upperb
, lowerb
, average
, sd
;
51 String averagevalue
= getValue(measures
,StatisticalMeasure
.AVERAGE());
52 if (averagevalue
!=null) average
=true; else average
=false;
53 String sdvalue
= getValue(measures
,StatisticalMeasure
.STANDARD_DEVIATION());
54 if (sdvalue
!=null) sd
=true; else sd
=false;
55 String minvalue
= getValue(measures
,StatisticalMeasure
.MIN());
56 if (minvalue
!=null) min
=true; else min
=false;
57 String maxvalue
= getValue(measures
,StatisticalMeasure
.MAX());
58 if (maxvalue
!=null) max
=true; else max
=false;
59 String lowerbvalue
= getValue(measures
,StatisticalMeasure
.TYPICAL_LOWER_BOUNDARY());
60 if (lowerbvalue
!=null) lowerb
=true; else lowerb
=false;
61 String upperbvalue
= getValue(measures
,StatisticalMeasure
.TYPICAL_UPPER_BOUNDARY());
62 if (upperbvalue
!=null) upperb
=true; else upperb
=false;
65 // depending on the different associations of values, a sentence is built
67 QuantitativeDescription
.append(space
+ from
+ space
+ minvalue
+ space
+ to
+ space
+ maxvalue
+ space
+ unit
);
70 QuantitativeDescription
.append(space
+ from
+ space
+ minvalue
+ space
+ unit
);
73 QuantitativeDescription
.append(space
+ up_To
+ space
+ maxvalue
+ space
+ unit
);
75 if ((max
||min
)&&(lowerb
||upperb
)) {
76 QuantitativeDescription
.append(separator
); // merge with below ?
78 if ((lowerb
||upperb
)&&(min
||max
)) {
79 QuantitativeDescription
.append(space
+ most_Frequently
);
81 if (upperb
&& lowerb
) {
82 QuantitativeDescription
.append(space
+ from
+ space
+ lowerbvalue
+ space
+ to
+ space
+ upperbvalue
+ space
+ unit
);
85 QuantitativeDescription
.append(space
+ from
+ space
+ lowerbvalue
+ space
+ unit
);
88 QuantitativeDescription
.append(space
+ up_To
+ space
+ upperbvalue
+ space
+ unit
);
90 if (((max
||min
)&&(average
))||((lowerb
||upperb
)&&(average
))) {
91 QuantitativeDescription
.append(separator
);
94 QuantitativeDescription
.append(space
+ averagevalue
+ space
+ unit
+ space
+ on_Average
);
96 QuantitativeDescription
.append("("+ more_Or_Less
+ space
+ sdvalue
+ ")");
99 textData
.putText(languages
.get(0), QuantitativeDescription
.toString()); // which language should be put here ?
100 textData
.setFormat(TextFormat
.NewInstance(null, "Text",null ));
108 * Returns the value of a given type of measure as a String. If the value is an integer it is printed
109 * as an integer instead of a float.
110 * If no value of this type is present, returns null.
112 * @param measures the map with the values
113 * @param key the desired measure
116 private String
getValue(Map
<StatisticalMeasure
,Float
> measures
, Object key
) {
119 if(measures
.containsKey(key
)) {
120 floatValue
= measures
.get(key
);
121 intValue
=floatValue
.intValue();
122 if (floatValue
.equals(intValue
.floatValue())) return intValue
.toString();
123 else return floatValue
.toString();