Comments (6)
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.
It would be great to have some of these tips in the documentation.
Done in #121
from ro-crate-py.
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.
Actually the equivalent to crate.getId() is crate.dereference - eg:
e = crate.dereference('#files/460/original_49a4d796174100b7f2d2b7529b51e79b.csv')
from ro-crate-py.
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.
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)
- Handle duplicates in property values HOT 2
- Add contentUrl property to files when it's known
- Fix behavior wrt "missing" data entities
- Broken error message in pick_type
- Add method to get entities by type
- Distribution request: rocrate-py on conda forge HOT 5
- Entity id should not be modifiable
- Support indirect data entity linking from root
- ro-crate profile functionality HOT 4
- Allow to attach partials to a crate? HOT 6
- Export entities/models in `rocrate.model.__init__`
- Document how to create a Workflow Run Crate file HOT 11
- dump the metadata of the RO-Crate HOT 1
- hasPart property on root dataset is assumed to be an array
- BUG: Duplicate references in hasPart on root dataset cause an error on loading crate HOT 1
- Add method to include additional contexts at the top level HOT 1
- Support tar.gz or other archive formats? HOT 1
- Raise an error, warning, or ignore duplicate ID's? HOT 2
- BUG: If Root Data Entity has an arcp:// ID the arcp:// part gets stripped off it HOT 1
- allow multiple types in `add_file()` or add documentation about type manipulation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ro-crate-py.