-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
486 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
""" | ||
|
||
__version__ = "2.0.0b3" | ||
__version__ = "2.0.0b4" |
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
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,31 @@ | ||
class CollectionDispatcher: | ||
""" | ||
:param collection: | ||
:param default_inventory_name: | ||
""" | ||
def __init__(self, collection, default_inventory_name=None): | ||
self.collection = collection | ||
if default_inventory_name is None: | ||
default_inventory_name = list(self.collection.children.values())[0].id | ||
self.__methods__ = [(default_inventory_name, lambda x, **k: True)] | ||
|
||
@property | ||
def methods(self): | ||
return self.__methods__ | ||
|
||
def add(self, func, inventory_name=None): | ||
self.methods.append((inventory_name, func)) | ||
|
||
def inventory(self, inventory_name): | ||
def decorator(f): | ||
self.add(func=f, inventory_name=inventory_name) | ||
return f | ||
return decorator | ||
|
||
def dispatch(self, collection, **kwargs): | ||
for inventory, method in self.methods[::-1]: | ||
if method(collection, **kwargs) is True: | ||
collection.parent = self.collection.children[inventory] | ||
return | ||
raise Exception("Text not dispatched %s" % collection.id) |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from MyCapytain.resources.prototypes.metadata import Collection | ||
from rdflib import URIRef | ||
|
||
|
||
class DTSCollection(Collection): | ||
@staticmethod | ||
def parse(resource, mimetype="application/json+ld"): | ||
""" Given a dict representation of a json object, generate a DTS Collection | ||
:param resource: | ||
:param mimetype: | ||
:return: | ||
""" | ||
obj = DTSCollection(identifier=resource["@id"]) | ||
obj.type = resource["type"] | ||
obj.version = resource["version"] | ||
for label in resource["label"]: | ||
obj.set_label(label["value"], label["lang"]) | ||
for key, value in resource["metadata"].items(): | ||
term = URIRef(key) | ||
if isinstance(value, list): | ||
if isinstance(value[0], dict): | ||
for subvalue in value: | ||
obj.metadata.add(term, subvalue["@value"], subvalue["@lang"]) | ||
else: | ||
for subvalue in value: | ||
if subvalue.startswith("http") or subvalue.startswith("urn"): | ||
obj.metadata.add(term, URIRef(subvalue)) | ||
else: | ||
obj.metadata.add(term, subvalue) | ||
else: | ||
if value.startswith("http") or value.startswith("urn"): | ||
obj.metadata.add(term, URIRef(value)) | ||
else: | ||
obj.metadata.add(term, value) | ||
|
||
for member in resource["members"]["contents"]: | ||
subobj = DTSCollectionShort.parse(member) | ||
subobj.parent = member | ||
|
||
last = obj | ||
for member in resource["parents"]: | ||
subobj = DTSCollectionShort.parse(member) | ||
last.parent = subobj | ||
|
||
return obj | ||
|
||
|
||
class DTSCollectionShort(DTSCollection): | ||
@staticmethod | ||
def parse(resource): | ||
""" Given a dict representation of a json object, generate a DTS Collection | ||
:param resource: | ||
:param mimetype: | ||
:return: | ||
""" | ||
obj = DTSCollectionShort(identifier=resource["@id"]) | ||
obj.type = resource["type"] | ||
obj.model = resource["model"] | ||
for label in resource["label"]: | ||
obj.set_label(label["value"], label["lang"]) | ||
return obj |
Oops, something went wrong.