How to use the biblib.metajson.Document function in biblib

To help you get started, we’ve selected a few biblib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github medialab / reference_manager / biblib / services / metajson_service.py View on Github external
def load_dict(meta_dict):
    if "rec_class" not in meta_dict:
        return Common(meta_dict)
    elif meta_dict["rec_class"] == "Document":
        return Document(meta_dict)
    elif meta_dict["rec_class"] == "Person":
        return Person(meta_dict)
    elif meta_dict["rec_class"] == "Orgunit":
        return Orgunit(meta_dict)
    elif meta_dict["rec_class"] == "Project":
        return Project(meta_dict)
    elif meta_dict["rec_class"] == "Event":
        return Event(meta_dict)
    elif meta_dict["rec_class"] == "Family":
        return Family(meta_dict)
    elif meta_dict["rec_class"] == "Field":
        return Field(meta_dict)
    elif meta_dict["rec_class"] == "Resource":
        return Resource(meta_dict)
    elif meta_dict["rec_class"] == "Target":
        return Target(meta_dict)
github medialab / reference_manager / biblib / crosswalks / csv_crosswalk.py View on Github external
def csv_dict_reader_to_metasjon(csv_row, input_format, source, rec_id_prefix):
    document = Document()

    if source:
        document["rec_source"] = source

    if input_format == constants.FORMAT_CSV_SITPOL:
        #logging.debug("csv_dict_reader_to_metasjon type(csv_row): {}".format(type(csv_row)))
        #print csv_row
        document["title"] = csv_row["title"]
        classifications_sitpol = [x.strip() for x in csv_row["classifications_sitpol"].split(";") if x.strip()]
        if classifications_sitpol:
            document["classifications_sitpol"] = classifications_sitpol
        classifications_ddc = [x.strip() for x in csv_row["classifications_ddc"].split(";") if x.strip()]
        if classifications_ddc:
            document["classifications_ddc"] = classifications_ddc
        formatted_names = [x.strip() for x in csv_row["creators@role=pbl"].split(";") if x.strip()]
        if formatted_names:
github medialab / reference_manager / biblib / crosswalks / bibtex_crosswalk.py View on Github external
date = year
        if month:
            try:
                if int(month) < 10:
                    month = "0" + month
            except ValueError:
                month_lower = month.lower()
                if month_lower in date_service.month_text_to_month_decimal:
                    month = date_service.month_text_to_month_decimal[month_lower]
            date += month
        document["date_issued"] = date

    # journal -> is_part_ofs
    journal = get_field(entry, 'journal')
    if journal:
        is_part_of = Document()
        is_part_of["rec_type"] = "Journal"
        is_part_of["title"] = journal
        document["is_part_ofs"] = [is_part_of]

    # booktitle -> is_part_ofs
    booktitle = get_field(entry, 'booktitle')
    if booktitle:
        is_part_of = Document()
        is_part_of["rec_type"] = "Book"
        is_part_of["title"] = booktitle
        document["is_part_ofs"] = [is_part_of]

    # abstract -> descriptions
    abstract = get_field(entry, 'abstract')
    note = get_field(entry, 'note')
    descriptions = []
github medialab / reference_manager / biblib / crosswalks / endnotexml_crosswalk.py View on Github external
else:
        if isbn_or_issn:
            document["identifiers"] = [metajson_service.create_identifier(isbn_or_issn_type, isbn_or_issn)]
        if publishers:
            if endnote_type == TYPE_THESIS:
                document.add_creators([creator_service.formatted_name_to_creator(publishers[0], "orgunit", "dgg")])
            elif endnote_type == TYPE_FILM_OR_BROADCAST:
                document.add_creators([creator_service.formatted_name_to_creator(publishers[0], "orgunit", "dst")])
            else:
                document.set_key_if_not_none("publishers", publishers)
        document.set_key_if_not_none("publication_places", publication_places)

    # seriess[]
    if endnote_type in [TYPE_BOOK, TYPE_BOOK_SECTION]:
        series = Document()
        series["rec_type"] = constants.DOC_TYPE_SERIES
        if endnote_type == TYPE_BOOK and title_secondary:
            series.set_key_if_not_none("title", title_secondary)
            series.add_creators(secondary_creators)
            series.set_key_if_not_none("part_volume", part_number)
        if endnote_type == TYPE_BOOK_SECTION and title_tertiary:
            series.set_key_if_not_none("title", title_tertiary)
            series.add_creators(tertiary_creators)
            series.set_key_if_not_none("part_volume", part_number)
        if "title" in series and len(series) > 2:
            document.add_items_to_key([series], "seriess")

    # originals[]
    if (reprint_edition or title_translated or orig_pub) and endnote_type in [TYPE_BOOK, TYPE_BOOK_SECTION, TYPE_JOURNAL_ARTICLE, TYPE_FILM_OR_BROADCAST]:
        original_title = None
        original_is_part_of = None
github medialab / reference_manager / biblib / crosswalks / mets_crosswalk.py View on Github external
def mets_xmletree_to_metajson(mets, source, rec_id_prefix):
    document = Document()

    # source
    if source:
        document["rec_source"] = source

    # mets

    # metsHdr

    # dmdSec
    document["dmds"] = extract_dmdsecs(mets)

    # techMD

    # sourceMD
github medialab / reference_manager / biblib / crosswalks / mods_crosswalk.py View on Github external
def get_mods_related_items(mods_root, root_rec_type):
    """ relatedItem ->
        is_part_ofs, has_parts, is_review_ofs, originals, seriess, is_referenced_bys, references,
        is_format_ofs, is_version_ofs, is_preceded_bys, is_succeeded_bys
    """
    mods_related_items = mods_root.findall(xmletree.prefixtag("mods", "relatedItem"))
    result = Document()
    if mods_related_items:
        # mods related_items

        for mods_related_item in mods_related_items:
            if mods_related_item is not None:
                # extract the relatedItem type attribute
                mods_related_item_type = mods_related_item.get("type")
                # mods_related_item_type in : preceding, succeeding, original, host, constituent, series, otherVersion, otherFormat, isReferencedBy, references, reviewOf)

                # convert like a mods record
                related_item = mods_root_or_related_item_to_metajson(mods_related_item, root_rec_type)

                if related_item is not None:
                    # extract related_item rec_type
                    related_item_rec_type = related_item["rec_type"]
github medialab / reference_manager / biblib / crosswalks / summonjson_crosswalk.py View on Github external
is_part_of.set_key_if_not_none("title", is_part_of_title)
        is_part_of.set_key_if_not_none("title_sub", is_part_of_title_sub)

        document.add_items_to_key(identifiers_item, "identifiers")

        document.add_items_to_key([is_part_of], "is_part_ofs")
    else:
        document.set_key_if_not_none("peer_reviewed", peer_reviewed)
        document.set_key_if_not_none("publishers", [publisher])
        document.set_key_if_not_none("publication_places", [publication_place])
        document.add_items_to_key(is_part_of_identifiers, "identifiers")
        document.add_items_to_key(identifiers_item, "identifiers")

    # series
    if series_title:
        series = Document()
        series["rec_type"] = constants.DOC_TYPE_SERIES
        series.set_key_if_not_none("title", series_title)

        document.add_items_to_key([series], "seriess")

    # classificiations
    extract_convert_add_classifications(sum_doc, document, "DEWEY", "ddc")
    extract_convert_add_classifications(sum_doc, document, "Discipline", "discipline")
    extract_convert_add_classifications(sum_doc, document, "NAICS", "NAICS")

    # set properties
    document.set_key_if_not_none("creators", creators)
    document.set_key_if_not_none("copyright_statement", copyright_statement)
    document.set_key_if_not_none("date_issued", date_issued)
    document.set_key_if_not_none("degree", degree)
    document.set_key_if_not_none("descriptions", descriptions)
github medialab / reference_manager / biblib / crosswalks / endnotexml_crosswalk.py View on Github external
def endnotexml_record_to_metajson(record, source, rec_id_prefix):
    document = Document()

    # TODO
    # translated_creators: /contributors/translated-authors/author/style
    # auth_address: /auth-address/style
    # label: /label/style
    # custom1

    # Extract endnote properties

    rec_id = record.find("rec-number").text
    endnote_type = record.find("ref-type").text
    rec_type = endnote_record_type_to_metajson_document_type[endnote_type]

    primary_creators = extract_creators(None, "aut", record, "./contributors/authors/author/style")
    secondary_creators = extract_creators(None, "pbd", record, "./contributors/secondary-authors/author/style")
    if endnote_type in [TYPE_BOOK, TYPE_BOOK_SECTION]:
github medialab / reference_manager / biblib / crosswalks / unimarc_crosswalk.py View on Github external
'453': ("has_translations", "same"),
        '454': ("is_translation_ofs", "same"),
        '455': ("is_version_ofs", "same"),
        '456': ("has_versions", "same"),
        '461': ("is_part_ofs", "is_part_ofs"),
        '462': ("has_parts", "has_parts"),
        '463': ("is_part_ofs", "is_part_ofs"),
        '464': ("has_parts", "has_parts"),
        '470': ("is_review_ofs", "is_review_ofs"),
        '481': ("is_bound_withs", "same"),
        '482': ("is_bound_afters", "same"),
        '488': ("has_relation_withs", "same")
    }
    if record.get_fields(*relateditems_dict.keys()):
        for field in record.get_fields(*relateditems_dict.keys()):
            related = Document()
            has_t = False
            if field.get_subfields('t'):
                has_t = True
            creators = []
            publication_places = []
            title_alternatives = []
            identifiers = []
            publishers = []
            seriess = []
            resources = []
            for subfield in field:
                # todo : trouble with "Technique des zones imbriquées"
                if subfield[1] is not None and subfield[1].strip() is not None:
                    if subfield[0] == "0":
                        related["rec_id"] = subfield[1].strip()
                    elif subfield[0] == "3":