import java.util.Set;
import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;
+import eu.etaxonomy.cdm.format.description.DefaultCategoricalDescriptionBuilder;
+import eu.etaxonomy.cdm.format.description.DefaultQuantitativeDescriptionBuilder;
+import eu.etaxonomy.cdm.format.description.DescriptionBuilder;
import eu.etaxonomy.cdm.model.common.Annotation;
import eu.etaxonomy.cdm.model.common.AnnotationType;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.description.TextData;
import eu.etaxonomy.cdm.model.description.TextFormat;
-import eu.etaxonomy.cdm.model.term.TermTreeNode;
-import eu.etaxonomy.cdm.model.term.FeatureTree;
+import eu.etaxonomy.cdm.model.term.TermTree;
+import eu.etaxonomy.cdm.model.term.TermNode;
/**
*
* @author m.venin
* @since 13.04.2010
- * @version 1.0
*/
@Component
public class NaturalLanguageGenerator implements INaturalLanguageGenerator {
+
@SuppressWarnings("unused")
- private static final Logger logger = Logger.getLogger(NaturalLanguageGenerator.class);
+ private static final Logger logger = LogManager.getLogger(NaturalLanguageGenerator.class);
private String firstSeparator = ",";
private String secondSeparator = ".";
- private List<Integer> levels = new ArrayList<Integer>();
+ private List<Integer> levels = new ArrayList<>();
private DescriptionBuilder<QuantitativeData> quantitativeDescriptionBuilder = new DefaultQuantitativeDescriptionBuilder();
private DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();
private TextData previousTextData;
- DeltaTextDataProcessor deltaTextDataProcessor = new DeltaTextDataProcessor();
+ private DeltaTextDataProcessor deltaTextDataProcessor = new DeltaTextDataProcessor();
private Map<String, INaturalLanguageTextDataProcessor> elementProcessors;
* @return a list of TextData, each one being a basic element of the natural language description
*/
@Override
- public List<TextData> generateNaturalLanguageDescription(FeatureTree featureTree,TaxonDescription description) {
+ public List<TextData> generateNaturalLanguageDescription(TermTree featureTree,TaxonDescription description) {
return generateNaturalLanguageDescription(featureTree,description,Language.DEFAULT());
}
* @return a list of TextData, each one being a basic element of the natural language description
*/
@Override
- public List<TextData> generateNaturalLanguageDescription(FeatureTree featureTree, TaxonDescription description, Language language) {
+ public List<TextData> generateNaturalLanguageDescription(TermTree featureTree, TaxonDescription description, Language language) {
List<Language> languages = new ArrayList<Language>();
languages.add(language);
initNaturalLanguageDescriptionElementProcessors(description.getAnnotations());
* @return a list of TextData, each one being a basic element of the natural language description
*/
@Override
- public List<TextData> generatePreferredNaturalLanguageDescription(FeatureTree featureTree,TaxonDescription description, List<Language> languages) {
+ public List<TextData> generatePreferredNaturalLanguageDescription(TermTree featureTree,TaxonDescription description, List<Language> languages) {
initNaturalLanguageDescriptionElementProcessors(description.getAnnotations());
return buildBranchesDescr(featureTree.getRootChildren(), featureTree.getRoot(), description, languages,0);
}
* @return a TextData in the default language.
*/
@Override
- public TextData generateSingleTextData(FeatureTree featureTree, TaxonDescription description) {
+ public TextData generateSingleTextData(TermTree featureTree, TaxonDescription description) {
return generateSingleTextData(featureTree,description,Language.DEFAULT());
}
* @return a TextData in the specified language.
*/
@Override
- public TextData generateSingleTextData(FeatureTree featureTree, TaxonDescription description, Language language) {
+ public TextData generateSingleTextData(TermTree featureTree, TaxonDescription description, Language language) {
List<Language> languages = new ArrayList<Language>();
languages.add(language);
return generatePreferredSingleTextData(featureTree,description,languages);
* @return a TextData using the languages (in the given order of preference)
*/
@Override
- public TextData generatePreferredSingleTextData(FeatureTree featureTree, TaxonDescription description, List<Language> languages) {
+ 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
* @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
*/
- private List<TextData> buildBranchesDescr(List<TermTreeNode> children, TermTreeNode<Feature> parent, TaxonDescription description, List<Language> languages, int floor) {
+ private List<TextData> buildBranchesDescr(List<TermNode> children, TermNode<Feature> parent, TaxonDescription description, List<Language> languages, int floor) {
List<TextData> listTextData = new ArrayList<TextData>();
floor++; // counter to know the current level in the tree
featureName = new TextData(); // else an empty TextData is created (because we keep track of the features, it is useful to inform when the upper node has no feature attached)
}
- for (Iterator<TermTreeNode> ifn = children.iterator() ; ifn.hasNext() ;){
+ for (Iterator<TermNode> ifn = children.iterator() ; ifn.hasNext() ;){
previousTextData = featureName; // this allows to keep track of the name of the feature one level up in the tree
- TermTreeNode fn = ifn.next();
+ TermNode fn = ifn.next();
listTextData.addAll(buildBranchesDescr(fn.getChildNodes(),fn,description, languages, floor));
}
}