@@ -46,9 +46,11 @@ function ObjectFrame(cls, jsonld, classframes, parent) {
46
46
if ( classframes && typeof classframes === 'object' ) {
47
47
this . loadClassFrames ( classframes ) ;
48
48
}
49
+ //console.log("this", this)
49
50
if ( jsonld && typeof jsonld == 'object' && Object . keys ( jsonld ) . length ) {
50
51
this . originalDocument = jsonld ;
51
52
this . loadJSONLDDocument ( jsonld ) ;
53
+ //console.log("this after jsonld doc call", this)
52
54
} else {
53
55
this . originalDocument = false ;
54
56
}
@@ -58,6 +60,7 @@ function ObjectFrame(cls, jsonld, classframes, parent) {
58
60
this . newDoc = false ;
59
61
}
60
62
63
+
61
64
/**
62
65
* Loads class frames for the object's class - the instructions about how to put an object together
63
66
*/
@@ -118,7 +121,7 @@ ObjectFrame.prototype.hasSchema = function () {
118
121
return this;
119
122
};*/
120
123
121
- ObjectFrame . prototype . loadJSONLDDocument = function ( rdoc ) {
124
+ ObjectFrame . prototype . loadJSONLDDocument = function ( rdoc ) { //KItty check herer
122
125
if ( typeof rdoc !== 'object' ) return undefined ;
123
126
let doc = FrameHelper . json_unshorten ( rdoc )
124
127
if ( ! this . originalDocument ) this . originalDocument = doc ;
@@ -130,8 +133,8 @@ ObjectFrame.prototype.loadJSONLDDocument = function (rdoc) {
130
133
if ( prop [ 0 ] == "@" || ( typeof doc [ prop ] == "object" && Object . keys ( doc [ prop ] ) . length == 0 ) ) continue
131
134
let cframe = this . getPropertyClassFrame ( prop , doc )
132
135
if ( cframe && cframe . isClassChoice ( ) ) {
133
- cframe = cframe . getChosenClassFrame ( FrameHelper . unshorten ( doc [ prop ] [ "@type" ] ) )
134
- if ( ! cframe ) {
136
+ // cframe = cframe.getChosenClassFrame(FrameHelper.unshorten(doc[prop]["@type"]), cframe.parent )
137
+ if ( ! cframe ) {
135
138
console . log ( `no choice frame ${ doc [ prop ] [ "@type" ] } ` ) ;
136
139
}
137
140
} else if ( cframe && cframe . isLogic ( ) ) {
@@ -239,7 +242,13 @@ ObjectFrame.prototype.mfilter = function (rules, onmatch) {
239
242
* second argument a class frame will be created from the instance frame.
240
243
*/
241
244
ObjectFrame . prototype . getPropertyClassFrame = function ( prop , jsonlddoc ) {
245
+
246
+ if ( typeof prop == 'object' ) {
247
+ return new ClassFrame ( prop ) ;
248
+ }
249
+
242
250
prop = FrameHelper . unshorten ( prop )
251
+
243
252
if ( this . classframes && typeof this . classframes === 'object' && typeof this . classframes [ prop ] === 'object' ) {
244
253
//console.log("returning " + prop, this.classframes[prop])
245
254
return this . classframes [ prop ] ;
@@ -311,7 +320,7 @@ ObjectFrame.prototype.getPossibleContainedClasses = function () {
311
320
if ( frames [ i ] . domain && cls . indexOf ( frames [ i ] . domain ) == - 1 ) cls . push ( frames [ i ] . domain )
312
321
if ( frames [ i ] . frame ) {
313
322
efcf ( frames [ i ] . frame )
314
- }
323
+ }
315
324
}
316
325
}
317
326
efcf ( Object . values ( this . classframes ) )
@@ -330,7 +339,7 @@ ObjectFrame.prototype.getDocumentLinks = function(){
330
339
for ( var l = 0 ; l < nvals . length ; l ++ ) {
331
340
if ( vals . indexOf ( nvals [ l ] ) == - 1 ) {
332
341
vals . push ( nvals [ l ] )
333
- }
342
+ }
334
343
}
335
344
}
336
345
else if ( dval . isDocument ( ) ) {
@@ -422,7 +431,7 @@ ObjectFrame.prototype.getChild = function (childid, prop) {
422
431
} ;
423
432
424
433
ObjectFrame . prototype . addProperty = function ( prop , cls ) {
425
- prop = FrameHelper . unshorten ( prop )
434
+ if ( typeof prop !== 'object' ) prop = FrameHelper . unshorten ( prop )
426
435
const cframe = this . getPropertyClassFrame ( prop ) ;
427
436
var ndata = false ;
428
437
if ( cframe ) {
@@ -446,11 +455,14 @@ ObjectFrame.prototype.addProperty = function (prop, cls) {
446
455
nprop . addValueFrame ( ndata ) ;
447
456
}
448
457
if ( typeof this . properties [ prop ] === 'undefined' ) {
449
- this . properties [ prop ] = nprop ;
458
+ if ( typeof prop == 'object' ) var p = prop . property
459
+ else var p = prop
460
+ this . properties [ p ] = nprop ;
461
+ //this.properties[prop] = nprop;
450
462
}
451
- else {
463
+ // else {
452
464
//this.properties[prop].push(nprop);
453
- }
465
+ // }
454
466
nprop . status = "new"
455
467
return nprop ;
456
468
}
@@ -487,15 +499,12 @@ ObjectFrame.prototype.error = function (msg) {
487
499
ObjectFrame . prototype . extract = function ( ) {
488
500
var extracts = { } ;
489
501
for ( var prop in this . properties ) {
490
- //if(!Array.isArray(this.properties[prop])) this.properties[prop] = [this.properties[prop]]
491
- //for(var i = 0; i<this.properties[prop].length; i++){
492
- var extracted = this . properties [ prop ] . extract ( ) ;
493
- if ( ! FrameHelper . empty ( extracted ) ) {
494
- if ( typeof extracts [ prop ] == "undefined" ) extracts [ prop ] = [ ] ;
495
- extracts [ prop ] = extracts [ prop ] . concat ( extracted ) ;
496
- }
497
- //}
498
- if ( extracts [ prop ] && extracts [ prop ] . length == 1 ) extracts [ prop ] = extracts [ prop ] [ 0 ]
502
+ var extracted = this . properties [ prop ] . extract ( ) ;
503
+ if ( ! FrameHelper . empty ( extracted ) ) {
504
+ if ( typeof extracts [ prop ] == "undefined" ) extracts [ prop ] = [ ] ;
505
+ extracts [ prop ] = extracts [ prop ] . concat ( extracted ) ;
506
+ }
507
+ if ( extracts [ prop ] && extracts [ prop ] . length == 1 ) extracts [ prop ] = extracts [ prop ] [ 0 ]
499
508
}
500
509
if ( FrameHelper . empty ( extracts ) && this . parent ) {
501
510
return false ;
@@ -526,6 +535,9 @@ ObjectFrame.prototype.set = function(val){
526
535
ObjectFrame . prototype . isObject = function ( ) { return true ; } ;
527
536
ObjectFrame . prototype . isProperty = function ( ) { return false ; } ;
528
537
ObjectFrame . prototype . isData = function ( ) { return false ; } ;
538
+ ObjectFrame . prototype . isClassChoice = function ( ) {
539
+ return ( this . frame && this . frame . type === 'class_choice' ) ;
540
+ } ;
529
541
530
542
531
543
ObjectFrame . prototype . subjectClass = function ( ) {
@@ -655,7 +667,7 @@ ObjectFrame.prototype.pathToDoc = function (q){
655
667
if ( this . parent . parent ) {
656
668
this . parent . parent . pathToDoc ( q )
657
669
}
658
- }
670
+ }
659
671
}
660
672
661
673
ObjectFrame . prototype . deleteQuery = function ( ) {
@@ -712,9 +724,12 @@ PropertyFrame.prototype.addFrame = function (frame) {
712
724
} ;
713
725
714
726
PropertyFrame . prototype . addValueFrame = function ( oframe ) {
715
- oframe . parent = this ;
716
- oframe . index = this . values . length ;
717
- this . values . push ( oframe ) ;
727
+ if ( oframe ) {
728
+ oframe . parent = this ;
729
+ oframe . index = this . values . length ;
730
+ this . values . push ( oframe ) ;
731
+
732
+ }
718
733
} ;
719
734
720
735
PropertyFrame . prototype . addValue = function ( val ) {
@@ -773,7 +788,7 @@ PropertyFrame.prototype.extract = function () {
773
788
const hasVal = ( val ) => {
774
789
if ( val [ '@value' ] ) {
775
790
for ( var i = 0 ; i < extracts . length ; i ++ ) {
776
- if ( extracts [ i ] [ "@value" ] && extracts [ i ] [ "@value" ] == val [ "@value" ]
791
+ if ( extracts [ i ] [ "@value" ] && extracts [ i ] [ "@value" ] == val [ "@value" ]
777
792
&& extracts [ i ] [ "@type" ] && extracts [ i ] [ "@type" ] == val [ "@type" ] ) return true
778
793
}
779
794
return false
@@ -786,6 +801,7 @@ PropertyFrame.prototype.extract = function () {
786
801
return false
787
802
}
788
803
}
804
+
789
805
for ( let i = 0 ; i < this . values . length ; i ++ ) {
790
806
const val = this . values [ i ] . extract ( ) ;
791
807
if ( val !== '' && val !== false && typeof val !== 'undefined' && ! hasVal ( val ) ) extracts . push ( val ) ;
@@ -810,7 +826,8 @@ PropertyFrame.prototype.range = function () {
810
826
} ;
811
827
PropertyFrame . prototype . getLabel = function ( ) {
812
828
return (
813
- this . cframe ? this . cframe . getLabel ( ) : '' ) ;
829
+ //this.cframe ? this.cframe.getLabel() : '');
830
+ this . cframe ? this . cframe . getLabel ( ) : this . predicate . getLabel ( ) ) ;
814
831
} ;
815
832
PropertyFrame . prototype . getComment = function ( ) {
816
833
return ( this . cframe ? this . cframe . getComment ( ) : false ) ;
@@ -832,11 +849,18 @@ PropertyFrame.prototype.deletePropertyValue = function (value, index) {
832
849
PropertyFrame . prototype . removeValue = function ( value , index ) {
833
850
let nvals = [ ]
834
851
for ( var i = 0 ; i < this . values . length ; i ++ ) {
835
- if ( this . values [ i ] . get ( ) != value ) {
852
+ if ( this . values [ i ] . index != value . index ) {
836
853
nvals . push ( this . values [ i ] )
837
854
}
838
855
}
839
856
this . values = nvals
857
+ /*let nvals = [] //trial
858
+ for(var i = 0; i<this.values.length; i++){
859
+ if(this.values[i].get() != value){
860
+ nvals.push(this.values[i])
861
+ }
862
+ }
863
+ this.values = nvals*/
840
864
}
841
865
842
866
@@ -894,24 +918,22 @@ PropertyFrame.prototype.getAsFrames = function(){
894
918
895
919
PropertyFrame . prototype . createEmpty = function ( ) {
896
920
if ( this . cframe . isData ( ) ) {
897
- const df = this . cframe . copy ( this . subject ( ) ) ;
921
+ const df = this . cframe . copy ( this . subject ( ) ) ;
898
922
df . set ( '' ) ;
899
923
df . status = "new"
900
- console . log ( df )
901
924
return df ;
902
925
}
903
926
else if ( this . cframe . isObject ( ) ) {
904
927
if ( ! this . cframe . isClassChoice ( ) ) {
905
928
const df = this . cframe . createEmpty ( FrameHelper . genBNID ( FrameHelper . urlFragment ( this . cframe . range ) + "_" ) ) ;
906
929
df . status = "new"
907
930
return df ;
908
- }
909
- const clss = this . cframe . getClassChoices ( ) ;
910
- if ( clss && clss . length ) {
911
- const df = this . cframe . createEmptyChoice ( clss [ 0 ] , FrameHelper . genBNID ( FrameHelper . urlFragment ( clss [ 0 ] ) + "_" ) ) ;
912
- df . status = "new"
913
- return df ;
914
- }
931
+ }
932
+
933
+ const df = new ClassFrame ( this . cframe )
934
+ df . status = "new"
935
+ return df ;
936
+
915
937
}
916
938
}
917
939
@@ -1015,8 +1037,8 @@ function DataFrame(jsonld, parent, index) {
1015
1037
if ( jsonld ) {
1016
1038
this . rangeValue = jsonld
1017
1039
if ( jsonld [ '@type' ] ) this . range = jsonld [ '@type' ]
1018
- if ( jsonld [ '@language' ] ) this . language = jsonld [ '@language' ]
1019
- if ( ! this . type ) this . type = ( jsonld [ '@value' ] ? "datatypeProperty" : "objectProperty" )
1040
+ if ( jsonld [ '@language' ] ) this . language = jsonld [ '@language' ]
1041
+ if ( ! this . type ) this . type = ( jsonld [ '@value' ] ? "datatypeProperty" : "objectProperty" )
1020
1042
}
1021
1043
return this
1022
1044
}
@@ -1140,7 +1162,7 @@ ObjectFrame.prototype.getComment = DataFrame.prototype.getComment;
1140
1162
DataFrame . prototype . error = function ( msg ) {
1141
1163
if ( msg ) this . err = msg ;
1142
1164
if ( ! this . errors ) this . errors = [ ]
1143
- this . errors . push ( { "type" : "Internal Data Frame Error" , msg} )
1165
+ this . errors . push ( { "type" : "Internal Data Frame Error" , msg} )
1144
1166
return this . err ;
1145
1167
} ;
1146
1168
@@ -1333,7 +1355,7 @@ DataFrame.prototype.saveQuery = function (newval, ntype, nlang){
1333
1355
else {
1334
1356
upd = { "@value" : newval }
1335
1357
upd [ "@type" ] = ntype || this . range
1336
- if ( nlang || this . language ) upd [ "@language" ] = nlang || this . language
1358
+ if ( nlang || this . language ) upd [ "@language" ] = nlang || this . language
1337
1359
}
1338
1360
let q
1339
1361
if ( this . get ( ) !== "" ) {
@@ -1358,15 +1380,25 @@ DataFrame.prototype.deleteQuery = function (){
1358
1380
/*
1359
1381
* Class frames represent the archetypal version of a property frame as returned by the class frame api
1360
1382
*/
1361
- function ClassFrame ( frame , parent ) {
1383
+ function ClassFrame ( frame , parent , label ) {
1362
1384
this . err = false ;
1363
1385
this . parent = parent ;
1364
1386
// the id of the object that owns this dataframe
1365
1387
this . subjid = ( parent ? parent . subjid : false ) ;
1366
1388
if ( frame ) {
1389
+ if ( frame . label ) {
1390
+ let dl = label ? label : ""
1391
+ if ( frame . label [ "@value" ] )
1392
+ this . label = frame . label [ "@value" ]
1393
+ else if ( frame . label )
1394
+ this . label = frame . label
1395
+ else this . label = dl
1396
+ }
1367
1397
this . load ( frame ) ;
1368
1398
}
1369
1399
}
1400
+
1401
+
1370
1402
ClassFrame . prototype = DataFrame . prototype ;
1371
1403
1372
1404
ClassFrame . prototype . load = function ( frame ) {
@@ -1380,7 +1412,6 @@ ClassFrame.prototype.load = function (frame) {
1380
1412
this . domain = frame . domain ;
1381
1413
this . predicate = frame . property ;
1382
1414
this . frame = frame . frame ;
1383
- this . label = frame . label ? frame . label [ "@value" ] : ""
1384
1415
this . comment = frame . comment ? frame . comment [ '@value' ] : ""
1385
1416
this . range = frame . range ;
1386
1417
@@ -1390,9 +1421,8 @@ ClassFrame.prototype.load = function (frame) {
1390
1421
1391
1422
1392
1423
1393
- //cf.loadFromJSONLD(jsonlddoc)
1424
+
1394
1425
ClassFrame . prototype . loadFromJSONLD = function ( jsonld , prop ) {
1395
- prop = FrameHelper . shorten ( prop )
1396
1426
if ( jsonld [ prop ] ) {
1397
1427
this . predicate = FrameHelper . unshorten ( prop )
1398
1428
this . type = ( jsonld [ prop ] [ "@value" ] ? 'datatypeProperty' : 'objectProperty' )
@@ -1405,6 +1435,10 @@ ClassFrame.prototype.loadFromJSONLD = function (jsonld, prop) {
1405
1435
this . comment = "" //this.getComment()
1406
1436
}
1407
1437
1438
+ ClassFrame . prototype . isClassChoice = function ( ) {
1439
+ return ( this . frame && this . frame . type === 'class_choice' )
1440
+ } ;
1441
+
1408
1442
1409
1443
ClassFrame . prototype . loadFromObjectFrame = function ( par , child ) {
1410
1444
// all the meta-data carried in frames:
@@ -1442,8 +1476,15 @@ ClassFrame.prototype.getChosenClassFrames = function (chosen) {
1442
1476
} ;
1443
1477
1444
1478
ClassFrame . prototype . createEmpty = function ( newid ) {
1479
+ var objframe
1445
1480
if ( this . isObject ( ) ) {
1446
- const objframe = new ObjectFrame ( this . range ) ;
1481
+ if ( this . isClassChoice ( ) ) {
1482
+ //objframe=new ObjectFrame(this.predicate, {}, this)
1483
+ objframe = new ObjectFrame ( this . predicate )
1484
+ }
1485
+ else {
1486
+ objframe = new ObjectFrame ( this . range ) ;
1487
+ }
1447
1488
if ( newid ) objframe . subjid = newid ;
1448
1489
objframe . loadClassFrames ( this . frame ) ;
1449
1490
const fframe = objframe . fillFromSchema ( ) ;
@@ -1472,35 +1513,30 @@ ClassFrame.prototype.clone = function (newid, other) {
1472
1513
return undefined ;
1473
1514
} ;
1474
1515
1516
+
1475
1517
ClassFrame . prototype . getClassChoices = function ( ) {
1476
1518
const choices = [ ] ;
1477
- if ( this . frame . operands ) {
1478
- for ( let i = 0 ; i < this . frame . operands . length ; i += 1 ) {
1519
+ // if (this.frame.operands) {
1520
+ /* for (let i = 0; i < this.frame.operands.length; i += 1) {
1479
1521
for (let j = 0; j < this.frame.operands[i].length; j += 1) {
1480
1522
const domcls = this.frame.operands[i][j].domain;
1481
1523
if (domcls && choices.indexOf(domcls) === -1) {
1482
1524
choices.push(domcls);
1483
1525
}
1484
1526
}
1485
- }
1486
- }
1527
+ }*/
1528
+ // }
1487
1529
return choices ;
1488
1530
} ;
1489
1531
1490
- ClassFrame . prototype . getChosenClassFrame = function ( chosen ) {
1491
- for ( let i = 0 ; i < this . frame . operands . length ; i += 1 ) {
1532
+
1533
+ ClassFrame . prototype . getChosenClassFrame = function ( chosen , parent ) {
1534
+ for ( let i = 0 ; i < this . frame . operands . length ; i += 1 ) {
1492
1535
const operand = this . frame . operands [ i ] ;
1493
- if ( operand . length ) {
1494
- for ( let j = 0 ; j < operand . length ; j += 1 ) {
1495
- if ( operand [ j ] && ( chosen === operand [ j ] . domain ) ) {
1496
- const cf = new ClassFrame ( operand ) ;
1497
- return cf ;
1498
- }
1499
- }
1500
- } else if ( operand . range && chosen === operand . range ) {
1501
- const cf = new ClassFrame ( operand ) ;
1502
- return cf ;
1503
- }
1536
+ if ( operand . class && chosen === operand . class ) {
1537
+ const cf = new ClassFrame ( operand , parent , this . label ) ;
1538
+ return cf ;
1539
+ }
1504
1540
}
1505
1541
return false ;
1506
1542
} ;
0 commit comments