Ejemplo n.º 1
0
   def __add_independent_titles(self):
       title_query = """
           PREFIX core: <http://purl.org/nampi/owl/core#>
           PREFIX mona: <http://purl.org/nampi/owl/monastic-life#>
           PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
           SELECT ?text
           WHERE {{
 	            ?event a core:event ;
                   core:assigns_title/core:has_xsd_string ?text ;
                   core:assigns_title_to/rdfs:label "{}" .
           }}
       """
       for _, row in self.__sheet.get_table(Table.PERSONS).iterrows():
           religious_title = safe_str(row, Column.religious_title)
           person_label = safe_str(row, Column.name)
           if religious_title:
               has_existing_title = bool(
                   self._graph.graph.query(title_query.format(person_label)))
               if not has_existing_title:
                   person = self.__get_person(person_label)
                   if person:
                       assert person_label
                       event = Event(
                           self._graph,
                           person,
                           label="Assign religious title " + religious_title,
                           main_person_relationship=Nampi_type.Core.
                           has_main_participant,
                       )
                       title = Title(
                           self._graph,
                           religious_title,
                           Nampi_type.Mona.religious_title,
                       )
                       event.add_relationship(Nampi_type.Core.adds_aspect,
                                              title)
                       self.__insert_di_act(event, row)
                       logging.debug("Assigns title '{}' to '{}'".format(
                           religious_title, person_label))
       logging.info("Finish adding independent titles")
    def add_persons(self, persondata, birthdate="", birthplace="", ids=""):
        """
        Add all persons from the persons table not being added in birth events.
        """

        if not persondata:
            # Only use entries with source
            logging.warning("No source entry for 'person' ")
            return

        person_label = persondata.Name  # persondata.Forename + " " + persondata.Surname

        person = self.__get_person(persondata.Name)
        print("Person in Progress...{}")
        if person:

            # if not has_birth_event:
            #     # Get all family name variants from the person table
            family_names = persondata.Surname
            #                     safe_str(row, Column.family_name_gender_neutral), safe_str(row, Column.family_name)]
            #     # Get the official family name by looking through the ordered family_names list and picking the first match
            family_group_name = next((s for s in family_names if s), None)
            # Add family name group membership

            family = Family(self._graph, persondata.Surname)
            aspect = Aspect(self._graph, family_member_label)

            if len(family_names) != 0:
                become_member_event = Event(
                    self._graph,
                    person,
                    Nampi_type.Core.has_main_participant,
                    label="Become family member",
                )
                become_member_event.add_relationship(
                    Nampi_type.Core.adds_aspect, aspect)
                become_member_event.add_relationship(
                    Nampi_type.Core.changes_aspect_related_to, family)
                logging.debug("Added 'membership' in family ")
                self.__insert_di_act(
                    become_member_event,
                    (),
                    authors,
                    "ProDomo",
                    "https://prodomo.icar-us.eu/person/" + persondata.Id,
                    self._d1,
                )

            if len(persondata.Mother) != 0:
                mother = self.__get_person(persondata.Mother)
                become_member_event_mother = Event(
                    self._graph,
                    mother,
                    Nampi_type.Core.has_main_participant,
                    label="Become family member",
                )
                become_member_event_mother.add_relationship(
                    Nampi_type.Core.adds_aspect, aspect)
                become_member_event_mother.add_relationship(
                    Nampi_type.Core.changes_aspect_related_to, family)

                self.__insert_di_act(
                    become_member_event_mother,
                    (),
                    authors,
                    "ProDomo",
                    "https://prodomo.icar-us.eu/aspekt/" + ids["Mutter"],
                    self._d1,
                )

            if len(persondata.Father) != 0:
                father = self.__get_person(persondata.Father)
                become_member_event_father = Event(
                    self._graph,
                    father,
                    Nampi_type.Core.has_main_participant,
                    label="Become family member",
                )
                become_member_event_father.add_relationship(
                    Nampi_type.Core.adds_aspect, aspect)
                become_member_event_father.add_relationship(
                    Nampi_type.Core.changes_aspect_related_to, family)

                self.__insert_di_act(
                    become_member_event_father,
                    (),
                    authors,
                    "ProDomo",
                    "https://prodomo.icar-us.eu/aspekt/" + ids["Vater"],
                    self._d1,
                )

                # Add names for persons that don't have birth events
                # if family_names:
                # Add personal family name
                fn_assignment = Appellation_assignment(
                    self._graph,
                    person,
                    family_names,
                    Appellation_type.FAMILY_NAME,
                )
                self.__insert_di_act(
                    fn_assignment,
                    (),
                    authors,
                    "ProDomo",
                    "https://prodomo.icar-us.eu/person/" + persondata.Id,
                    self._d1,
                )

            if birthdate:
                self.__add_births(
                    birthdate,
                    person_label,
                    family_names,
                    birthplace,
                    ids["Geburt"],
                    persondata.Mother,
                    persondata.Father,
                )

        logging.info("Parsed the persons")
    def add_investiture_events(self, person, invest_dates):
        # get Event label from dict
        # print(invest_date.SemanticStm)
        # print(Entities_dict.keys())
        if not isinstance(invest_dates, list):
            # If type is not list then make it list
            invest_dates = [invest_dates]

        for invest_date in invest_dates:
            if (invest_date.SemanticStm in Entities_dict
                    and Entities_dict[invest_date.SemanticStm] is not None):
                Monastery = Entities_dict[invest_date.SemanticStm]
            elif (invest_date.Reference in Entities_dict
                  and Entities_dict[invest_date.Reference] is not None):
                Monastery = Entities_dict[invest_date.Reference]
            else:
                Monastery = ""

            strPlace = ""

            if hasattr(Monastery, "Place_Label"):
                strPlace = Monastery.Place_Label
                Place = self.__get_place(strPlace, Monastery.GeoId)

            Person = self.__get_person(person.Name)

            Religious_Name = Appellation(self._graph, person.Forename,
                                         Appellation_type.RELIGIOUS_NAME)

            Novice = Aspect(self._graph, "Novice",
                            Nampi_type.Mona.member_of_a_religious_community)

            investiture = Event(
                self._graph,
                Person,
                Nampi_type.Core.has_main_participant,
                "Investiture in " + Monastery.Event,
                Nampi_type.Core.event,
                Place,
                invest_date.When,
            )

            if type(Monastery) is Entity_Importer:
                Kloster = self.__get_group(Monastery.Class, Monastery.Label,
                                           Monastery.Part_Of_Label)
                investiture.add_relationship(
                    Nampi_type.Core.changes_aspect_related_to, Kloster)

            investiture.add_relationship(Nampi_type.Core.adds_aspect,
                                         Religious_Name.node)
            investiture.add_relationship(Nampi_type.Core.adds_aspect, Novice)

            # investiture.add_relationship(Nampi_type.Core.changes_aspect_related_to, Group)
            self.__insert_di_act(
                investiture,
                (),
                authors,
                "ProDomo",
                "https://prodomo.icar-us.eu/aspect/" + invest_date.Id,
                self._d1,
            )
    def add_other_events(
        self,
        person: Person,
        label: str,
        date: str,
        semantics: Optional[str],
        reference: Optional[str],
        aspect: Optional[str],
        aspectkey: Optional[str],
        occupationkey: Optional[str],
        aspectlabel,
        name: Optional[str],
        participant: Optional[str],
        id: Optional[str],
        place: Optional[str],
        datefrom: Optional[str],
        dateto: Optional[str],
    ):
        # get Event label from dict
        Monastery = None
        Kloster = None

        if semantics in Entities_dict and Entities_dict[semantics] is not None:
            Monastery = Entities_dict[semantics]
        elif reference in Entities_dict and Entities_dict[
                reference] is not None:
            Monastery = Entities_dict[reference]
        else:
            Monastery = ""

        if not person:
            # Only use entries with source
            logging.warning("No source entry for 'person' ")
            return

        Person = self.__get_person(person.Name)

        strPlace = ""
        Place = ""
        place = ""

        if hasattr(Monastery, "Place_Label"):
            strPlace = Monastery.Place_Label
            Place = self.__get_place(strPlace, Monastery.GeoId)
        elif place:
            Place = self.__get_place(place, "")

        # check date
        # if it contains 4 digits, make earliest and latest date

        dateearly = ""
        datelast = ""
        datetokens = ""
        if date:
            if len(date) == 4:
                dateearly = date + "-01-01"
                datelast = date + "-12-31"
                date = None

            elif len(date) == 7:
                datetokens = date.split("-")
                dateearly = date + "-01"
                datelast = (date + "-" + str(
                    calendar.monthrange(int(datetokens[0]), int(
                        datetokens[1]))[1]))
                date = None

        if datefrom:
            if (len(datefrom)) == 4:
                dateearly = datefrom + "-01-01"
            elif (len(datefrom)) == 7:
                dateearly = datefrom + "-01"
            else:
                dateearly = datefrom

        if dateto:

            if (len(dateto.strip())) == 4:
                datelast = dateto + "-12-31"
            elif (len(dateto.strip())) == 7:
                datetokens = dateto.split("-")
                datelast = (dateto + "-" + str(
                    calendar.monthrange(int(datetokens[0]), int(
                        datetokens[1]))[1]))
            else:
                datelast = dateto

        if dateearly == "0000-00-00":
            dateearly = ""

        if datelast == "0000-00-00":
            datelast = ""

        if dateearly.find("0000") > -1:
            dateearly = ""

        if datelast.find("0000") > -1:
            datelast = ""

        if len(dateearly) > 0:
            PlainEvent = Event(
                self._graph,
                Person,
                Nampi_type.Core.has_main_participant,
                label,
                Nampi_type.Core.event,
                Place,
                "",
                dateearly,
                datelast,
            )
        elif date:
            PlainEvent = Event(
                self._graph,
                Person,
                Nampi_type.Core.has_main_participant,
                label,
                Nampi_type.Core.event,
                Place,
                date,
            )
        else:
            PlainEvent = Event(
                self._graph,
                Person,
                Nampi_type.Core.has_main_participant,
                label,
                Nampi_type.Core.event,
                Place,
            )

        if type(Monastery) is Entity_Importer:
            Kloster = self.__get_group(Monastery.Class, Monastery.Label,
                                       Monastery.Part_Of_Label)
            PlainEvent.add_relationship(
                Nampi_type.Core.changes_aspect_related_to, Kloster)

        # get various type by key from dict
        # leave if not present; core:aspect will be set automatically
        types = []
        try:
            if len(str(aspectkey)) > 0:
                types.append(_status_types[aspectkey])

            if len(occupationkey) > 0:
                types.append(_occupation_types[occupationkey])

            if len(types) == 0:
                types.append(_status_types["Unspecified"])

        except:
            logging.info("Key not in Dict")

        varAspect = ""
        alabel = ""

        if aspectlabel is not None:
            if aspectlabel.find("[Orden]") > -1 and hasattr(
                    Monastery, "AspectPart"):
                alabel = aspectlabel.replace("[Orden]", Monastery.AspectPart)
            else:
                alabel = aspectlabel

        if alabel is not None and len(alabel.strip()) > 0:

            varAspect = Aspect(self._graph, alabel.capitalize(), types)

            PlainEvent.add_relationship(Nampi_type.Core.adds_aspect, varAspect)

            self.__insert_di_act(
                PlainEvent,
                (),
                authors,
                "ProDomo",
                "https://prodomo.icar-us.eu/aspect/" + id,
                self._d1,
            )
Ejemplo n.º 5
0
 def __add_persons(self):
     """
     Add all persons from the persons table not being added in birth events.
     """
     for _, row in self.__sheet.get_table(Table.PERSONS).iterrows():
         if not row[Column.source]:
             # Only use entries with source
             logging.warning(
                 "No source entry for 'person' table row '{}'".format(
                     row[Column.name]))
             continue
         person_label = safe_str(row, Column.name)
         has_birth_event = self.__sheet.table_has_value(
             Table.BIRTHS,
             Column.person,
             person_label,
         )
         person = self.__get_person(safe_str(row, Column.name))
         if not person:
             continue
         if not has_birth_event:
             # Get all family name variants from the person table
             family_names = [
                 safe_str(row, Column.family_name_with_group),
                 safe_str(row, Column.family_name_gender_neutral),
                 safe_str(row, Column.family_name),
             ]
             # Get the official family name by looking through the ordered family_names list and picking the first match
             family_group_name = next((s for s in family_names if s), None)
             # Add family name group membership
             if family_group_name:
                 family = Family(self._graph, family_group_name)
                 aspect = Aspect(self._graph, family_member_label)
                 become_member_event = Event(
                     self._graph,
                     person,
                     Nampi_type.Core.has_main_participant,
                     label="Become family member",
                 )
                 become_member_event.add_relationship(
                     Nampi_type.Core.adds_aspect, aspect)
                 become_member_event.add_relationship(
                     Nampi_type.Core.changes_aspect_related_to, family)
                 self.__insert_di_act(become_member_event, row=row)
                 logging.debug(
                     "Added 'membership' in family '{}' for birthless person '{}'"
                     .format(family.label, row[Column.name]))
             # Add names for persons that don't have birth events
             if family_names[2]:
                 # Add personal family name
                 fn_assignment = Appellation_assignment(
                     self._graph,
                     person,
                     family_names[2],
                     Appellation_type.FAMILY_NAME,
                 )
                 self.__insert_di_act(fn_assignment, row=row)
             if row[Column.given_name]:
                 # Add given name
                 gn_assignment = Appellation_assignment(
                     self._graph, person,
                     str(safe_str(row, Column.given_name)))
                 self.__insert_di_act(gn_assignment, row=row)
             logging.debug("Added 'names' for birthless person '{}'".format(
                 row[Column.name]))
     logging.info("Parsed the persons")
Ejemplo n.º 6
0
 def __add_investiture_events_for_professions(self):
     """
     Add investiture events for persons that have specific profession events
     """
     professions_query = """
         PREFIX core: <http://purl.org/nampi/owl/core#>
         PREFIX mona: <http://purl.org/nampi/owl/monastic-life#>
         PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
         SELECT ?author ?authoring_date ?source ?source_location ?group ?person_node ?person ?place ?exact_date ?earliest_date ?latest_date
         WHERE {
             ?event_node a core:event ;
                 rdfs:label ?event_label .
             ?dia_node core:has_interpretation ?event_node ;
                 core:is_authored_by/rdfs:label ?author ;
                 core:is_authored_on/core:has_date_time ?authoring_date ;
                 core:has_source_location ?source_node .
             ?source_node (core:has_source|core:has_online_source|mona:has_paged_source)/rdfs:label ?source ;
                 (core:has_value|core:has_text|core:has_url|mona:has_page_number) ?source_location .
             ?event_node core:changes_aspect_related_to/rdfs:label ?group ;
                 core:has_main_participant ?person_node .
             ?person_node rdfs:label ?person .
             OPTIONAL { ?event_node core:takes_place_at/rdfs:label ?place }
             OPTIONAL { ?event_node core:takes_place_on/core:has_date_time ?exact_date }
             OPTIONAL { ?event_node core:takes_place_not_later_than/core:has_date_time ?latest_date }
             OPTIONAL { ?event_node core:takes_place_not_earlier_than/core:has_date_time ?earliest_date }
             VALUES ?event_label { "Profession as choir monk in Astheim" "Profession as choir monk in Bistra" "Profession as choir monk in Gaming" "Profession as choir monk in Žiče" "Profession as choir nun in Imbach" "Profession as choir nun in St. Jakob" "Profession as converse in Gaming" "Profession as lay sister in Imbach" "Profession as priest monk in Gaming" "Profession as choir nun in St. Laurenz" "Profession as choir monk in Brno" "Second profession as choir nun in Imbach" "Secret profession as choir nun in Imbach" }
         }
     """
     has_investiture_event_query = """
         PREFIX core: <http://purl.org/nampi/owl/core#>
         PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
         ASK WHERE {{
         ?event core:has_main_participant <{}> ;
                 rdfs:label ?label .
         FILTER ( CONTAINS(LCASE(?label), "investiture") )
         }}
     """
     for row in self._graph.graph.query(professions_query):
         has_investiture_event = bool(
             self._graph.graph.query(
                 has_investiture_event_query.format(row["person_node"])))
         if not has_investiture_event:
             person = self.__get_person(str(row["person"]))
             if not person:
                 continue
             status_type = self.__get_status_type(added_investiture_label)
             aspect = Aspect(self._graph, added_investiture_label,
                             status_type)
             author_label = str(row["author"])
             interpretation_date_text = str(
                 row["authoring_date"]).partition("T")[0]
             source_label = str(row["source"])
             source_location_label = str(row["source_location"])
             group = self.__get_group(str(row["group"]))
             assert group is not None
             place = self.__get_place(str(row["place"]))
             exact_date = (str(row["exact_date"]).partition("T")[0]
                           if row["exact_date"] else None)
             earliest_date = (str(row["earliest_date"]).partition("T")[0]
                              if row["earliest_date"] else None)
             latest_date = (str(row["latest_date"]).partition("T")[0]
                            if row["latest_date"] else None)
             dates_sorted_by_specificity = [
                 exact_date, latest_date, earliest_date
             ]
             most_specific_date = next(
                 (s for s in dates_sorted_by_specificity if s), None)
             event = Event(
                 self._graph,
                 person,
                 main_person_relationship=Nampi_type.Core.
                 has_main_participant,
                 place=place,
                 latest_date=most_specific_date,
                 label="Investiture in " + str(group.label),
             )
             event.add_relationship(
                 obj=group, pred=Nampi_type.Core.changes_aspect_related_to)
             event.add_relationship(obj=aspect,
                                    pred=Nampi_type.Core.adds_aspect)
             self.__insert_di_act(
                 event,
                 author_label=author_label,
                 source_label=source_label,
                 source_location_label=source_location_label,
                 interpretation_date_text=interpretation_date_text,
             )
             logging.debug(
                 "Added investiture event and interpretation for '{}'".
                 format(person.label))
     logging.info("Finished adding investiture events")