Beispiel #1
0
def selected_document():
    docid = get_docid(main_buf[main_win.cursor[0] - 1])
    if docid:
        fields = headers + ('bibtex', 'tags', 'filename', 'notes')
        docs = list(ref.select_documents(fields, (docid,)))
        if docs:
            return docs[0]
Beispiel #2
0
    def test_insert_document(self):
        doc = \
            {'author': 'Koren',
             'bibtex': '@inproceedings{koren2008factorization,\n  title={Factorization meets the neighborhood: a multifaceted collaborative filtering model},\n  author={Koren, Y.},\n  booktitle={Proceeding of the 14th ACM SIGKDD international conference on Knowledge discovery and data mining},\n  pages={426--434},\n  year={2008},\n  organization={ACM}\n}\n',
             'docid': 3,
             'filename': 'Koren - 2008 - Factorization meets the neighborhood a multifaceted collaborative filtering model - 3.pdf',
             'journal': 'Proceeding of the 14th ACM SIGKDD international conference on Knowledge discovery and data mining',
             'notes': '',
             'rating': 'U',
             'tags': '',
             'title': 'Factorization meets the neighborhood: a multifaceted collaborative filtering model',
             'year': 2008}

        # normal usecase test
        self.assertEqual(ref.insert_document('data/kdd08koren.pdf'), 3)
        self.assertDictEqual(dict(ref.select_documents('*', docids=[3]).fetchone()), doc)
        self.assertTrue(self.file_in_docdir(doc['filename']))

        # duplicate
        with self.assertRaises(ref.DuplicateError) as e:
            ref.insert_document('data/kdd08koren.pdf')
        self.assertEqual(e.exception.message, doc['filename'])
        
        with self.assertRaises(IOError):
            ref.insert_document('not_exist.pdf')
        with self.assertRaises(IOError):
            ref.insert_document('data')
        with self.assertRaises(ValueError):
            ref.insert_document('test_ref.py')
Beispiel #3
0
    def test_insert_document(self):
        doc = \
            {'author': 'Koren',
             'bibtex': '@inproceedings{koren2008factorization,\n  title={Factorization meets the neighborhood: a multifaceted collaborative filtering model},\n  author={Koren, Y.},\n  booktitle={Proceeding of the 14th ACM SIGKDD international conference on Knowledge discovery and data mining},\n  pages={426--434},\n  year={2008},\n  organization={ACM}\n}\n',
             'docid': 3,
             'filename': 'Koren - 2008 - Factorization meets the neighborhood a multifaceted collaborative filtering model - 3.pdf',
             'journal': 'Proceeding of the 14th ACM SIGKDD international conference on Knowledge discovery and data mining',
             'notes': '',
             'rating': 'U',
             'tags': '',
             'title': 'Factorization meets the neighborhood: a multifaceted collaborative filtering model',
             'year': 2008}

        # normal usecase test
        self.assertEqual(ref.insert_document('data/kdd08koren.pdf'), 3)
        self.assertDictEqual(
            dict(ref.select_documents('*', docids=[3]).fetchone()), doc)
        self.assertTrue(self.file_in_docdir(doc['filename']))

        # duplicate
        with self.assertRaises(ref.DuplicateError) as e:
            ref.insert_document('data/kdd08koren.pdf')
        self.assertEqual(e.exception.message, doc['filename'])

        with self.assertRaises(IOError):
            ref.insert_document('not_exist.pdf')
        with self.assertRaises(IOError):
            ref.insert_document('data')
        with self.assertRaises(ValueError):
            ref.insert_document('test_ref.py')
Beispiel #4
0
    def test_update_document(self):
        get_doc = lambda: dict(
            ref.select_documents('*', docids=(2, )).fetchone())

        doc = dict(self.documents[2])
        ref.update_document(doc)
        self.assertDictEqual(self.documents[2], doc)
        self.assertDictEqual(self.documents[2], get_doc())
        self.assertTrue(self.file_in_docdir(doc['filename']))

        doc = \
            {'author': 'author',
             'bibtex': 'bibtex',
             'docid': 2,
             'filename': 'Yu et al - 2010 - Feature engineering and classifier ensemble for KDD cup 2010 - 2.pdf',
             'journal': 'journal',
             'notes': 'notes',
             'rating': 'rating',
             'tags': 'tags',
             'title': 'title',
             'year': 42}
        ref.update_document(dict(doc))
        doc['filename'] = 'author - 42 - title - 2.pdf'
        self.assertDictEqual(doc, get_doc())
        self.assertTrue(self.file_in_docdir(doc['filename']))
Beispiel #5
0
def selected_document():
    docid = get_docid(main_buf[main_win.cursor[0] - 1])
    if docid:
        fields = headers + ('bibtex', 'tags', 'filename', 'notes')
        docs = list(ref.select_documents(fields, (docid, )))
        if docs:
            return docs[0]
Beispiel #6
0
def parse_info():
    bibtex, rest, notes = '\n'.join(info_buf).split('\n---')
    doc = ref.parse_bibtex(bibtex)
    doc.update(dict(re.findall(r'(\w+)=(.*)', rest)))
    doc['bibtex'] = bibtex
    doc['docid'] = int(doc['docid'])
    doc['notes'] = notes.strip()
    doc.update(next(ref.select_documents(('filename',), (doc['docid'],))))
    tags.update(doc['tags'].split('; '))
    return doc
Beispiel #7
0
def parse_info():
    bibtex, rest, notes = '\n'.join(info_buf).split('\n---')
    doc = ref.parse_bibtex(bibtex)
    doc.update(dict(re.findall(r'(\w+)=(.*)', rest)))
    doc['bibtex'] = bibtex
    doc['docid'] = int(doc['docid'])
    doc['notes'] = notes.strip()
    doc.update(next(ref.select_documents(('filename', ), (doc['docid'], ))))
    tags.update(doc['tags'].split('; '))
    return doc
Beispiel #8
0
def update_main(docids=None):
    if not docids:
        docids = filter(None, (get_docid(line) for line in main_buf))
        if not docids:
            return
    cur = ref.select_documents(headers, docids)
    docs = {doc['docid']: str_document(doc) for doc in cur}

    for i, line in enumerate(main_buf):
        id = get_docid(line)
        if id in docs:
            main_buf[i] = docs[id]
Beispiel #9
0
def update_main(docids=None):
    if not docids:
        docids = filter(None, (get_docid(line) for line in main_buf))
        if not docids:
            return
    cur = ref.select_documents(headers, docids)
    docs = {doc['docid']: str_document(doc) for doc in cur}

    for i, line in enumerate(main_buf):
        id = get_docid(line)
        if id in docs:
            main_buf[i] = docs[id]
Beispiel #10
0
    def test_select_documents(self):
        r = [(r['docid'], r['title']) for r in ref.select_documents(['docid', 'title'])]
        self.assertListEqual(r, 
            [(2, 'Feature engineering and classifier ensemble for KDD cup 2010'),
             (1, 'Improving regularized singular value decomposition for collaborative filtering')])

        with self.assertRaises(IndexError):
            ref.select_documents(['docid']).fetchone()['title']

        self.assertListEqual([r['docid'] for r in ref.select_documents('*', order='year ASC')], [1, 2])
        self.assertListEqual([r['docid'] for r in ref.select_documents('*', docids=[1])], [1])
        self.assertDictEqual(dict(ref.select_documents('*', docids=(1,)).fetchone()), self.documents[1])
Beispiel #11
0
    def test_update_document(self):
        get_doc = lambda: dict(ref.select_documents('*', docids=(2,)).fetchone())

        doc = dict(self.documents[2])
        ref.update_document(doc)
        self.assertDictEqual(self.documents[2], doc)
        self.assertDictEqual(self.documents[2], get_doc())
        self.assertTrue(self.file_in_docdir(doc['filename']))

        doc = \
            {'author': 'author',
             'bibtex': 'bibtex',
             'docid': 2,
             'filename': 'Yu et al - 2010 - Feature engineering and classifier ensemble for KDD cup 2010 - 2.pdf',
             'journal': 'journal',
             'notes': 'notes',
             'rating': 'rating',
             'tags': 'tags',
             'title': 'title',
             'year': 42}
        ref.update_document(dict(doc))
        doc['filename'] = 'author - 42 - title - 2.pdf'
        self.assertDictEqual(doc, get_doc())
        self.assertTrue(self.file_in_docdir(doc['filename']))
Beispiel #12
0
    def test_select_documents(self):
        r = [(r['docid'], r['title'])
             for r in ref.select_documents(['docid', 'title'])]
        self.assertListEqual(r, [
            (2,
             'Feature engineering and classifier ensemble for KDD cup 2010'),
            (1,
             'Improving regularized singular value decomposition for collaborative filtering'
             )
        ])

        with self.assertRaises(IndexError):
            ref.select_documents(['docid']).fetchone()['title']

        self.assertListEqual(
            [r['docid'] for r in ref.select_documents('*', order='year ASC')],
            [1, 2])
        self.assertListEqual(
            [r['docid'] for r in ref.select_documents('*', docids=[1])], [1])
        self.assertDictEqual(
            dict(ref.select_documents('*', docids=(1, )).fetchone()),
            self.documents[1])
Beispiel #13
0
 def test_update_document(self):
     t = time()
     for doc in map(dict, ref.select_documents('*', docids=range(100))):
         doc['notes'] += 'foo bar baz'
         ref.update_document(doc)
     self.assertLess(time() - t, 0.2)
Beispiel #14
0
def add_document(fname):
    docid = ref.insert_document(fname)
    if docid:
        doc = next(ref.select_documents(headers, (docid, )))
        main_buf[:0] = [str_document(doc)]
    main_win.cursor = (1, 0)
Beispiel #15
0
def reload_main():
    global last_select_cmd

    last_select_cmd = reload_main
    docs = list(map(str_document, ref.select_documents(headers, order=order)))
    main_buf[:] = docs
Beispiel #16
0
 def test_select_documents(self):
     t = time()
     for i in range(100):
         ref.select_documents(['docid'], docids=[i])
     self.assertLess(time() - t, 0.2)
Beispiel #17
0
def add_document(fname):
    docid = ref.insert_document(fname)
    if docid:
        doc = next(ref.select_documents(headers, (docid,)))
        main_buf[:0] = [str_document(doc)]
    main_win.cursor = (1, 0)
Beispiel #18
0
def reload_main():
    global last_select_cmd

    last_select_cmd = reload_main
    docs = list(map(str_document, ref.select_documents(headers, order=order)))
    main_buf[:] = docs
Beispiel #19
0
 def test_select_documents(self):
     t = time()
     for i in range(100):
         ref.select_documents(['docid'], docids=[i])
     self.assertLess(time() - t, 0.2)
Beispiel #20
0
 def test_update_document(self):
     t = time()
     for doc in map(dict, ref.select_documents('*', docids=range(100))):
         doc['notes'] += 'foo bar baz'
         ref.update_document(doc)
     self.assertLess(time() - t, 0.2)