Two tasks completed
Posted by mholmes on 09 May 2012 in Activity log
Completed the tasks set yesterday, as follows:
- Generated a list of all surnames for which multiple ethnicities are associated with owners bearing those surnames (so, for instance, if there are several owners with the surname Lee, and some have ethnicity Chinese while others have Unknown, that surname is added to the list). I used XQuery running against the XML output of the db to do this:
xquery version "1.0"; (: The purpose of this query is to find all examples where the same owner surname has been associated with different ethnicities. :) declare namespace saxon="http://saxon.sf.net/"; declare option saxon:output "method=text"; let $surnames := distinct-values(//own_surname), (:return count($surnames):) $names := for $name in $surnames order by $name return <name> <surname>{$name}</surname> <ids> {let $ids := //owners[own_surname = $name]/own_owner_id for $id in $ids return xs:string($id) } </ids> <ethnicities> {let $ids := //owners[own_surname = $name]/own_owner_id, $eths := //owners_to_ethnicities[ote_owner_id_fk = $ids] for $eth in $eths return <eth>{$eth/ote_ethnicity_id_fk/text()}</eth> } </ethnicities> </name> return <names> {for $n in $names where count(distinct-values($n/ethnicities/eth)) gt 1 return concat(string-join(($n/surname, ': ', for $e in distinct-values($n//eth) return //ethnicities[eth_ethnicity_id = $e]/eth_name/text()), ' '), '
') } return </names> - Generated a list of owners who have the same surname and forename, and are associated with titles on the same property. These are likely to be either duplicate owners or cross-generation family transactions. Again, this was done with XQuery:
xquery version "1.0"; (: The purpose of this query is to pull out instances of owners who have the same surname and forename, and who are associated with titles that have the same property. :) (:declare namespace map="http://www.w3.org/2005/xpath-functions/map";:) declare namespace saxon="http://saxon.sf.net/"; declare option saxon:output "method=text"; let $owners := //owners, $dupes := for $curr in $owners where $curr/following-sibling::owners[own_surname = $curr/own_surname and own_forenames = $curr/own_forenames and $curr/own_surname != '' and $curr/own_forenames != ''] return $curr, $dupeIds := for $d in $dupes let $owner_set := //owners[own_surname = $d/own_surname and own_forenames = $d/own_forenames] return <group> <surname>{$d/own_surname/text()}</surname> <forenames>{$d/own_forenames/text()}</forenames> {$owner_set//own_owner_id} <properties> {let $owner_ids := $owner_set//own_owner_id/text(), $titles_for_group := (//owners_to_titles[ott_owner_id_fk = $owner_ids], //sellers_to_titles[stt_owner_id_fk = $owner_ids]) for $t in $titles_for_group return if ($t/ott_owner_id_fk) then <title><title_id>{$t/ott_title_id_fk/text()}</title_id> <property_id>{//titles[ttl_title_id = $t/ott_title_id_fk/text()]/ttl_property_id_fk/text()}</property_id></title> else <title><title_id>{$t/stt_title_id_fk/text()}</title_id> <property_id>{//titles[ttl_title_id = $t/stt_title_id_fk/text()]/ttl_property_id_fk/text()}</property_id></title> </properties> </group> return <result> {for $d in $dupeIds where count($d//property_id) gt count(distinct-values($d//property_id)) order by $d/surname, $d/forenames return ('
', $d/surname/text(), ', ', $d/forenames/text(), '
owner ids: ', for $o in $d//own_owner_id return ($o/text(), ' '), for $t in $d//title return ( '
	title: ', $t/title_id/text(), '		property: ', $t/property_id/text() ), '

' ) } </result>