Skip to content

Commit

Permalink
Fixed maxlath#12
Browse files Browse the repository at this point in the history
Compiling with coffee 1.12.2 instead of 1.11.1
  • Loading branch information
larsgw committed Dec 31, 2016
1 parent d20d191 commit 8f07bd7
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 65 deletions.
2 changes: 1 addition & 1 deletion build/helpers/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/helpers/parse_responses.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 30 additions & 24 deletions build/helpers/simplify_claims.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/helpers/wikidata_time_to_date_object.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/queries/get_entities.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/queries/get_many_entities.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/queries/get_reverse_claims.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/queries/get_wikidata_ids_from_sitelinks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/queries/search_entities.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/queries/simplify_sparql_results.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/queries/sparql_query.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/utils/build_url.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/utils/querystring_lite.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/utils/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/wikidata-sdk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/helpers/simplify_claims.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ simplifyClaim = (claim, entityPrefix, propertyPrefix)->
# tries to replace wikidata deep claim object by a simple value
# e.g. a string, an entity Qid or an epoch time number
{ mainsnak } = claim

# should only happen in snaktype: "novalue" cases or alikes
unless mainsnak? then return null

{ datatype, datavalue } = mainsnak
{ datatype, datavalue, qualifiers } = mainsnak
# known case: snaktype set to "somevalue"
unless datavalue? then return null


value =
switch datatype
when 'string', 'commonsMedia', 'url', 'external-id' then datavalue.value
when 'monolingualtext' then datavalue.value.text
Expand All @@ -41,6 +42,8 @@ simplifyClaim = (claim, entityPrefix, propertyPrefix)->
when 'quantity' then parseFloat datavalue.value.amount
when 'globe-coordinate' then getLatLngFromCoordinates datavalue.value
else null

return { value, qualifiers: if qualifiers then simplifyClaims qualifiers else {} }

prefixedId = (datavalue, prefix)->
{ id } = datavalue.value
Expand Down
46 changes: 23 additions & 23 deletions test/simplify_claims.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ describe 'simplifyClaims', ->

it 'should pass entity and property prefixes down', (done)->
simplified = simplifyClaims Q2112.claims, 'wd'
simplified.P190[0].should.equal 'wd:Q207614'
simplified.P190[0].value.should.equal 'wd:Q207614'
simplified = simplifyClaims Q2112.claims, null, 'wdt'
simplified['wdt:P123456789'][0].should.equal 'wdt:P207614'
simplified['wdt:P123456789'][0].value.should.equal 'wdt:P207614'
done()

it 'should return prefixed properties if passed a property prefix', (done)->
simplified = simplifyClaims Q2112.claims, 'wd', 'wdt'
simplified['wdt:P190'].should.be.an.Array()
simplified['wdt:P190'][0].should.equal 'wd:Q207614'
simplified['wdt:P190'][0].value.should.equal 'wd:Q207614'
simplified = simplifyClaims Q2112.claims, null, 'wdt'
simplified['wdt:P123456789'][0].should.equal 'wdt:P207614'
simplified['wdt:P123456789'][0].value.should.equal 'wdt:P207614'
done()

describe 'simplifyPropertyClaims', ->
Expand All @@ -66,57 +66,57 @@ describe 'simplifyPropertyClaims', ->

it 'should pass entity and property prefixes down', (done)->
simplified = simplifyPropertyClaims Q2112.claims.P190, 'wd'
simplified[0].should.equal 'wd:Q207614'
simplified[0].value.should.equal 'wd:Q207614'
simplified = simplifyPropertyClaims Q2112.claims.P123456789, null, 'wdt'
simplified[0].should.equal 'wdt:P207614'
simplified[0].value.should.equal 'wdt:P207614'
done()

describe 'simplifyClaim', ->
it 'should return a valid time for possible invalid dates', (done)->
# exemple: Q4132785>P577 is 1953-00-00T00:00:00Z
simplified = simplifyClaim Q4132785.claims.P577[0]
isNaN(simplified).should.equal false
simplified.should.equal -536457600000
isNaN(simplified.value).should.equal false
simplified.value.should.equal -536457600000
done()

it 'should return a valid time even for possible invalid negative date', (done)->
simplified = simplifyClaim Q4132785NegativeDate.claims.P577[0]
isNaN(simplified).should.equal false
simplified.should.equal -123797894400000
isNaN(simplified.value).should.equal false
simplified.value.should.equal -123797894400000
done()

it 'should return a url for datatype url', (done)->
simplified = simplifyClaim Q328212.claims.P856[0]
simplified.should.equal "http://veronicarothbooks.blogspot.com"
simplified.value.should.equal "http://veronicarothbooks.blogspot.com"
done()

it 'should return simplify globecoordinate as a latLng array', (done)->
simplified = simplifyClaim Q2112.claims.P625[0]
simplified.should.be.an.Array()
simplified[0].should.equal 52.016666666667
simplified[1].should.equal 8.5166666666667
simplified.value.should.be.an.Array()
simplified.value[0].should.equal 52.016666666667
simplified.value[1].should.equal 8.5166666666667
done()

it 'should return prefixed entity ids if passed an entity prefix', (done)->
simplified = simplifyClaim Q2112.claims.P190[0]
simplified.should.equal 'Q207614'
simplified.value.should.equal 'Q207614'
simplified = simplifyClaim Q2112.claims.P190[0], 'wd'
simplified.should.equal 'wd:Q207614'
simplified.value.should.equal 'wd:Q207614'
simplified = simplifyClaim Q2112.claims.P190[0], 'wd:'
simplified.should.equal 'wd::Q207614'
simplified.value.should.equal 'wd::Q207614'
simplified = simplifyClaim Q2112.claims.P190[0], 'wdbla'
simplified.should.equal 'wdbla:Q207614'
simplified.value.should.equal 'wdbla:Q207614'
done()

it 'should return prefixed property ids if passed a property prefix', (done)->
simplified = simplifyClaim Q2112.claims.P123456789[0]
simplified.should.equal 'P207614'
simplified.value.should.equal 'P207614'
simplified = simplifyClaim Q2112.claims.P123456789[0], null
simplified.should.equal 'P207614'
simplified.value.should.equal 'P207614'
simplified = simplifyClaim Q2112.claims.P123456789[0], null, 'wdt'
simplified.should.equal 'wdt:P207614'
simplified.value.should.equal 'wdt:P207614'
simplified = simplifyClaim Q2112.claims.P123456789[0], null, 'wdt:'
simplified.should.equal 'wdt::P207614'
simplified.value.should.equal 'wdt::P207614'
simplified = simplifyClaim Q2112.claims.P123456789[0], null, 'wdtbla'
simplified.should.equal 'wdtbla:P207614'
simplified.value.should.equal 'wdtbla:P207614'
done()

0 comments on commit 8f07bd7

Please sign in to comment.