-
Notifications
You must be signed in to change notification settings - Fork 3
added a file about how to search and delete resources in the ts #397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8626e69
added a file about how to search and delete resources in the ts
francescalb 20c519d
Merge branch 'criteria_update_and_doc' into flb/update-documentation-…
jesper-friis 8543952
Added possibility of adding more than one type or several values for …
francescalb b879d7b
Merge branch 'flb/update-documentation-search-delete' of github.com:E…
francescalb 7d06099
Merge branch 'master' into flb/update-documentation-search-delete
francescalb 914ada8
Merge branch 'flb/update-documentation-search-delete' of github.com:E…
francescalb a4693c6
Updated documentation so it can be tested
francescalb e23d7b6
Corrected typos
francescalb dd422ee
import delete in documentation
francescalb 7c6a833
typo
francescalb 194e629
Skip doctest on output
francescalb 1505b7e
remove doctest on documentation...
francescalb 7a8a92b
remove more tests
francescalb 8da5ef9
Test running doctest, remove output
francescalb 672d445
Run the tests
francescalb 9255301
more testing
francescalb 8062ae1
Merge branch 'master' into flb/update-documentation-search-delete
francescalb 76f82b8
Added acquire and load in doc
francescalb 0d3e11b
Merge branch 'flb/update-documentation-search-delete' of github.com:E…
francescalb 9b8b21c
Apply suggestions from code review
jesper-friis 7302feb
Merge branch 'master' into flb/update-documentation-search-delete
jesper-friis 89a3f82
Update docs/datadoc/fetching-resources-from-a-triplestore.md
francescalb 8a609b8
Merge branch 'master' into flb/update-documentation-search-delete
francescalb 7c61e59
Typos
francescalb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| Working with already documented resources | ||
| ========================================= | ||
|
|
||
| The [tripper.datadoc] module also includes functionality for easy searching of the documented resources. | ||
|
|
||
| For these examples there must be a triplestore instance available, poplated with some data. | ||
| ```python | ||
| >>> from tripper import Triplestore | ||
| >>> from tripper.datadoc import save_datadoc | ||
| >>> ts = Triplestore(backend="rdflib") | ||
| >>> save_datadoc(ts,"https://raw.githubusercontent.com/EMMC-ASBL/tripper/refs/heads/master/tests/input/semdata.yaml") # doctest: +ELLIPSIS | ||
| {'@graph': [...], ...} | ||
|
|
||
| ``` | ||
|
|
||
| Searching the knowledge base | ||
| ---------------------------- | ||
|
|
||
| ### Get all IRIs of all datasets in the kb | ||
|
|
||
| ```python | ||
| >>> from tripper.datadoc import search | ||
| >>> search(ts) # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| ``` | ||
|
|
||
| This will return a list of all datasets in the knowledge base. | ||
|
|
||
|
|
||
| ### Search with filtering criteria | ||
|
|
||
| Before adding specific filtering criteria it is important to bind non-standard prefixes to corresponding namespaces (standard prefixes defined in the keywords file, like dcterms, dcat, etc do not need to be defined again): | ||
|
|
||
| ```python | ||
| >>> DATA = ts.bind("data", "http://example.com/data#") | ||
| >>> MAT = ts.bind("mat", "http://example.com/materials#") | ||
|
|
||
| ``` | ||
|
|
||
| It is possible to search for instances of type `dcat:Dataset` in two ways: | ||
|
|
||
| ```python | ||
| >>> search(ts, type="Dataset") # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| >>> search(ts, type="dcat:Dataset") # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| ``` | ||
| The first shortened version is only possible for [predefined keywords] that are specifically added in tripper. | ||
|
|
||
| Note that full iris (e.g. `http://www.w3.org/ns/dcat#Dataset`) are currently not supported. | ||
|
|
||
|
|
||
| You can also search for documented resources of other types or include more than one type in the search. | ||
| ```python | ||
| >>> SEM = ts.bind("sem", "https://w3id.com/emmo/domain/sem/0.1#") | ||
| >>> search(ts, type="sem:SEMImage") # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| >>> search(ts, type=["sem:SEMImage", "dcat:Dataset"]) # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| It is also possible to filter through other criteria: | ||
| ```python | ||
| >>> search(ts, criteria={"creator.name": "Sigurd Wenner"}) # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| >>> search(ts, criteria={"creator.name": ["Sigurd Wenner", "Named Lab Assistant"]}) # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| >>> KB = ts.bind('kb', 'http://example.com/kb/' ) | ||
| >>> search(ts, criteria={"@id": KB.image1}) # doctest: +ELLIPSIS | ||
| [...] | ||
|
|
||
| ``` | ||
|
|
||
| Note that here the object created when binding the `kb` prefix is a tripper.Namespace, and can be used directly as the second example above. | ||
|
|
||
| Fetching metadata and data | ||
| -------------------------- | ||
|
|
||
| The `acquire` function can be used to fetch metadata from the triplestore. | ||
| ```python | ||
| >>> from tripper.datadoc import acquire | ||
| >>> acquire(ts, 'https://he-matchmaker.eu/data/sem/SEM_cement_batch2/77600-23-001/77600-23-001_5kV_400x_m001') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE | ||
| AttrDict({'@id': 'https://he-matchmaker.eu/data/sem/SEM_cement_batch2/77600-23-001/77600-23-001_5kV_400x_m001', ...}) | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| Similarly the load function can be used to fetch the data using the information about the dowload URL in the metadata. | ||
| The syntax is the same as above. Note though that for this specific example you would need access to a server that | ||
| is not available to the general public. | ||
|
|
||
|
|
||
| Removing instances in the knowledge base | ||
| ---------------------------------------- | ||
|
|
||
| Be very careful when using this, as there is a high risk that you delete data from others if you have access to delete on a shared knowledge base. | ||
|
|
||
| The same criteria as shown above can be used e.g.: | ||
|
|
||
| ```python | ||
| >>> from tripper.datadoc import delete | ||
| >>> delete(ts, criteria={"@id": KB.image1}) | ||
| >>> delete(ts, criteria={"creator.name": "Sigurd Wenner"}) | ||
|
|
||
| ``` | ||
| It is also possible to remove everything in the triplestore with `delete(ts)`, but this is strongly discouraged. | ||
|
|
||
|
|
||
|
|
||
| [predefined keywords]: keywords.md | ||
| [tripper.datadoc]: https://emmc-asbl.github.io/tripper/latest/datadoc/introduction | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe an example of how to use
load()can be added here...