- * recursive function that goes through a tree containing the order in which
- * the description has to be generated, if an element of this tree matches
- * one of the TaxonDescription, a DescriptionBuilder is called which returns
- * a TextData with the corresponding description.
- * <p>
- * Also applies the folowing formatting rules which are special for data coming from Delta, DeltaAccess, DiversityDescriptions:
- *
- * <ul>
- * <li><b>(1.A) if( doSkipTextInBrackets) : </b>Label Text in brackets is always skipped the remaining text string I the TEXT_TO_DISPLAY. The text may contain multiple substrings tagged with the brackets. A tagged substring may also occur in the middle of the whole string.</li>
- * <li><b>(1.B) else : </b>just remove the brackets
- * <li><b>(2) : </b> If the TEXT_TO_DISPLAY is equal the TEXT_TO_DISPLAY of the previous element output of this text is suppressed.</li>
- * </ul>
- *
- * @param children
- * @param parent
- * @param description
- * @param language
- * The language in which the description has to be written
- * @return
+ * Generate a description with a specified list of preferred languages.
+ *
+ * @param featureTree the FeatureTree holding the order in which features and their states must be printed
+ * @param description the TaxonDescription with all the data
+ * @param languages the ordered list of languages preferred for printing the description
+ *
+ * @return a TextData using the languages (in the given order of preference)
+ */
+ @Override
+ public TextData generatePreferredSingleTextData(TermTree featureTree, TaxonDescription description, List<Language> languages) {
+ levels.clear(); // before the start, the table containing the levels of each node must be cleared
+ // Note: this is not the most efficient way to keep track of the levels of the nodes but it allows some flexibility
+ List<TextData> texts = generatePreferredNaturalLanguageDescription(featureTree,description, languages);// first get the description as a raw list of TextData
+
+ StringBuilder descriptionStringBuilder = new StringBuilder(); // the StringBuilder used to generate the description
+ int i = 0,j,level; // i is used to store the index of the TextData to use
+ boolean startSentence = false, firstOne = true;
+
+ for (j=0 ; j<levels.size() ; j++){
+ level = levels.get(j);
+ if (level==-1){
+ if ((j+1)<levels.size() && levels.get(j+1).equals(0)){ // if this node is the direct father of a leaf
+ descriptionStringBuilder.append(secondSeparator + " ");
+ startSentence=true;
+ firstOne=false;
+ String asString = texts.get(i).getText(Language.DEFAULT()).toString();
+ if (asString.length()>1) {
+ descriptionStringBuilder.append(asString.substring(0,1).toUpperCase() + asString.substring(1));
+ }
+ }
+ i++;
+ }
+ else if (level==0) { // if this node is a leaf
+ if (startSentence) {
+ descriptionStringBuilder.append(texts.get(i).getText(Language.DEFAULT()));
+ } else {
+ descriptionStringBuilder.append(firstSeparator + texts.get(i).getText(Language.DEFAULT()));
+ }
+ startSentence=false;
+ i++;
+ }
+ else {
+ if (!firstOne && levels.get(j-1).equals(0)){ // if this node corresponds to the states linked to the previous leaf
+ if (i<texts.size()) {
+ descriptionStringBuilder.append(texts.get(i).getText(Language.DEFAULT()));
+ }
+ i++;
+ }
+ }
+ }
+ descriptionStringBuilder.append(secondSeparator);
+ String returnString = descriptionStringBuilder.toString();
+ returnString = StringUtils.replace(returnString, " ", " ");
+ returnString = StringUtils.removeStart(returnString, secondSeparator + " ");
+ return TextData.NewInstance(returnString,Language.DEFAULT(),TextFormat.NewInstance("", "Text", ""));
+ }
+
+
+
+ /** recursive function that goes through a tree containing the order in which the description has to be generated,
+ * if an element of this tree matches one of the TaxonDescription, a DescriptionBuilder is called which returns a TextData with the corresponding description.
+ *
+ * @param children the children of the feature node considered
+ * @param parent the feature node considered
+ * @param description the TaxonDescription element for which we want a natural language output
+ * @param language The language in which the description has to be written
+ * @param floor integer to keep track of the level in the tree
+ * @return a list of TextData elements containing the part of description corresponding to the feature node considered