예제 #1
0
  @Override
  public void process() {
    if (containers.length > 1) {
      throw new RuntimeException("This processor can only handle single containers");
    }
    ContainerUnloader container = containers[0];

    // Workspace
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    if (workspace == null) {
      workspace = pc.newWorkspace(pc.getCurrentProject());
      pc.openWorkspace(workspace);
    }
    processConfiguration(container, workspace);

    if (container.getSource() != null) {
      pc.setSource(workspace, container.getSource());
    }

    process(container, workspace);

    // Clean
    workspace = null;
    graphModel = null;
    containers = null;
    progressTicket = null;
  }
예제 #2
0
  public void script() {

    NetworkLayer nl = MultiLayerNetwork.getSelected();

    if (pc == null) pc = Lookup.getDefault().lookup(ProjectController.class);

    // Init a project - and therefore a workspace
    Project pro = pc.getCurrentProject();

    if (pro == null) {
      pc.newProject();
      pro = pc.getCurrentProject();
    }

    Workspace workspace = pc.newWorkspace(pro);

    // Get controllers and models
    ImportController importController = Lookup.getDefault().lookup(ImportController.class);
    GraphModel graphModel =
        Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
    //        AttributeModel attributeModel =
    // Lookup.getDefault().lookup(AttributeController.class).getModel();

    // Import database
    EdgeListHiveDatabaseImpl db = new EdgeListHiveDatabaseImpl();

    db.setDBName("default"); // !!!
    db.setHost("127.0.0.1");
    //       db.setHost( HadoopClusterDefaults.HIVE_SERVER_IP );
    db.setPort(10000); // !!!

    db.setUsername("kamir");
    db.setPasswd("8cwrr");

    db.setSQLDriver(new HiveJDBCDriver());

    String tab = "edgelist_es_de_erfurt2";

    db.setNodeQuery(
        "SELECT UNIQUE( " + tab + ".source ) AS id, " + tab + ".source AS label FROM " + tab);
    db.setEdgeQuery(
        "SELECT "
            + tab
            + ".source AS source, "
            + tab
            + ".target AS target "
            + tab
            + ".q0 AS weight FROM "
            + tab);

    ImporterEdgeList edgeListImporter = new ImporterEdgeList();

    Container container = null;

    String url = SQLUtils.getUrl(db.getSQLDriver(), db.getHost(), db.getPort(), db.getDBName());

    System.out.println(url);

    javax.swing.JOptionPane.showMessageDialog(null, "Go ... Hive! \n> " + url);

    try {
      container = importController.importDatabase(db, edgeListImporter);

      //            container.setAllowAutoNode(false);      //Don't create missing nodes
      container.getLoader().setEdgeDefault(EdgeDirectionDefault.UNDIRECTED); // Force UNDIRECTED

      // Append imported data to GraphAPI
      importController.process(container, new DefaultProcessor(), workspace);
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      if (container != null) System.out.println(container.getReport().getText());
    }

    // See if graph is well imported
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    System.out.println("Nodes: " + graph.getNodeCount());
    System.out.println("Edges: " + graph.getEdgeCount());

    // Layout - 100 Yifan Hu passes
    //        YifanHuLayout layout = new YifanHuLayout(null, new StepDisplacement(1f));
    //        layout.setGraphModel(graphModel);
    //        layout.resetPropertiesValues();
    //        layout.initAlgo();
    //        for (int i = 0; i < 100 && layout.canAlgo(); i++) {
    //            layout.goAlgo();
    //        }
    //        layout.endAlgo();

  }
예제 #3
0
  public void process() {
    // Workspace
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    if (workspace == null) {
      workspace = pc.newWorkspace(pc.getCurrentProject());
      pc.openWorkspace(workspace);
    }
    if (container.getSource() != null) {
      pc.setSource(workspace, container.getSource());
    }

    // Architecture
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel(workspace);

    HierarchicalGraph graph = null;
    switch (container.getEdgeDefault()) {
      case DIRECTED:
        graph = graphModel.getHierarchicalDirectedGraph();
        break;
      case UNDIRECTED:
        graph = graphModel.getHierarchicalUndirectedGraph();
        break;
      case MIXED:
        graph = graphModel.getHierarchicalMixedGraph();
        break;
      default:
        graph = graphModel.getHierarchicalMixedGraph();
        break;
    }
    GraphFactory factory = graphModel.factory();

    // Attributes - Creates columns for properties
    attributeModel = Lookup.getDefault().lookup(AttributeController.class).getModel(workspace);
    attributeModel.mergeModel(container.getAttributeModel());

    // Dynamic
    if (container.getTimeFormat() != null) {
      DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
      if (dynamicController != null) {
        dynamicController.setTimeFormat(container.getTimeFormat());
      }
    }

    int nodeCount = 0;
    // Create all nodes
    for (NodeDraftGetter draftNode : container.getNodes()) {
      Node n = factory.newNode(draftNode.isAutoId() ? null : draftNode.getId());
      flushToNode(draftNode, n);
      draftNode.setNode(n);
      nodeCount++;
    }

    // Push nodes in data structure
    for (NodeDraftGetter draftNode : container.getNodes()) {
      Node n = draftNode.getNode();
      NodeDraftGetter[] parents = draftNode.getParents();
      if (parents != null) {
        for (int i = 0; i < parents.length; i++) {
          Node parent = parents[i].getNode();
          graph.addNode(n, parent);
        }
      } else {
        graph.addNode(n);
      }
    }

    // Create all edges and push to data structure
    int edgeCount = 0;
    for (EdgeDraftGetter edge : container.getEdges()) {
      Node source = edge.getSource().getNode();
      Node target = edge.getTarget().getNode();
      Edge e = null;
      switch (container.getEdgeDefault()) {
        case DIRECTED:
          e =
              factory.newEdge(
                  edge.isAutoId() ? null : edge.getId(), source, target, edge.getWeight(), true);
          break;
        case UNDIRECTED:
          e =
              factory.newEdge(
                  edge.isAutoId() ? null : edge.getId(), source, target, edge.getWeight(), false);
          break;
        case MIXED:
          e =
              factory.newEdge(
                  edge.isAutoId() ? null : edge.getId(),
                  source,
                  target,
                  edge.getWeight(),
                  edge.getType().equals(EdgeType.UNDIRECTED) ? false : true);
          break;
      }

      flushToEdge(edge, e);
      edgeCount++;
      graph.addEdge(e);
    }
    workspace = null;
  }
 @Override
 public void actionPerformed(ActionEvent e) {
   ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
   pc.newWorkspace(project);
 }