All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.carrot2.source.pubmed.PubMedIdSearchHandler Maven / Gradle / Ivy

Go to download

Carrot2 search results clustering framework core, document sources and clustering algorithms.

There is a newer version: 4.6.0
Show newest version

/*
 * Carrot2 project.
 *
 * Copyright (C) 2002-2015, Dawid Weiss, Stanisław Osiński.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * http://www.carrot2.org/carrot2.LICENSE
 */

package org.carrot2.source.pubmed;

import java.util.List;

import org.xml.sax.SAXException;

import com.google.common.collect.Lists;

/**
 * A SAX content handler that collects PubMed IDs.
 */
class PubMedIdSearchHandler extends PathTrackingHandler
{
    /** Collects IDs of PubMed entries to retrieve */
    private List pubMedPrimaryIds;

    /** Total match count. */
    private long matchCount;

    public PubMedIdSearchHandler()
    {
        super.addTrigger("/eSearchResult/Count", new Trigger() {
            @Override
            public void afterElement(String localName, String path, String text)
            {
                matchCount = Long.parseLong(text);
            }
        });
        
        super.addTrigger("/eSearchResult/IdList/Id", new Trigger() {
            @Override
            public void afterElement(String localName, String path, String text)
            {
                pubMedPrimaryIds.add(text);
            }
        });
    }
    
    @Override
    public void startDocument() throws SAXException
    {
        matchCount = -1;
        pubMedPrimaryIds = Lists.newArrayList();
    }
    
    public List getPubMedPrimaryIds()
    {
        return pubMedPrimaryIds;
    }

    public long getMatchCount()
    {
        return matchCount;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy