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