Project

General

Profile

« Previous | Next » 

Revision 26

In data2xml, fixed pointer handling to deal with pointer targets that are themselves pointers

View differences:

scripts/data2xml/NYBG-VegBank-VegX_mapping.csv
1 1
"NYBG","VegBank","VegX"
2 2
"key",,
3 3
"DateLastModified",,
4
"InstitutionCode","/taxonInterpretation/museum_ID->/party/OrganizationName/_name/firstName","/*s/taxonNameUsageConcept/partyWithRole/partyID->/parties/party/organizationName/_name/firstName"
5
"CollectionCode","/taxonInterpretation/museum_ID->/party/OrganizationName/_name/lastName","/*s/taxonNameUsageConcept/partyWithRole/partyID->/parties/party/organizationName/_name/lastName"
6
"CatalogNumber","/taxonInterpretation/museumAccessionNumber","/*s/taxonNameUsageConcept/voucher"
7
"ScientificName","/plantName/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonNameID->/*s/taxonName/Simple"
4
"InstitutionCode","/taxonInterpretation/museum_ID->/party/OrganizationName/_name/firstName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept/partyWithRole/partyID->/parties/party/organizationName/_name/firstName"
5
"CollectionCode","/taxonInterpretation/museum_ID->/party/OrganizationName/_name/lastName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept/partyWithRole/partyID->/parties/party/organizationName/_name/lastName"
6
"CatalogNumber","/taxonInterpretation/museumAccessionNumber","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept/voucher"
7
"ScientificName","/plantName/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonNameID->/*s/taxonName/Simple"
8 8
"BasisOfRecord",,
9
"Kingdom","/plantName[plantStatus/plantLevel=Kingdom]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=reg]/Name"
10
"Phylum","/plantName[plantStatus/plantLevel=Subkingdom]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=phyl_div]/Name"
11
"Class","/plantName[plantStatus/plantLevel=Class]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=cl]/Name"
12
"Order","/plantName[plantStatus/plantLevel=Order]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=ord]/Name"
13
"Family","/plantName[plantStatus/plantLevel=Family]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=fam]/Name"
14
"Genus","/plantName[plantStatus/plantLevel=Genus]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=gen]/Name"
15
"Species","/plantName[plantStatus/plantLevel=Species]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=sp]/Name"
16
"Subspecies","/plantName[plantStatus/plantLevel=Subspecies]/plantName","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=ssp]/Name"
17
"ScientificNameAuthor","/plantConcept/reference_ID->/referenceParty/{givenName,surname}","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept/AccordingTo/Simple"
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"
9
"Kingdom","/plantName[plantStatus/plantLevel=Kingdom]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=reg]/Name"
10
"Phylum","/plantName[plantStatus/plantLevel=Subkingdom]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=phyl_div]/Name"
11
"Class","/plantName[plantStatus/plantLevel=Class]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=cl]/Name"
12
"Order","/plantName[plantStatus/plantLevel=Order]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=ord]/Name"
13
"Family","/plantName[plantStatus/plantLevel=Family]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=fam]/Name"
14
"Genus","/plantName[plantStatus/plantLevel=Genus]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=gen]/Name"
15
"Species","/plantName[plantStatus/plantLevel=Species]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=sp]/Name"
16
"Subspecies","/plantName[plantStatus/plantLevel=Subspecies]/plantName","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept[Rank/@code=ssp]/Name"
17
"ScientificNameAuthor","/plantConcept/reference_ID->/referenceParty/{givenName,surname}","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/*s/taxonRelationshipAssertion!/assertion/taxonConceptID->/*s/taxonConcept/AccordingTo/Simple"
18
"IdentifiedBy","/taxonInterpretation/PARTY_ID->/party/{givenName,middleName,surName}","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/partyWithRole[role=identifier]/partyID->/parties/party/individualName/{givenName,surName}"
19
"YearIdentified","/taxonInterpretation/interpretationDate/_date/year","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/date/_date/year"
20
"MonthIdentified","/taxonInterpretation/interpretationDate/_date/month","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/date/_date/month"
21
"DayIdentified","/taxonInterpretation/interpretationDate/_date/day","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/date/_date/day"
22 22
"TypeStatus",,
23 23
"CollectorNumber",,
24
"FieldNumber","/taxonInterpretation/collectionNumber","/*s/taxonNameUsageConcept/authorCode"
25
"Collector","/taxonInterpretation/collector_ID->/party/{givenName,middleName,surName}","/*s/taxonNameUsageConcept->/*s/taxonDetermination[taxonNameUsageConceptID]/partyWithRole[role=collector]/partyID->/parties/party/individualName/{givenName,surName}"
24
"FieldNumber","/taxonInterpretation/collectionNumber","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept/authorCode"
25
"Collector","/taxonInterpretation/collector_ID->/party/{givenName,middleName,surName}","/*s/individualOrganism/taxonNameUsageConceptsID->/*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"
......
47 47
"PreviousCatalogNumber",,
48 48
"RelationshipType",,
49 49
"RelatedCatalogItem",,
50
"Notes","/taxonInterpretation/notes","/*s/taxonNameUsageConcept/note/text"
50
"Notes","/taxonInterpretation/notes","/*s/individualOrganism/taxonNameUsageConceptsID->/*s/taxonNameUsageConcept/note/text"
51 51
"Habitat","/userDefined[tableName=stemLocation,userDefinedName=habitat]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=habitat]/value"
52 52
"PlantFungusDescription","/userDefined[tableName=stemLocation,userDefinedName=plantFungusDescription]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=plantFungusDescription]/value"
53 53
"Substrate","/userDefined[tableName=stemLocation,userDefinedName=substrate]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=substrate]/value"
scripts/data2xml/xpath.py
82 82
    
83 83
    def _value(self): return self._match_re(r'[\w.|]+', required=True)
84 84

  
85
types_id_level = 1
85
instance_level = 1
86 86

  
87
def obj(path):
88
    obj_path = deepcopy(path[:instance_level+1])
89
    obj_path[-1].is_ptr = False # prevent pointer w/o target
90
    return obj_path
91

  
87 92
def set_id(path, id_, has_types=True):
88
    if has_types: id_level = types_id_level
93
    if has_types: id_level = instance_level
89 94
    else: id_level = 0
90 95
    path[id_level].attrs.append([XpathElem('id', id_, is_attr=True)])
91 96

  
......
125 130
        # Follow pointer
126 131
        if elem.is_ptr:
127 132
            path = deepcopy(path[elem_idx+1:]) # rest of path
128
            attrs = path[types_id_level].attrs
133
            attrs = path[instance_level].attrs
129 134
            if len(attrs) >= 1 and value(attrs[0]) == None:
130 135
                # backward (child-to-parent) pointer with target ID attr
131 136
                set_value(attrs[0], xml_util.get_id(node))
132 137
            else: # forward (parent-to-child) pointer
133 138
                id_ = xml_util.value(node)
134
                obj_path = path[:types_id_level+1] # target object
139
                obj_path = obj(path) # target object
135 140
                if id_ == None or get(doc, obj_path, False, True) == None:
136 141
                    # no target or target attrs don't match
137 142
                    if not create: return None
138 143
                    
139 144
                    # Use last target object's ID + 1
140
                    last_path = deepcopy(obj_path)
141
                    last_path[-1].attrs = [] # just get by tag name
142
                    last = get(doc, last_path, False, True)
145
                    obj_path[-1].attrs = [] # just get by tag name
146
                    last = get(doc, obj_path, False, True)
143 147
                    if last != None: id_ = str(int(xml_util.get_id(last)) + 1)
144 148
                    else: id_ = '0'
145 149
                    

Also available in: Unified diff