|
|
@ -512,17 +512,26 @@ class Parser (Process):
|
|
|
|
_claim['index'] = index #len(claims)
|
|
|
|
_claim['index'] = index #len(claims)
|
|
|
|
# claims.append(dict(DEFAULT_VALUE,**_claim))
|
|
|
|
# claims.append(dict(DEFAULT_VALUE,**_claim))
|
|
|
|
#
|
|
|
|
#
|
|
|
|
schema = [key for key in _claim.keys() if type(_claim[key]) == list]
|
|
|
|
# schema = [ {key:{"mergeStrategy":"append" if list( type(_claim[key])) else "overwrite"}} for key in _claim.keys()] # if type(_claim[key]) == list]
|
|
|
|
if schema :
|
|
|
|
# _schema = set(DEFAULT_VALUE.keys()) - schema
|
|
|
|
schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})}
|
|
|
|
# if schema :
|
|
|
|
|
|
|
|
# schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})}
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
# else:
|
|
|
|
schema = None
|
|
|
|
|
|
|
|
|
|
|
|
# schema = {"properties":{}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# schema = jsonmerge.merge(schema['properties'],dict.fromkeys(_schema,{"mergeStrategy":"overwrite"}))
|
|
|
|
|
|
|
|
schema = {"properties":{}}
|
|
|
|
|
|
|
|
for attr in _claim.keys() :
|
|
|
|
|
|
|
|
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
|
|
|
|
merger = jsonmerge.Merger(schema)
|
|
|
|
merger = jsonmerge.Merger(schema)
|
|
|
|
if not schema :
|
|
|
|
_baseclaim = None
|
|
|
|
merger = jsonmerge
|
|
|
|
_baseclaim = merger.merge(_baseclaim,DEFAULT_VALUE.copy())
|
|
|
|
|
|
|
|
_claim = merger.merge(_baseclaim,_claim)
|
|
|
|
|
|
|
|
|
|
|
|
_claim = merger.merge(DEFAULT_VALUE.copy(),_claim)
|
|
|
|
# _claim = merger.merge(DEFAULT_VALUE.copy(),_claim)
|
|
|
|
|
|
|
|
|
|
|
|
claims.append( _claim)
|
|
|
|
claims.append( _claim)
|
|
|
|
segment = [row]
|
|
|
|
segment = [row]
|
|
|
|
|
|
|
|
|
|
|
@ -539,22 +548,30 @@ class Parser (Process):
|
|
|
|
claim = self.apply(segment,_code)
|
|
|
|
claim = self.apply(segment,_code)
|
|
|
|
if claim :
|
|
|
|
if claim :
|
|
|
|
claim['index'] = len(claims)
|
|
|
|
claim['index'] = len(claims)
|
|
|
|
schema = [key for key in claim.keys() if type(claim[key]) == list]
|
|
|
|
# schema = [key for key in claim.keys() if type(claim[key]) == list]
|
|
|
|
if schema :
|
|
|
|
# if schema :
|
|
|
|
schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})}
|
|
|
|
# schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})}
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
# else:
|
|
|
|
schema = None
|
|
|
|
# print (claim.keys())
|
|
|
|
|
|
|
|
# schema = {}
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# @TODO: Fix merger related to schema (drops certain fields ... NOT cool)
|
|
|
|
# @TODO: Fix merger related to schema (drops certain fields ... NOT cool)
|
|
|
|
if not schema :
|
|
|
|
|
|
|
|
merger = jsonmerge
|
|
|
|
# merger = jsonmerge.Merger(schema)
|
|
|
|
merger = jsonmerge.Merger(schema)
|
|
|
|
|
|
|
|
# top_row_claim = self.apply(_toprows,_code)
|
|
|
|
# top_row_claim = self.apply(_toprows,_code)
|
|
|
|
|
|
|
|
|
|
|
|
# claim = merger.merge(claim,self.apply(_toprows,_code))
|
|
|
|
# claim = merger.merge(claim,self.apply(_toprows,_code))
|
|
|
|
# claims.append(dict(DEFAULT_VALUE,**claim))
|
|
|
|
# claims.append(dict(DEFAULT_VALUE,**claim))
|
|
|
|
claims.append(merger.merge(DEFAULT_VALUE.copy(),claim))
|
|
|
|
schema = {"properties":{}}
|
|
|
|
|
|
|
|
for attr in _claim.keys() :
|
|
|
|
|
|
|
|
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
|
|
|
|
|
|
|
|
_baseclaim = None
|
|
|
|
|
|
|
|
_baseclaim = merger.merge(_baseclaim,DEFAULT_VALUE.copy())
|
|
|
|
|
|
|
|
claim = merger.merge(_baseclaim,claim)
|
|
|
|
|
|
|
|
claims.append(claim)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# claims.append(merger.merge(DEFAULT_VALUE.copy(),claim))
|
|
|
|
if type(file) != list :
|
|
|
|
if type(file) != list :
|
|
|
|
file.close()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
|
|
|