Search in sources :

Example 1 with TreeList

use of org.apache.commons.collections4.list.TreeList in project eol-globi-data by jhpoelen.

the class DatasetImporterForGlobalWebDbTest method parseMatrix.

@Test
public void parseMatrix() throws IOException, StudyImporterException {
    List<Map<String, String>> interactions = new TreeList<>();
    InteractionListener listener = interactions::add;
    DatasetImporterForGlobalWebDb.parseDietMatrix(listener, aDietMatrix, "some source citation");
    assertThat(interactions.size(), is(6));
    Map<String, String> first = interactions.get(0);
    assertThat(first.get(TaxonUtil.SOURCE_TAXON_NAME), is("Balanus balanoides"));
    assertThat(first.get(TaxonUtil.TARGET_TAXON_NAME), is("detritus"));
    assertThat(first.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME), is("eats"));
    assertThat(first.get(DatasetImporterForTSV.INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(first.get(DatasetImporterForTSV.HABITAT_NAME), is("Exposed rocky shore"));
    assertThat(first.get(DatasetImporterForTSV.LOCALITY_NAME), is("New England, U.S.A."));
    assertThat(first.get(DatasetImporterForTSV.REFERENCE_ID), is("df06df18abafa63a6f0473d6d0e6ce68"));
    assertThat(first.get(DatasetImporterForTSV.REFERENCE_CITATION), is("B.A. Menge and J.P. Sutherland. Species Diversity Gradients: Synthesis of the Roles of Predation, Competition, and Temporal Heterogeneity. The American Naturalist, 110(973), pp. 351-369."));
    assertThat(first.get(DatasetImporterForTSV.DATASET_CITATION), is("some source citation"));
    Map<String, String> last = interactions.get(5);
    assertThat(last.get(TaxonUtil.SOURCE_TAXON_NAME), is("Thais lapillus"));
    assertThat(last.get(TaxonUtil.TARGET_TAXON_NAME), is("Mytilus edulis"));
    assertThat(last.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME), is("eats"));
    assertThat(last.get(DatasetImporterForTSV.INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(last.get(DatasetImporterForTSV.HABITAT_NAME), is("Exposed rocky shore"));
    assertThat(last.get(DatasetImporterForTSV.LOCALITY_NAME), is("New England, U.S.A."));
    assertThat(last.get(DatasetImporterForTSV.REFERENCE_ID), is("df06df18abafa63a6f0473d6d0e6ce68"));
    assertThat(last.get(DatasetImporterForTSV.REFERENCE_CITATION), is("B.A. Menge and J.P. Sutherland. Species Diversity Gradients: Synthesis of the Roles of Predation, Competition, and Temporal Heterogeneity. The American Naturalist, 110(973), pp. 351-369."));
    assertThat(last.get(DatasetImporterForTSV.DATASET_CITATION), is("some source citation"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) TreeList(org.apache.commons.collections4.list.TreeList) Map(java.util.Map) Test(org.junit.Test)

Example 2 with TreeList

use of org.apache.commons.collections4.list.TreeList in project eol-globi-data by jhpoelen.

the class DatasetRegistryZenodo method findZenodoGitHubArchives.

private static Map<String, List<Pair<Long, URI>>> findZenodoGitHubArchives(NodeList records) throws XPathExpressionException, MalformedURLException {
    Map<String, List<Pair<Long, URI>>> namespace2ZenodoPubs = new TreeMap<>();
    Long idMax = null;
    for (int i = 0; i < records.getLength(); i++) {
        Node item = records.item(i);
        String fullId = (String) XmlUtil.applyXPath(item, "header/identifier", XPathConstants.STRING);
        if (StringUtils.startsWith(fullId, PREFIX_ZENODO)) {
            String idString = StringUtils.replace(fullId, PREFIX_ZENODO, "");
            String relatedIdentifier = StringUtils.trim((String) XmlUtil.applyXPath(item, ".//*[local-name()='relatedIdentifier']", XPathConstants.STRING));
            if (StringUtils.startsWith(relatedIdentifier, PREFIX_GITHUB_RELATION)) {
                String replace = StringUtils.replace(StringUtils.trim(relatedIdentifier), PREFIX_GITHUB_RELATION, "");
                String[] split = StringUtils.split(replace, "/");
                Long id = NumberUtils.createLong(idString);
                if (split.length > 3) {
                    String githubRepo = split[0] + "/" + split[1];
                    URI archiveURI = URI.create("https://zenodo.org/record/" + idString + "/files/" + githubRepo + "-" + split[3] + ".zip");
                    List<Pair<Long, URI>> versions = namespace2ZenodoPubs.getOrDefault(githubRepo, new TreeList<>());
                    namespace2ZenodoPubs.put(githubRepo, new TreeList<Pair<Long, URI>>(versions) {

                        {
                            add(Pair.of(id, archiveURI));
                        }
                    });
                }
            }
        }
    }
    return namespace2ZenodoPubs;
}
Also used : Node(org.w3c.dom.Node) TreeMap(java.util.TreeMap) URI(java.net.URI) ArrayList(java.util.ArrayList) TreeList(org.apache.commons.collections4.list.TreeList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

TreeList (org.apache.commons.collections4.list.TreeList)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Pair (org.apache.commons.lang3.tuple.Pair)1 InteractionListener (org.eol.globi.process.InteractionListener)1 Test (org.junit.Test)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1