def get_place_type(self, place_type_str): if place_type_str in self.place_types: return PlaceType( (self.place_types[place_type_str], place_type_str)) else: # New custom type: return PlaceType((0, place_type_str))
def on_edit_clicked(self, dummy): """User wants to jump directly to the results view to finish off the place, possibly because a place was not found""" # if ',' in self.place.name.value: # name = self.place.name.value # else: name = self.place.name.value self.newplace = NewPlace(name) names = name.split(',') names = [name.strip() for name in names] self.newplace.name = PlaceName() self.newplace.name.value = names[0] self.newplace.gramps_id = self.place.gramps_id self.newplace.lat = self.place.lat self.newplace.long = self.place.long self.newplace.code = self.place.code if self.place.place_type == PlaceType.UNKNOWN: self.newplace.place_type = PlaceType(PlaceType.UNKNOWN) if any(i.isdigit() for i in self.newplace.name.value): self.newplace.place_type = PlaceType(PlaceType.STREET) ptype = PlaceType() for tname in self.newplace.name.value.split(' '): # see if it is an English PlaceType ptype.set_from_xml_str(tname.capitalize()) if ptype != PlaceType.CUSTOM: self.newplace.place_type = ptype break # see if it is a translated PlaceType ptype.set(tname.capitalize()) if ptype != PlaceType.CUSTOM: self.newplace.place_type = ptype break # see if it is an already added custom type cust_types = self.dbstate.db.get_place_types() if tname.capitalize() in cust_types: self.newplace.place_type = ptype else: self.newplace.place_type = self.place.place_type self.newplace.add_name(self.newplace.name) self.newplace.add_name(self.place.name) self.newplace.add_names(self.place.alt_names) if self.place.placeref_list: # If we already have an enclosing place, use it. parent = self.dbstate.db.get_place_from_handle( self.place.placeref_list[0].ref) self.newplace.parent_ids = [parent.gramps_id] elif len(names) > 1: # we have an enclosing place, according to the name string self.newplace.parent_names = names[1:] self.gui.get_child().remove(self.mainwin) self.gui.get_child().add(self.results_win) self.res_gui()
def __apply(self,obj): with DbTxn(_("Setting place properties"), self.dbstate.db) as self.trans: tagname = self.tagcombo.get_child().get_text().strip() if tagname: tag = self.__find_tag(tagname) else: tag = None typename = self.typecombo.get_child().get_text().strip() if typename: ptype = PlaceType(typename) else: ptype = None selected_handles = self.uistate.viewmanager.active_page.selected_handles() num_places = len(selected_handles) x = self.clear_enclosing.get_active() for handle in selected_handles: place = self.dbstate.db.get_place_from_handle(handle) pname = place.get_name().value if self.clear_enclosing.get_active(): self.__clear_enclosing_place(place,handle) if self.clear_tags.get_active(): self.__clear_tags(place,handle) self.__set_enclosing_place(place,handle) if typename: self.__set_type(place,handle,typename) if tag: self.__set_tag(place,handle,tag) self.dbstate.db.commit_place(place,self.trans)
def __apply(self, obj): with DbTxn(_("Setting place properties"), self.dbstate.db) as self.trans: tagname = self.tagcombo.get_child().get_text().strip() if tagname: tag = self.__find_tag(tagname) else: tag = None typename = self.typecombo.get_child().get_text().strip() if typename: ptype = PlaceType(typename) else: ptype = None selected_handles = self.uistate.viewmanager.active_page.selected_handles( ) num_places = len(selected_handles) for handle in selected_handles: place = self.dbstate.db.get_place_from_handle(handle) if self.clear_enclosing.get_active(): self.__clear_enclosing_place(place, handle) self.__set_enclosing_place(place) self.dbstate.db.commit_place(place, self.trans) for handle in selected_handles: place = self.dbstate.db.get_place_from_handle(handle) pname = place.get_name().value if self.clear_tags.get_active(): self.__clear_tags(place, handle) if typename: self.__set_type(place, handle, typename) if tag: self.__set_tag(place, handle, tag) original_enclosing_places = place.get_placeref_list().copy() top = place if self.generate_hierarchy.get_active(): top = self.__generate_hierarchy( place, handle, original_enclosing_places) or place top.set_placeref_list(original_enclosing_places) if self.replace_text.get_active(): old_text = self.old_text.get_text() new_text = self.new_text.get_text() if self.use_regex.get_active(): try: new_pname = re.sub(old_text, new_text, pname) except Exception as e: traceback.print_exc() raise RuntimeError( _("Regex operation failed: {}").format(e)) else: new_pname = pname.replace(old_text, new_text) place.get_name().set_value(new_pname) self.dbstate.db.commit_place(place, self.trans) if place != top: self.dbstate.db.commit_place(top, self.trans)
def __add_place(self, name, type_num, parent, title, trans): """ Add a missing place to the database. """ place = Place() place.name = name place.title = title place.place_type = PlaceType(7 - type_num) if parent is not None: placeref = PlaceRef() placeref.ref = handle2internal(parent) place.set_placeref_list([placeref]) handle = self.db.add_place(place, trans) self.db.commit_place(place, trans) return handle
def __get_hastype(self, element, curr_lang, type_dic, preferred_lang): place_type = PlaceType() ptype = element.getElementsByTagName('gov:PropertyType') if len(ptype): value = ptype[0].getElementsByTagName('gov:type') if len(value): type_url = value[0].attributes['rdf:resource'].value type_code = type_url.split('#')[1] if tuple([type_code, curr_lang]) in type_dic: place_type.set_from_xml_str(type_dic.get(tuple([type_code,curr_lang]),'No Type')) elif tuple([type_code, preferred_lang]) in type_dic: place_type.set_from_xml_str(type_dic.get(tuple([type_code,preferred_lang]),'No Type')) elif tuple([type_code, 'de']) in type_dic: place_type.set_from_xml_str(type_dic.get(tuple([type_code,'de']),'No Type')) elif tuple([type_code, 'en']) in type_dic: place_type.set_from_xml_str(type_dic.get(tuple([type_code,'en']),'No Type')) return place_type
def __add_place(self, name, type_num, parent, title, trans): """ Add a missing place to the database. """ place = Place() place_name = PlaceName() place_name.set_value(name) place.name = place_name place.title = title place.place_type = PlaceType(7 - type_num) if parent is not None: placeref = PlaceRef() placeref.ref = parent.decode('utf-8') place.set_placeref_list([placeref]) handle = self.db.add_place(place, trans) self.db.commit_place(place, trans) return handle
def on_typecheck(self, *dummy): """ Check toggled; if active, load type from original place, else use type from gazetteer """ obj = self.top.get_object("typecheck") combo = self.top.get_object('place_type') additional = sorted(self.dbstate.db.get_place_types(), key=lambda s: s.lower()) self.type_combo = StandardCustomSelector(PlaceType().get_map(), combo, PlaceType.CUSTOM, PlaceType.UNKNOWN, additional) if not dummy: # inititlization obj.set_sensitive(True) obj.set_active(False) place = self.newplace if (self.place.place_type and self.place.place_type != PlaceType.UNKNOWN): if obj.get_active(): place = self.place else: obj.set_sensitive(False) self.type_combo.set_values( (int(place.place_type), str(place.place_type)))
def column_type(self, data): return str(PlaceType(data[8]))
def __init__(self, dbase, user, default_tag_format=None): self.db = dbase self.user = user self.trans = None self.lineno = 0 self.index = 0 self.fam_count = 0 self.indi_count = 0 self.place_count = 0 self.pref = {} # person ref, internal to this sheet self.fref = {} # family ref, internal to this sheet self.placeref = {} self.place_types = {} # Build reverse dictionary, name to type number for items in PlaceType().get_map().items(): # (0, 'Custom') self.place_types[items[1]] = items[0] self.place_types[items[1].lower()] = items[0] if _(items[1]) != items[1]: self.place_types[_(items[1])] = items[0] # Add custom types: for custom_type in self.db.get_place_types(): self.place_types[custom_type] = 0 self.place_types[custom_type.lower()] = 0 column2label = { "surname": ("Lastname", "Surname", _("Surname"), "lastname", "last_name", "surname", _("surname")), "firstname": ("Firstname", "Given name", _("Given name"), "Given", _("Given"), "firstname", "first_name", "given_name", "given name", _("given name"), "given", _("given")), "callname": ("Callname", "Call name", _("Call name"), "Call", _("Call"), "callname", "call_name", "call name", "call", _("call")), "title": ("Title", _("Person or Place|Title"), "title", _("Person or Place|title")), "prefix": ("Prefix", _("Prefix"), "prefix", _("prefix")), "suffix": ("Suffix", _("Suffix"), "suffix", _("suffix")), "gender": ("Gender", _("Gender"), "gender", _("gender")), "source": ("Source", _("Source"), "source", _("source")), "note": ("Note", _("Note"), "note", _("note")), "birthplace": ("Birthplace", "Birth place", _("Birth place"), "birthplace", "birth_place", "birth place", _("birth place")), "birthplace_id": ("Birthplaceid", "Birth place id", _("Birth place id"), "birthplaceid", "birth_place_id", "birth place id", _("birth place id"), "birthplace_id"), "birthdate": ("Birthdate", "Birth date", _("Birth date"), "birthdate", "birth_date", "birth date", _("birth date")), "birthsource": ("Birthsource", "Birth source", _("Birth source"), "birthsource", "birth_source", "birth source", _("birth source")), "baptismplace": ("Baptismplace", "Baptism place", _("Baptism place"), "baptismplace", "baptism place", _("baptism place")), "baptismplace_id": ("Baptismplaceid", "Baptism place id", _("Baptism place id"), "baptismplaceid", "baptism place id", _("baptism place id"), "baptism_place_id", "baptismplace_id"), "baptismdate": ("Baptismdate", "Baptism date", _("Baptism date"), "baptismdate", "baptism date", _("baptism date")), "baptismsource": ("Baptismsource", "Baptism source", _("Baptism source"), "baptismsource", "baptism source", _("baptism source")), "burialplace": ("Burialplace", "Burial place", _("Burial place"), "burialplace", "burial place", _("burial place")), "burialplace_id": ("Burialplaceid", "Burial place id", _("Burial place id"), "burialplaceid", "burial place id", _("burial place id"), "burial_place_id", "burialplace_id"), "burialdate": ("Burialdate", "Burial date", _("Burial date"), "burialdate", "burial date", _("burial date")), "burialsource": ("Burialsource", "Burial source", _("Burial source"), "burialsource", "burial source", _("burial source")), "deathplace": ("Deathplace", "Death place", _("Death place"), "deathplace", "death_place", "death place", _("death place")), "deathplace_id": ("Deathplaceid", "Death place id", _("Death place id"), "deathplaceid", "death_place_id", "death place id", _("death place id"), "death_place_id", "deathplace_id"), "deathdate": ("Deathdate", "Death date", _("Death date"), "deathdate", "death_date", "death date", _("death date")), "deathsource": ("Deathsource", "Death source", _("Death source"), "deathsource", "death_source", "death source", _("death source")), "deathcause": ("Deathcause", "Death cause", _("Death cause"), "deathcause", "death_cause", "death cause", _("death cause")), "grampsid": ("Grampsid", "ID", "Gramps id", _("Gramps ID"), "grampsid", "id", "gramps_id", "gramps id", _("Gramps id")), "person": ("Person", _("Person"), "person", _("person")), # ---------------------------------- "child": ("Child", _("Child"), "child", _("child")), "family": ("Family", _("Family"), "family", _("family")), # ---------------------------------- "wife": ("Mother", _("Mother"), "Wife", _("Wife"), "Parent2", _("Parent2"), "mother", _("mother"), "wife", _("wife"), "parent2", _("parent2")), "husband": ("Father", _("Father"), "Husband", _("Husband"), "Parent1", _("Parent1"), "father", _("father"), "husband", _("husband"), "parent1", _("parent1")), "marriage": ("Marriage", _("Marriage"), "marriage", _("marriage")), "date": ("Date", _("Date"), "date", _("date")), "place": ("Place", _("Place"), "place", _("place")), "place_id": ("Placeid", "place id", "Place id", "place_id", "placeid"), "name": ("Name", _("Name"), "name", _("name")), "type": ("Type", _("Type"), "type", _("type")), "latitude": ("Latitude", _("latitude"), "latitude", _("latitude")), "longitude": ("Longitude", _("Longitude"), "longitude", _("longitude")), "code": ("Code", _("Code"), "code", _("code")), "enclosed_by": ("Enclosed by", _("Enclosed by"), "enclosed by", _("enclosed by"), "enclosed_by", _("enclosed_by"), "Enclosed_by", _("Enclosed_by"), "enclosedby") } lab2col_dict = [] for key in list(column2label.keys()): for val in column2label[key]: lab2col_dict.append((val, key)) self.label2column = dict(lab2col_dict) if default_tag_format: name = time.strftime(default_tag_format) tag = self.db.get_tag_from_name(name) if tag: self.default_tag = tag else: self.default_tag = Tag() self.default_tag.set_name(name) else: self.default_tag = None
def __typenames(self): for ptype in self.dbstate.db.get_place_types(): yield ptype place_type_instance = PlaceType() for ptype in place_type_instance.get_standard_names(): yield ptype
def geoparse(self, geoid, title, h_geoid_list, h_name_list, *dummy): """ get data for place and parse out g_name dom structure into the NewPlace structure """ geo_url = ('http://api.geonames.org/get?geonameId=%s&style=FULL' '&username=%s' % (geoid.replace('GEO', ''), self.geonames_id)) dom = self.get_geo_data(geo_url) if not dom: return False g_name = dom.getElementsByTagName('geoname')[0] self.newplace = NewPlace(title) self.newplace.geoid = geoid self.newplace.gramps_id = geoid value = g_name.getElementsByTagName('lat') self.newplace.lat = str(value[0].childNodes[0].data) value = g_name.getElementsByTagName('lng') self.newplace.long = str(value[0].childNodes[0].data) value = g_name.getElementsByTagName('toponymName') topname = value[0].childNodes[0].data new_place = PlaceName() new_place.set_value(topname) new_place.set_language("") # make sure we have the topname in the names list and default to # primary self.newplace.add_name(new_place) self.newplace.name = new_place # lets parse the alternative names alt_names = g_name.getElementsByTagName('alternateName') for a_name in alt_names: pattr = a_name.getAttribute("lang") value = a_name.childNodes[0].data if pattr == "post": if self.newplace.code: self.newplace.code += " " + value else: self.newplace.code = value elif pattr == "link": url = Url() url.set_path(value) url.set_description(value) url.set_type(UrlType(UrlType.WEB_HOME)) self.newplace.links.append(url) elif pattr not in ['iata', 'iaco', 'faac', 'wkdt', 'unlc']: new_place = PlaceName() new_place.set_language(pattr) new_place.set_value(value) self.newplace.add_name(new_place) if a_name.hasAttribute('isPreferredName') and (pattr and pattr == self.lang): # if not preferred lang, we use topo name, otherwise # preferred name for lang self.newplace.name = new_place # Try to deduce PlaceType: # If populated place, set as City. Long description could over-ride # Parse long description, looking for keyword (Region, County, ...) # Top-level must be a country. # Children of USA are States. # Children of Canada are Provinces. # value = g_name.getElementsByTagName('fcl') fcl = value[0].childNodes[0].data value = g_name.getElementsByTagName('fcode') fcode = value[0].childNodes[0].data value = g_name.getElementsByTagName('countryCode') countrycode = value[0].childNodes[0].data self.newplace.place_type = PlaceType(PlaceType.UNKNOWN) ptype = PlaceType() # scan thorough names looking for name portion that matches a Placetype for name in self.newplace.names: for tname in name.value.split(' '): ptype.set_from_xml_str(tname.capitalize()) if ptype != PlaceType.CUSTOM: self.newplace.place_type = ptype break # see if it is a translated PlaceType ptype.set(tname.capitalize()) if ptype != PlaceType.CUSTOM: self.newplace.place_type = ptype break # see if it is an already added custom type cust_types = self.dbstate.db.get_place_types() if tname.capitalize() in cust_types: self.newplace.place_type = ptype break else: # Continue if the inner loop wasn't broken. continue # Inner loop was broken, break the outer. break if fcl == 'P': self.newplace.place_type = PlaceType(PlaceType.CITY) elif fcode == 'PRSH': self.newplace.place_type = PlaceType(PlaceType.PARISH) elif 'PCL' in fcode: self.newplace.place_type = PlaceType(PlaceType.COUNTRY) elif 'ADM' in fcode: if countrycode in self.adm_table: _ptype = self.adm_table[countrycode].get(fcode[:4]) if _ptype and (_ptype[1] or self.newplace.place_type.is_default()): self.newplace.place_type = PlaceType(_ptype[0]) # save a parent for enclosing if len(h_geoid_list) > 1: # we have a parent self.newplace.parent_names = h_name_list[1:] self.newplace.parent_ids = h_geoid_list[1:] return True
def set_type(self, place,ptype): if ptype: placetype = PlaceType() #placetype.set_from_xml_str(ptype) placetype.unserialize(ptype) place.set_type(placetype)