author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2016 23:43:29 +0200 | |
changeset 304 | 20071981ba2a |
parent 141 | c0e8626a271c |
child 392 | 4fbe94af93e8 |
permissions | -rw-r--r-- |
135 | 1 |
import * as constants from 'corpus-common-addon/utils/constants'; |
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
2 |
import _ from 'lodash/lodash'; |
135 | 3 |
|
141
c0e8626a271c
literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents:
137
diff
changeset
|
4 |
export function isLexvoLink(s) { |
c0e8626a271c
literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents:
137
diff
changeset
|
5 |
return s && typeof s === 'string' && s.startsWith(constants.LEXVO_BASE_URL); |
c0e8626a271c
literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents:
137
diff
changeset
|
6 |
}; |
c0e8626a271c
literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents:
137
diff
changeset
|
7 |
|
135 | 8 |
export function isBnfLink(s) { |
141
c0e8626a271c
literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents:
137
diff
changeset
|
9 |
return s && typeof s === 'string' && (s.startsWith(constants.BNF_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_ID)); |
137 | 10 |
}; |
11 |
||
12 |
export function isArkBnfLink(s) { |
|
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
13 |
return s && typeof s === 'string' && (s.startsWith(constants.BNF_BASE_URL + constants.BNF_ARK_BASE_ID) || s.startsWith(constants.BNF_ARK_BASE_URL + constants.BNF_ARK_BASE_ID)); |
135 | 14 |
}; |
137 | 15 |
|
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
16 |
export function isGeonamesLink(s) { |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
17 |
return (typeof s === 'string') && (s.match(constants.GEONAMES_BASE_URLS) !== null); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
18 |
} |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
19 |
|
137 | 20 |
export function switchArkBnfLink(s) { |
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
21 |
if (!s) { |
137 | 22 |
return s; |
23 |
} |
|
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
24 |
if (typeof s === 'string' && s.startsWith(constants.BNF_BASE_URL + constants.BNF_ARK_BASE_ID)) { |
137 | 25 |
return constants.BNF_ARK_BASE_URL + s.slice(constants.BNF_BASE_URL.length); |
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
26 |
} else if (typeof s === 'string' && s.startsWith(constants.BNF_ARK_BASE_URL + constants.BNF_ARK_BASE_ID)) { |
137 | 27 |
return constants.BNF_BASE_URL + s.slice(constants.BNF_ARK_BASE_URL.length); |
28 |
} else { |
|
29 |
return s; |
|
30 |
} |
|
31 |
}; |
|
32 |
||
33 |
export function calculateBnfArkControlChar(id) { |
|
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
34 |
if (!id) { |
137 | 35 |
return null; |
36 |
} |
|
37 |
var sum = _.reduce(id, function(s, c, i) { |
|
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
141
diff
changeset
|
38 |
return s + (i + 1) * (c in constants.NOID_CHARS_POS ? constants.NOID_CHARS_POS[c] : 0); |
137 | 39 |
}, 0); |
40 |
return constants.NOID_CHARS[sum % constants.NOID_CHARS.length]; |
|
41 |
}; |