From e1f56fb212297b7f13b1cc5afee375d09325737d Mon Sep 17 00:00:00 2001 From: emnllm Date: Tue, 25 Jun 2019 11:08:29 +0000 Subject: [PATCH 1/4] adds chronological listing using bibtex year field --- pubs/commands/list_cmd.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pubs/commands/list_cmd.py b/pubs/commands/list_cmd.py index e38c4f7..e0639e9 100644 --- a/pubs/commands/list_cmd.py +++ b/pubs/commands/list_cmd.py @@ -22,6 +22,9 @@ def parser(subparsers, conf): parser.add_argument('-a', '--alphabetical', action='store_true', dest='alphabetical', default=False, help='lexicographic order on the citekeys.') + parser.add_argument('-C', '--chronological', action='store_true', + dest='chronological', default=False, + help='chronological order on the year field.') parser.add_argument('--no-docs', action='store_true', dest='nodocs', default=False, help='list only pubs without attached documents.') @@ -45,6 +48,8 @@ def command(conf, args): papers = [p for p in papers if p.docpath is None] if args.alphabetical: papers = sorted(papers, key=lambda p: p.citekey) + if args.chronological: + papers = sorted(papers, key=lambda p: p.bibdata['year']) else: papers = sorted(papers, key=date_added) if len(papers) > 0: From b3e9db62e15a4339c09ccecf9c474187188a4679 Mon Sep 17 00:00:00 2001 From: emnllm Date: Tue, 25 Jun 2019 18:22:58 +0000 Subject: [PATCH 2/4] improves chronological listing (year, month), adds test --- pubs/commands/list_cmd.py | 4 ++-- tests/bibexamples/noyear.bib | 5 +++++ tests/test_usecase.py | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/bibexamples/noyear.bib diff --git a/pubs/commands/list_cmd.py b/pubs/commands/list_cmd.py index e0639e9..503bb52 100644 --- a/pubs/commands/list_cmd.py +++ b/pubs/commands/list_cmd.py @@ -48,8 +48,8 @@ def command(conf, args): papers = [p for p in papers if p.docpath is None] if args.alphabetical: papers = sorted(papers, key=lambda p: p.citekey) - if args.chronological: - papers = sorted(papers, key=lambda p: p.bibdata['year']) + elif args.chronological: + papers = sorted(papers, key=lambda p: ('year' not in p.bibdata, p.bibdata.get('year'), p.bibdata.get('month'), date_added)) else: papers = sorted(papers, key=date_added) if len(papers) > 0: diff --git a/tests/bibexamples/noyear.bib b/tests/bibexamples/noyear.bib new file mode 100644 index 0000000..3ec056b --- /dev/null +++ b/tests/bibexamples/noyear.bib @@ -0,0 +1,5 @@ +@article{Doe_noyear, + title={About Assigning Timestamps to Research Articles}, + author={Doe, John}, + journal={Journal Example}, +} diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 66d9260..4c0c086 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -516,6 +516,28 @@ class TestList(DataCommandTestCase): self.assertEqual(0, len(outs[3].splitlines())) self.assertEqual(1, len(outs[4].splitlines())) + def test_list_chronological_order(self): + cmds = ['pubs init', + 'pubs import data/', + 'pubs list --chronological', + 'pubs import bibexamples/noyear.bib', + 'pubs list -C', + + ] + data_chrono_correct = '[Einstein_1935] Einstein, A. et al. "Can Quantum-Mechanical Description of Physical Reality Be Considered Complete?" Physical Review (1935) \n' \ + '[Schrodinger_1935] Schrödinger, E. and Born, M. "Discussion of Probability Relations between Separated Systems" Mathematical Proceedings of the Cambridge Philosophical Society (1935) \n' \ + '[turing1950computing] Turing, Alan M "Computing machinery and intelligence" Mind (1950) \n' \ + '[Bell_1964] Bell, J. S. "On the Einstein Podolsky Rosen paradox" Physics Physique физика (1964) \n' \ + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' \ + '[10.1371_journal.pone.0038236] Saunders, Caroline Lyon AND Chrystopher L. Nehaniv AND Joe "Interactive Language Learning by Robots: The Transition from Babbling to Word Forms" PLoS ONE (2012) \n' \ + '[10.1371_journal.pone.0063400] Ay, Georg Martius AND Ralf Der AND Nihat "Information Driven Self-Organization of Complex Robotic Behaviors" PLoS ONE (2013) \n' \ + '[Cesar2013] César, Jean "An amazing title" Nice Journal (2013) \n' + correct = [ data_chrono_correct, + data_chrono_correct + '[Doe_noyear] Doe, John "About Assigning Timestamps to Research Articles" Journal Example \n' + ] + outs = self.execute_cmds(cmds) + self.assertEqual(outs[2], correct[0]) + self.assertEqual(outs[4], correct[1]) class TestTag(DataCommandTestCase): From 2e4af1d38fbd68b6f68ddccae66b335a399434ca Mon Sep 17 00:00:00 2001 From: emnllm Date: Tue, 25 Jun 2019 19:00:37 +0000 Subject: [PATCH 3/4] removes the month field from the chronological listing --- pubs/commands/list_cmd.py | 2 +- tests/test_usecase.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pubs/commands/list_cmd.py b/pubs/commands/list_cmd.py index 503bb52..b615e54 100644 --- a/pubs/commands/list_cmd.py +++ b/pubs/commands/list_cmd.py @@ -49,7 +49,7 @@ def command(conf, args): if args.alphabetical: papers = sorted(papers, key=lambda p: p.citekey) elif args.chronological: - papers = sorted(papers, key=lambda p: ('year' not in p.bibdata, p.bibdata.get('year'), p.bibdata.get('month'), date_added)) + papers = sorted(papers, key=lambda p: ('year' not in p.bibdata, p.bibdata.get('year'), date_added)) else: papers = sorted(papers, key=date_added) if len(papers) > 0: diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 4c0c086..0dcbbe2 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -530,8 +530,8 @@ class TestList(DataCommandTestCase): '[Bell_1964] Bell, J. S. "On the Einstein Podolsky Rosen paradox" Physics Physique физика (1964) \n' \ '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' \ '[10.1371_journal.pone.0038236] Saunders, Caroline Lyon AND Chrystopher L. Nehaniv AND Joe "Interactive Language Learning by Robots: The Transition from Babbling to Word Forms" PLoS ONE (2012) \n' \ - '[10.1371_journal.pone.0063400] Ay, Georg Martius AND Ralf Der AND Nihat "Information Driven Self-Organization of Complex Robotic Behaviors" PLoS ONE (2013) \n' \ - '[Cesar2013] César, Jean "An amazing title" Nice Journal (2013) \n' + '[Cesar2013] César, Jean "An amazing title" Nice Journal (2013) \n' \ + '[10.1371_journal.pone.0063400] Ay, Georg Martius AND Ralf Der AND Nihat "Information Driven Self-Organization of Complex Robotic Behaviors" PLoS ONE (2013) \n' correct = [ data_chrono_correct, data_chrono_correct + '[Doe_noyear] Doe, John "About Assigning Timestamps to Research Articles" Journal Example \n' ] From 94112c02fecd07e625fd187e080002951aaaf98b Mon Sep 17 00:00:00 2001 From: emnllm Date: Thu, 27 Jun 2019 06:10:30 +0000 Subject: [PATCH 4/4] fixes inconsistant chronological listing test * Chronological order listing output for a same year, without entry timestamp (added metadata field), may vary --- tests/test_usecase.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 0dcbbe2..33301a4 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -519,25 +519,24 @@ class TestList(DataCommandTestCase): def test_list_chronological_order(self): cmds = ['pubs init', 'pubs import data/', + 'pubs remove -f Einstein_1935', + 'pubs remove -f Cesar2013', 'pubs list --chronological', 'pubs import bibexamples/noyear.bib', 'pubs list -C', - ] - data_chrono_correct = '[Einstein_1935] Einstein, A. et al. "Can Quantum-Mechanical Description of Physical Reality Be Considered Complete?" Physical Review (1935) \n' \ - '[Schrodinger_1935] Schrödinger, E. and Born, M. "Discussion of Probability Relations between Separated Systems" Mathematical Proceedings of the Cambridge Philosophical Society (1935) \n' \ + data_chrono_correct = '[Schrodinger_1935] Schrödinger, E. and Born, M. "Discussion of Probability Relations between Separated Systems" Mathematical Proceedings of the Cambridge Philosophical Society (1935) \n' \ '[turing1950computing] Turing, Alan M "Computing machinery and intelligence" Mind (1950) \n' \ '[Bell_1964] Bell, J. S. "On the Einstein Podolsky Rosen paradox" Physics Physique физика (1964) \n' \ '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' \ '[10.1371_journal.pone.0038236] Saunders, Caroline Lyon AND Chrystopher L. Nehaniv AND Joe "Interactive Language Learning by Robots: The Transition from Babbling to Word Forms" PLoS ONE (2012) \n' \ - '[Cesar2013] César, Jean "An amazing title" Nice Journal (2013) \n' \ '[10.1371_journal.pone.0063400] Ay, Georg Martius AND Ralf Der AND Nihat "Information Driven Self-Organization of Complex Robotic Behaviors" PLoS ONE (2013) \n' correct = [ data_chrono_correct, data_chrono_correct + '[Doe_noyear] Doe, John "About Assigning Timestamps to Research Articles" Journal Example \n' ] outs = self.execute_cmds(cmds) - self.assertEqual(outs[2], correct[0]) - self.assertEqual(outs[4], correct[1]) + self.assertEqual(outs[4], correct[0]) + self.assertEqual(outs[6], correct[1]) class TestTag(DataCommandTestCase):