1 package eu
.etaxonomy
.cdm
.api
.service
;
3 import static org
.junit
.Assert
.assertNotNull
;
4 import static org
.junit
.Assert
.assertTrue
;
6 import java
.io
.FileNotFoundException
;
7 import java
.util
.HashSet
;
8 import java
.util
.Iterator
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.junit
.Before
;
14 import org
.junit
.Ignore
;
15 import org
.junit
.Test
;
16 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
18 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
19 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
20 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
21 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
22 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
23 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
24 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
25 import eu
.etaxonomy
.cdm
.model
.description
.State
;
26 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
27 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
28 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
29 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
30 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
31 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
36 @Ignore //FIXME Remove @Ignore once maximes code is completely comitted
37 public class NaturalLanguageGeneratorTest
extends CdmIntegrationTest
{
39 @SuppressWarnings("unused")
40 private static final Logger logger
= Logger
.getLogger(NaturalLanguageGeneratorTest
.class);
43 private INaturalLanguageGenerator generator
;
45 private FeatureTree featureTree
;
46 private TaxonDescription description
;
47 Set
<Feature
> featureSet
= new HashSet
<Feature
>();
50 public void setUp() throws Exception
{
51 // set up your test objects here
53 INonViralName tnb
= TaxonNameFactory
.NewNonViralInstance(null);
54 Taxon taxon
= Taxon
.NewInstance(tnb
, null);
55 description
= TaxonDescription
.NewInstance(taxon
);
57 featureTree
= FeatureTree
.NewInstance();
58 FeatureNode root
= FeatureNode
.NewInstance();
59 featureTree
.setRoot(root
);
60 String
[][][] tableStrings
= { { {"a","b"} } , { { "a1" , "a2" } , { "b1" } } };
61 buildBranches(root
,tableStrings
,0,2,0);
62 for (Iterator
<Feature
> f
= featureSet
.iterator() ; f
.hasNext() ;){
63 Feature feature
= f
.next();
64 CategoricalData cg
= CategoricalData
.NewInstance();
65 cg
.setFeature(feature
);
66 State state
= State
.NewInstance(null, feature
.getLabel()+"state", null);
67 StateData stateData
= StateData
.NewInstance();
68 stateData
.setState(state
);
69 cg
.addStateData(stateData
);
70 description
.addElement(cg
);
72 Feature qFeature
= Feature
.NewInstance(null, "c", null);
73 QuantitativeData qd
= QuantitativeData
.NewInstance();
74 MeasurementUnit munit
= MeasurementUnit
.NewInstance(null, "mm", null);
75 StatisticalMeasurementValue smv
= StatisticalMeasurementValue
.NewInstance();
76 smv
.setType(StatisticalMeasure
.AVERAGE());
78 qd
.addStatisticalValue(smv
);
80 qd
.setFeature(qFeature
);
81 description
.addElement(qd
);
82 FeatureNode qNode
= FeatureNode
.NewInstance(qFeature
);
87 public void testGenerateNaturalLanguageDescription() {
88 assertNotNull("FeatureTree should exist", featureTree
);
89 assertNotNull("TaxonDescription should exist", description
);
90 StringBuilder stringBuilder
= new StringBuilder();
91 List
<TextData
> result
= generator
.generateNaturalLanguageDescription(featureTree
,description
, Language
.DEFAULT());
92 for (Iterator
<TextData
> td
= result
.iterator() ; td
.hasNext();) {
93 TextData textD
= td
.next();
94 stringBuilder
.append(textD
.getText(Language
.DEFAULT()));
96 assertTrue("Empty text",!stringBuilder
.equals(""));
97 System
.out
.println(stringBuilder
.toString());
100 public void buildBranches(FeatureNode parent
, String
[][][] children
, int level
, int depth
, int nodeNumber
) {
103 for (j
=0; j
<children
[level
][i
].length
; j
++) {
104 Feature feature
= Feature
.NewInstance(null, children
[level
][i
][j
], null);
105 featureSet
.add(feature
);
106 FeatureNode child
= FeatureNode
.NewInstance(feature
);
107 parent
.addChild(child
);
109 buildBranches(child
, children
,level
+1,depth
, j
);
116 * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
119 public void createTestDataSet() throws FileNotFoundException
{
120 // TODO Auto-generated method stub