1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.tcsrdf;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Iterator;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.jdom.Attribute;
|
17
|
import org.jdom.Element;
|
18
|
import org.jdom.Namespace;
|
19
|
import org.jdom.filter.ElementFilter;
|
20
|
import org.jdom.filter.Filter;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
|
23
|
import com.hp.hpl.jena.rdf.model.Model;
|
24
|
|
25
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
26
|
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
27
|
import eu.etaxonomy.cdm.io.common.TdwgAreaProvider;
|
28
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
29
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
30
|
import eu.etaxonomy.cdm.model.description.Feature;
|
31
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
32
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
33
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
34
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
35
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
36
|
|
37
|
/**
|
38
|
* @author a.mueller
|
39
|
* @since 29.05.2008
|
40
|
*/
|
41
|
@Component
|
42
|
public class TcsRdfTaxonImport extends TcsRdfImportBase implements ICdmIO<TcsRdfImportState> {
|
43
|
private static final long serialVersionUID = 4615869699069336295L;
|
44
|
|
45
|
private static final Logger logger = Logger.getLogger(TcsRdfTaxonImport.class);
|
46
|
|
47
|
private static int modCount = 30000;
|
48
|
|
49
|
public TcsRdfTaxonImport(){
|
50
|
super();
|
51
|
}
|
52
|
|
53
|
|
54
|
@Override
|
55
|
public boolean doCheck(TcsRdfImportState state){
|
56
|
boolean result = true;
|
57
|
logger.warn("Checking for Taxa not yet implemented");
|
58
|
//result &= checkArticlesWithoutJournal(bmiConfig);
|
59
|
//result &= checkPartOfJournal(bmiConfig);
|
60
|
|
61
|
return result;
|
62
|
}
|
63
|
|
64
|
protected static CdmSingleAttributeRDFMapperBase[] standardMappers = new CdmSingleAttributeRDFMapperBase[]{
|
65
|
// new CdmTextElementMapper("genusPart", "genusOrUninomial")
|
66
|
|
67
|
};
|
68
|
|
69
|
|
70
|
protected static CdmSingleAttributeRDFMapperBase[] operationalMappers = new CdmSingleAttributeRDFMapperBase[]{
|
71
|
new CdmUnclearMapper("hasName")
|
72
|
,new CdmUnclearMapper("hasName")
|
73
|
, new CdmUnclearMapper("accordingTo")
|
74
|
, new CdmUnclearMapper("hasRelationship")
|
75
|
, new CdmUnclearMapper("code", nsTgeo)
|
76
|
};
|
77
|
|
78
|
protected static CdmSingleAttributeRDFMapperBase[] unclearMappers = new CdmSingleAttributeRDFMapperBase[]{
|
79
|
new CdmUnclearMapper("primary")
|
80
|
, new CdmUnclearMapper("note", nsTcom)
|
81
|
, new CdmUnclearMapper("taxonStatus", nsTpalm)
|
82
|
|
83
|
, new CdmUnclearMapper("TaxonName", nsTn)
|
84
|
, new CdmUnclearMapper("dateOfEntry", nsTpalm)
|
85
|
};
|
86
|
|
87
|
|
88
|
|
89
|
@Override
|
90
|
protected void doInvoke(TcsRdfImportState state){
|
91
|
|
92
|
MapWrapper<TaxonBase> taxonMap = (MapWrapper<TaxonBase>)state.getStore(ICdmIO.TAXON_STORE);
|
93
|
MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>)state.getStore(ICdmIO.TAXONNAME_STORE);
|
94
|
MapWrapper<Reference> referenceMap = (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
|
95
|
MapWrapper<Reference> nomRefMap = (MapWrapper<Reference>)state.getStore(ICdmIO.NOMREF_STORE);
|
96
|
|
97
|
String xmlElementName;
|
98
|
String xmlAttributeName;
|
99
|
String elementNamespace;
|
100
|
String attributeNamespace;
|
101
|
|
102
|
logger.info("start makeTaxa ...");
|
103
|
|
104
|
TcsRdfImportConfigurator config = state.getConfig();
|
105
|
Model root = config.getSourceRoot();
|
106
|
|
107
|
String rdfNamespace = config.getRdfNamespaceURIString();
|
108
|
|
109
|
String idNamespace = "TaxonConcept";
|
110
|
xmlElementName = "TaxonConcept";
|
111
|
elementNamespace = config.getTcNamespaceURIString();
|
112
|
|
113
|
return;
|
114
|
}
|
115
|
|
116
|
|
117
|
/**
|
118
|
* @param rdfNamespace
|
119
|
* @param elTaxonConcept
|
120
|
* @return
|
121
|
*/
|
122
|
private boolean isSynonym(Element elTaxonConcept, Namespace tpalmNamespace) {
|
123
|
if (elTaxonConcept == null || ! "TaxonConcept".equalsIgnoreCase(elTaxonConcept.getName()) ){
|
124
|
return false;
|
125
|
}
|
126
|
Element status = elTaxonConcept.getChild("taxonStatus", tpalmNamespace);
|
127
|
if (status == null){
|
128
|
return false;
|
129
|
}else{
|
130
|
String statusText = status.getTextNormalize();
|
131
|
if ("S".equalsIgnoreCase(statusText)){
|
132
|
return true;
|
133
|
}else if ("A".equalsIgnoreCase(statusText)){
|
134
|
return false;
|
135
|
}else if ("C".equalsIgnoreCase(statusText)){
|
136
|
return false;
|
137
|
}else if ("V".equalsIgnoreCase(statusText)){
|
138
|
return false;
|
139
|
}else if ("O".equalsIgnoreCase(statusText)){
|
140
|
return false;
|
141
|
}else if ("U".equalsIgnoreCase(statusText)){
|
142
|
return false;
|
143
|
}else{
|
144
|
logger.warn("Unknown taxon status: " + statusText);
|
145
|
return false;
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
|
150
|
|
151
|
private boolean hasIsSynonymRelation(Element elTaxonConcept, Namespace rdfNamespace){
|
152
|
boolean result = false;
|
153
|
if (elTaxonConcept == null || ! "TaxonConcept".equalsIgnoreCase(elTaxonConcept.getName()) ){
|
154
|
return false;
|
155
|
}
|
156
|
|
157
|
String elName = "relationshipCategory";
|
158
|
Filter filter = new ElementFilter(elName, elTaxonConcept.getNamespace());
|
159
|
Iterator<Element> relationshipCategories = elTaxonConcept.getDescendants(filter);
|
160
|
while (relationshipCategories.hasNext()){
|
161
|
Element relationshipCategory = relationshipCategories.next();
|
162
|
Attribute resource = relationshipCategory.getAttribute("resource", rdfNamespace);
|
163
|
String isSynonymFor = "http://rs.tdwg.org/ontology/voc/TaxonConcept#IsSynonymFor";
|
164
|
if (resource != null && isSynonymFor.equalsIgnoreCase(resource.getValue()) ){
|
165
|
return true;
|
166
|
}
|
167
|
}
|
168
|
return result;
|
169
|
}
|
170
|
|
171
|
private List<DescriptionElementBase> makeGeo(Element elConcept, Namespace geoNamespace, Namespace rdfNamespace){
|
172
|
List<DescriptionElementBase> result = new ArrayList<DescriptionElementBase>();
|
173
|
String xmlElementName = "code";
|
174
|
List<Element> elGeos = elConcept.getChildren(xmlElementName, geoNamespace);
|
175
|
|
176
|
int i = 0;
|
177
|
//for each geoTag
|
178
|
for (Element elGeo : elGeos){
|
179
|
//if ((i++ % modCount) == 0){ logger.info("Geocodes handled: " + (i-1));}
|
180
|
|
181
|
String strGeoRegion = elGeo.getAttributeValue("resource", rdfNamespace);
|
182
|
strGeoRegion = strGeoRegion.replace("http://rs.tdwg.org/ontology/voc/GeographicRegion#", "");
|
183
|
NamedArea namedArea = TdwgAreaProvider.getAreaByTdwgAbbreviation(strGeoRegion);
|
184
|
PresenceAbsenceTerm status = PresenceAbsenceTerm.PRESENT();
|
185
|
DescriptionElementBase distribution = Distribution.NewInstance(namedArea, status);
|
186
|
distribution.setFeature(Feature.DISTRIBUTION());
|
187
|
//System.out.println(namedArea);
|
188
|
|
189
|
result.add(distribution);
|
190
|
}
|
191
|
return result;
|
192
|
}
|
193
|
|
194
|
/* (non-Javadoc)
|
195
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
196
|
*/
|
197
|
@Override
|
198
|
protected boolean isIgnore(TcsRdfImportState state){
|
199
|
return ! state.getConfig().isDoTaxa();
|
200
|
}
|
201
|
|
202
|
|
203
|
}
|