@Test public void doLink() throws NodeFactoryException, PropertyEnricherException { StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "some citation")); new LinkerDOI().index(new GraphServiceFactoryProxy(getGraphDb())); Study studyResolved = nodeFactory.getOrCreateStudy(study); assertThat(studyResolved.getDOI(), is(nullValue())); assertThat(study.getDOI(), is(nullValue())); }
@Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction transaction = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("studies"); IndexHits<Node> hits = taxons.query("*:*"); int counter = 0; int counterResolved = 0; String msg = "linking study citations to DOIs"; LOG.info(msg + " started..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); Map<String, StudyNode> batch = new HashMap<>(); for (Node hit : hits) { counter++; StudyNode study = new StudyNode(hit); if (shouldResolve(study)) { counterResolved++; batch.put(study.getCitation(), study); } if (batch.size() >= BATCH_SIZE) { LOG.info(logProgress(counterResolved, stopWatch)); resolveBatch(doiResolver, batch); batch.clear(); transaction.success(); transaction.close(); transaction = graphDb.beginTx(); } } resolveBatch(doiResolver, batch); LOG.info(msg + " complete. Out of [" + counter + "] references, [" + counterResolved + "] needed resolving."); if (counter % 100 != 0) { LOG.info(logProgress(counterResolved, stopWatch)); } stopWatch.stop(); transaction.success(); } finally { transaction.close(); } }
LinkerDOI implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction transaction = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("studies"); IndexHits<Node> hits = taxons.query("*:*"); int counter = 0; int counterResolved = 0; String msg = "linking study citations to DOIs"; LOG.info(msg + " started..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); Map<String, StudyNode> batch = new HashMap<>(); for (Node hit : hits) { counter++; StudyNode study = new StudyNode(hit); if (shouldResolve(study)) { counterResolved++; batch.put(study.getCitation(), study); } if (batch.size() >= BATCH_SIZE) { LOG.info(logProgress(counterResolved, stopWatch)); resolveBatch(doiResolver, batch); batch.clear(); transaction.success(); transaction.close(); transaction = graphDb.beginTx(); } } resolveBatch(doiResolver, batch); LOG.info(msg + " complete. Out of [" + counter + "] references, [" + counterResolved + "] needed resolving."); if (counter % 100 != 0) { LOG.info(logProgress(counterResolved, stopWatch)); } stopWatch.stop(); transaction.success(); } finally { transaction.close(); } } }
LinkerDOI implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction transaction = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("studies"); IndexHits<Node> hits = taxons.query("*:*"); int counter = 0; int counterResolved = 0; String msg = "linking study citations to DOIs"; LOG.info(msg + " started..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); Map<String, StudyNode> batch = new HashMap<>(); for (Node hit : hits) { counter++; StudyNode study = new StudyNode(hit); if (shouldResolve(study)) { counterResolved++; batch.put(study.getCitation(), study); } if (batch.size() >= BATCH_SIZE) { LOG.info(logProgress(counterResolved, stopWatch)); resolveBatch(doiResolver, batch); batch.clear(); transaction.success(); transaction.close(); transaction = graphDb.beginTx(); } } resolveBatch(doiResolver, batch); LOG.info(msg + " complete. Out of [" + counter + "] references, [" + counterResolved + "] needed resolving."); if (counter % 100 != 0) { LOG.info(logProgress(counterResolved, stopWatch)); } stopWatch.stop(); transaction.success(); } finally { transaction.close(); } } LinkerDOI();  LinkerDOI(DOIResolver resolver); }
LinkerDOI implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction transaction = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("studies"); IndexHits<Node> hits = taxons.query("*:*"); int counter = 0; int counterResolved = 0; String msg = "linking study citations to DOIs"; LOG.info(msg + " started..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); Map<String, StudyNode> batch = new HashMap<>(); for (Node hit : hits) { counter++; StudyNode study = new StudyNode(hit); if (shouldResolve(study)) { counterResolved++; batch.put(study.getCitation(), study); } if (batch.size() >= BATCH_SIZE) { LOG.info(logProgress(counterResolved, stopWatch)); resolveBatch(doiResolver, batch); batch.clear(); transaction.success(); transaction.close(); transaction = graphDb.beginTx(); } } resolveBatch(doiResolver, batch); LOG.info(msg + " complete. Out of [" + counter + "] references, [" + counterResolved + "] needed resolving."); if (counter % 100 != 0) { LOG.info(logProgress(counterResolved, stopWatch)); } stopWatch.stop(); transaction.success(); } finally { transaction.close(); } } LinkerDOI();  LinkerDOI(DOIResolver resolver); @Override void index(GraphServiceFactory factory); void resolveBatch(DOIResolver doiResolver, Map<String, StudyNode> batch); void resolve(DOIResolver doiResolver, Map<String, StudyNode> batch, Collection<String> citations); String logProgress(int counter, StopWatch stopWatch); static void linkStudy(DOIResolver doiResolver, StudyNode study); static boolean shouldResolve(Study study); }
LinkerDOI implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction transaction = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("studies"); IndexHits<Node> hits = taxons.query("*:*"); int counter = 0; int counterResolved = 0; String msg = "linking study citations to DOIs"; LOG.info(msg + " started..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); Map<String, StudyNode> batch = new HashMap<>(); for (Node hit : hits) { counter++; StudyNode study = new StudyNode(hit); if (shouldResolve(study)) { counterResolved++; batch.put(study.getCitation(), study); } if (batch.size() >= BATCH_SIZE) { LOG.info(logProgress(counterResolved, stopWatch)); resolveBatch(doiResolver, batch); batch.clear(); transaction.success(); transaction.close(); transaction = graphDb.beginTx(); } } resolveBatch(doiResolver, batch); LOG.info(msg + " complete. Out of [" + counter + "] references, [" + counterResolved + "] needed resolving."); if (counter % 100 != 0) { LOG.info(logProgress(counterResolved, stopWatch)); } stopWatch.stop(); transaction.success(); } finally { transaction.close(); } } LinkerDOI();  LinkerDOI(DOIResolver resolver); @Override void index(GraphServiceFactory factory); void resolveBatch(DOIResolver doiResolver, Map<String, StudyNode> batch); void resolve(DOIResolver doiResolver, Map<String, StudyNode> batch, Collection<String> citations); String logProgress(int counter, StopWatch stopWatch); static void linkStudy(DOIResolver doiResolver, StudyNode study); static boolean shouldResolve(Study study); static final int BATCH_SIZE; }