Monday, June 13, 2011

Grabbing NeXML data: Part I

NeXML is fundamentally a type of XML only; with some special schema. Viewing it in this light it should not be difficult to extract any information from it. Here is the explanation for code snippet which is used to grab the metadata attached to the nodes.
One short note before that, There are no trees that have geographic coordinates attached to their nodes in TreeBase. However there are trees with metadata but none with geographic coordinates?

Here is what was suggested by Rutger to attach and access DarwinCore predicates for lat/lon coordinates.

<!-- surrounded by rest of tree description --> <node id="uid1" label="Some taxon" about="#uid1"

<meta id="uid2" property="dwc:DecimalLongitude" content="45.65"
xsi:type="nex:LiteralMeta" datatype="xsd:double"/>
<meta id="uid2" property="dwc:DecimalLatitude" content="37.21"
xsi:type="nex:LiteralMeta" datatype="xsd:double"/> </node>
<!-- surrounded by rest of tree description -->

1) To attach a darwin core coordinate to a node, you would do:
          URI nameSpaceURI = URI.create("");
          Annotation longitude = node.addAnnotationValue("dwc:DecimalLongitude", nameSpaceURI, new Double("45.65"));
          Annotation latitude = node.addAnnotationValue("dwc:DecimalLatitude",nameSpaceURI, new Double("37.21"));

2) Conversely, to read one:
  // a Set is returned because multiple annotations with the same predicate can exist, e.g.
  // for multiple authors on the same study Set<Object> longitudes = node.getAnnotationValues("dwc:      DecimalLongitude");
    Double longitude = (Double) longitudes.iterator().next(); Set<Object> latitudes = node.getAnnotationValues("dwc:DecimalLatitude");
    Double latitude = (Double) latitudes.iterator().next();"

Likewise information can be extracted from an OTU, I will show it in the next blog.

No comments:

Post a Comment