Exemplo n.º 1
0
 def _unfold_map(self, display_text_map):
     """Parses a display text dictionary map."""
     from ..type.primitives import Type
     lt_identifier = Id(display_text_map['languageTypeId']).get_identifier()
     st_identifier = Id(display_text_map['scriptTypeId']).get_identifier()
     ft_identifier = Id(display_text_map['formatTypeId']).get_identifier()
     try:
         self._language_type = Type(
             **language_types.get_type_data(lt_identifier))
     except AttributeError:
         raise NotFound('Language Type: ' +
                        lt_identifier)  # or move on to another source
     try:
         self._script_type = Type(
             **script_types.get_type_data(st_identifier))
     except AttributeError:
         raise NotFound('Script Type: ' +
                        st_identifier)  # or move on to another source
     try:
         self._format_type = Type(
             **format_types.get_type_data(ft_identifier))
     except AttributeError:
         raise NotFound('Format Type: ' +
                        ft_identifier)  # or move on to another source
     self._text = display_text_map['text']
Exemplo n.º 2
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    if name in ISO_CURRENCY_TYPES:
        article = 'the '
        type_name = ISO_CURRENCY_TYPES[name]
    elif name in ISO_CURRENCY_ELEMENT_TYPES:
        article = ''
        type_name = ISO_CURRENCY_ELEMENT_TYPES[name]
    else:
        raise NotFound('Currency Type: ' + name)

    return {
        'authority': 'ISO',
        'namespace': '4217',
        'identifier': name,
        'domain': 'ISO Currency Types',
        'display_name': type_name + ' Currency Type',
        'display_label': type_name,
        'description':
        ('The ISO currency type for ' + article + type_name + '.')
    }
Exemplo n.º 3
0
Arquivo: string.py Projeto: UOC/dlkit
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    try:
        return {
            'authority':
            'okapia.net',
            'namespace':
            'string match types',
            'identifier':
            name,
            'domain':
            'String Match Types',
            'display_name':
            STRING_MATCH_TYPES[name] + ' String Match Type',
            'display_label':
            STRING_MATCH_TYPES[name],
            'description':
            ('The string match type for the ' + STRING_MATCH_TYPES[name])
        }
    except KeyError:
        raise NotFound('String Type: ' + name)
Exemplo n.º 4
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    if name in CELESTIAL_TIME_TYPES:
        namespace = 'time'
        domain = 'Celestial Time Systems'
        time_name = CELESTIAL_TIME_TYPES[name]
    elif name in EARTH_TIME_TYPES:
        namespace = 'time'
        domain = 'Earth Time Systems'
        time_name = EARTH_TIME_TYPES[name]
    elif name in SUPER_FUN_TIME_TYPES:
        namespace = 'time'
        domain = 'Alternative Time Systems'
        time_name = SUPER_FUN_TIME_TYPES[name]
    else:
        raise NotFound('Time Type: ' + name)

    return {
        'authority': 'okapia.net',
        'namespace': namespace,
        'identifier': name,
        'domain': domain,
        'display_name': time_name + ' Time Type',
        'display_label': time_name,
        'description': ('The time type for ' + time_name + ' time.')
    }
Exemplo n.º 5
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    if name in CALENDAR_TYPES:
        domain = 'Calendar Types'
        calendar_name = CALENDAR_TYPES[name]
    elif name in ANCIENT_CALENDAR_TYPES:
        domain = 'Ancient Calendar Types'
        calendar_name = ANCIENT_CALENDAR_TYPES[name]
    elif name in ALTERNATE_CALENDAR_TYPES:
        domain = 'Alternative Calendar Types'
        calendar_name = ALTERNATE_CALENDAR_TYPES[name]
    else:
        raise NotFound('Calendar Type: ' + name)

    return {
        'authority': 'okapia.net',
        'namespace': 'calendar',
        'identifier': name,
        'domain': domain,
        'display_name': calendar_name + ' Calendar Type',
        'display_label': calendar_name,
        'description':
        ('The time type for the ' + calendar_name + ' calendar.')
    }
Exemplo n.º 6
0
Arquivo: format.py Projeto: UOC/dlkit
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    try:
        return {
            'authority':
            'okapia.net',
            'namespace':
            'TextFormats',
            'identifier':
            name,
            'domain':
            'DisplayText Formats',
            'display_name':
            FORMAT_TYPES[name] + ' Format Type',
            'display_label':
            FORMAT_TYPES[name],
            'description': ('The display text format type for the ' +
                            FORMAT_TYPES[name] + ' format.')
        }
    except KeyError:
        raise NotFound('Format Type:' + name)
Exemplo n.º 7
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    if name in ISO_LANGUAGE_CODES:
        name = ISO_LANGUAGE_CODES[name]
    if name in ISO_MAJOR_LANGUAGE_TYPES:
        namespace = '639-2'
        lang_name = ISO_MAJOR_LANGUAGE_TYPES[name]
    elif name in ISO_OTHER_LANGUAGE_TYPES:
        namespace = '639-3'
        lang_name = ISO_OTHER_LANGUAGE_TYPES[name]
    else:
        raise NotFound('Language Type: ' + name)

    return {
        'authority':
        'ISO',
        'namespace':
        namespace,
        'identifier':
        name,
        'domain':
        'DisplayText Languages',
        'display_name':
        lang_name + ' Language Type',
        'display_label':
        lang_name,
        'description':
        ('The display text language type for the ' + lang_name + ' language.')
    }
Exemplo n.º 8
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    try:
        return {
            'authority':
            'birdland.mit.edu',
            'namespace':
            'unit system',
            'identifier':
            name,
            'domain':
            'Unit System Types',
            'display_name':
            JEFFS_UNIT_SYSTEM_TYPES[name] + ' Unit System Type',
            'display_label':
            JEFFS_UNIT_SYSTEM_TYPES[name],
            'description': ('The unit system type for the ' +
                            JEFFS_UNIT_SYSTEM_TYPES[name] + ' System')
        }
    except KeyError:
        raise NotFound('Unit System Type: ' + name)
Exemplo n.º 9
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    if name in CELESTIAL_COORDINATE_TYPES:
        domain = 'Celestial Coordinate Systems'
        coordinate_name = CELESTIAL_COORDINATE_TYPES[name]
    elif name in GEOGRAPHIC_COORDINATE_TYPES:
        domain = 'Geographic Coordinate Systems'
        coordinate_name = GEOGRAPHIC_COORDINATE_TYPES[name]
    else:
        raise NotFound('Coordinate Type' + name)

    return {
        'authority': 'okapia.net',
        'namespace': 'coordinate',
        'identifier': name,
        'domain': domain,
        'display_name': coordinate_name + ' Type',
        'display_label': coordinate_name,
        'description': ('The type for the ' + coordinate_name + ' System.')
    }
Exemplo n.º 10
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    try:
        return {
            'authority':
            'birdland.mit.edu',
            'namespace':
            'time format',
            'identifier':
            name,
            'domain':
            'Time Format Types',
            'display_name':
            JEFFS_TIME_FORMAT_TYPES[name] + ' Time Format Type',
            'display_label':
            JEFFS_TIME_FORMAT_TYPES[name],
            'description':
            ('The time format type for ' + JEFFS_TIME_FORMAT_TYPES[name])
        }
    except KeyError:
        raise NotFound('Time Format Type: ' + name)
Exemplo n.º 11
0
Arquivo: script.py Projeto: UOC/dlkit
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    try:
        return {
            'authority':
            'ISO',
            'namespace':
            '15924',
            'identifier':
            name,
            'domain':
            'ISO Script Types',
            'display_name':
            ISO_SCRIPT_TYPES[name] + ' Script Type',
            'display_label':
            ISO_SCRIPT_TYPES[name],
            'description': ('The display text script type for the ' +
                            ISO_SCRIPT_TYPES[name] + ' script.')
        }
    except KeyError:
        raise NotFound('Script Type:' + name)
Exemplo n.º 12
0
 def get_answer_for_response(self, response):
     response_set = set([str(c) for c in response.get_choice_ids()])
     for answer in self.my_osid_object.get_answers():
         if response_set == set([str(c) for c in answer.get_choice_ids()]):
             return answer
     for answer in self.my_osid_object.get_wrong_answers():
         if response_set == set([str(c) for c in answer.get_choice_ids()]):
             return answer
     raise NotFound('no matching answer found for response')
Exemplo n.º 13
0
def order_ids(new_id_list, old_idstr_list):
    compare = (lambda new_id_list, old_idstr_list: collections.Counter(
        new_id_list) == collections.Counter(old_idstr_list))
    new_idstr_list = []
    for id_ in new_id_list:
        new_idstr_list.append(str(id_))
    if compare(new_idstr_list, old_idstr_list):
        return new_idstr_list
    else:
        raise NotFound()
Exemplo n.º 14
0
 def get_type_data(self, name):
     """Return dictionary representation of type."""
     try:
         return {
             'authority': 'DLKIT',
             'namespace': 'relationship.Relationship',
             'identifier': name.lower(),
             'domain': 'Generic Types',
             'display_name': name.title() + ' Type',
             'display_label': name.title(),
             'description': ('The ' + name.title() + ' Type.')
         }
     except IndexError:
         raise NotFound('RelationshipType: ' + name.title())
Exemplo n.º 15
0
 def get_type_data(self, name):
     """Return dictionary representation of type."""
     try:
         return {
             'authority': 'DLKIT.MIT.EDU',
             'namespace': 'NoneType',
             'identifier': name,
             'domain': 'Generic Types',
             'display_name': self.none_types[name] + ' Type',
             'display_label': self.none_types[name],
             'description': ('The ' + self.none_types[name] +
                             ' Type. This type indicates that no type is specified.')
         }
     except IndexError:
         raise NotFound('NoneType: ' + name)
Exemplo n.º 16
0
 def get_type_data(self, name):
     """Return dictionary representation of type."""
     try:
         return {
             'authority': 'DLKIT.MIT.EDU',
             'namespace': 'GenusType',
             'identifier': name,
             'domain': 'Generic Types',
             'display_name': self.generic_types[name] + ' Generic Type',
             'display_label': self.generic_types[name],
             'description': ('The ' + self.generic_types[name] +
                             ' Type. This type has no symantic meaning.')
         }
     except IndexError:
         raise NotFound('GenusType: ' + name)
Exemplo n.º 17
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    try:
        return {
            'authority': 'birdland.mit.edu',
            'namespace': 'Genus Types',
            'identifier': name,
            'domain': 'Generic Types',
            'display_name': OBJECTIVE_TYPES[name] + ' Genus Type',
            'display_label': OBJECTIVE_TYPES[name],
            'description': ('The ' + OBJECTIVE_TYPES[name] + ' Genus Type.')
        }
    except IndexError:
        raise NotFound('Objective Genus Type: ' + name)
Exemplo n.º 18
0
 def clear_preview(self):
     """stub"""
     try:
         rm = self.my_osid_object._get_provider_manager('REPOSITORY')
     except AttributeError:
         rm = self.my_osid_object_form._get_provider_manager('REPOSITORY')
     try:
         aas = rm.get_asset_admin_session_for_repository(
             Id(self.my_osid_object._my_map['assignedBankIds'][0]))
     except AttributeError:
         # for update forms
         aas = rm.get_asset_admin_session_for_repository(
             Id(self.my_osid_object_form._my_map['assignedBankIds'][0]))
     if 'preview' not in self.my_osid_object_form._my_map['fileIds']:
         raise NotFound()
     aas.delete_asset(
         Id(self.my_osid_object_form._my_map['fileIds']['preview']
            ['assetId']))
     del self.my_osid_object_form._my_map['fileIds']['preview']
Exemplo n.º 19
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    try:
        return {
            'authority': 'okapia.net',
            'namespace': 'heading',
            'identifier': name,
            'domain': 'Headings',
            'display_name': HEADING_TYPES[name] + ' Heading Type',
            'display_label': HEADING_TYPES[name],
            'description': ('The heading type for the ' +
                            HEADING_TYPES[name] + ' heading.')
        }
    except KeyError:
        raise NotFound('Heading Type:' + name)
Exemplo n.º 20
0
    def get_answer_for_response(self, response):
        for answer in self.my_osid_object.get_answers():
            if self._is_match(response, answer):
                return answer

        wrong_answers = None
        try:
            wrong_answers = list(self.my_osid_object.get_wrong_answers())
        except AttributeError:
            pass
        else:
            for answer in wrong_answers:
                if self._is_match(response, answer):
                    return answer
        # also look for generic incorrect answer
        if wrong_answers is not None:
            for answer in wrong_answers:
                if len(list(answer.get_inline_choice_ids().keys())) == 0:
                    return answer

        raise NotFound('no matching answer found for response')
Exemplo n.º 21
0
def get_type_data(name):
    """Return dictionary representation of type.

    Can be used to initialize primordium.type.primitives.Type

    """
    name = name.upper()
    try:
        return {
            'authority': 'gnu.org',
            'namespace': 'Basic Numeric Formats',
            'identifier': name,
            'domain': 'Numeric Format Types',
            'display_name': GNU_BASIC_NUMERIC_FORMAT_TYPES[name] + ' Numeric Format Type',
            'display_label': GNU_BASIC_NUMERIC_FORMAT_TYPES[name],
            'description': ('The type for the ' +
                            GNU_BASIC_NUMERIC_FORMAT_TYPES[name] +
                            ' numeric format.')
        }
    except KeyError:
        raise NotFound('NumericFormat Type: ' + name)
Exemplo n.º 22
0
    def get_answer_for_response(self, response):
        for answer in self.my_osid_object.get_answers():
            if self._is_match(response, answer):
                return answer

        wrong_answers = None
        try:
            wrong_answers = list(self.my_osid_object.get_wrong_answers())
        except AttributeError:
            pass
        else:
            for answer in wrong_answers:
                if self._is_match(response, answer):
                    return answer

        # also look for generic incorrect answer
        if wrong_answers is not None:
            for answer in wrong_answers:
                if not answer.has_decimal_value():
                    return answer

        raise NotFound('no matching answer found for response')
Exemplo n.º 23
0
 def get_type_data(self, name):
     """gets language type default data dictionary"""
     if name == 'DEFAULT':
         return LANGUAGETYPE
     else:
         raise NotFound(name + 'Language Type')
Exemplo n.º 24
0
 def get_type_data(self, name):
     """gets script type default data dictionary"""
     if name == 'DEFAULT':
         return SCRIPTTYPE
     else:
         raise NotFound(name + 'Script Type')
Exemplo n.º 25
0
 def get_type_data(self, name):
     """Return dictionary representation of type."""
     if name == 'DEFAULT':
         return FORMATTYPE
     else:
         raise NotFound('DEFAULT Format Type')
Exemplo n.º 26
0
 def get_type_data(self, name):
     """Return dictionary representation of type."""
     if name == 'DEFAULT':
         return SCRIPTTYPE
     else:
         raise NotFound('DEFAULT Script Type')
Exemplo n.º 27
0
 def get_type_data(self, name):
     """Return dictionary representation of type."""
     if name == 'DEFAULT':
         return LANGUAGETYPE
     else:
         raise NotFound('DEFAULT Language Type')
Exemplo n.º 28
0
 def get_type_data(self, name):
     """gets format type default data dictionary"""
     if name == 'DEFAULT':
         return FORMATTYPE
     else:
         raise NotFound(name + 'Format Type')
Exemplo n.º 29
0
 def clear_solution(self):
     """stub"""
     if 'solution' not in self.my_osid_object_form._my_map:
         raise NotFound()
     self.my_osid_object_form._my_map['solution'] = \
         dict(self._solution_metadata['default_string_values'][0])