Project

General

Profile

« Previous | Next » 

Revision 24

In data2xml, fixed backward (child-to-parent) pointer handling to get and set attribute values properly

View differences:

scripts/data2xml/NYBG-VegBank-VegX_mapping.csv
4 4
"InstitutionCode","/taxonInterpretation/museum_ID->/party/OrganizationName/_name/firstName","/*s/taxonNameUsageConcept/partyWithRole/partyID->/parties/party/organizationName/_name/firstName"
5 5
"CollectionCode","/taxonInterpretation/museum_ID->/party/OrganizationName/_name/lastName","/*s/taxonNameUsageConcept/partyWithRole/partyID->/parties/party/organizationName/_name/lastName"
6 6
"CatalogNumber","/taxonInterpretation/museumAccessionNumber","/*s/taxonNameUsageConcept/voucher"
7
"ScientificName","/plantName/plantName","/*s/taxonName/Simple"
7
"ScientificName","/plantName/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion/assertion/taxonNameID->/*s/taxonName/Simple"
8 8
"BasisOfRecord",,
9 9
"Kingdom","/plantName[plantStatus/plantLevel=Kingdom]/plantName","/*s/taxonConcept[Rank/@code=reg]/Name"
10 10
"Phylum","/plantName[plantStatus/plantLevel=Subkingdom]/plantName","/*s/taxonConcept[Rank/@code=phyl_div]/Name"
......
15 15
"Species","/plantName[plantStatus/plantLevel=Species]/plantName","/*s/taxonConcept[Rank/@code=sp]/Name"
16 16
"Subspecies","/plantName[plantStatus/plantLevel=Subspecies]/plantName","/*s/taxonConcept[Rank/@code=ssp]/Name"
17 17
"ScientificNameAuthor","/plantConcept/reference_ID->/referenceParty/{givenName,surname}","/*s/taxonConcept/AccordingTo/Simple"
18
"IdentifiedBy","/taxonInterpretation/PARTY_ID->/party/{givenName,middleName,surName}","/*s/taxonDetermination/partyWithRole[role=identifier]/partyID->/parties/party/individualName/{givenName,surName}"
19
"YearIdentified","/taxonInterpretation/interpretationDate/_date/year","/*s/taxonDetermination/date/_date/year"
20
"MonthIdentified","/taxonInterpretation/interpretationDate/_date/month","/*s/taxonDetermination/date/_date/month"
21
"DayIdentified","/taxonInterpretation/interpretationDate/_date/day","/*s/taxonDetermination/date/_date/day"
18
"IdentifiedBy","/taxonInterpretation/PARTY_ID->/party/{givenName,middleName,surName}","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/partyWithRole[role=identifier]/partyID->/parties/party/individualName/{givenName,surName}"
19
"YearIdentified","/taxonInterpretation/interpretationDate/_date/year","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/date/_date/year"
20
"MonthIdentified","/taxonInterpretation/interpretationDate/_date/month","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/date/_date/month"
21
"DayIdentified","/taxonInterpretation/interpretationDate/_date/day","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/date/_date/day"
22 22
"TypeStatus",,
23 23
"CollectorNumber",,
24 24
"FieldNumber","/taxonInterpretation/collectionNumber","/*s/taxonNameUsageConcept/authorCode"
25
"Collector","/taxonInterpretation/collector_ID->/party/{givenName,middleName,surName}","/*s/taxonDetermination/partyWithRole[role=collector]/partyID->/parties/party/individualName/{givenName,surName}"
25
"Collector","/taxonInterpretation/collector_ID->/party/{givenName,middleName,surName}","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/partyWithRole[role=collector]/partyID->/parties/party/individualName/{givenName,surName}"
26 26
"YearCollected","/taxonInterpretation/collectionDate/_date/year","/*s/plotObservation/obsStartDate/_date/year"
27 27
"MonthCollected","/taxonInterpretation/collectionDate/_date/month","/*s/plotObservation/obsStartDate/_date/month"
28 28
"DayCollected","/taxonInterpretation/collectionDate/_date/day","/*s/plotObservation/obsStartDate/_date/day"
......
32 32
"Country","/namedPlace[placeSystem=area|country|territory]/placeName","/*s/plot/country"
33 33
"StateProvince","/namedPlace[placeSystem=region|state|province]/placeName","/*s/plot/state"
34 34
"County","/namedPlace[placeSystem=county]/placeName","/*s/plot/county"
35
"Locality","/namedPlace/placeDescription","/*s/plot/simpleUserdefined[name=<name>]/value"
35
"Locality","/namedPlace/placeDescription","/*s/plot/simpleUserdefined[name=locality]/value"
36 36
"Longitude","/plot/realLongitude","/*s/plot/geospatial/DecimalLongitude"
37 37
"Latitude","/plot/realLatitude","/*s/plot/geospatial/DecimalLatitude"
38 38
"CoordinatePrecision","/plot/locationAccuracy","/*s/plot/geospatial/CoordinateUncertaintyInMeters"
......
41 41
"MaximumElevation","/plot/elevation/max,plot/elevationRange/to","/*s/plot/geospatial/maximumElevationInMeters"
42 42
"MinimumDepth","/observation/waterDepth/min","/*s/plot/geospatial/minimumDepthInMeters"
43 43
"MaximumDepth","/observation/waterDepth/max","/*s/plot/geospatial/maximumDepthInMeters"
44
"Sex","/userDefined[tableName=taxonInterpretation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=<name>]/value"
44
"Sex","/userDefined[tableName=taxonInterpretation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=sex]/value"
45 45
"PreparationType",,
46 46
"IndividualCount",,
47 47
"PreviousCatalogNumber",,
48 48
"RelationshipType",,
49 49
"RelatedCatalogItem",,
50 50
"Notes","/taxonInterpretation/notes","/*s/taxonNameUsageConcept/note/text"
51
"Habitat","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=<name>]/value"
52
"PlantFungusDescription","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=<name>]/value"
53
"Substrate","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=<name>]/value"
54
"Vegetation","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=<name>]/value"
51
"Habitat","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=habitat]/value"
52
"PlantFungusDescription","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=plantFungusDescription]/value"
53
"Substrate","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=substrate]/value"
54
"Vegetation","/userDefined[tableName=stemLocation,userDefinedName=<name>]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=vegetation]/value"
55 55
"UniqueNYInternalRecordNumber",,
scripts/data2xml/xpath.py
25 25
    
26 26
    def __eq__(self, other): return self.__dict__ == other.__dict__
27 27

  
28
def value(path): return path[-1].value
29

  
28 30
def set_value(path, value): path[-1].value = value
29 31

  
30 32
class XpathParser(Parser):
......
116 118
        if elem.is_ptr:
117 119
            target = deepcopy(path[elem_idx+1:]) # rest of path
118 120
            attrs = target[types_id_level].attrs
119
            if len(attrs) >= 1 and attrs[0].value == None:
121
            if len(attrs) >= 1 and value(attrs[0]) == None:
120 122
                # backward (child-to-parent) pointer with target ID attr
121
                attrs[0].value = xml_util.get_id(node)
123
                set_value(attrs[0], xml_util.get_id(node))
122 124
            else: # forward (parent-to-child) pointer
123 125
                id_ = xml_util.value(node)
124 126
                if id_ == None:

Also available in: Unified diff