def load_metadata_for_docs(conn_meta, query, split_metadata=False):
    """
    loads the metadata for documents
    @param conn_meta: connection to the database which includes PubMed metadata
    @param query: the query to contain metadata (must project pmid and metadata)
    @param split_metadata: if true the metadata attribute is first split and afterwise stored as a set
    @return: a dict mapping a pmid to a set of metadata values
    """
    cur = conn_meta.cursor()
    cur.execute(query)
    rows = cur.fetchall()
    doc2meta = {}
    for r in rows:
        pmid, metadata = str(r[0]), str(r[1])

        if split_metadata:
            metadata = metadata.lower().split()
        else:
            # to avoid automatic splitting in sets
            metadata = [metadata]

        if pmid not in doc2meta:
            doc2meta[pmid] = set()
        doc2meta[pmid].update(metadata)

    return doc2meta