Commit bcebc4a2 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Handle start nodes without JSON metadata

parent ee89d7fd
......@@ -247,6 +247,10 @@ def get_places_data(places, model):
.. note:: v1 models return a dict with only 1 key: 'cadbiom_name'
.. note:: Start nodes (with a name like __start__x) are handled even
with no JSON data.
They are counted in the other_types and other_locations fields.
:Example of JSON data that can be found in the model:
.. code-block:: python
......@@ -290,20 +294,27 @@ def get_places_data(places, model):
}
# Init final dictionary
data = list()
for place in places:
temp = dict()
# Get JSON data ('' if the field is not present)
json_data = json.loads(model.node_dict[place].note)
for place_name in places:
try:
# Model type 2 => We use JSON data in each nodes
# Get JSON data ('' if the field is not present)
json_data = json.loads(model.node_dict[place_name].note)
except ValueError as e:
# Handle start nodes (name: __start__x)
if e.message == 'No JSON object could be decoded':
json_data = dict()
temp = \
{fieldname: json_data.get(fieldname, def_type)
for fieldname, def_type in json_note_fieldnames.items()}
{fieldname: json_data.get(fieldname, default_data)
for fieldname, default_data in json_note_fieldnames.items()}
# Add the cadbiom name (name attribute of xml element
temp['cadbiom_name'] = place
temp['cadbiom_name'] = place_name
data.append(temp)
return data
else:
# v1 model: return only the name of the place
return [{'cadbiom_name': place} for place in places]
return [{'cadbiom_name': place_name} for place_name in places]
......@@ -199,6 +199,10 @@ class StaticAnalyzer(object):
def get_stats_entities_data(self):
"""Return occurences of various locations and entity types in the model
.. note:: Start nodes (with a name like __start__x) are handled even
with no JSON data.
They are counted in the other_types and other_locations fields.
:Example:
.. code-blocks:: python
......@@ -221,8 +225,12 @@ class StaticAnalyzer(object):
# Iterate on model nodes
for node_name, node in self.model.node_dict.iteritems():
# Model type 2 => We use JSON data in each nodes
json_data = json.loads(node.note)
try:
# Model type 2 => We use JSON data in each nodes
json_data = json.loads(node.note)
except ValueError as e:
if e.message == 'No JSON object could be decoded':
json_data = dict()
# Count occurences of types of entities
entity_types[json_data.get('entityType', 'other_types')] += 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment