Skip to content

Commit

Permalink
print(a.res, b.res, URIRef(a.res + '/prov/se/1'), self.prov_set.get_e…
Browse files Browse the repository at this point in the history
…ntity(URIRef(a.res + '/prov/se/1')))
  • Loading branch information
arcangelo7 committed Oct 20, 2024
1 parent 3d8a46c commit db8bc74
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 18 deletions.
18 changes: 1 addition & 17 deletions oc_ocdm/prov/prov_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
from oc_ocdm.prov.prov_entity import ProvEntity
from oc_ocdm.support.support import (get_count, get_prefix, get_short_name)

import logging

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

class ProvSet(AbstractSet):
# Labels
Expand Down Expand Up @@ -122,35 +118,25 @@ def generate_provenance(self, c_time: float = None) -> set:
else:
cur_time: str = datetime.fromtimestamp(c_time, tz=timezone.utc).replace(microsecond=0).isoformat(sep="T")

logger.debug(f"Starting generate_provenance with cur_time: {cur_time}")

# MERGED ENTITIES
for cur_subj in self.prov_g.res_to_entity.values():
logger.debug(f"Processing entity: {cur_subj}")
if cur_subj is None or (not cur_subj.was_merged or cur_subj.to_be_deleted):
logger.debug(f"Skipping entity: {cur_subj}")
# Here we must skip every entity that was not merged or that must be deleted.
continue

# Previous snapshot
last_snapshot_res: Optional[URIRef] = self._retrieve_last_snapshot(cur_subj.res)
logger.debug(f"Last snapshot for {cur_subj.res}: {last_snapshot_res}")

if last_snapshot_res is None:
# CREATION SNAPSHOT
logger.debug(f"Creating new snapshot for {cur_subj.res}")
cur_snapshot: SnapshotEntity = self._create_snapshot(cur_subj, cur_time)
cur_snapshot.has_description(f"The entity '{cur_subj.res}' has been created.")
modified_entities.add(cur_subj.res)
else:
update_query: str = get_update_query(cur_subj, entity_type="graph")[0]
was_modified: bool = (update_query != "")
logger.debug(f"Entity {cur_subj.res} was_modified: {was_modified}")
snapshots_list: List[SnapshotEntity] = self._get_snapshots_from_merge_list(cur_subj)
logger.debug(f"Snapshots from merge list: {snapshots_list}")

if was_modified and len(snapshots_list) <= 0:
# MODIFICATION SNAPSHOT
logger.debug(f"Creating modification snapshot for {cur_subj.res}")
last_snapshot: SnapshotEntity = self.add_se(prov_subject=cur_subj, res=last_snapshot_res)
last_snapshot.has_invalidation_time(cur_time)

Expand All @@ -161,7 +147,6 @@ def generate_provenance(self, c_time: float = None) -> set:
modified_entities.add(cur_subj.res)
elif len(snapshots_list) > 0:
# MERGE SNAPSHOT
logger.debug(f"Creating merge snapshot for {cur_subj.res}")
last_snapshot: SnapshotEntity = self.add_se(prov_subject=cur_subj, res=last_snapshot_res)
last_snapshot.has_invalidation_time(cur_time)
cur_snapshot: SnapshotEntity = self._create_snapshot(cur_subj, cur_time)
Expand Down Expand Up @@ -214,7 +199,6 @@ def generate_provenance(self, c_time: float = None) -> set:
cur_snapshot.has_description(f"The entity '{cur_subj.res}' has been modified.")
cur_snapshot.has_update_action(update_query)
modified_entities.add(cur_subj.res)
logger.debug(f"Finished generate_provenance. Modified entities: {modified_entities}")
return modified_entities

def _add_prov(self, graph_url: str, short_name: str, prov_subject: GraphEntity,
Expand Down
2 changes: 1 addition & 1 deletion oc_ocdm/test/prov/test_prov_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_creation_merged_entity(self):
a.merge(b, prefer_self=True)

result = self.prov_set.generate_provenance(self.cur_time)

print(a.res, b.res, URIRef(a.res + '/prov/se/1'), self.prov_set.get_entity(URIRef(a.res + '/prov/se/1')))
se_a = self.prov_set.get_entity(URIRef(a.res + '/prov/se/1'))
self.assertIsNotNone(se_a)
self.assertIsInstance(se_a, SnapshotEntity)
Expand Down
Binary file modified virtuoso-opensource/database/virtuoso.trx
Binary file not shown.

0 comments on commit db8bc74

Please sign in to comment.