Skip to content

Commit

Permalink
trove:Indexcard rdfs:subClassOf dcat:CatalogRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed May 22, 2024
1 parent 8c018eb commit d993057
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 12 additions & 1 deletion trove/render/simple_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def _render_card(self, graph: rdf.RdfGraph, card: str | rdf.RdfBlanknode):
raise NotImplementedError
assert isinstance(_card_contents, rdf.Literal)
assert RDF.JSON in _card_contents.datatype_iris
return json.loads(_card_contents.unicode_value)
_json_contents = json.loads(_card_contents.unicode_value)
if isinstance(card, str):
self._add_twople(_json_contents, 'foaf:primaryTopicOf', card)
return _json_contents

def _render_meta(self, graph: rdf.RdfGraph, focus_iri: str):
_meta = {}
Expand All @@ -98,3 +101,11 @@ def _render_links(self, graph: rdf.RdfGraph, focus_iri: str):
(_link_url,) = _twopledict[RDF.value]
_links[_membername.unicode_value] = _link_url
return _links

def _add_twople(self, json_dict, predicate_iri: str, object_iri: str):
_obj_ref = {'@id': object_iri}
_obj_list = json_dict.setdefault(predicate_iri, [])
if isinstance(_obj_list, list):
_obj_list.append(_obj_ref)
else:
json_dict[predicate_iri] = [_obj_list, _obj_ref]
15 changes: 12 additions & 3 deletions trove/trovesearch_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from share.search.search_response import ValuesearchResult
from trove import models as trove_db
from trove.render.osfmap_jsonld import RdfOsfmapJsonldRenderer
from trove.vocab.namespaces import RDF, FOAF, DCTERMS, RDFS
from trove.vocab.namespaces import RDF, FOAF, DCTERMS, RDFS, DCAT
from trove.vocab.jsonapi import (
JSONAPI_LINK_OBJECT,
JSONAPI_MEMBERNAME,
Expand Down Expand Up @@ -196,6 +196,7 @@ def gather_valuesearch(focus, *, specific_index, search_params, use_osfmap_json)
)
def gather_card(focus, *, use_osfmap_json, **kwargs):
# TODO: batch gatherer -- load all cards in one query
yield (RDF.type, DCAT.CatalogRecord)
_indexcard_namespace = trove_indexcard_namespace()
try:
_indexcard_iri = next(
Expand Down Expand Up @@ -224,8 +225,12 @@ def gather_card(focus, *, use_osfmap_json, **kwargs):
.prefetch_related('upriver_indexcard__focus_identifier_set')
.get()
)
yield (DCTERMS.issued, _osfmap_indexcard.upriver_indexcard.created.date())
yield (DCTERMS.modified, _osfmap_indexcard.modified.date())
for _identifier in _osfmap_indexcard.upriver_indexcard.focus_identifier_set.all():
yield (TROVE.focusIdentifier, literal(_identifier.as_iri()))
_iri = _identifier.as_iri()
yield (FOAF.primaryTopic, _iri)
yield (TROVE.focusIdentifier, literal(_iri))
yield (
TROVE.resourceMetadata,
literal(_osfmap_indexcard.derived_text, datatype_iris={RDF.JSON})
Expand All @@ -238,8 +243,12 @@ def gather_card(focus, *, use_osfmap_json, **kwargs):
.prefetch_related('indexcard__focus_identifier_set')
.get()
)
yield (DCTERMS.issued, _indexcard_rdf.indexcard.created.date())
yield (DCTERMS.modified, _indexcard_rdf.modified.date())
for _identifier in _indexcard_rdf.indexcard.focus_identifier_set.all():
yield (TROVE.focusIdentifier, _identifier.as_iri())
_iri = _identifier.as_iri()
yield (FOAF.primaryTopic, _iri)
yield (TROVE.focusIdentifier, literal(_iri))
for _triple in iter_tripleset(_indexcard_rdf.as_rdf_tripledict()):
yield (TROVE.resourceMetadata, QuotedTriple(*_triple))

Expand Down

0 comments on commit d993057

Please sign in to comment.