Revision 5ab3e456
Added by Katja Luther over 8 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfTaxonNameImport.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.io.tcsrdf; |
11 | 11 |
|
12 |
import java.io.IOException; |
|
12 | 13 |
import java.io.InputStream; |
14 |
import java.util.List; |
|
13 | 15 |
import java.util.Set; |
14 | 16 |
|
15 | 17 |
import org.apache.log4j.Logger; |
... | ... | |
20 | 22 |
|
21 | 23 |
import com.hp.hpl.jena.rdf.model.Model; |
22 | 24 |
import com.hp.hpl.jena.rdf.model.ModelFactory; |
23 |
import com.hp.hpl.jena.rdf.model.Property; |
|
24 | 25 |
import com.hp.hpl.jena.rdf.model.RDFNode; |
25 | 26 |
import com.hp.hpl.jena.rdf.model.ResIterator; |
26 | 27 |
import com.hp.hpl.jena.rdf.model.Resource; |
27 | 28 |
import com.hp.hpl.jena.rdf.model.Statement; |
28 | 29 |
import com.hp.hpl.jena.rdf.model.StmtIterator; |
30 |
import com.hp.hpl.jena.rdf.model.Property; |
|
31 |
|
|
32 |
|
|
33 |
|
|
29 | 34 |
|
30 | 35 |
import eu.etaxonomy.cdm.common.XmlHelp; |
31 | 36 |
import eu.etaxonomy.cdm.io.common.ICdmIO; |
... | ... | |
44 | 49 |
import eu.etaxonomy.cdm.model.reference.Reference; |
45 | 50 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
46 | 51 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
47 |
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser; |
|
48 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
|
49 | 52 |
|
50 | 53 |
/** |
51 | 54 |
* @author a.mueller |
... | ... | |
57 | 60 |
private static final Logger logger = Logger.getLogger(TcsRdfTaxonNameImport.class); |
58 | 61 |
|
59 | 62 |
private static int modCount = 5000; |
60 |
INonViralNameParser nameParser = new NonViralNameParserImpl(); |
|
61 | 63 |
|
62 | 64 |
public TcsRdfTaxonNameImport(){ |
63 | 65 |
super(); |
... | ... | |
125 | 127 |
Resource elTaxonName = root.getResource(taxonNameNamespace); |
126 | 128 |
|
127 | 129 |
int i = 0; |
128 |
|
|
130 |
|
|
129 | 131 |
TaxonNameBase name; |
130 | 132 |
Property property = root.getProperty(taxonNameNamespace+"authorship"); |
131 |
|
|
133 |
|
|
132 | 134 |
ResIterator iterator = root.listSubjectsWithProperty(property, (RDFNode) null); |
133 | 135 |
String id ; |
134 | 136 |
while (iterator.hasNext()){ |
135 |
|
|
137 |
|
|
136 | 138 |
Resource resource = iterator.next(); |
137 |
|
|
139 |
|
|
138 | 140 |
name = handleNameResource(resource, config); |
139 | 141 |
id = resource.getNameSpace(); |
140 | 142 |
taxonNameMap.put(id, name); |
141 | 143 |
} |
142 |
|
|
144 |
|
|
143 | 145 |
logger.info(i + " names handled"); |
144 | 146 |
getNameService().save(taxonNameMap.objects()); |
145 | 147 |
// makeNameSpecificData(nameMap); |
... | ... | |
154 | 156 |
protected boolean isIgnore(TcsRdfImportState state){ |
155 | 157 |
return ! state.getConfig().isDoTaxonNames(); |
156 | 158 |
} |
157 |
|
|
159 |
|
|
158 | 160 |
protected TaxonNameBase handleNameModel(Model model, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap, String uri){ |
159 | 161 |
Resource nameAbout = model.getResource(uri); |
160 | 162 |
TaxonNameBase result = handleNameResource(nameAbout, config); |
161 | 163 |
taxonNameMap.put(uri, result); |
162 | 164 |
return result; |
163 |
|
|
165 |
|
|
164 | 166 |
} |
165 |
|
|
167 |
|
|
166 | 168 |
private TaxonNameBase handleNameResource(Resource nameAbout, TcsRdfImportConfigurator config){ |
167 | 169 |
String idNamespace = "TaxonName"; |
168 |
|
|
170 |
|
|
169 | 171 |
StmtIterator stmts = nameAbout.listProperties(); |
170 | 172 |
while(stmts.hasNext()){ |
171 | 173 |
System.out.println(stmts.next().getPredicate().toString()); |
172 | 174 |
} |
173 |
|
|
175 |
|
|
174 | 176 |
Property prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nomenclaturalCode"); |
175 | 177 |
Statement stateNomenclaturalCode = nameAbout.getProperty(prop); |
176 | 178 |
String strNomenclaturalCode = stateNomenclaturalCode.getObject().toString(); |
177 | 179 |
//Rank |
178 | 180 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"rankString"); |
179 | 181 |
String strRank = nameAbout.getProperty(prop).getString(); |
180 |
|
|
181 |
|
|
182 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
183 | 185 |
try { |
184 |
|
|
186 |
|
|
185 | 187 |
Rank rank = TcsRdfTransformer.rankString2Rank(strRank); |
186 | 188 |
NomenclaturalCode nomCode; |
187 | 189 |
if (strNomenclaturalCode != null){ |
... | ... | |
189 | 191 |
}else{ |
190 | 192 |
nomCode = NomenclaturalCode.ICNAFP; |
191 | 193 |
} |
192 |
|
|
194 |
|
|
193 | 195 |
TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank); |
194 | 196 |
|
195 | 197 |
Set<String> omitAttributes = null; |
196 | 198 |
//makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers); |
197 |
|
|
199 |
|
|
198 | 200 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nameComplete"); |
199 | 201 |
String strNameComplete = nameAbout.getProperty(prop).getString(); |
200 | 202 |
nameBase.setTitleCache(strNameComplete, true); |
201 |
|
|
203 |
|
|
202 | 204 |
prop = nameAbout.getModel().getProperty(config.getCommonNamespaceURIString()+"publishedIn"); |
203 | 205 |
String strPublishedIn = nameAbout.getProperty(prop).getString(); |
204 | 206 |
if (strPublishedIn != null && strPublishedIn != ""){ |
... | ... | |
224 | 226 |
((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false)); |
225 | 227 |
} |
226 | 228 |
} |
227 |
|
|
229 |
|
|
228 | 230 |
if (nameBase instanceof NonViralName){ |
229 | 231 |
NonViralName<?> nonViralName = (NonViralName<?>)nameBase; |
230 | 232 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"genusPart"); |
... | ... | |
235 | 237 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"uninomial"); |
236 | 238 |
strGenusPart = nameAbout.getProperty(prop).getString(); |
237 | 239 |
} |
238 |
|
|
240 |
|
|
239 | 241 |
nonViralName.setGenusOrUninomial(strGenusPart); |
240 |
|
|
242 |
|
|
241 | 243 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infragenericEpithet"); |
242 | 244 |
try{ |
243 | 245 |
String strInfragenericEpithet = nameAbout.getProperty(prop).getString(); |
244 | 246 |
nonViralName.setInfraGenericEpithet(strInfragenericEpithet); |
245 | 247 |
}catch(NullPointerException e){ |
246 |
|
|
248 |
|
|
247 | 249 |
} |
248 | 250 |
try { |
249 | 251 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"specificEpithet"); |
250 | 252 |
String strSpecificEpithet = nameAbout.getProperty(prop).getString(); |
251 | 253 |
nonViralName.setSpecificEpithet(strSpecificEpithet); |
252 | 254 |
}catch(NullPointerException e){ |
253 |
|
|
255 |
|
|
254 | 256 |
} |
255 | 257 |
try{ |
256 | 258 |
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infraspecificEpithet"); |
257 | 259 |
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString(); |
258 | 260 |
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet); |
259 | 261 |
}catch(NullPointerException e){ |
260 |
|
|
262 |
|
|
261 | 263 |
} |
262 | 264 |
//Authorships |
263 | 265 |
//TODO |
... | ... | |
268 | 270 |
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:2691-1" |
269 | 271 |
tm:index="1" |
270 | 272 |
tm:role="Combination Author"/> |
271 |
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1" |
|
273 |
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1"
|
|
272 | 274 |
tm:index="1" |
273 | 275 |
tm:role="Basionym Author"/> |
274 | 276 |
</tm:Team> |
... | ... | |
288 | 290 |
try{ |
289 | 291 |
stateAutorTeamTeam = stateAuthorTeam.getProperty(prop); |
290 | 292 |
}catch(Exception e){ |
291 |
|
|
293 |
|
|
292 | 294 |
} |
293 | 295 |
try{ |
294 | 296 |
prop = stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString()+"name"); |
295 | 297 |
stateAutorTeamName = stateAuthorTeam.getProperty(prop); |
296 | 298 |
}catch(Exception e){ |
297 |
|
|
299 |
|
|
298 | 300 |
} |
299 | 301 |
try{ |
300 | 302 |
prop = nameAbout.getModel().getProperty(config.getTeamNamespaceURIString()+"hasMember"); |
301 | 303 |
stateTeamMember = ((Resource)stateAuthorTeam.getObject()).listProperties(prop); |
302 | 304 |
String memberString = null; |
303 | 305 |
Person person; |
304 |
if (stateTeamMember.toList().size() ==1){ |
|
305 |
person = Person.NewTitledInstance(authorTeam.getTitleCache()); |
|
306 |
}else { |
|
307 |
nameParser.parseAuthors(nonViralName, authorTeam.getTitleCache()); |
|
308 |
} |
|
309 |
/* for (Statement statement :stateTeamMember.toList()){ |
|
306 |
for (Statement statement :stateTeamMember.toList()){ |
|
310 | 307 |
memberString =statement.getObject().toString(); |
311 | 308 |
if (memberString != null){ |
312 | 309 |
person = Person.NewTitledInstance(memberString); |
313 | 310 |
authorTeam.addTeamMember(person); |
314 | 311 |
} |
315 |
}*/
|
|
312 |
} |
|
316 | 313 |
}catch(Exception e){ |
317 | 314 |
System.err.println(e.getMessage()); |
318 | 315 |
} |
319 | 316 |
} |
320 |
|
|
321 |
|
|
322 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
323 | 320 |
nonViralName.setCombinationAuthorship(authorTeam); |
324 |
|
|
321 |
|
|
325 | 322 |
//Annotations: |
326 | 323 |
/* |
327 | 324 |
* <tn:hasAnnotation> |
... | ... | |
329 | 326 |
<tn:noteType rdf:resource="http://rs.tdwg.org/ontology/voc/TaxonName#replacementNameFor"/> |
330 | 327 |
<tn:objectTaxonName rdf:resource="urn:lsid:ipni.org:names:151538-1"/> |
331 | 328 |
</tn:NomenclaturalNote> |
332 |
</tn:hasAnnotation> |
|
329 |
</tn:hasAnnotation>
|
|
333 | 330 |
*/ |
334 | 331 |
/* |
335 | 332 |
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString(); |
... | ... | |
373 | 370 |
//ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace); |
374 | 371 |
|
375 | 372 |
//checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers); |
376 |
|
|
373 |
|
|
377 | 374 |
return nameBase; |
378 |
|
|
375 |
|
|
379 | 376 |
}catch(Exception e){ |
380 | 377 |
e.printStackTrace(); |
381 | 378 |
return null; |
... | ... | |
384 | 381 |
//name |
385 | 382 |
String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace); |
386 | 383 |
nameBase.setTitleCache(strNameComplete, true); |
387 |
|
|
384 |
|
|
388 | 385 |
//Reference |
389 | 386 |
//TODO |
390 | 387 |
String tcsElementName = "publishedIn"; |
... | ... | |
442 | 439 |
if (nameBase instanceof NonViralName){ |
443 | 440 |
NonViralName<?> nonViralName = (NonViralName<?>)nameBase; |
444 | 441 |
String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace); |
445 |
|
|
442 |
|
|
446 | 443 |
//for names of rank genus the uninomial property should be used |
447 | 444 |
if (strGenusPart == null){ |
448 | 445 |
strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace); |
449 | 446 |
} |
450 | 447 |
nonViralName.setGenusOrUninomial(strGenusPart); |
451 |
|
|
448 |
|
|
452 | 449 |
String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace); |
453 | 450 |
nonViralName.setGenusOrUninomial(strInfragenericEpithet); |
454 |
|
|
455 |
|
|
456 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
457 | 454 |
String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace); |
458 | 455 |
nonViralName.setSpecificEpithet(strSpecificEpithet); |
459 |
|
|
456 |
|
|
460 | 457 |
String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace); |
461 | 458 |
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet); |
462 | 459 |
//AuthorTeams |
... | ... | |
512 | 509 |
} |
513 | 510 |
return null;*/ |
514 | 511 |
} |
515 |
|
|
512 |
|
|
516 | 513 |
protected TaxonNameBase handleNameElement(Element elTaxonName, Namespace rdfNamespace, Namespace taxonNameNamespace, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap){ |
517 | 514 |
String idNamespace = "TaxonName"; |
518 | 515 |
Attribute about = elTaxonName.getAttribute("about", rdfNamespace); |
519 |
|
|
516 |
|
|
520 | 517 |
//create TaxonName element |
521 |
|
|
522 |
|
|
518 |
|
|
519 |
|
|
523 | 520 |
String nameAbout = elTaxonName.getAttributeValue("about", rdfNamespace); |
524 | 521 |
if (nameAbout == null){ |
525 | 522 |
nameAbout = XmlHelp.getChildAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "about", rdfNamespace); |
526 | 523 |
} |
527 |
|
|
528 |
|
|
524 |
|
|
525 |
|
|
529 | 526 |
String strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rankString", taxonNameNamespace, "rankString", rdfNamespace); |
530 | 527 |
if (strRank == null){ |
531 | 528 |
strRank = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "rankString", rdfNamespace); |
532 |
|
|
529 |
|
|
533 | 530 |
} |
534 |
|
|
531 |
|
|
535 | 532 |
if (strRank == null){ |
536 | 533 |
strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rank", taxonNameNamespace, "resource", rdfNamespace); |
537 |
|
|
534 |
|
|
538 | 535 |
} |
539 |
|
|
536 |
|
|
540 | 537 |
String strNomenclaturalCode = XmlHelp.getChildContentAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "nomenclaturalCode", rdfNamespace); |
541 | 538 |
if (strNomenclaturalCode == null){ |
542 | 539 |
strNomenclaturalCode = XmlHelp.getChildAttributeValue(elTaxonName, "nomenclaturalCode", taxonNameNamespace, "resource", rdfNamespace); |
543 |
|
|
540 |
|
|
544 | 541 |
} |
545 | 542 |
try { |
546 |
|
|
543 |
|
|
547 | 544 |
Rank rank = TcsRdfTransformer.rankString2Rank(strRank); |
548 | 545 |
NomenclaturalCode nomCode; |
549 | 546 |
if (strNomenclaturalCode != null){ |
... | ... | |
551 | 548 |
}else{ |
552 | 549 |
nomCode = NomenclaturalCode.ICNAFP; |
553 | 550 |
} |
554 |
|
|
551 |
|
|
555 | 552 |
TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank); |
556 | 553 |
|
557 | 554 |
Set<String> omitAttributes = null; |
558 | 555 |
//makeStandardMapper(elTaxonName, nameBase, omitAttributes, standardMappers); |
559 |
|
|
556 |
|
|
560 | 557 |
//name |
561 | 558 |
String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace); |
562 | 559 |
nameBase.setTitleCache(strNameComplete, true); |
563 |
|
|
560 |
|
|
564 | 561 |
//Reference |
565 | 562 |
//TODO |
566 | 563 |
String tcsElementName = "publishedIn"; |
... | ... | |
618 | 615 |
if (nameBase instanceof NonViralName){ |
619 | 616 |
NonViralName<?> nonViralName = (NonViralName<?>)nameBase; |
620 | 617 |
String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace); |
621 |
|
|
618 |
|
|
622 | 619 |
//for names of rank genus the uninomial property should be used |
623 | 620 |
if (strGenusPart == null){ |
624 | 621 |
strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace); |
625 | 622 |
} |
626 | 623 |
nonViralName.setGenusOrUninomial(strGenusPart); |
627 |
|
|
624 |
|
|
628 | 625 |
String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace); |
629 | 626 |
nonViralName.setGenusOrUninomial(strInfragenericEpithet); |
630 |
|
|
631 |
|
|
632 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
633 | 630 |
String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace); |
634 | 631 |
nonViralName.setSpecificEpithet(strSpecificEpithet); |
635 |
|
|
632 |
|
|
636 | 633 |
String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace); |
637 | 634 |
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet); |
638 | 635 |
//AuthorTeams |
... | ... | |
693 | 690 |
Model model = ModelFactory.createDefaultModel(); |
694 | 691 |
try{ |
695 | 692 |
model.read(is, null); |
696 |
|
|
693 |
|
|
697 | 694 |
config.makeNamespaces(model); |
698 |
|
|
695 |
|
|
699 | 696 |
String rdfNamespace = config.getRdfNamespaceURIString(); |
700 | 697 |
String taxonNameNamespace = config.getTnNamespaceURIString(); |
701 | 698 |
return handleNameModel(model, config, taxonNameMap, uri); |
702 |
|
|
703 |
|
|
699 |
|
|
700 |
|
|
704 | 701 |
}catch(Exception e){ |
705 | 702 |
logger.debug("The file was no valid rdf file"); |
706 | 703 |
} |
707 |
|
|
708 |
|
|
709 |
|
|
704 |
|
|
705 |
|
|
706 |
|
|
710 | 707 |
return null; |
711 | 708 |
} |
712 |
|
|
709 |
|
|
713 | 710 |
} |
Also available in: Unified diff
Revert "minor"
This reverts commit 64367d007ba404e037ccc2b6794b46c4f1f321bc.