Skip to content

Commit

Permalink
adsabs#65 partial support for multi-file fulltext records
Browse files Browse the repository at this point in the history
the fulltext is spread over multiple files for over 11k bibcodes.  currently, fulltext fails on all of them.  with this change only the first file of the list of files will be processed.  this is very much a partial solution, fortunately the first file holds the bulk of the text.  other files in the list typically hold text from tables.
  • Loading branch information
SpacemanSteve authored and SpacemanSteve committed Jan 10, 2018
1 parent d411452 commit 08728bf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions adsft/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def check_if_extract(message_list, extract_path):
logger.debug('No existing meta file')
update = 'NOT_EXTRACTED_BEFORE'

# clobber muliple filenames, replace with first
message['ft_source'] = filename_cleanup(message['ft_source'])
if os.path.exists(message['ft_source']):
ft_source_size = os.stat(message['ft_source']).st_size # bytes
if ft_source_size == 0:
Expand Down Expand Up @@ -268,3 +270,10 @@ def check_if_extract(message_list, extract_path):

return {'Standard': publish_list_of_standard_dictionaries,
'PDF': publish_list_of_pdf_dictionaries}

def filename_cleanup(filename):
"""if multiple filenames, return only first"""
clean = filename
if clean and ',/' in clean:
clean = clean[:clean.find(',/')]
return clean
29 changes: 28 additions & 1 deletion adsft/tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,34 @@ def test_that_file_should_be_updated_if_forced(self):
self.assertTrue(first_doc_false['UPDATE'],
'DIFFERING_FULL_TEXT')
self.assertTrue(len(payload_false['PDF']) != 0)


def test_filename_cleanup(self):
"""check code that deals with multiple files for bibcode"""

file = '/foo/bar.pdf'
clean = checker.filename_cleanup(file)
self.assertEqual(file, clean)

file = '/foo/ba,r.pdf'
clean = checker.filename_cleanup(file)
self.assertEqual(file, clean)

file = ''
clean = checker.filename_cleanup(file)
self.assertEqual(file, clean)

file = None
clean = checker.filename_cleanup(file)
self.assertEqual(file, clean)

file = '/foo/bar.pdf,/foo/baz.pdf'
clean = checker.filename_cleanup(file)
self.assertEqual('/foo/bar.pdf', clean)

file = '/foo/bar.pdf,/foo/baz.pdf,/foo/quux.pdf'
clean = checker.filename_cleanup(file)
self.assertEqual('/foo/bar.pdf', clean)


if __name__ == '__main__':
unittest.main()

0 comments on commit 08728bf

Please sign in to comment.