示例#1
0
def get_rml_uris(rml):
    """ uri -> urls """
    result = {}
    rml_uris = rml.findall(xmletree.prefixtag("rml", "uri"))
    if rml_uris is not None:
        urls = []
        for rml_uri in rml_uris:
            if rml_uri is not None:
                preferred = xmletree.get_element_attribute_as_boolean(rml_uri, "preferred")
                relation_type = rml_uri.get("relationType")
                visible = xmletree.get_element_attribute_as_boolean(rml_uri, "visible")
                value = xmletree.get_element_text(rml_uri)

                url = metajson_service.create_url(value, preferred, relation_type, None, None, visible)
                if url:
                    urls.append(url)
        if urls:
            result["urls"] = urls
    return result
示例#2
0
def get_rml_self_archiving_policy(rml):
    """ ckbData -> self_archiving_policy """
    result = {}
    rml_ckbdata = rml.find(xmletree.prefixtag("rml", "ckbData"))
    if rml_ckbdata is not None:

        sap = {}
        # romeoPublisher -> .
        rml_romeo = rml_ckbdata.find(xmletree.prefixtag("rml", "romeoPublisher"))
        if rml_romeo is not None:
            # publisher : don't repeate this information
            #publisher = Orgunit()
            #publisher["rec_type"] = "publisher"

            # alias -> publisher.acronym
            #publisher.update(get_rml_element_text_and_set_key(rml_romeo, "alias", "acronym"))

            # homeurl -> publisher.urls[]
            #rml_homeurl_value = xmletree.get_element_text(rml_romeo.find(xmletree.prefixtag("rml", "homeurl")))
            #if rml_homeurl_value:
            #    publisher["urls"] = [metajson_service.create_url(rml_homeurl_value, True, "work", None, None, True)]

            # id -> publisher.identifiers[i]
            #rml_id_value = xmletree.get_element_text(rml_romeo.find(xmletree.prefixtag("rml", "id")))
            #if rml_id_value:
            #    publisher["identifiers"] = [metajson_service.create_identifier("romeo", rml_id_value)]

            # name -> publisher.name
            #publisher.update(get_rml_element_text_and_set_key(rml_romeo, "name", "name"))

            #sap["publisher"] = publisher

            # conditions.condition -> conditions[]
            rml_conditions = rml_romeo.find(xmletree.prefixtag("rml", "conditions"))
            if rml_conditions is not None:
                rml_conditions_list = rml_conditions.findall(xmletree.prefixtag("rml", "condition"))
                if rml_conditions_list is not None:
                    conditions = []
                    for rml_condition in rml_conditions_list:
                        value = xmletree.get_element_text(rml_condition)
                        if value:
                            conditions.append(value)
                    if conditions:
                        sap["conditions"] = conditions

            # copyright -> copyright
            sap.update(get_rml_element_text_and_set_key(rml_romeo, "copyright", "copyright"))

            # copyrightlinks -> copyright_urls
            rml_copyrightlinks = rml_romeo.find(xmletree.prefixtag("rml", "copyrightlinks"))
            if rml_copyrightlinks is not None:
                rml_copyrightlinks_list = rml_copyrightlinks.findall(xmletree.prefixtag("rml", "copyrightlink"))
                if rml_copyrightlinks_list is not None:
                    copyright_urls = []
                    for rml_copyrightlink in rml_copyrightlinks_list:
                        copyrightlinktext = xmletree.get_element_text(rml_copyrightlink.find(xmletree.prefixtag("rml", "copyrightlinktext")))
                        copyrightlinkurl = xmletree.get_element_text(rml_copyrightlink.find(xmletree.prefixtag("rml", "copyrightlinkurl")))
                        copyright_url = metajson_service.create_url(copyrightlinkurl, None, None, copyrightlinktext, None, None)
                        copyright_urls.append(copyright_url)
                    if copyright_urls:
                        sap["copyright_urls"] = copyright_urls

            # paidaccess -> paid_access
            rml_paidaccess = rml_romeo.find(xmletree.prefixtag("rml", "paidaccess"))
            if rml_paidaccess is not None:
                paid_access = {}

                # paidaccessname -> label
                paid_access.update(get_rml_element_text_and_set_key(rml_paidaccess, "paidaccessname", "label"))

                # paidaccessurl -> url
                paid_access.update(get_rml_element_text_and_set_key(rml_paidaccess, "paidaccessurl", "url"))

                # paidaccessnotes -> notes
                # rml_paidaccessnotes = rml_paidaccess.findall(xmletree.prefixtag("rml", "paidaccessnotes"))

                sap["paid_access"] = paid_access

            # postprints -> postprint
            rml_postprints = rml_romeo.find(xmletree.prefixtag("rml", "postprints"))
            if rml_postprints is not None:
                postprint = {}

                # postarchiving -> possibility
                postprint.update(get_rml_element_text_and_set_key(rml_postprints, "postarchiving", "possibility"))

                # postrestrictions -> restrictions
                postprint.update(get_rml_textlangs_and_set_key(rml_postprints, "postrestrictions", "restrictions"))

                sap["postprint"] = postprint

            # preprints -> preprint
            rml_preprints = rml_romeo.find(xmletree.prefixtag("rml", "preprints"))
            if rml_preprints is not None:
                preprint = {}

                # prearchiving -> possibility
                preprint.update(get_rml_element_text_and_set_key(rml_preprints, "prearchiving", "possibility"))

                # prerestrictions -> restrictions
                preprint.update(get_rml_textlangs_and_set_key(rml_preprints, "prerestrictions", "pre_restrictions"))

                sap["preprint"] = preprint

            # romeocolour -> romeo_color
            sap.update(get_rml_element_text_and_set_key(rml_romeo, "romeocolour", "romeo_color"))

        if sap:
            result["self_archiving_policy"] = sap
    return result