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 __get_hastype(self, element, 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] for lang in (preferred_lang, 'de', 'en'): t_nam = type_dic.get((type_code, lang), None) if not t_nam: continue place_type.set((-int(type_code), t_nam, self.type_groups[int(type_code)])) break date = self.__get_date_range(ptype[0]) if date: place_type.set_date_object(date) return place_type
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 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