Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Citations (bibtex?) support #120

Merged
merged 7 commits into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions app/__tests__/bibtex-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { expect } from 'chai';
import path from 'path';
import fs from 'fs';

import bibtex from '../bibtex';

// see: https://github.com/mochajs/mocha/issues/1847
const { describe, it } = global;


function fixture(name) {
const content = fs.readFileSync(
path.join(__dirname, `./fixtures/bib/${name}.bib`),
{ encoding: 'utf8' }
);

return content
.split('--- EXPECTED ---\n')
.map((part) => part.trim());
}

describe('bibtex', () => {
describe('normalizeAuthors()', () => {
it('should normalize an author without comma and multiple names', () => {
const authors = 'Victoria J. Hodge';
const result = bibtex.normalizeAuthors(authors);

expect(result).to.have.length(1);
expect(result[0]).to.eql({ fullname: 'Hodge, V. J.', lastname: 'Hodge' });
});

it('should normalize an author without comma', () => {
const authors = 'William Durand';
const result = bibtex.normalizeAuthors(authors);

expect(result).to.have.length(1);
expect(result[0]).to.eql({ fullname: 'Durand, W.', lastname: 'Durand' });
});

it('should normalize multiple authors without comma', () => {
const authors = 'William Durand and Sebastien Salva';
const result = bibtex.normalizeAuthors(authors);

expect(result).to.have.length(2);
expect(result[0]).to.eql({ fullname: 'Durand, W.', lastname: 'Durand' });
expect(result[1]).to.eql({ fullname: 'Salva, S.', lastname: 'Salva' });
});

it('should normalize multiple authors with comma', () => {
const authors = 'Hunter, Sarah and Corbett, Matthew and Denise, Hubert';
const result = bibtex.normalizeAuthors(authors);

expect(result).to.have.length(3);
expect(result[0]).to.eql({ fullname: 'Hunter, S.', lastname: 'Hunter' });
expect(result[1]).to.eql({ fullname: 'Corbett, M.', lastname: 'Corbett' });
expect(result[2]).to.eql({ fullname: 'Denise, H.', lastname: 'Denise' });
});

it('should deal with empty authors', () => {
const authors = '';
const result = bibtex.normalizeAuthors(authors);

expect(result).to.have.length(0);
});

it('should normalize only a lastname', () => {
const authors = 'Durand';
const result = bibtex.normalizeAuthors(authors);

expect(result).to.have.length(1);
expect(result[0]).to.eql({ fullname: 'Durand', lastname: 'Durand' });
});

it('should normalize only lastnames', () => {
const authors = 'Durand and Salva';
const result = bibtex.normalizeAuthors(authors);

expect(result).to.have.length(2);
expect(result[0]).to.eql({ fullname: 'Durand', lastname: 'Durand' });
expect(result[1]).to.eql({ fullname: 'Salva', lastname: 'Salva' });
});
});

describe('parse()', () => {
it('should parse inproceedings', () => {
const [content, expected] = fixture('inproceedings');
const result = bibtex.parse(content);

expect(result).to.have.length(1);
expect(result[0].html).to.equal(expected);
});

it('should parse articles', () => {
const [content, expected] = fixture('article');
const result = bibtex.parse(content);

expect(result).to.have.length(1);
expect(result[0].html).to.equal(expected);
});

it('should parse multiple bibtex entries', () => {
const [content, expected] = fixture('multi-entries');
const result = bibtex.parse(content);

expect(result).to.have.length(2);
expect(result.map((e) => e.html).join('\n\n')).to.equal(expected);
});

it('should parse books', () => {
const [content, expected] = fixture('book');
const result = bibtex.parse(content);

expect(result).to.have.length(1);
expect(result[0].html).to.equal(expected);
});

it('should parse misc (fallback)', () => {
const [content, expected] = fixture('misc');
const result = bibtex.parse(content);

expect(result).to.have.length(1);
expect(result[0].html).to.equal(expected);
});

it('should return the same entry exactly once', () => {
const [content, expected] = fixture('multi-same');
const result = bibtex.parse(content);

expect(result).to.have.length(2);
expect(result.map((e) => e.html).join('\n\n')).to.equal(expected);
});

it('should sort the entries', () => {
const [content, expected] = fixture('multi-unsorted');
const result = bibtex.parse(content);

expect(result).to.have.length(2);
expect(result.map((e) => e.html).join('\n\n')).to.equal(expected);
});
});

describe('html.renderReferences()', () => {
it('should format the keys of a set of citations', () => {
const [content, _] = fixture('multi-entries');
const result = bibtex.html.renderReferences(bibtex.parse(content));

expect(result).to.equal('(Durand & Salva, 2015; Hodge & Austin, 2004)');
});

it('should deal with empty authors', () => {
const [content, _] = fixture('no-authors');
const result = bibtex.html.renderReferences(bibtex.parse(content));

expect(result).to.equal('(Unknown authors, 2007)');
});

// TODO: implement this feature
it.skip('should handle same authors with different dates', () => {
const [content, _] = fixture('multi-same-authors-diff-dates');
const result = bibtex.html.renderReferences(bibtex.parse(content));

expect(result).to.equal('(Li & Durbin, 2009, 2010)');
});
});
});
20 changes: 20 additions & 0 deletions app/__tests__/fixtures/bib/article.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@article{hunter_ebi_2014,
title = {{EBI} metagenomics—a new resource for the analysis and archiving of metagenomic data},
volume = {42},
issn = {0305-1048, 1362-4962},
url = {http://nar.oxfordjournals.org/content/42/D1/D600},
doi = {10.1093/nar/gkt961},
abstract = {Metagenomics is a relatively recently established but rapidly expanding field that uses high-throughput next-generation sequencing technologies to characterize the microbial communities inhabiting different ecosystems (including oceans, lakes, soil, tundra, plants and body sites). Metagenomics brings with it a number of challenges, including the management, analysis, storage and sharing of data. In response to these challenges, we have developed a new metagenomics resource (http://www.ebi.ac.uk/metagenomics/) that allows users to easily submit raw nucleotide reads for functional and taxonomic analysis by a state-of-the-art pipeline, and have them automatically stored (together with descriptive, standards-compliant metadata) in the European Nucleotide Archive.},
language = {en},
number = {D1},
urldate = {2015-01-08},
journal = {Nucleic Acids Research},
author = {Hunter, Sarah and Corbett, Matthew and Denise, Hubert and Fraser, Matthew and Gonzalez-Beltran, Alejandra and Hunter, Christopher and Jones, Philip and Leinonen, Rasko and McAnulla, Craig and Maguire, Eamonn and Maslen, John and Mitchell, Alex and Nuka, Gift and Oisel, Arnaud and Pesseat, Sebastien and Radhakrishnan, Rajesh and Rocca-Serra, Philippe and Scheremetjew, Maxim and Sterk, Peter and Vaughan, Daniel and Cochrane, Guy and Field, Dawn and Sansone, Susanna-Assunta},
month = jan,
year = {2014},
pmid = {24165880},
pages = {D600--D606},
annote = {Description de l'interface web d'EBI metagenomics}
}
--- EXPECTED ---
Hunter, S., Corbett, M., Denise, H., Fraser, M., Gonzalez-Beltran, A. & Hunter, C. et al. (2014). EBI metagenomics—a new resource for the analysis and archiving of metagenomic data. <em>Nucleic Acids Research</em>, 42(D1), D600—D606. <a href="http://dx.doi.org/10.1093/nar/gkt961" rel="noreferrer noopener">http://dx.doi.org/10.1093/nar/gkt961</a>
12 changes: 12 additions & 0 deletions app/__tests__/fixtures/bib/book.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@book{Warmer:1998:OCL:291202,
author = {Warmer, Jos and Kleppe, Anneke},
title = {The Object Constraint Language: Precise Modeling
with UML},
year = {1999},
isbn = {0-201-37940-6},
publisher = {Addison-Wesley Longman Publishing Co.,
Inc.},
address = {Boston, MA, USA},
}
--- EXPECTED ---
Warmer, J. & Kleppe, A. (1999). <em>The Object Constraint Language: Precise Modeling with UML</em>. Addison-Wesley Longman Publishing Co., Inc.
14 changes: 14 additions & 0 deletions app/__tests__/fixtures/bib/inproceedings.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@inproceedings{DBLP:conf/fm/DurandS15,
author = {William Durand and S{\'{e}}bastien Salva},
title = {Autofunk: An Inference-Based Formal Model Generation Framework for Production Systems},
booktitle = {{FM} 2015: Formal Methods - 20th International Symposium, Oslo, Norway, June 24-26, 2015, Proceedings},
pages = {577--580},
year = {2015},
url = {http://dx.doi.org/10.1007/978-3-319-19249-9_36},
doi = {10.1007/978-3-319-19249-9_36},
timestamp = {Tue, 26 May 2015 14:26:29 +0200},
biburl = {http://dblp.uni-trier.de/rec/bib/conf/fm/DurandS15},
bibsource = {dblp computer science bibliography, http://dblp.org}
}
--- EXPECTED ---
Durand, W. & Salva, S. (2015). Autofunk: An Inference-Based Formal Model Generation Framework for Production Systems. In <em>FM 2015: Formal Methods - 20th International Symposium, Oslo, Norway, June 24-26, 2015, Proceedings</em> (pp. 577—580). <a href="http://dx.doi.org/10.1007/978-3-319-19249-9_36" rel="noreferrer noopener">http://dx.doi.org/10.1007/978-3-319-19249-9_36</a>
9 changes: 9 additions & 0 deletions app/__tests__/fixtures/bib/misc.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@misc{logicreasoning,
title={Artificial Intelligence, Logic and Reasoning},
author={Martial Hebert and Mike Lewicki},
note={Lecture. Available from
https://www.cs.cmu.edu/afs/cs/academic/class/15381-s07/www/slides/022707reasoning.pdf},
year={2007}
}
--- EXPECTED ---
Hebert, M. & Lewicki, M. (2007). Artificial Intelligence, Logic and Reasoning. Lecture. Available from https://www.cs.cmu.edu/afs/cs/academic/class/15381-s07/www/slides/022707reasoning.pdf
28 changes: 28 additions & 0 deletions app/__tests__/fixtures/bib/multi-entries.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@inproceedings{DBLP:conf/fm/DurandS15,
author = {William Durand and S{\'{e}}bastien Salva},
title = {Autofunk: An Inference-Based Formal Model Generation Framework for Production Systems},
booktitle = {{FM} 2015: Formal Methods - 20th International Symposium, Oslo, Norway, June 24-26, 2015, Proceedings},
pages = {577--580},
year = {2015},
url = {http://dx.doi.org/10.1007/978-3-319-19249-9_36},
doi = {10.1007/978-3-319-19249-9_36},
timestamp = {Tue, 26 May 2015 14:26:29 +0200},
biburl = {http://dblp.uni-trier.de/rec/bib/conf/fm/DurandS15},
bibsource = {dblp computer science bibliography, http://dblp.org}
}

@article{1695852,
author = {Victoria J. Hodge and Jim Austin},
title = {A Survey of Outlier Detection Methodologies},
journal = {Artificial Intelligence Review},
volume = {22},
year = {2004},
pages = {85--126},
issue = {2},
doi = {http://dx.doi.org/10.1023/B:AIRE.0000045502.10941.a9},
masid = {1695852}
}
--- EXPECTED ---
Durand, W. & Salva, S. (2015). Autofunk: An Inference-Based Formal Model Generation Framework for Production Systems. In <em>FM 2015: Formal Methods - 20th International Symposium, Oslo, Norway, June 24-26, 2015, Proceedings</em> (pp. 577—580). <a href="http://dx.doi.org/10.1007/978-3-319-19249-9_36" rel="noreferrer noopener">http://dx.doi.org/10.1007/978-3-319-19249-9_36</a>

Hodge, V. J. & Austin, J. (2004). A Survey of Outlier Detection Methodologies. <em>Artificial Intelligence Review</em>, 22(2), 85—126. <a href="http://dx.doi.org/10.1023/B:AIRE.0000045502.10941.a9" rel="noreferrer noopener">http://dx.doi.org/10.1023/B:AIRE.0000045502.10941.a9</a>
41 changes: 41 additions & 0 deletions app/__tests__/fixtures/bib/multi-same-authors-diff-dates.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@article{li_fast_2010,
title = {Fast and accurate long-read alignment with {Burrows}–{Wheeler} transform},
volume = {26},
issn = {1367-4803, 1460-2059},
url = {http://bioinformatics.oxfordjournals.org/content/26/5/589},
doi = {10.1093/bioinformatics/btp698},
abstract = {Motivation: Many programs for aligning short sequencing reads to a reference genome have been developed in the last 2 years. Most of them are very efficient for short reads but inefficient or not applicable for reads {\textgreater}200 bp because the algorithms are heavily and specifically tuned for short queries with low sequencing error rate. However, some sequencing platforms already produce longer reads and others are expected to become available soon. For longer reads, hashing-based software such as BLAT and SSAHA2 remain the only choices. Nonetheless, these methods are substantially slower than short-read aligners in terms of aligned bases per unit time.
Results: We designed and implemented a new algorithm, Burrows-Wheeler Aligner's Smith-Waterman Alignment (BWA-SW), to align long sequences up to 1 Mb against a large sequence database (e.g. the human genome) with a few gigabytes of memory. The algorithm is as accurate as SSAHA2, more accurate than BLAT, and is several to tens of times faster than both.
Availability: http://bio-bwa.sourceforge.net
Contact: rd@sanger.ac.uk},
language = {en},
number = {5},
urldate = {2016-05-12},
journal = {Bioinformatics},
author = {Li, Heng and Durbin, Richard},
month = mar,
year = {2010},
pmid = {20080505},
pages = {589--595}
}

@article{li_fast_2009,
title = {Fast and accurate short read alignment with {Burrows}-{Wheeler} transform},
volume = {25},
issn = {1367-4811},
doi = {10.1093/bioinformatics/btp324},
abstract = {MOTIVATION: The enormous amount of short reads generated by the new DNA sequencing technologies call for the development of fast and accurate read alignment programs. A first generation of hash table-based methods has been developed, including MAQ, which is accurate, feature rich and fast enough to align short reads from a single individual. However, MAQ does not support gapped alignment for single-end reads, which makes it unsuitable for alignment of longer reads where indels may occur frequently. The speed of MAQ is also a concern when the alignment is scaled up to the resequencing of hundreds of individuals.
RESULTS: We implemented Burrows-Wheeler Alignment tool (BWA), a new read alignment package that is based on backward search with Burrows-Wheeler Transform (BWT), to efficiently align short sequencing reads against a large reference sequence such as the human genome, allowing mismatches and gaps. BWA supports both base space reads, e.g. from Illumina sequencing machines, and color space reads from AB SOLiD machines. Evaluations on both simulated and real data suggest that BWA is approximately 10-20x faster than MAQ, while achieving similar accuracy. In addition, BWA outputs alignment in the new standard SAM (Sequence Alignment/Map) format. Variant calling and other downstream analyses after the alignment can be achieved with the open source SAMtools software package.
AVAILABILITY: http://maq.sourceforge.net.},
language = {eng},
number = {14},
journal = {Bioinformatics (Oxford, England)},
author = {Li, Heng and Durbin, Richard},
month = jul,
year = {2009},
pmid = {19451168},
pmcid = {PMC2705234},
keywords = {Algorithms, Genomics, Sequence Alignment, Sequence Analysis, DNA, software},
pages = {1754--1760}
}
--- EXPECTED ---
41 changes: 41 additions & 0 deletions app/__tests__/fixtures/bib/multi-same.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@inproceedings{DBLP:conf/fm/DurandS15,
author = {William Durand and S{\'{e}}bastien Salva},
title = {Autofunk: An Inference-Based Formal Model Generation Framework for Production Systems},
booktitle = {{FM} 2015: Formal Methods - 20th International Symposium, Oslo, Norway, June 24-26, 2015, Proceedings},
pages = {577--580},
year = {2015},
url = {http://dx.doi.org/10.1007/978-3-319-19249-9_36},
doi = {10.1007/978-3-319-19249-9_36},
timestamp = {Tue, 26 May 2015 14:26:29 +0200},
biburl = {http://dblp.uni-trier.de/rec/bib/conf/fm/DurandS15},
bibsource = {dblp computer science bibliography, http://dblp.org}
}

@article{1695852,
author = {Victoria J. Hodge and Jim Austin},
title = {A Survey of Outlier Detection Methodologies},
journal = {Artificial Intelligence Review},
volume = {22},
year = {2004},
pages = {85--126},
issue = {2},
doi = {http://dx.doi.org/10.1023/B:AIRE.0000045502.10941.a9},
masid = {1695852}
}

@inproceedings{DBLP:conf/fm/DurandS15,
author = {William Durand and S{\'{e}}bastien Salva},
title = {Autofunk: An Inference-Based Formal Model Generation Framework for Production Systems},
booktitle = {{FM} 2015: Formal Methods - 20th International Symposium, Oslo, Norway, June 24-26, 2015, Proceedings},
pages = {577--580},
year = {2015},
url = {http://dx.doi.org/10.1007/978-3-319-19249-9_36},
doi = {10.1007/978-3-319-19249-9_36},
timestamp = {Tue, 26 May 2015 14:26:29 +0200},
biburl = {http://dblp.uni-trier.de/rec/bib/conf/fm/DurandS15},
bibsource = {dblp computer science bibliography, http://dblp.org}
}
--- EXPECTED ---
Durand, W. & Salva, S. (2015). Autofunk: An Inference-Based Formal Model Generation Framework for Production Systems. In <em>FM 2015: Formal Methods - 20th International Symposium, Oslo, Norway, June 24-26, 2015, Proceedings</em> (pp. 577—580). <a href="http://dx.doi.org/10.1007/978-3-319-19249-9_36" rel="noreferrer noopener">http://dx.doi.org/10.1007/978-3-319-19249-9_36</a>

Hodge, V. J. & Austin, J. (2004). A Survey of Outlier Detection Methodologies. <em>Artificial Intelligence Review</em>, 22(2), 85—126. <a href="http://dx.doi.org/10.1023/B:AIRE.0000045502.10941.a9" rel="noreferrer noopener">http://dx.doi.org/10.1023/B:AIRE.0000045502.10941.a9</a>
Loading