Project

General

Profile

« Previous | Next » 

Revision 38

data2xml: Added syntax for split paths, which map to multiple leaves

View differences:

scripts/data2xml/Parser.py
20 20
            self._pos = matcher.end(0)
21 21
            return matcher.group(0)
22 22
        elif required: self._syntax_err(pattern)
23
        else: return False
23
        else: return None
24 24
    
25 25
    def _match_str(self, string, required=False):
26 26
        end_pos = self._pos + len(string)
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/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept/partyWithRole/*ID->/parties/party/organizationName/_name/firstName"
5
"CollectionCode","/taxonInterpretation/museum_ID->/party/OrganizationName/_name/lastName","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept/partyWithRole/*ID->/parties/party/organizationName/_name/lastName"
4
"InstitutionCode","/taxonInterpretation/museum_ID/party/OrganizationName/_name/firstName","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept/partyWithRole/*ID->/parties/party/organizationName/_name/firstName"
5
"CollectionCode","/taxonInterpretation/museum_ID/party/OrganizationName/_name/lastName","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept/partyWithRole/*ID->/parties/party/organizationName/_name/lastName"
6 6
"CatalogNumber","/taxonInterpretation/museumAccessionNumber","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept/voucher"
7 7
"ScientificName","/plantName/plantName","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/*s/taxonRelationshipAssertion(/assertion/*ID->/*s/taxonName)/Simple"
8 8
"BasisOfRecord",,
......
14 14
"Genus","/plantName[plantStatus/plantLevel=Genus]/plantName","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/*s/taxonRelationshipAssertion(/assertion/*ID->/*s/taxonConcept[Rank/@code=gen])/Name"
15 15
"Species","/plantName[plantStatus/plantLevel=Species]/plantName","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/*s/taxonRelationshipAssertion(/assertion/*ID->/*s/taxonConcept[Rank/@code=sp])/Name"
16 16
"Subspecies","/plantName[plantStatus/plantLevel=Subspecies]/plantName","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/*s/taxonRelationshipAssertion(/assertion/*ID->/*s/taxonConcept[Rank/@code=ssp])/Name"
17
"ScientificNameAuthor","/plantConcept/reference_ID->/referenceParty/{givenName,surname}","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/*s/taxonRelationshipAssertion(/assertion/*ID->/*s/taxonConcept[Rank/@code=sp])/AccordingTo/Simple"
18
"IdentifiedBy","/taxonInterpretation/PARTY_ID->/party/{givenName,middleName,surName}","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/partyWithRole[role=identifier]/*ID->/parties/party/individualName/{givenName,surName}"
17
"ScientificNameAuthor","/plantConcept/reference_ID/reference/referenceContributor/referenceParty_ID/referenceParty/{givenName,surname}","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/*s/taxonRelationshipAssertion(/assertion/*ID->/*s/taxonConcept[Rank/@code=sp])/AccordingTo/Simple"
18
"IdentifiedBy","/taxonInterpretation/PARTY_ID/party/{givenName,middleName,surName}","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/partyWithRole[role=identifier]/*ID->/parties/party/individualName/{givenName,surName}"
19 19
"YearIdentified","/taxonInterpretation/interpretationDate/_date/year","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/date/_date/year"
20 20
"MonthIdentified","/taxonInterpretation/interpretationDate/_date/month","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/date/_date/month"
21 21
"DayIdentified","/taxonInterpretation/interpretationDate/_date/day","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/date/_date/day"
22 22
"TypeStatus",,
23 23
"CollectorNumber",,
24 24
"FieldNumber","/taxonInterpretation/collectionNumber","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept/authorCode"
25
"Collector","/taxonInterpretation/collector_ID->/party/{givenName,middleName,surName}","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/partyWithRole[role=collector]/*ID->/parties/party/individualName/{givenName,surName}"
25
"Collector","/taxonInterpretation/collector_ID/party/{givenName,middleName,surName}","/*s/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept->/*s/taxonDetermination[*ID]/partyWithRole[role=collector]/*ID->/parties/party/individualName/{givenName,surName}"
26 26
"YearCollected","/taxonInterpretation/collectionDate/_date/year","/*s/individualOrganismObservation/*ID->/*s/plotObservation/obsStartDate/_date/year"
27 27
"MonthCollected","/taxonInterpretation/collectionDate/_date/month","/*s/individualOrganismObservation/*ID->/*s/plotObservation/obsStartDate/_date/month"
28 28
"DayCollected","/taxonInterpretation/collectionDate/_date/day","/*s/individualOrganismObservation/*ID->/*s/plotObservation/obsStartDate/_date/day"
......
37 37
"Latitude","/plot/realLatitude","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/DecimalLatitude"
38 38
"CoordinatePrecision","/plot/locationAccuracy","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/CoordinateUncertaintyInMeters"
39 39
"BoundingBox","/plot/dsgpoly","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/FootprintWKT"
40
"MinimumElevation","/plot/elevation/min,plot/elevationRange/from","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/minimumElevationInMeters"
41
"MaximumElevation","/plot/elevation/max,plot/elevationRange/to","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/maximumElevationInMeters"
40
"MinimumElevation","/plot/{elevation/min,elevationRange/from}","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/minimumElevationInMeters"
41
"MaximumElevation","/plot/{elevation/max,elevationRange/to}","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/maximumElevationInMeters"
42 42
"MinimumDepth","/observation/waterDepth/min","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/minimumDepthInMeters"
43 43
"MaximumDepth","/observation/waterDepth/max","/*s/individualOrganismObservation/*ID->/*s/plotObservation/*UniqueIdentifierID->/*s/plot/geospatial/maximumDepthInMeters"
44
"Sex","/userDefined[tableName=taxonInterpretation,userDefinedName=sex]/definedValue ","/*s/individualOrganismObservation/individualOrganismID->/*s/individualOrganismObservation/simpleUserdefined[name=sex]/value"
44
"Sex","/userDefined[tableName=taxonInterpretation,userDefinedName=sex]/definedValue","/*s/individualOrganismObservation/individualOrganismID->/*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/individualOrganismObservation/*ID->/*s/individualOrganism/*sID->/*s/taxonNameUsageConcept/note/text"
51
"Habitat","/userDefined[tableName=stemLocation,userDefinedName=habitat]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=habitat]/value"
52
"PlantFungusDescription","/userDefined[tableName=stemLocation,userDefinedName=plantFungusDescription]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=plantFungusDescription]/value"
53
"Substrate","/userDefined[tableName=stemLocation,userDefinedName=substrate]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=substrate]/value"
54
"Vegetation","/userDefined[tableName=stemLocation,userDefinedName=vegetation]/definedValue ","/*s/individualOrganismObservation/simpleUserdefined[name=vegetation]/value"
51
"Habitat","/userDefined[tableName=stemLocation,userDefinedName=habitat]/definedValue","/*s/individualOrganismObservation/simpleUserdefined[name=habitat]/value"
52
"PlantFungusDescription","/userDefined[tableName=stemLocation,userDefinedName=plantFungusDescription]/definedValue","/*s/individualOrganismObservation/simpleUserdefined[name=plantFungusDescription]/value"
53
"Substrate","/userDefined[tableName=stemLocation,userDefinedName=substrate]/definedValue","/*s/individualOrganismObservation/simpleUserdefined[name=substrate]/value"
54
"Vegetation","/userDefined[tableName=stemLocation,userDefinedName=vegetation]/definedValue","/*s/individualOrganismObservation/simpleUserdefined[name=vegetation]/value"
55 55
"UniqueNYInternalRecordNumber",,
scripts/data2xml/xpath.py
43 43
    
44 44
    def _path(self):
45 45
        tree = []
46
        trailing_slash = False
46 47
        while True:
47
            elem = XpathElem(is_attr=self._match_str('@'), name=self._fields())
48
            # Split path
49
            if self._match_str('{'):
50
                paths = []
51
                while True:
52
                    paths.append(tree + self._path())
53
                    if not self._match_str(','): break
54
                self._match_str('}', required=True)
55
                tree = paths[0] # just use first subpath for now
56
                break # nothing allowed after split path
48 57
            
58
            elem = XpathElem(is_attr=self._match_str('@'),
59
                name=self._match_re(r'[\w.*]+', required=True))
60
            
49 61
            # Attrs
50 62
            if self._match_str('['):
51 63
                elem.attrs = []
52 64
                while True:
53 65
                    path = self._path()
54
                    if self._match_str('='): set_value(path, self._value())
66
                    if self._match_str('='):
67
                        set_value(path, self._match_re(r'[\w.|]*'))
55 68
                    elem.attrs.append(path)
56 69
                    if not self._match_str(','): break
57 70
                self._match_str(']', required=True)
......
83 96
            elem_idx += 1
84 97
        
85 98
        return tree
86
    
87
    def _fields(self):
88
        if self._match_str('{'):
89
            tree = []
90
            while True:
91
                tree.append(self._field())
92
                if not self._match_str(','): break
93
            self._match_str('}', required=True)
94
            tree = tuple(tree)
95
            tree = tree[0] # just use first field for now
96
        else: tree = self._field()
97
        return tree
98
    
99
    def _field(self):
100
        return self._name()
101
    
102
    def _name(self): return self._match_re(r'[\w.*]+', required=True)
103
    
104
    def _value(self): return self._match_re(r'[\w.|]+', required=True)
105 99

  
106 100
instance_level = 1
107 101

  

Also available in: Unified diff