<commit_before>
var selectowl = {
  aardvark : {
  }, 

  gui : {
    CURRENT_STEP_CLASS : "current-step", //TODO load from prefs
    WORKFLOW_LINK_PREFIX : 'wf-link-',   //TODO load from prefs
  }, 

  workflow : {
    'select-object' : {
      selected : null,
    }, 
    'select-objprop' : {
      selected : null,
    }
  }
}


selectowl.init = function () {
  selectowl.gui.init();
  selectowl.load(); //TODO debug only - delete
}


selectowl.load = function (url) {
  //console.log('loading url: ' + url + ', !url: ' + !url);
  if (!url) { url =  $('#ontology-url').val(); }

  //TODO remove default to foaf (testing only)
  if (!url) url = 'http://xmlns.com/foaf/spec/index.rdf';

  //TODO put back the "empty url" exception
  //if (!url) { throw "empty url, nothing to load"; }

  // Call load on jOWL and refresh after
  var callback = function () {
    //TODO load to selectowl and delete jOWL
    selectowl.feedMee();
    selectowl.refreshList();
    selectowl.gui.showStep('select-action');
  };

  jOWL.load(url, callback, {reason: true, locale: 'en'});
}


selectowl.model = {}; //XXX !!!
selectowl.prefixes = {};

selectowl.feedMee = function () {
  // index is a hashmap from URI to jOWL Ontology object representing the resource
  // sometimes the URI is shortened when base-namespace is present
  // 
  // we use full URI to reference everything here.. in our inner repre this.model
  var index = jOWL.index('ID');
  var m = selectowl.model;
  var r, el, my;
  for ( r in index ) {
    el = index[r];
    my = {};
    my.baseURI = el.baseURI
    my.URI = el.URI;
    my.type = el.type;
    my.name = el.name;
    my.isProperty = el.isProperty;
    if ( el.isProperty ) {
      my.domain = el.domain;
      my.range = el.range;
    }
    m[my.URI] = my;
  } 

  var ns = jOWL.NS;
  for ( p in ns ) {
    p = ns[p];
    if (p.URI && p.prefix) {
      selectowl.prefixes[p.URI] = p.prefix;
    }
  }
}




selectowl.refreshList = function() {

  var onClick_listItem = function ( event ) {
    var owlObj = event.target.owlObj;
    selectowl.workflow['select-object'].selected = owlObj;
    selectowl.aardvark.start();
  }
  
  var list = $('#ontology-objects-list');
  //var list = $('#ontology-resources-list');
  var idx = selectowl.model;
  var $listitem;
  var p, q, prefix;

  list.empty();

  for ( p in idx ) {
    q = idx[p];
    if ( !q.isProperty ) {
      // create listitem tag with all the functionality ;)
      $listitem = $('<listitem />');
      prefix = selectowl.prefixes[q.baseURI];
      if (!prefix) prefix = "";
      $listitem.attr('label', prefix + ':' + q.name + '[' + q.type + ']');
      //$listitem.val(q.name + '[' + q.type + ']');
      $listitem.get(0).owlObj = q;
      $listitem.click(onClick_listItem);
      // crate a list for it
      list.append($listitem);
      //t += p + ": " + idx[p] + '\n';
    }
  } 

  //-------------------------------------------------------

  var onClick_listItem = function ( event ) {
    var owlObj = event.target.owlObj;
    selectowl.workflow['select-objprop'].selected = owlObj;
    selectowl.aardvark.start();
  }
  
  var list = $('#ontology-objprops-list');
  var idx = selectowl.model;
  var $listitem;
  var p, q, prefix;

  list.empty();

  for ( p in idx ) {
    q = idx[p];
    if (q.isProperty) { // && q.domain && q.domain == domenaTohoVybranehoObjektu ) {
      // create listitem tag with all the functionality ;)
      $listitem = $('<listitem />');
      prefix = selectowl.prefixes[q.baseURI];
      if (!prefix) prefix = "";
      $listitem.attr('label', prefix + ':' + q.name + '[' + q.type + ']');
      //$listitem.val(q.name + '[' + q.type + ']');
      $listitem.get(0).owlObj = q;
      $listitem.click(onClick_listItem);
      // crate a list for it
      list.append($listitem);
      //t += p + ": " + idx[p] + '\n';
    }
  } 
}

<commit_msg>refactoring: changed population of resources lists (Object list, Object Properties list)<commit_after>
var selectowl = {
  aardvark : {
  }, 

  gui : {
    CURRENT_STEP_CLASS : "current-step", //TODO load from prefs
    WORKFLOW_LINK_PREFIX : 'wf-link-',   //TODO load from prefs
  }, 

  workflow : {
    'select-object' : {
      selected : null,
    }, 
    'select-objprop' : {
      selected : null,
    }
  }
}


selectowl.init = function () {
  selectowl.gui.init();
  selectowl.load(); //TODO debug only - delete
}


selectowl.load = function (url) {
  //console.log('loading url: ' + url + ', !url: ' + !url);
  if (!url) { url =  $('#ontology-url').val(); }

  //TODO remove default to foaf (testing only)
  if (!url) url = 'http://xmlns.com/foaf/spec/index.rdf';

  //TODO put back the "empty url" exception
  //if (!url) { throw "empty url, nothing to load"; }

  // Call load on jOWL and refresh after
  var callback = function () {
    //TODO load to selectowl and delete jOWL
    selectowl.feedMee();
    selectowl.refreshAllLists();
    selectowl.gui.showStep('select-action');
  };

  jOWL.load(url, callback, {reason: true, locale: 'en'});
}


selectowl.model = {}; //XXX !!!
selectowl.prefixes = {};

selectowl.feedMee = function () {
  // index is a hashmap from URI to jOWL Ontology object representing the resource
  // sometimes the URI is shortened when base-namespace is present
  // 
  // we use full URI to reference everything here.. in our inner repre this.model
  var index = jOWL.index('ID');
  var m = selectowl.model;
  var r, el, my;
  for ( r in index ) {
    el = index[r];
    my = {};
    my.baseURI = el.baseURI
    my.URI = el.URI;
    my.type = el.type;
    my.name = el.name;
    my.isProperty = el.isProperty;
    if ( el.isProperty ) {
      my.domain = el.domain;
      my.range = el.range;
    }
    m[my.URI] = my;
  } 

  var ns = jOWL.NS;
  for ( p in ns ) {
    p = ns[p];
    if (p.URI && p.prefix) {
      selectowl.prefixes[p.URI] = p.prefix;
    }
  }
}



selectowl.refreshAllLists = function() {
  var lists = [
    // List of all Classes in ontology
    { 
      id : '#ontology-objects-list',
      item_onClick : function( event ) {
        var owlObj = event.target.owlObj;
        selectowl.workflow['select-object'].selected = owlObj;    //TODO change it to right (correct) step selection in scenario view
        //selectowl.gui.showStep(selectowl.gui.SCENARIO_STEP_ID); //TODO show the scenario step with the right object selected
        selectowl.aardvark.start();                               //TODO blink the document on aardwar start
      }, 
      accepts : function( item ) {
        return !item.isProperty;
      }
      //TODO createListItemFor: function( item ) {}, 
      
      //TODO column IDs

      //TODO function that will return column values for each column ID, XXX NOPE will do wit createListItemFor( item )
    }, 

    // List of all Properties in ontology
    {
      id : '#ontology-objprops-list',
      item_onClick : function( event ) {
        var owlObj = event.target.owlObj;
        selectowl.workflow['select-objprop'].selected = owlObj;
        selectowl.aardvark.start();
      }, 
      accepts : function( item ) {
        return item.isProperty;
      }
    }
  ];

  // go, go, go!
  var l;
  for ( l in lists ) {
    selectowl.refreshList(lists[l]);
  }

}


selectowl.refreshList = function( list ) {
  var $list = $(list.id);
  var idx = selectowl.model;
  var $listitem;
  var p, q, prefix;

  $list.empty();

  for ( p in idx ) {
    q = idx[p];
    if ( list.accepts(q) ) {
      //TODO change this to list-specific method XXX !!!
      // create listitem tag with all the functionality ;)
      $listitem = $('<listitem />');
      prefix = selectowl.prefixes[q.baseURI]; //TODO wrap in function
      if (!prefix) prefix = "some_uri";       //TODO guess prefix
      $listitem.attr('label', prefix + ':' + q.name + '[' + q.type + ']');
      //TODO prefix and type will be other coumns of this list
      //     see refreshAllLists()
      
      // Item holds it object in owlObj!!!
      $listitem.get(0).owlObj = q;

      // Specify, what to do when accessing the resource
      // - this method should make us aware, what we're doing
      // - we will create selector for selected Resource by using aardwark
      // - we will then edit the selector so that it matches our needs
      // - this should also show the "scenario" view of selectowl
      $listitem.click(list.item_onClick);

      $list.append($listitem);
    }
  } 
}


{'fraction_non_alphanumeric': 0.1566623083323428, 'fraction_numerical': 0.00035659099013431595, 'mean_word_length': 2.281591263650546, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2390900', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2824, 'n_words': 756}