Skip to content

Commit

Permalink
planetary names data (gpn) added (#43)
Browse files Browse the repository at this point in the history
* planetary names data (gpn) added

* debugged error

* updated test_read

* changes  to

* gpn field made multiline

* gpn format changes and gpn_id added

* rogue import removed

---------

Co-authored-by: Mugdha Polimera <mugdhapolimera@saos-MacBook-Pro.local>
  • Loading branch information
mugdhapolimera and Mugdha Polimera committed Dec 4, 2023
1 parent 3461596 commit 3d1c6aa
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions adsdata/file_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
data_files['data_link'] = {'path': 'links/facet_datasources/datasources.links', 'default_value': {},
'extra_values': {'link_type': 'DATA', 'property': ['DATA']}, 'multiline': True,
'subparts': ['link_sub_type', 'item_count', ['url'], ['title']]}
data_files['gpn'] = {'path': 'links/gpn/all.links', 'default_value': [], 'multiline': True}

# file properties definitions required to generate metrics for CitationCapture records
# use dict to hold each input files and their properties and idiosycrasies
Expand Down
10 changes: 8 additions & 2 deletions adsdata/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ def read_value_for(self, bibcode):
# at this point, we have the first line with the bibcode in it
# roll up possible other values on adjacent lines in file
value = []
value.append(self._get_rest(current_line))
if self.file_info['path'] == 'links/gpn/all.links':
value.append("/".join(self._get_rest(current_line).split("\t")))
else:
value.append(self._get_rest(current_line))
current_line = self._readline()
while self.file_info.get('multiline', False) and (current_line not in [None, '']) and (bibcode == self._get_bibcode(current_line)):
value.append(self._get_rest(current_line))
if self.file_info['path'] == 'links/gpn/all.links':
value.append("/".join(self._get_rest(current_line).split("\t")))
else:
value.append(self._get_rest(current_line))
current_line = self._readline()

# at this point we have read beyond the desired bibcode, must back up
Expand Down
22 changes: 22 additions & 0 deletions adsdata/tests/data1/config/links/gpn/all.links
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
2000Icar..146..420D Moon Crater Langrenus 3273
2000P&SS...48..181W Mars Crater Gusev 2289
2000P&SS...48..181W Mars Crater Marca 3655
2000P&SS...48..181W Mars Patera Apollinaris Patera 323
2000P&SS...48..181W Mars Chasma Capri Chasma 1012
2004JGRE..10912009I Mars Patera Apollinaris Patera 323
2004JGRE..10912009I Mars Fossa Medusae Fossae 3795
2004JGRE..10912009I Mars Fossa Sirenum Fossae 5575
2004JGRE..10912009I Mars Terra Terra Cimmeria 5930
2004JGRE..10912009I Mars Terra Terra Sirenum 5932
2004JGRE..10912009I Mars Crater Copernicus 1297
2004JGRE..10912009I Mars Crater Gusev 2289
2004JGRE..10912009I Mars Crater Kepler 2991
2004JGRE..10912009I Mars Crater New Plymouth 4231
2004JGRE..10912009I Mars Crater Newton 4236
2024Icar..40815837G Moon Mare Mare Imbrium 3678
2024Icar..40815837G Moon Crater Alder 171
2024Icar..40815837G Moon Crater Finsen 1959
2024Icar..40815837G Moon Crater Leibnitz 3335
2024Icar..40815821L Mars Mons Aeolis Mons 15000
2024Icar..40815821L Mars Crater Gale 2071
2024Icar..40815821L Mars Crater Jezero 14300
12 changes: 11 additions & 1 deletion adsdata/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from adsdata.file_defs import data_files
from adsdata.memory_cache import Cache


class TestMemoryCache(unittest.TestCase):
"""test higher level operations for reading in a set of data for a bibcode"""

Expand Down Expand Up @@ -44,6 +43,17 @@ def test_read(self):
self.assertEqual(d['refereed'], {'refereed': False})
self.assertEqual(d['relevance'], {'norm_cites': 0, 'read_count': 25, 'boost': 0.32, 'deprecated_citation_count': 0})

with Processor(compute_metrics=False) as processor, patch('adsputils.load_config', return_value={'INPUT_DATA_ROOT': './test/data1/config/'}):
d = processor._read_next_bibcode('2024Icar..40815837G')
self.assertEqual(d['canonical'], '2024Icar..40815837G')
self.assertFalse(d['grants'])
self.assertFalse(d['ned_objects'])
self.assertTrue(d['nonarticle'])
self.assertEqual(d['ocrabstract'], {'ocrabstract': False})
self.assertEqual(d['private'], {'private': False})
self.assertEqual(d['pub_openaccess'], {'pub_openaccess': False})
self.assertEqual(d['refereed'], {'refereed': False})
self.assertEqual(d['gpn'], ['Moon/Mare/Mare Imbrium/3678', 'Moon/Crater/Alder/171', 'Moon/Crater/Finsen/1959', 'Moon/Crater/Leibnitz/3335'])
def test_protobuf(self):
"""make sure protobuf are created without an exception"""
with Processor(compute_metrics=False) as processor, patch('adsputils.load_config', return_value={'INPUT_DATA_ROOT': './test/data1/config/'}):
Expand Down
7 changes: 6 additions & 1 deletion adsdata/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from adsdata import reader
from adsdata.file_defs import data_files


class TestReader(unittest.TestCase):
""" it is important to have comprehensive tests for reader
Expand Down Expand Up @@ -330,3 +329,9 @@ def test_bibgroup(self):
self.assertEqual({"bibgroup": ["GTC", "Keck"]}, f.read_value_for('2021MNRAS.502..510J'))
self.assertEqual({"bibgroup": []}, f.read_value_for('2021ZZZZZ.502..510J'))

def test_planetary_names(self):
f = reader.NonbibFileReader('gpn', data_files['gpn'])
self.assertEqual({'gpn': ['Moon/Crater/Langrenus/3273']}, f.read_value_for('2000Icar..146..420D'))
self.assertEqual({'gpn': ['Mars/Patera/Apollinaris Patera/323', 'Mars/Fossa/Medusae Fossae/3795', 'Mars/Fossa/Sirenum Fossae/5575', 'Mars/Terra/Terra Cimmeria/5930', 'Mars/Terra/Terra Sirenum/5932', 'Mars/Crater/Copernicus/1297','Mars/Crater/Gusev/2289','Mars/Crater/Kepler/2991','Mars/Crater/New Plymouth/4231','Mars/Crater/Newton/4236'] },f.read_value_for('2004JGRE..10912009I'))


2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
adsputils==1.3.0
adsputils==1.5.1

0 comments on commit 3d1c6aa

Please sign in to comment.