Mercurial > hg > anteater
comparison src/de/mpiwg/anteater/xml/impl/LinnaeusParser.java @ 5:35d8c78ccd36
include linneaus findings
author | jdamerow |
---|---|
date | Thu, 25 Oct 2012 15:26:03 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:dcc35f89dce3 | 5:35d8c78ccd36 |
---|---|
1 package de.mpiwg.anteater.xml.impl; | |
2 | |
3 import java.io.InputStream; | |
4 import java.util.ArrayList; | |
5 import java.util.List; | |
6 | |
7 import org.jdom2.Attribute; | |
8 import org.jdom2.DataConversionException; | |
9 import org.jdom2.Element; | |
10 | |
11 import de.mpiwg.anteater.species.scientific.ScientificName; | |
12 import de.mpiwg.anteater.xml.ICommonNameFinderParser; | |
13 | |
14 public class LinnaeusParser extends JDOMParser implements ICommonNameFinderParser { | |
15 | |
16 public LinnaeusParser(String content) { | |
17 super(content, false); | |
18 } | |
19 | |
20 public LinnaeusParser(InputStream stream) { | |
21 super(stream); | |
22 } | |
23 | |
24 @Override | |
25 public List<ScientificName> parseSpeciesNames() { | |
26 List<Element> names = executeXPath("/linnaeus/species", null); | |
27 | |
28 List<ScientificName> commonNames = new ArrayList<ScientificName>(); | |
29 for (Element name : names) { | |
30 ScientificName commonName = new ScientificName(); | |
31 | |
32 Attribute id = name.getAttribute("id"); | |
33 commonName.setNcbiId(id.getValue()); | |
34 commonName.setIdentifiedName(id.getValue()); | |
35 | |
36 Attribute start = name.getAttribute("start"); | |
37 try { | |
38 commonName.setStart(start.getIntValue()); | |
39 } catch (DataConversionException e) { | |
40 // TODO Auto-generated catch block | |
41 e.printStackTrace(); | |
42 } | |
43 | |
44 Attribute end = name.getAttribute("end"); | |
45 try { | |
46 commonName.setLength(end.getIntValue() - start.getIntValue()); | |
47 } catch (DataConversionException e) { | |
48 // TODO Auto-generated catch block | |
49 e.printStackTrace(); | |
50 } | |
51 | |
52 Attribute text = name.getAttribute("text"); | |
53 commonName.setScientificName(text.getValue()); | |
54 commonName.setReferenceInText(text.getValue()); | |
55 | |
56 commonNames.add(commonName); | |
57 } | |
58 | |
59 return commonNames; | |
60 } | |
61 | |
62 } |