-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added "store_collection" option to generate strategy.
- Loading branch information
1 parent
ecb66df
commit 040030a
Showing
3 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
DLite-Python>=0.3.3,<0.4 | ||
DLite-Python>=0.3.3,<0.5 | ||
numpy>=1.21,<2 | ||
oteapi-core>=0.1.2 | ||
Pillow>=9.0.1,<11 | ||
|
This file contains 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,60 @@ | ||
"""Test to store the entire collection with the generate strategy.""" | ||
from pathlib import Path | ||
|
||
import dlite | ||
from oteapi.datacache import DataCache | ||
|
||
from oteapi_dlite.strategies.generate import ( | ||
DLiteGenerateConfig, | ||
DLiteGenerateStrategy, | ||
) | ||
from oteapi_dlite.utils import get_meta | ||
|
||
thisdir = Path(__file__).resolve().parent | ||
entitydir = thisdir / ".." / "entities" | ||
outdir = thisdir / ".." / "output" | ||
|
||
|
||
config = DLiteGenerateConfig( | ||
functionType="application/vnd.dlite-generate", | ||
configuration={ | ||
"driver": "json", | ||
"location": str(outdir / "coll.json"), | ||
"options": "mode=w", | ||
"store_collection": True, | ||
}, | ||
) | ||
|
||
coll = dlite.Collection("coll_id") | ||
|
||
Image = get_meta("http://onto-ns.com/meta/1.0/Image") | ||
image = Image([2, 2, 1]) | ||
image.data = [[[1], [2]], [[3], [4]]] | ||
coll.add("image", image) | ||
coll.add_relation("image", "rdf:type", "onto:Image") | ||
coll.add_relation("image", "dcterms:title", "Madonna") | ||
|
||
|
||
session = {"collection_id": coll.uuid} | ||
DataCache().add(coll.asjson(), key=coll.uuid) | ||
|
||
generator = DLiteGenerateStrategy(config) | ||
session.update(generator.initialize(session)) | ||
|
||
generator = DLiteGenerateStrategy(config) | ||
session.update(generator.get(session)) | ||
|
||
|
||
# Check that the data in the newly created generated json file matches our | ||
# collection. | ||
# Before loading the generated file, we delete the original collection | ||
# to ensure that we are not just fetching it from the dlite cache... | ||
del coll | ||
with dlite.Storage("json", outdir / "coll.json", "mode=r") as s: | ||
# Assume we don't know the collection uuid, but we know that there is only | ||
# one collection in the json file | ||
(coll_uuid,) = s.get_uuids("http://onto-ns.com/meta/0.1/Collection") | ||
coll = s.load(id=coll_uuid) | ||
assert coll.uri == "coll_id" | ||
assert coll.nrelations == 5 | ||
assert coll["image"] == image |