def add_se(self, prov_subject: GraphEntity, res: URIRef = None) -> SnapshotEntity: if res is not None and get_short_name(res) != "se": raise ValueError(f"Given res: <{res}> is inappropriate for an SnapshotEntity entity.") if res is not None and res in self.res_to_entity: return self.res_to_entity[res] g_prov: str = str(prov_subject) + "/prov/" cur_g, count, label = self._add_prov(g_prov, "se", prov_subject, res) return SnapshotEntity(prov_subject, cur_g, self, res, prov_subject.resp_agent, prov_subject.source, ProvEntity.iri_entity, count, label, "se")
def add_ci(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> Citation: if res is not None and get_short_name(res) != "ci": raise ValueError( f"Given res: <{res}> is inappropriate for a Citation entity.") if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_ci, "ci", res) return Citation(cur_g, self, res, GraphEntity.iri_citation, resp_agent, source, count, label, "ci", preexisting_graph)
def _get_multiple_uri_references(self, predicate: URIRef, short_name: str = None) -> List[URIRef]: result: List[URIRef] = [] for o in self.g.objects(self.res, predicate): if type(o) == URIRef: if not is_string_empty(short_name): # If a particular short_name is explicitly required, # then the following additional check must be performed: if (short_name == '_dataset_' and is_dataset(o)) or get_short_name(o) == short_name: result.append(o) else: result.append(o) return result
def _retrieve_last_snapshot(self, prov_subject: URIRef) -> Optional[URIRef]: subj_short_name: str = get_short_name(prov_subject) subj_count: str = get_count(prov_subject) try: if int(subj_count) <= 0: raise ValueError('prov_subject is not a valid URIRef. Extracted count value should be a positive ' 'non-zero integer number!') except ValueError: raise ValueError('prov_subject is not a valid URIRef. Unable to extract the count value!') last_snapshot_count: str = str(self.counter_handler.read_counter(subj_short_name, "se", int(subj_count))) if int(last_snapshot_count) <= 0: return None else: return URIRef(str(prov_subject) + '/prov/se/' + last_snapshot_count)
def add_ra(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> ResponsibleAgent: if res is not None and get_short_name(res) != "ra": raise ValueError( f"Given res: <{res}> is inappropriate for a ResponsibleAgent entity." ) if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_ra, "ra", res) return ResponsibleAgent(cur_g, self, res, GraphEntity.iri_agent, resp_agent, source, count, label, "ra", preexisting_graph)
def add_rp(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> ReferencePointer: if res is not None and get_short_name(res) != "rp": raise ValueError( f"Given res: <{res}> is inappropriate for a ReferencePointer entity." ) if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_rp, "rp", res) return ReferencePointer(cur_g, self, res, GraphEntity.iri_intextref_pointer, resp_agent, source, count, label, "rp", preexisting_graph)
def add_pl(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> PointerList: if res is not None and get_short_name(res) != "pl": raise ValueError( f"Given res: <{res}> is inappropriate for a PointerList entity." ) if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_pl, "pl", res) return PointerList(cur_g, self, res, GraphEntity.iri_singleloc_pointer_list, resp_agent, source, count, label, "pl", preexisting_graph)
def add_id(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> Identifier: if res is not None and get_short_name(res) != "id": raise ValueError( f"Given res: <{res}> is inappropriate for an Identifier entity." ) if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_id, "id", res) return Identifier(cur_g, self, res, GraphEntity.iri_identifier, resp_agent, source, count, label, "id", preexisting_graph)
def add_de(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> DiscourseElement: if res is not None and get_short_name(res) != "de": raise ValueError( f"Given res: <{res}> is inappropriate for a DiscourseElement entity." ) if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_de, "de", res) return DiscourseElement(cur_g, self, res, GraphEntity.iri_discourse_element, resp_agent, source, count, label, "de", preexisting_graph)
def add_ar(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> AgentRole: if res is not None and get_short_name(res) != "ar": raise ValueError( f"Given res: <{res}> is inappropriate for an AgentRole entity." ) if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_ar, "ar", res) return AgentRole(cur_g, self, res, GraphEntity.iri_role_in_time, resp_agent, source, count, label, "ar", preexisting_graph)
def add_br(self, resp_agent: str, source: str = None, res: URIRef = None, preexisting_graph: Graph = None) -> BibliographicResource: if res is not None and get_short_name(res) != "br": raise ValueError( f"Given res: <{res}> is inappropriate for a BibliographicResource entity." ) if res is not None and res in self.res_to_entity: return self.res_to_entity[res] cur_g, count, label = self._add(self.g_br, "br", res) return BibliographicResource(cur_g, self, res, GraphEntity.iri_expression, resp_agent, source, count, label, "br", preexisting_graph)