<commit_before>/*
  Coloring triples colors edges.
  Coloring resources colors nodes.
  
  Only nodes may be moved.
  
  Only triples may be hidden/shown.
*/

import controlP5.*;
import peasy.*;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.*;
import virtuoso.jena.driver.*;

PeasyCam cam;
boolean zooming;
boolean laying;
int backG;

ControlP5 cp5;
UnProjector proj;

Graph graph;

CallbackListener selector;

// Virtuoso test environment data
String URL = "jdbc:virtuoso://172.16.31.10:1111";
String USER = "dba";
String PASS = "<PASSWORD>";
String GRAPH = "Arts";
String PICASSO_URI = "http://dbpedia.org/resource/Pablo_Picasso";
String EDVARD_URI = "http://dbpedia.org/resource/Edvard_Munch";
String CLIFFORD_URI = "http://dbpedia.org/resource/Clifton_Pugh";

void setup() {
  int w = 800;
  int h = 600;
  size(w, h , P3D);
  
  cam = new PeasyCam(this, 0, 0, 0, 1500);
  cam.setMinimumDistance(10);
  cam.setMaximumDistance(10000);
  zooming = false;
  backG = 0xFFE07924;
  
  
  cp5 = new ControlP5(this);
  proj = new UnProjector();
  
  graph = new Graph(proj, cp5);
  
  virtAddNeighbors(PICASSO_URI);
  virtAddNeighbors(EDVARD_URI);
  virtAddNeighbors(CLIFFORD_URI);
  
  selector = new CallbackListener() {
    public void controlEvent(CallbackEvent event) {
      if (event.getAction() == ControlP5.ACTION_PRESSED
          && event.getController() instanceof Node) {
            Node n = (Node) event.getController();
        print(n.getName());
      }
    }
  };
  cp5.addCallback(selector);

}

void draw() {
  if (laying) {
    graph.layout();
  }
  
  proj.captureViewMatrix((PGraphics3D) this.g);
  
  proj.calculatePickPoints(mouseX, mouseY);
  pointLight(255, 255, 255, proj.ptStartPos.x, proj.ptStartPos.y, proj.ptStartPos.z);
  
  background(backG);
}

String getStarQuery(String URI) {
  return "CONSTRUCT { <" + URI + "> ?p ?o } WHERE { GRAPH <" + GRAPH + "> { <" + URI + "> ?p ?o } }";
}

void keyPressed() {
  if (key == ' ') {
    if (!zooming) {
      cam.setLeftDragHandler(cam.getZoomDragHandler());
      backG = 0xFF96D876;
    } else {
      cam.setLeftDragHandler(cam.getRotateDragHandler());
      backG = 0xFFE07924;
    }
    zooming = !zooming;
  } else if (key == 'l') {
    laying = !laying;
  }
}

void virtAddNeighbors(String uri) {
  VirtGraph g = new VirtGraph(GRAPH, URL, USER, PASS);
  Query sparql = QueryFactory.create(getStarQuery(uri));
  VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create(sparql, g);
  Model toAdd = ModelFactory.createDefaultModel();
  vqe.execConstruct(toAdd);
  
  graph.addTriples(toAdd);
  
  g.close();
  vqe.close();
  toAdd.close();
}<commit_msg>implement basic controller with zoom, layout, and element identification<commit_after>/*
  Coloring triples colors edges.
  Coloring resources colors nodes.
  
  Only nodes may be moved.
  
  Only triples may be hidden/shown.
*/

import controlP5.*;
import peasy.*;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.*;
import virtuoso.jena.driver.*;

import java.awt.Frame;
import java.awt.BorderLayout;

PeasyCam cam;
int initZoom;
int backG;

ControlP5 cp5;
UnProjector proj;

Graph graph;

TestFrame tf;
ArrayList<String> dispHolder;
String defaultDisp;

// Virtuoso test environment data
String URL = "jdbc:virtuoso://172.16.31.10:1111";
String USER = "dba";
String PASS = "<PASSWORD>";
String GRAPH = "Arts";
String PICASSO_URI = "http://dbpedia.org/resource/Pablo_Picasso";
String EDVARD_URI = "http://dbpedia.org/resource/Edvard_Munch";
String CLIFFORD_URI = "http://dbpedia.org/resource/Clifton_Pugh";

void setup() {
  int w = 800;
  int h = 600;
  size(w, h , P3D);
  
  initZoom = 1500;
  dispHolder = new ArrayList<String>();
  defaultDisp = "Hover over graph elements for information:\n\n";
  dispHolder.add(defaultDisp);
  
  cam = new PeasyCam(this, 0, 0, 0, initZoom);
  cam.setMinimumDistance(10);
  cam.setMaximumDistance(10000);
  
  
  cp5 = new ControlP5(this);
  proj = new UnProjector();
  
  graph = new Graph(proj, cp5);
  
  virtAddNeighbors(PICASSO_URI);
  virtAddNeighbors(EDVARD_URI);
  virtAddNeighbors(CLIFFORD_URI);
  
  tf = addTestFrame("Test Controls", cam);
  
  CallbackListener hoverer = new CallbackListener() {
    public void controlEvent(CallbackEvent event) {
      if (event.getAction() == ControlP5.ACTION_ENTER) {
        if (event.getController() instanceof Node) {
          Node n = (Node) event.getController();
          dispHolder.add(getNodeString(n));
        } else {
          Edge e = (Edge) event.getController();
          dispHolder.add(getEdgeString(e));
        }
      } else if (event.getAction() == ControlP5.ACTION_LEAVE) {
        if (event.getController() instanceof Node) {
          Node n = (Node) event.getController();
          dispHolder.remove(getNodeString(n));
        } else {
          Edge e = (Edge) event.getController();
          dispHolder.remove(getEdgeString(e));
        }
      }
    }
  };
  cp5.addCallback(hoverer);

}

void draw() {
  if (tf.layout.getItem(0).getState()) {
    graph.layout();
  }
  
  proj.captureViewMatrix((PGraphics3D) this.g);
  
  proj.calculatePickPoints(mouseX, mouseY);
  pointLight(255, 255, 255, proj.ptStartPos.x, proj.ptStartPos.y, proj.ptStartPos.z);
  
  background(0xFFE07924);
}

String getStarQuery(String URI) {
  return "CONSTRUCT { <" + URI + "> ?p ?o } WHERE { GRAPH <" + GRAPH + "> { <" + URI + "> ?p ?o } }";
}

void virtAddNeighbors(String uri) {
  VirtGraph g = new VirtGraph(GRAPH, URL, USER, PASS);
  Query sparql = QueryFactory.create(getStarQuery(uri));
  VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create(sparql, g);
  Model toAdd = ModelFactory.createDefaultModel();
  vqe.execConstruct(toAdd);
  
  graph.addTriples(toAdd);
  
  g.close();
  vqe.close();
  toAdd.close();
}

/*
*  TEST CONTROL WINDOW
*/

TestFrame addTestFrame(String theName, PeasyCam c) {
  Frame f = new Frame(theName);
  TestFrame p = new TestFrame(this, c);
  f.add(p);
  p.init();
  f.setTitle(theName);
  f.setSize(p.w, p.h);
  f.setLocation(0, 0);
  f.setResizable(true);
  f.setVisible(true);
  return p;
}

public class TestFrame extends PApplet {
  
  ControlP5 _cp5;
  Object _parent;
  
  PeasyCam viewCam;
  
  int w, h;
  
  public Slider zoom;
  public RadioButton layout;
  public Textlabel info;
  
  public String def;
  
  public void setup() {
    size(w, h);
    frameRate(25);
    _cp5 = new ControlP5(this);
    
    zoom = _cp5.addSlider("Zoom")
               .setPosition(10, 10)
               .setSize(200, 20)
               .setRange(100, 3000)
               .setValue(initZoom);
               
    zoom.addCallback(new CallbackListener() {
      public void controlEvent(CallbackEvent event) {
        if (event.getAction() == ControlP5.ACTION_BROADCAST) {
          viewCam.setDistance(zoom.getValue());
        }
      }
    }
    );
               
    layout = _cp5.addRadioButton("layout")
                 .setPosition(10, 50)
                 .setSize(40,20)
                 .setColorForeground(color(120))
                 .setColorActive(color(255))
                 .setColorLabel(color(255))
                 .setItemsPerRow(1)
                 .setSpacingColumn(50)
                 .addItem("LAYOUT",0);
                 
    Toggle t = layout.getItem(0);
    t.captionLabel().setColorBackground(color(255,80));
    t.captionLabel().style().moveMargin(-7,0,0,-3);
    t.captionLabel().style().movePadding(7,0,0,3);
    t.captionLabel().style().backgroundWidth = 45;
    t.captionLabel().style().backgroundHeight = 13;
    
               
    info = _cp5.addTextlabel("Info")
               .setText(defaultDisp)
               .setPosition(10, 100)
               .setColorValue(0xffffff00)
               .setFont(createFont("Georgia",16));
  }
  
  public void draw() {
    String toDisp = "";
    for (String s : dispHolder) {
      toDisp += s;
    }
    info.setText(toDisp);
    background(0);
  }
  
  private TestFrame() {
    
  }
  
  public TestFrame(Object P, PeasyCam c) {
    _parent = P;
    viewCam = c;
    
    w = 600;
    h = 600;
  }
  
  public ControlP5 control() {
    return _cp5;
  }
}

String getNodeString(Node n) {
  return "Node:\n  " + n.getName() + "\n\n";
}

String getEdgeString(Edge e) {
  String toAdd = "Edge between:\n  "
                 + e.src.getName() + "\nand\n  " + e.dst.getName()
                 + "\nwith predicates\n  ";
  
  for (String p : e.predicates) {
    toAdd += p + "\n  ";
  }
  return toAdd + "\n\n";
}
{'fraction_non_alphanumeric': 0.13787433940105695, 'fraction_numerical': 0.02536699941280094, 'mean_word_length': 2.832583258325833, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3243075', 'n_tokens_mistral': 3198, 'n_tokens_neox': 3019, 'n_words': 609}