Giter Club home page Giter Club logo

Comments (6)

simleo avatar simleo commented on May 28, 2024 1

Some documentation I could not find.

How to:

  • Iterate over all the items in a crate's graph? It's crude but in the javacript library it's for (let item crate.getGraph()) { ... }
from rocrate.rocrate import ROCrate
crate = ROCrate("./")  # assuming crate dir is CWD
for e in crate.get_entities():
    print(f"{e.id}, (e.type)")  # id and type
    print(e.as_jsonld())  # JSON entry
  • Add a custom item that is not a Person etc that I have constructed myself in JSON (in the Javascript library we say crate.addItem({"@id": "#someid", "@type": ["CorpusItem", "RepositoryObject"], "name": ....})
from rocrate.model.contextentity import ContextEntity
# from the RO-Crate docs
obj = {
    "@id": "https://omeka.uws.edu.au/farmstofreeways/api/items/166",
    "@type": ["RepositoryObject", "Text"],
    "title": "Western Sydney Women's Oral History Project: Flier (illustrated)"
}
flier = crate.add(ContextEntity(crate, identifier=obj["@id"], properties=obj))
  • Fetch an item by @id in js:`crate.getItem("#someid")
crate.dereference("#someid")
  • Example task: Add an array of references to RepositoryObjects to the root dataset using a hasMember property and add the Repository Objects to the graph

We're using "mentions" to link context entities directly to the root dataset, see #55 (and ResearchObject/ro-crate#122 on which it is based). Anyway, what follows would work the same for any other root dataset property.

This is a bit tricky due to the "fancy" get/set item overload in entities:

crate = ROCrate("ro-crate-galaxy-sortchangecase")
json = [
    {
        "@id": "https://example.com/ro/1",
        "@type": "RepositoryObject",
        "title": "RO 1"
    },
    {
        "@id": "https://example.com/ro/2",
        "@type": "RepositoryObject",
        "title": "RO 2"
    },
]
mentions = set(crate.root_dataset["mentions"] or [])
for j in json:
    mentions.add(crate.add(ContextEntity(crate, identifier=j["@id"], properties=j)))
crate.root_dataset["mentions"] = list(mentions)

I'm going to keep this open for now, since we should open some "todo" issues stemming from the above considerations before closing.

from ro-crate-py.

simleo avatar simleo commented on May 28, 2024 1

It would be great to have some of these tips in the documentation.

Done in #121

from ro-crate-py.

ptsefton avatar ptsefton commented on May 28, 2024

Thanks @simleo this is really useful.

I don't understand how to use the r = crate._ROCrate__entity_map hack ; if I try it on the example I added in #77 get an entity map that looks like this:

print (crate._ROCrate__entity_map)
{'arcp://uuid,accb7567-49e9-4ce8-bab4-f4876fc89160/ro-crate-metadata.json': <ro-crate-metadata.json CreativeWork>, 'arcp://uuid,accb7567-49e9-4ce8-bab4-f4876fc89160': <./ Dataset>, 'arcp://uuid,accb7567-49e9-4ce8-bab4-f4876fc89160/#collection': <#collection RepositoryCollection >, 'arcp://uuid,accb7567-49e9-4ce8-bab4-f4876fc89160/#./test.csv': <#./test.csv File>}

from ro-crate-py.

ptsefton avatar ptsefton commented on May 28, 2024

Actually the equivalent to crate.getId() is crate.dereference - eg:

e = crate.dereference('#files/460/original_49a4d796174100b7f2d2b7529b51e79b.csv')

from ro-crate-py.

simleo avatar simleo commented on May 28, 2024

Actually the equivalent to crate.getId() is crate.dereference

You're right. Apparently, not working on the library for a couple of months was enough to make me unable to name the method off the top of my head 🙂 I have updated my previous reply accordingly.

from ro-crate-py.

dgarijo avatar dgarijo commented on May 28, 2024

It would be great to have some of these tips in the documentation. I have a student that almost discarded using this package because he could not find the right documentation for accessing the elements of an RO-Crate and their metadata :)

from ro-crate-py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.