vis-chronicle 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vis-chronicle",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Generates JSON for populating a vis.js timeline from Wikidata queries.",
5
5
  "keywords": [
6
6
  "wikidata",
package/src/fetch.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  // Uses an input specification file to produce an output file for vis.js Timeline.
4
4
 
@@ -368,8 +368,11 @@ entryPoint()
368
368
  if (startTime)
369
369
  {
370
370
  const range = wikidataToRange(startTime)
371
- item.start_min = range.min
372
- item.start_max = range.max
371
+ if (range)
372
+ {
373
+ item.start_min = range.min
374
+ item.start_max = range.max
375
+ }
373
376
  }
374
377
  else
375
378
  console.error(`Date for '${item.startPath}' wasn't cached.`)
@@ -380,8 +383,11 @@ entryPoint()
380
383
  if (endTime)
381
384
  {
382
385
  const range = wikidataToRange(endTime)
383
- item.end_min = range.min
384
- item.end_max = range.max
386
+ if (range)
387
+ {
388
+ item.end_min = range.min
389
+ item.end_max = range.max
390
+ }
385
391
  }
386
392
  else
387
393
  console.error(`Date for '${item.endPath}' wasn't cached.`)
@@ -54,8 +54,25 @@ module.exports = function flattenRelativeDate(wikidataCache, dateString)
54
54
  else
55
55
  {
56
56
  const cacheEntry = wikidataCache[relSplit[0]]
57
- if (relSplit.length > 1)
57
+ if (cacheEntry.value && relSplit.length > 1)
58
58
  {
59
+ // break up operators
60
+ const dateOperators = []
61
+ var opStartIndex = 0
62
+ const operatorString = relSplit[1]
63
+ if (operatorString.length > 0)
64
+ {
65
+ for (var i = 1; i < operatorString.length; i++)
66
+ {
67
+ if (operatorString[i] == '+' || operatorString[i] == '>')
68
+ {
69
+ dateOperators.push(operatorString.substring(opStartIndex, i))
70
+ opStartIndex = i
71
+ }
72
+ }
73
+ dateOperators.push(operatorString.substring(opStartIndex, i))
74
+ }
75
+
59
76
  // handle relative segments of date
60
77
  // About precision:
61
78
  // - The actual value is assumed to lie in a range the size of the precision
@@ -64,9 +81,8 @@ module.exports = function flattenRelativeDate(wikidataCache, dateString)
64
81
  var momentDate = moment(cacheEntry.value, 'YYYYYY-MM-DDThh:mm:ss')
65
82
  var precision = cacheEntry.precision
66
83
  //console.log(momentDate)
67
- for (var i = 1; i < relSplit.length; i++)
84
+ for (const component of dateOperators)
68
85
  {
69
- const component = relSplit[i]
70
86
  if (!component)
71
87
  {
72
88
  // empty group from regex
@@ -120,7 +136,7 @@ module.exports = function flattenRelativeDate(wikidataCache, dateString)
120
136
  }
121
137
  else
122
138
  {
123
- console.error(`Cannot advance/'>' to '${componentVal}'.`)
139
+ console.error(`Cannot advance/'>' to '${component.substring(1)}'.`)
124
140
  }
125
141
  }
126
142
  else
package/src/wikidata.js CHANGED
@@ -41,7 +41,7 @@ const wikidata = module.exports = {
41
41
  rankNormal: "http://wikiba.se/ontology#NormalRank",
42
42
  rankPreferred: "http://wikiba.se/ontology#PreferredRank",
43
43
 
44
- pathQueryRegex: /^(Q[0-9]+(?::P[0-9]+)?(?::Q[0-9]+:P[0-9]+)?)([\+>](?:[A-Za-z]+(?:![0-9]+)?|P\-?[0-9A-Z]+)+)*$/,
44
+ pathQueryRegex: /^(Q[0-9]+(?::P[0-9]+)?(?::Q[0-9]+:P[0-9]+)?)((?:[\+>](?:[A-Za-z]+(?:![0-9]+)?|P\-?[0-9A-Z]+)+)*)$/,
45
45
 
46
46
  initialize: function()
47
47
  {