Skip to content

Commit

Permalink
Id
Browse files Browse the repository at this point in the history
Default mappings for unmapped exceptions
  • Loading branch information
albertmeronyo committed Apr 4, 2015
1 parent c9242fd commit 5bb9222
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ def __init__(self, data):
# Save the mapping
if len(values) > 0:
self._mappings.setdefault(literal, {})
# Store the default mappings
self._mappings[literal]['default'] = values
# Store the specific context if applicable
if context != '':
self._mappings[literal].setdefault('context', {})
self._mappings[literal]['context'][context] = values
else:
# Store the default mappings
self._mappings[literal]['default'] = values


def get_src_URI(self):
Expand Down Expand Up @@ -113,7 +114,12 @@ def get_mappings_for(self, literal, context_map):
if context in self._mappings[literal]['context']:
return self._mappings[literal]['context'][context]

# Nothing matches
# Current context match no exception for this literal
# If no default mapping is defined, don't map the literal
if 'default' not in self._mappings[literal]:
return None

# Exceptions don't match but we have a default mapping
return self._mappings[literal]['default']

class RuleMaker(object):
Expand Down

0 comments on commit 5bb9222

Please sign in to comment.