thegetty / crom

Python library to make creation of CIDOC CRM easier by mapping classes/predicates to python objects
Apache License 2.0
51 stars 15 forks source link

Exemple fix ? #178

Open ghost opened 4 years ago

ghost commented 4 years ago

Hey !

As I'm discovering this cromulent package you developed, I might have encountered several issues with the exemple, I allowed the use of E31_Document which was discouraged (not to say, forbidden) and property names in the .tsv which were renamed.

Thus, I updated the example code but I haven't done the pull request (may I ?), the reason is mainly because you don't mess in somemone else's voacab ;) Maybe there are some issues with the E31 I don't have knowledge of.

from cromulent.model import factory, Identifier, AuthorityDocument, Document, Activity, Event, TimeSpan, HumanMadeObject, Acquisition, Type

# Locally "subclass" to create consistent patterns with E55 and AAT
class Painting(HumanMadeObject):
    def __init__(self, *args, **kw):
        super(Painting, self).__init__(*args, **kw)
        self.classified_as = Type("http://vocab.getty.edu/aat/300033618")

class LugtNumber(Identifier):
    def __init__(self, *args, **kw):
        super(LugtNumber, self).__init__(*args, **kw)
        # ???
        self.classified_as = Type("http://vocab.getty.edu/aat/300033618")   

class TMSNumber(Identifier):
    def __init__(self, *args, **kw):
        super(TMSNumber, self).__init__(*args, **kw)
        # Repository Number
        self.classified_as = Type("http://vocab.getty.edu/aat/300404621")

class LotNumber(Identifier):
    def __init__(self, *args, **kw):
        super(TMSNumber, self).__init__(*args, **kw)
        # Lot Number
        self.classified_as = Type("http://vocab.getty.edu/aat/300404628")

# Or actually subclass in an extension vocab
class Mosaic(HumanMadeObject):
    _type = "extension:Mosaic"

factory.base_url = "http://data.getty.edu/provenance/"
factory.default_lang = "en"

catalog = Document("catalog")
page = Document("catalog-entry")
catalog.c_part = page
auction = Activity("auction")
catalog.documents = auction
lot = Activity("lot")
auction.part = lot
page.documents = lot
txn = Acquisition("sale")
lot.part = txn
what = Painting('my-painting')
txn.transferred_title_of = what
what._label = "My First Paint By Numbers"
what.identified_by = TMSNumber("")

# print(factory.toString(catalog, compact=False))
factory.elasticsearch_compatible = True
factory.context_uri = {
    "name": "http://schema.org/name",
    # This means that 'name' is shorthand for 'http://schema.org/name'
    "image": {
      "@id": "http://schema.org/image",
      # This means that 'image' is shorthand for 'http://schema.org/image'
      "@type": "@id"
      # This means that a string value associated with 'image' should be interpreted as an identifier that is an IRI
    },
    "homepage": {
      "@id": "http://schema.org/url",
      # This means that 'homepage' is shorthand for 'http://schema.org/url'
      "@type": "@id"
      # This means that a string value associated with 'homepage' should be interpreted as an identifier that is an IRI 
    }
}
factory.base_dir = "C:/_Archi/Etudes/20ND_Reperage/CRM_ModélisationConnaissances/PY-A_Script Exif/_out"
factory.full_names = True
factory.toFile(catalog, filename="out.json",compact=False)

print(factory.toString(catalog, compact=True))

Looking forward to output via python some .ttl from the crom json. Bests, Antoine