Skip to content

Commit

Permalink
parse number as int and float as appropiate
Browse files Browse the repository at this point in the history
  • Loading branch information
saggu committed Jan 25, 2018
1 parent 3b462e1 commit 2274223
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions etk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,11 +2021,11 @@ def parse_number(d, config=None):
return None

if isinstance(text, numbers.Number):
return float(text)
return str(text)

try:
text = text.strip().replace('\n', '').replace('\t', '')
num = float(text)
num = str(float(text)) if '.' in text else str(int(text))
return num
except:
pass
Expand Down
11 changes: 9 additions & 2 deletions etk/unit_tests/test_content_extractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,12 @@ def test_extract_as_is_post_filter_3(self):
{
"description": "Noncombatant Status Asserted",
"id": "assertedcontestednoncombatantnoncombatantnotstatusstatus",
"size": "red34"
"size": "34.0"
},
{
"description": "Noncombatant Status Asserted",
"id": "assertedcontestednoncombatantnoncombatantnotstatusstatus",
"size": "redme34"
}
]
}
Expand Down Expand Up @@ -539,7 +544,9 @@ def test_extract_as_is_post_filter_3(self):
}
c = Core(extraction_config=e_config)
r = c.process(doc)
self.assertEqual(r['knowledge_graph']['actor_size'][0]['value'], 54.0)
self.assertTrue(len(r['knowledge_graph']['actor_size']) == 2)
self.assertEqual(r['knowledge_graph']['actor_size'][0]['value'], '54')
self.assertEqual(r['knowledge_graph']['actor_size'][1]['value'], '34.0')

def test_extract_as_is_artbitrary_path(self):
doc = {
Expand Down

0 comments on commit 2274223

Please sign in to comment.