Skip to content

Commit

Permalink
update entity_index when adding triples
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelo7 committed Oct 16, 2024
1 parent c5fe601 commit 041cc8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rdflib-ocdm"
version = "0.3.11"
version = "0.3.12"
description = ""
authors = ["arcangelo7 <[email protected]>"]
license = "ISC"
Expand Down
15 changes: 11 additions & 4 deletions rdflib_ocdm/ocdm_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, counter_handler: CounterHandler):
def preexisting_finished(self: Graph|ConjunctiveGraph|OCDMGraphCommons, resp_agent: str = None, source: str = None, c_time: str = None):
self.preexisting_graph = deepcopy(self)
for subject in self.subjects(unique=True):
self.__entity_index[subject] = {'to_be_deleted': False, 'resp_agent': resp_agent, 'source': source}
self.entity_index[subject] = {'to_be_deleted': False, 'resp_agent': resp_agent, 'source': source}
self.all_entities.add(subject)
count = self.provenance.counter_handler.read_counter(subject)
if count == 0:
Expand All @@ -68,10 +68,10 @@ def merge(self: Graph|ConjunctiveGraph|OCDMGraphCommons, res: URIRef, other: URI
for triple in triples_list:
self.remove(triple)
self.__merge_index.setdefault(res, set()).add(other)
self.__entity_index[other]['to_be_deleted'] = True
self.entity_index[other]['to_be_deleted'] = True

def mark_as_deleted(self, res: URIRef) -> None:
self.__entity_index[res]['to_be_deleted'] = True
self.entity_index[res]['to_be_deleted'] = True

@property
def merge_index(self) -> dict:
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, counter_handler: CounterHandler = None):
self.preexisting_graph = Graph()
OCDMGraphCommons.__init__(self, counter_handler)

def add(self, triple: "_TripleType"):
def add(self, triple: "_TripleType", resp_agent = None, source = None):
"""Add a triple with self as context"""
s, p, o = triple
assert isinstance(s, Node), "Subject %s must be an rdflib term" % (s,)
Expand All @@ -117,6 +117,9 @@ def add(self, triple: "_TripleType"):
if s not in self.all_entities:
self.all_entities.add(s)

if s not in self.entity_index:
self.entity_index[s] = {'to_be_deleted': False, 'resp_agent': resp_agent, 'source': source}

return self

class OCDMConjunctiveGraph(OCDMGraphCommons, ConjunctiveGraph):
Expand All @@ -131,6 +134,7 @@ def add(
Tuple["_SubjectType", "_PredicateType", "_ObjectType", Optional[Any]],
"_TripleType",
],
resp_agent = None, source = None
) -> "ConjunctiveGraph":
"""
Add a triple or quad to the store.
Expand All @@ -149,6 +153,9 @@ def add(
if s not in self.all_entities:
self.all_entities.add(s)

if s not in self.entity_index:
self.entity_index[s] = {'to_be_deleted': False, 'resp_agent': resp_agent, 'source': source}

return self

def _assertnode(*terms):
Expand Down

0 comments on commit 041cc8c

Please sign in to comment.