예제 #1
0
def toRdf(collection, model='saa'):

    g = rdfSubject.db = Graph(identifier=ga.term('collections'))

    collectionNumber = collection.collectionNumber.lower().replace('.', '')
    scanNamespace = Namespace(
        f"https://archief.amsterdam/inventarissen/inventaris/{collectionNumber}.nl.html#"
    )

    col = SAACollection(ga.term(collectionNumber),
                        identifier=collection.collection_id,
                        code=collection.collectionNumber,
                        title=collection.title,
                        publisher=collection.publisher,
                        date=collection.collectionDate,
                        label=[collection.title])

    parts = [
        cToRdf(c,
               parent=col,
               collectionNumber=collectionNumber,
               scanNamespace=scanNamespace) for c in collection.children
    ]

    if parts != []:
        col.hasParts = parts

    return g
예제 #2
0
def cToRdf(c, parent=None, collectionNumber=None, scanNamespace=None):

    if collectionNumber:
        saaCollection = Namespace(
            f"https://data.goldenagents.org/datasets/SAA/{collectionNumber}/")
    else:
        saaCollection = ga

    if (c.scans or not c.children) and collectionNumber:
        # Then this is a book --> InventoryBook

        inventoryId = c.id
        saaInventory = Namespace(
            f"https://data.goldenagents.org/datasets/SAA/{collectionNumber}/{inventoryId}/"
        )

        if c.scans:

            saaScan = Namespace(
                f"https://data.goldenagents.org/datasets/SAA/Scan/")

            urlScans = [scanNamespace.term(i) for i in c.scans]
            scans = [saaInventory.term(i) for i in c.scans]

            parts = [
                SAADoublePageSpread(sUri,
                                    hasDigitalRepresentation=SAAScan(
                                        saaScan.term(img), depiction=imgUri),
                                    partOf=saaCollection.term(c.id))
                for img, sUri, imgUri in zip(c.scans, scans, urlScans)
            ]
        else:
            parts = []

        col = SAAInventoryBook(
            saaCollection.term(c.id),
            identifier=c.id,
            inventoryNumber=c.code,
            title=c.title,
            label=[Literal(f"Inventaris {c.code}", lang='nl')],
            date=c.date,
            hasParts=parts)

        try:
            parsedDate = parseDate(c.date)
        except:
            print(c.date)

        for k, v in parsedDate.items():
            if v:
                col.__setattr__(k, Literal(v.date(), datatype=XSD.date))

    else:
        # Not yet reached the end of the tree

        # collectionId = f"{collectionId}/{c.id}"

        col = SAACollection(saaCollection.term(c.id),
                            identifier=c.id,
                            code=c.code,
                            title=c.title,
                            date=c.date,
                            comment=[c.comment] if c.comment else [],
                            partOf=parent,
                            label=[c.title])

        parts = [
            cToRdf(c,
                   parent=col,
                   collectionNumber=collectionNumber,
                   scanNamespace=scanNamespace) for c in c.children
        ]

        if parts != []:
            col.hasParts = parts

    return col