Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 479bb1fb55
...
compare: 8f4123befe
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
9 .classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
View
23 .project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>pubmed_ws</name>
+ <comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
6 .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,6 @@
+#Thu May 03 14:42:26 CEST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
View
5 .settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
+#Thu May 03 14:42:23 CEST 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
View
65 pom.xml
@@ -0,0 +1,65 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>pubmed_ws</artifactId>
+ <packaging>jar</packaging>
+ <groupId>ch.epfl.bbp.nlp</groupId>
+ <version>0.1.0-SNAPSHOT</version>
+
+ <repositories>
+ <repository>
+ <id>ren_googlecode</id>
+ <url>https://ren-maven-repo.googlecode.com/git/snapshots/</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <!-- WServices -->
+ <dependency>
+ <groupId>gov.nih.nlm.ncbi</groupId>
+ <artifactId>eutils</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-adb</artifactId>
+ <version>1.5.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-transport-local</artifactId>
+ <version>1.5.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-transport-http</artifactId>
+ <version>1.5.4</version>
+ </dependency>
+
+ <!-- LOGGING -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>1.5.9-RC0</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>0.9.17</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.9-RC0</version>
+ </dependency>
+
+ <!-- TESTING -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
View
126 src/main/java/ch/epfl/bbp/uima/pubmed/PubmedSearch.java
@@ -0,0 +1,126 @@
+package ch.epfl.bbp.uima.pubmed;
+
+import gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub;
+import gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub.PubmedArticleType;
+import gov.nih.nlm.ncbi.www.soap.eutils.EUtilsServiceStub;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.axis2.AxisFault;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author renaud.richardet@epfl.ch
+ */
+public class PubmedSearch {
+ private static Logger LOG = LoggerFactory.getLogger(PubmedSearch.class);
+
+ private EUtilsServiceStub service;
+ private EFetchPubmedServiceStub service2;
+
+ public PubmedSearch() throws AxisFault {
+ init();
+ }
+
+ private void init() throws AxisFault {
+ service = new EUtilsServiceStub();
+ service2 = new EFetchPubmedServiceStub();
+ }
+
+ /**
+ * @param query
+ * @return a list of articles
+ */
+ public List<PubmedArticleType> search(String query) throws RemoteException {
+ return search(query, Integer.MAX_VALUE);
+ }
+
+ /**
+ * @param query
+ * @param maxNrResults
+ * @return a list of articles
+ */
+ public List<Integer> searchIds(String query) throws RemoteException {
+
+ EUtilsServiceStub.ESearchRequest req = new EUtilsServiceStub.ESearchRequest();
+ req.setDb("pubmed");
+ req.setEmail("gmail@gmail.com");
+ req.setTerm(query);
+ req.setRetStart("0");
+ req.setRetMax(Integer.MAX_VALUE + "");
+ EUtilsServiceStub.ESearchResult res = service.run_eSearch(req);
+ int count = new Integer(res.getCount());
+ LOG.debug("Found {} ids for query '{}'", count, query);
+
+ List<Integer> articleIds = new ArrayList<Integer>();
+ String[] idList = res.getIdList().getId();
+ for (String id : idList) {
+ articleIds.add(new Integer(id));
+ }
+ assert (count == articleIds.size()) : "result counts should match, "
+ + articleIds.size() + ":" + count;
+ return articleIds;
+ }
+
+ /**
+ * @param query
+ * @param maxNrResults
+ * @return a list of articles
+ */
+ public List<PubmedArticleType> search(String query, int maxNrResults)
+ throws RemoteException {
+ // STEP #1: search in PubMed for "query"
+ EUtilsServiceStub.ESearchRequest req = new EUtilsServiceStub.ESearchRequest();
+ req.setDb("pubmed");
+ req.setTerm(query);
+ req.setEmail("gmail@gmail.com");
+ // not working req.setRetStart("0"); req.setRetMax(maxNrResults + "");
+ // req.setSort("PublicationDate");
+ req.setUsehistory("y");// important!
+ EUtilsServiceStub.ESearchResult res = service.run_eSearch(req);
+ int count = new Integer(res.getCount());
+ LOG.debug("Found {} results for query '{}'", count, query);
+ // results output
+ String webEnv = res.getWebEnv();
+ String query_key = res.getQueryKey();
+ LOG.trace("WebEnv: " + webEnv + "\nQueryKey: " + query_key);
+
+ // STEP #2: fetch articles from Pubmed
+ List<PubmedArticleType> articles = new ArrayList<EFetchPubmedServiceStub.PubmedArticleType>();
+ int fetchesPerRuns = Math.min(2000, maxNrResults);
+ int runs = (int) Math.ceil(count / new Double(fetchesPerRuns));
+ int start = 0;
+ for (int i = 0; i < runs; i++) {
+ LOG.debug("Fetching results from id {} to id {} ", start, start
+ + fetchesPerRuns);
+ EFetchPubmedServiceStub.EFetchRequest req2 = new EFetchPubmedServiceStub.EFetchRequest();
+ req2.setWebEnv(webEnv);
+ req2.setQuery_key(query_key);
+ req2.setRetstart(start + "");
+ req2.setRetmax(fetchesPerRuns + "");
+
+ EFetchPubmedServiceStub.EFetchResult res2 = service2
+ .run_eFetch(req2);
+ for (int j = 0; j < res2.getPubmedArticleSet()
+ .getPubmedArticleSetChoice().length; j++) {
+
+ PubmedArticleType art = res2.getPubmedArticleSet()
+ .getPubmedArticleSetChoice()[j].getPubmedArticle();
+ if (art != null) {
+ LOG.trace("found ID{}:{}", art.getMedlineCitation()
+ .getPMID(), art.getMedlineCitation().getArticle()
+ .getArticleTitle());
+ articles.add(art);
+ if (articles.size() == maxNrResults) { // enough!
+ return articles;
+ }
+ }
+ }
+ start += fetchesPerRuns;
+ }
+ return articles;
+ }
+}
View
33 src/test/java/ch/epfl/bbp/uima/pubmed/PubmedSearchTest.java
@@ -0,0 +1,33 @@
+package ch.epfl.bbp.uima.pubmed;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub.PubmedArticleType;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class PubmedSearchTest {
+
+ @Test
+ public void testNeuron() throws Exception {
+ List<PubmedArticleType> articles = new PubmedSearch().search("axon",
+ 5);
+ assertEquals(5, articles.size());
+ }
+ @Test
+ public void testNeuron2() throws Exception {
+ List<PubmedArticleType> articles = new PubmedSearch().search("axon",
+ 100);
+ assertEquals(100, articles.size());
+ }
+
+
+
+ @Test
+ public void testMesh() throws Exception {
+ List<Integer> articles = new PubmedSearch().searchIds("Axons[mesh]");
+ assertTrue(articles.size() > 10000);
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.