changeset 5:35d8c78ccd36

include linneaus findings
author jdamerow
date Thu, 25 Oct 2012 15:26:03 -0700
parents dcc35f89dce3
children 50aeb96a8ee9
files src/de/mpiwg/anteater/xml/ICommonNameFinderParser.java src/de/mpiwg/anteater/xml/impl/LinnaeusParser.java
diffstat 2 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/anteater/xml/ICommonNameFinderParser.java	Thu Oct 25 15:26:03 2012 -0700
@@ -0,0 +1,11 @@
+package de.mpiwg.anteater.xml;
+
+import java.util.List;
+
+import de.mpiwg.anteater.species.scientific.ScientificName;
+
+public interface ICommonNameFinderParser {
+
+	public abstract List<ScientificName> parseSpeciesNames();
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/anteater/xml/impl/LinnaeusParser.java	Thu Oct 25 15:26:03 2012 -0700
@@ -0,0 +1,62 @@
+package de.mpiwg.anteater.xml.impl;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jdom2.Attribute;
+import org.jdom2.DataConversionException;
+import org.jdom2.Element;
+
+import de.mpiwg.anteater.species.scientific.ScientificName;
+import de.mpiwg.anteater.xml.ICommonNameFinderParser;
+
+public class LinnaeusParser extends JDOMParser implements ICommonNameFinderParser {
+
+	public LinnaeusParser(String content) {
+		super(content, false);
+	}	
+	
+	public LinnaeusParser(InputStream stream) {
+		super(stream);
+	}
+	
+	@Override
+	public List<ScientificName> parseSpeciesNames() {
+		List<Element> names = executeXPath("/linnaeus/species", null);
+		
+		List<ScientificName> commonNames = new ArrayList<ScientificName>();
+		for (Element name : names) {
+			ScientificName commonName = new ScientificName();
+			
+			Attribute id = name.getAttribute("id");
+			commonName.setNcbiId(id.getValue());
+			commonName.setIdentifiedName(id.getValue());
+			
+			Attribute start = name.getAttribute("start");
+			try {
+				commonName.setStart(start.getIntValue());
+			} catch (DataConversionException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			
+			Attribute end = name.getAttribute("end");
+			try {
+				commonName.setLength(end.getIntValue() - start.getIntValue());
+			} catch (DataConversionException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			
+			Attribute text = name.getAttribute("text");
+			commonName.setScientificName(text.getValue());
+			commonName.setReferenceInText(text.getValue());
+			
+			commonNames.add(commonName);
+		}
+		
+		return commonNames;
+	}
+
+}