9
9
isArray : _isArray ,
10
10
isObject : _isObject ,
11
11
isString : _isString ,
12
- isUndefined : _isUndefined
12
+ isUndefined : _isUndefined ,
13
+ isBoolean,
14
+ isDouble,
15
+ isNumber
13
16
} = require ( './types' ) ;
14
17
15
18
const {
@@ -38,6 +41,12 @@ const {
38
41
asArray : _asArray ,
39
42
compareShortestLeast : _compareShortestLeast
40
43
} = require ( './util' ) ;
44
+ const {
45
+ XSD_BOOLEAN ,
46
+ XSD_DOUBLE ,
47
+ XSD_INTEGER ,
48
+ XSD_STRING
49
+ } = require ( './constants' ) ;
41
50
42
51
const api = { } ;
43
52
module . exports = api ;
@@ -996,6 +1005,10 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => {
996
1005
if ( '@direction' in value && value [ '@direction' ] === direction ) {
997
1006
return value [ '@value' ] ;
998
1007
}
1008
+ if ( ! ( '@type' in value ) && type === XSD_STRING ) {
1009
+ return value [ '@value' ] ;
1010
+ }
1011
+
999
1012
}
1000
1013
1001
1014
// return just the value of @value if all are true:
@@ -1139,6 +1152,7 @@ function _selectTerm(
1139
1152
prefs . push ( '@none' ) ;
1140
1153
1141
1154
const containerMap = activeCtx . inverse [ iri ] ;
1155
+
1142
1156
for ( const container of containers ) {
1143
1157
// if container not available in the map, continue
1144
1158
if ( ! ( container in containerMap ) ) {
@@ -1155,6 +1169,32 @@ function _selectTerm(
1155
1169
// select term
1156
1170
return typeOrLanguageValueMap [ pref ] ;
1157
1171
}
1172
+
1173
+ // special case of @type from native types in context and no @type and no
1174
+ // @language specified in value
1175
+ if ( containerMap [ container ] . hasOwnProperty ( '@type' ) &&
1176
+ value !== null &&
1177
+ ! value . hasOwnProperty ( '@type' ) &&
1178
+ ! value . hasOwnProperty ( '@language' )
1179
+ ) {
1180
+ const containerType = containerMap [ container ] [ '@type' ] ;
1181
+ const valueLiteralValue = value [ '@value' ] ;
1182
+ if ( isBoolean ( valueLiteralValue ) &&
1183
+ containerType . hasOwnProperty ( XSD_BOOLEAN )
1184
+ ) {
1185
+ return containerType [ XSD_BOOLEAN ] ;
1186
+ } else if ( isDouble ( valueLiteralValue ) &&
1187
+ containerType . hasOwnProperty ( XSD_DOUBLE )
1188
+ ) {
1189
+ return containerType [ XSD_DOUBLE ] ;
1190
+ } else if ( isNumber ( valueLiteralValue ) &&
1191
+ containerType . hasOwnProperty ( XSD_INTEGER )
1192
+ ) {
1193
+ return containerType [ XSD_INTEGER ] ;
1194
+ } else if ( containerType . hasOwnProperty ( XSD_STRING ) ) {
1195
+ return containerType [ XSD_STRING ] ;
1196
+ }
1197
+ }
1158
1198
}
1159
1199
1160
1200
return null ;
0 commit comments