| Line 1: |
Line 1: |
| | // License: GPL | | // License: GPL |
| | // Experimental Main | | // Experimental Main |
| − |
| |
| | console.log("'⌣'"); | | console.log("'⌣'"); |
| − |
| |
| | var mwEStruct = { | | var mwEStruct = { |
| − | wbXntity: 'config.values.wbEntity'
| + | wbXntity: 'config.values.wbEntity' |
| − | },
| + | }, |
| | | | |
| − | language = "en",
| + | language = "en", |
| | | | |
| | wbEStruct = { | | wbEStruct = { |
| − | subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity
| + | subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity |
| − | defaultValRelation: 'claims.P108',
| + | defaultValRelation: 'claims.P108', |
| − | concernsRelation: 'claims.P110',
| + | concernsRelation: 'claims.P110', |
| − | instanceOfRelations: 'claims.P3',
| + | instanceOfRelations: 'claims.P3', |
| − | IDPropLoc: 'mainsnak.datavalue.value', // location of ID properties in related entity
| + | IDPropLoc: 'mainsnak.datavalue.value', // location of ID properties in related entity |
| − | IDName: 'numeric-id', // ID property name which checked
| + | IDName: 'numeric-id', // ID property name which checked |
| − | qIDPropName: 'id',
| + | qIDPropName: 'id', |
| − | standardValue: 'labels' + '.' + language + '.' + 'value'
| + | standardValue: 'labels' + '.' + language + '.' + 'value' |
| − | },
| + | }, |
| | | | |
| | relational_id_list = { | | relational_id_list = { |
| − | controller_id: [ wbEStruct['instanceOfRelations'], 96 ],
| + | controller_id: [ wbEStruct['instanceOfRelations'], wbEStruct['IDPropLoc'], wbEStruct['IDName'], 96 ], |
| − | personal_data_id: [ wbEStruct['subclassOfRelations'], 421 ],
| + | personal_data_id: [ wbEStruct['subclassOfRelations'], wbEStruct['IDPropLoc'], wbEStruct['IDName'], 421 ], |
| − | interface_button_id: [ wbEStruct ['instanceOfRelations'], 487 ]
| + | interface_button_id: [ wbEStruct ['instanceOfRelations'], wbEStruct['IDPropLoc'], wbEStruct['IDName'], 487 ] |
| − | };
| + | }; |
| | | | |
| | var wbproc = new wbContainer(mw, mwEStruct['wbXntity']), | | var wbproc = new wbContainer(mw, mwEStruct['wbXntity']), |
| | | | |
| | // Check whether the current page is in a relation of interest to an id of interest | | // Check whether the current page is in a relation of interest to an id of interest |
| − | current_entity = wbproc.checkentity( relational_id_list, [ wbEStruct['IDPropLoc'], wbEStruct['IDName'] ] ); | + | current_entity = wbproc.checkentity( relational_id_list ); |
| | // This should return an object of relations and ids | | // This should return an object of relations and ids |
| | | | |
| Line 41: |
Line 39: |
| | // Wikibase Processor | | // Wikibase Processor |
| | | | |
| − | function wbContainer( universe, location ) {
| + | function wbContainer( universe, location ) { |
| | + | |
| | + | this.main = interjson( checkdive( universe, location )); |
| | + | var the = this.main; |
| | + | |
| | + | this.checkentity = function ( paths ) { |
| | + | return proceed( the, paths ); |
| | + | } |
| | + | |
| | + | // the list of private helper functions, could not be accessed from outside |
| | + | function indexinterpolate(obj,i) { return (obj[i] !== undefined) ? obj[i] : obj}; |
| | + | // helper function for checking a part of an array exists |
| | + | function indexcheck(obj,i) { if ( obj !== undefined) { return ( obj[i] !== undefined ) ? obj[i] : undefined } }; |
| | + | // dive selects matrix.a.b.c.d from the array called matrix and 'a.b.c.d' as string |
| | + | // if a.b.c.d does not exists, it returns the substructure until the substructure exists, if d does not exist, it returns matrix.a.b.c e.g. |
| | + | function dive(array, read){ |
| | + | if ( array !== undefined ) { |
| | + | return (read + '').split('.').reduce(indexinterpolate, array); |
| | + | } |
| | + | } |
| | + | function check(array, read){ |
| | + | if ( array !== undefined ) { |
| | + | return (read + '').split('.').reduce(indexcheck, array); |
| | + | } |
| | + | } |
| | + | function proceed(array, read) { |
| | + | var ret_obj = {}, |
| | + | temp_obj = array, |
| | + | // Have a holder for instructional control return array |
| | + | future_instructional_return = [], |
| | + | // Hava a holder for data return array |
| | + | |
| | + | //|||||||||||||||||||||||||||||||||||||||||||||||||||||[ I N S T R U C T I O N S C O N T R O L ]|||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | |
| | + | // Init program, check if instructions are an object : |
| | + | if ( ( !Array.isArray(read) ) && ( Object.keys(read).length > 0 ) ) { |
| | + | |
| | + | |
| | + | Object.keys(read).forEach( function(path) { |
| | + | console.log("instructions are an array"); |
| | + | |
| | + | //|||||||||||||||||| Check if elements of instruction object are arrays themselves |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | |
| | + | if ( Array.isArray (read[path]) ) { |
| | + | var future_return_partition = temp_obj; |
| | + | Object.keys(read[path]).forEach( function( path2 ) { |
| | + | |
| | + | console.log("instructions are an array of arrays"); |
| | + | future_return_partition = proceed( future_instructional_return, read[ path ][ path2 ] ); |
| | + | |
| | + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | //|||||||||||||||||||||||||||||||||||||||||||||||||||[ I N S T R U C T I O N S C O N T R O L |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | |
| | + | } |
| | + | // Put the result of the travel along the paths in array element of array into the future_instructional_return bunch |
| | + | future_instructional_return.push(future_return_partition); |
| | + | |
| | + | } |
| | + | |
| | + | //|||||||||||||||||| If instruction array element is not an array anymore, lets just do one step |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | |
| | + | else if { |
| | + | |
| | + | // INCLUDE step block with read[path] |
| | + | future_instructional_return.push( proceed( temp_obj, read[ path ] ) ); |
| | + | |
| | + | } |
| | + | } |
| | + | |
| | + | temp_obj = future_instructional_return; |
| | + | } |
| | + | |
| | + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | //||||||||||||[ If we are not in instruction object, let's see if we have an instruction array ]||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | |
| | + | else if ( Array.isArray(read) ) { |
| | + | // If so let's follow the array of instructions |
| | + | Object.keys( read ).forEach( function ( ect ) { |
| | + | temp_obj = proceed( temp_obj, read[ ect ] ); |
| | + | }); |
| | + | } |
| | + | |
| | + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | + | |
| | + | else { |
| | + | data_function( temp_obj, read ); |
| | + | } |
| | + | } |
| | + | |
| | + | |
| | | | |
| − | this.main = interjson( check( universe, location ) );
| + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| − | var container = this;
| + | //|||||||||||||||||||||||||||||||||||||||||||||||||||||[ S T E P B L O C K ]||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | | | |
| − | this.checkentity = function ( rel_id_list, paths ) {
| + | function data_function ( temp_obj, moving ) { |
| − | var return_obj = [],
| + | var future_temp_obj = []; |
| − | temporary_obj = [],
| + | if ( Array.isArray( temp_obj ) ) { |
| − | baseRelation;
| + | console.log("data is on an array level"); |
| − | if ( Object.keys(rel_id_list).length > 0 ) {
| + | Object.keys( temp_obj ).forEach( function ( ect ) { |
| − | Object.keys(rel_id_list).forEach( function( item ){
| + | // if we are on an array level in the data, lets iterate through the array |
| − | temporary_obj = [];
| + | console.log("Within partition: " + ect ); |
| − | baseRelation = checkdive( container.main, rel_id_list[item][0] );
| + | future_temp_obj.push( checkdive( temp_obj[ ect ], moving ) ); |
| − | rise( temporary_obj, depthdive( baseRelation, paths ));
| |
| − | if ( Object.keys(temporary_obj).length > 0 ) {
| |
| − | Object.keys(temporary_obj).forEach( function (hit) {
| |
| − | if ( temporary_obj[hit] == rel_id_list[item][1] ) {
| |
| − | return_obj.push(rel_id_list[item]);
| |
| − | }
| |
| − | });
| |
| − | } else if ( temporary_obj == rel_id_list[item][1] ) {
| |
| − | return_obj.push(rel_id_list[item]);
| |
| − | }
| |
| − | });
| |
| − | }
| |
| − | return return_obj;
| |
| − | }
| |
| | | | |
| − | // the list of private helper functions, could not be accessed from outside
| + | }); |
| − | function indexinterpolate(obj,i) { return (obj[i] !== undefined) ? obj[i] : obj};
| + | temp_obj = future_temp_obj; |
| − | // helper function for checking a part of an array exists
| + | |
| − | function indexcheck(obj,i) { if ( obj !== undefined) { return (obj[i] !== undefined) ? obj[i] : undefined } };
| + | } else { |
| − | // dive selects matrix.a.b.c.d from the array called matrix and 'a.b.c.d' as string
| + | // if we are not on an array level, proceed with the path |
| − | // if a.b.c.d does not exists, it returns the substructure until the substructure exists, if d does not exist, it returns matrix.a.b.c e.g.
| + | console.log("data is on an objective level"); |
| − |
| + | temp_obj = checkdive( temp_obj, moving ); |
| − | function dive(array, read){
| |
| − | return (read + '').split('.').reduce(indexinterpolate, array);
| |
| − | }
| |
| − |
| |
| − | function check(array, read){
| |
| − | if ( array !== undefined ) {
| |
| − | return (read + '').split('.').reduce(indexcheck, array);
| |
| − | }
| |
| − | }
| |
| − |
| |
| − | function checkdive( array, read){
| |
| − | if ( check(array, read) !== undefined) {
| |
| − | return dive(array, read);
| |
| − | } else if ( Array.isArray(array) ) {
| |
| − | return complexcheck( array, read );
| |
| − | }
| |
| − | }
| |
| | | | |
| − | function complexcheck(array, read){
| + | } |
| − | var ret_obj;
| |
| − | Object.keys(array).forEach( function(item){
| |
| − | rise( ret_obj, checkdive(array[item], read)) ;
| |
| − | });
| |
| − | return ret_obj;
| |
| − | }
| |
| | | | |
| − | function depthdive(array, read){
| + | return temp_obj; |
| − | var ret_obj,
| + | } |
| − | temp_obj = array;
| + | |
| − | if ( Object.keys(read).length > 0 ) {
| + | //|||||||||||||||||||||||||||||||||||||||||||||||||||||[ E N D O F S T E P B L O C K ]||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| − | Object.keys(read).forEach( function(path) {
| |
| − | temp_obj = checkdive(temp_obj, path);
| |
| − | });
| |
| − | rise(ret_obj, temp_obj);
| |
| − | return ret_obj;
| |
| − | } else {
| |
| − | return checkdive(array, read);
| |
| − | }
| |
| − | }
| |
| | | | |
| − | function rise(array, to_push) {
| + | function checkdive( array, read){ |
| − | if ( to_push !== undefined) {
| + | if ( check(array, read) !== undefined) { |
| − | if ( Object.keys(to_push).length > 0 ){
| + | return dive(array, read); |
| − | Object.keys(to_push).forEach( function(item){
| + | } else if ( Array.isArray(array) ) { |
| − | if ( array !== undefined ) {
| + | var potential_return; |
| − | array.push(to_push[item]);
| + | Object.keys(array).forEach( function(item){ |
| − | }
| + | potential_return.push( checkdive( array[item], read) ); |
| − | });
| + | }); |
| − | } else {
| + | return potential_return; |
| − | array.push(to_push);
| + | } |
| − | }
| + | } |
| − | }
| |
| − | }
| |
| | | | |
| − | function interjson( obj ) {
| + | function interjson( obj ) { |
| − | try {
| + | try { |
| − | return JSON.parse( obj )
| + | return JSON.parse( obj ) |
| − | } catch (e) {
| + | } catch (e) { |
| − | // if not JSON, do silly things
| + | // if not JSON, do silly things |
| − | console.log('not a json ¯\_(ツ)_/¯');
| + | console.log('not a json ¯\_(ツ)_/¯'); |
| − | };
| + | }; |
| − | }
| + | } |
| − |
| + | |
| − | }
| + | } |