Package edu.isi.karma.controller.command.selection

Examples of edu.isi.karma.controller.command.selection.SuperSelection


   *     number of rows not inserted. A row is not inserted if we have a type mismatch.
   * @throws SQLException
   */
  private int insertInTable(Worksheet w, String tableName, Map<String, String> colNamesMap,Connection conn) throws SQLException{
    int numOfRowsNotInserted = 0;
    SuperSelection selection = getSuperSelection(w);
    //get col names for existing table
    //some databases are case sensitive when referring to column/table names, so we have
    //to use the "real" case in the queries
    //I don't do this check for now; not sure for which DBs it is required
    List<String> existingColNames = dbUtil.getColumnNames(null, tableName, conn);
View Full Code Here


  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    inputColumns.clear();
    outputColumns.clear();
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory factory = workspace.getFactory();
    SuperSelection superSel = this.getSuperSelection(worksheet);
    HTable hTable = factory.getHTable(factory.getHNode(hNodeId).getHTableId());
    if (type.equals("Column")) {
      Selection currentSel = superSel.getSelection(hTable.getId());
      if (currentSel != null) {
        outputColumns.addAll(currentSel.getInputColumns());
        oldSelections.put(currentSel.getHTableId(), currentSel);
        worksheet.getSelectionManager().removeSelection(currentSel);
        superSel.removeSelection(currentSel);
      }
    }
    if (type.equals("All")) {
      for (Selection sel : superSel.getAllSelection()) {
        if (sel != null) {
          oldSelections.put(sel.getHTableId(), sel);
          worksheet.getSelectionManager().removeSelection(sel);
          superSel.removeSelection(sel);
        }
      }
    }
    WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this);
    UpdateContainer uc = WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(worksheetId, superSel);
View Full Code Here

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    inputColumns.clear();
    outputColumns.clear();
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection superSel = getSuperSelection(worksheet);
    for (Entry<String, Selection> entry : oldSelections.entrySet()) {
      outputColumns.addAll(entry.getValue().getInputColumns());
      superSel.addSelection(entry.getValue());
      worksheet.getSelectionManager().addSelection(entry.getValue());
    }
    WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this);
    UpdateContainer uc = WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(worksheetId, superSel);
    uc.add(new WorksheetSuperSelectionListUpdate(worksheetId));
View Full Code Here

  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
   
    String[] entities = entitiesToBeExt.split(",");
    HashSet<String> entitiesReqd = new HashSet<String>();
   
    entitiesReqd.addAll(Arrays.asList(entities));

    JSONArray array = new JSONArray();
    AddValuesCommand cmd;

    RepFactory repFactory = workspace.getFactory();
    HTable ht = repFactory.getHTable(repFactory.getHNode(hNodeId).getHTableId());
   
    List<Table> tables = new ArrayList<Table>();
   
    CloneTableUtils.getDatatable(worksheet.getDataTable(), ht, tables, selection);
    for(Table table : tables) {
      ArrayList<Row> rows = table.getRows(0, table.getNumRows(), selection);
   
        for (Row row : rows) {
          String id = row.getId();
          row.getNode(hNodeId);
          Node node = row.getNeighbor(hNodeId);
          String value = node.getValue().asString();
          JSONObject obj = new JSONObject();
          System.out.println(value);
 
          obj.put("rowId", id);
          obj.put("text", value);
          array.put(obj);
        }
    }
   
    String extractions = null;
    String urlParameters = array.toString();
    urlParameters = new String(urlParameters.getBytes(Charset.forName("UTF-8")), Charset.forName("ISO-8859-1"));
   
    // POST Request to ExtractEntities API.
    try {
      if(entityExtractor != null && entityExtractorMethod != null) {
        logger.info("Using the Extract Entities JAR");
        logger.info("Sending:" + urlParameters);
        Object returnValue = entityExtractorMethod.invoke(entityExtractor, urlParameters);
        extractions = returnValue.toString();
      } else {
        logger.info("Using the Extract Entities Service: " + extractionURL);
        logger.info("Sending:" + urlParameters);
       
        String url = extractionURL;
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
 
        // add request header
        con.setRequestMethod("POST");
        con.setRequestProperty("Accept", "application/json");
        con.setRequestProperty("Content-Type", "application/json");
        con.setRequestProperty("charset","utf-8");
 
        // Send POST request
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();
 
        int responseCode = con.getResponseCode();
        logger.info("Response Code : " + responseCode);
 
        BufferedReader in = new BufferedReader(new InputStreamReader(
            con.getInputStream()));
        String inputLine;
        StringBuffer extractionsBuffer = new StringBuffer();
 
        while ((inputLine = in.readLine()) != null) {
          extractionsBuffer.append(inputLine);
        }
        in.close();
       
        extractions = extractionsBuffer.toString();
      }

    } catch (Exception e) {
      logger.error("Error in ExtractEntitiesCommand" + e.toString());
      Util.logException(logger, e);
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }

    // print result
    logger.info("Got extractions:");
    logger.info(extractions);

    JSONArray result = (JSONArray) JSONUtil.createJson(extractions);

    //Final Data for AddValuesCommand
    JSONArray rowData = new JSONArray();

    // index for result iteration
    int index = 0;

    for(Table table : tables) {
      ArrayList<Row> rows = table.getRows(0, table.getNumRows(), selection);
      for (Row row : rows) {
 
        if (index < result.length()) {
          JSONObject extraction = (JSONObject) result.getJSONObject(index++).get("extractions");
         
          JSONObject extractionValues = new JSONObject();
         
          //Check if the user wants People entities
          if(entitiesReqd.contains("People")) {
          //***Extracting People***
          JSONArray peopleExtract = (JSONArray) extraction.get("people");
          JSONArray peopleValues = new JSONArray();
         
         
          for(int i=0; i<peopleExtract.length(); i++) {
            peopleValues.put(new JSONObject().put("extraction", ((JSONObject)peopleExtract.get(i)).getString("extraction")));
          }
         
          extractionValues.put("People", peopleValues);
          }
                 
         
          //Check if the user wants Places entities
          if(entitiesReqd.contains("Places")) {
          //***Extracting Places***
         
          JSONArray placesExtract = (JSONArray) extraction.get("places");
          JSONArray placesValues = new JSONArray();
         
         
          for(int i=0; i<placesExtract.length(); i++) {
            placesValues.put(new JSONObject().put("extraction", ((JSONObject)placesExtract.get(i)).getString("extraction")));
          }
         
         
          extractionValues.put("Places", placesValues);
          }
         
          //Check if the user wants Date entities
          if(entitiesReqd.contains("Dates")) {
          //***Extracting People***
         
          JSONArray datesExtract = (JSONArray) extraction.get("dates");
          JSONArray datesValues = new JSONArray();
           
         
          for(int i=0; i<datesExtract.length(); i++) {
            datesValues.put(new JSONObject().put("extraction", ((JSONObject)datesExtract.get(i)).getString("extraction")));
          }
         
          extractionValues.put("Dates", datesValues);
          }
         
          JSONObject extractionsObj = new JSONObject();
          extractionsObj.put("extractions", extractionValues);
         
          JSONObject rowDataObject = new JSONObject();
          rowDataObject.put("values", extractionsObj);
          rowDataObject.put("rowId", row.getId());
          rowData.put(rowDataObject);
        }
      }
    }

    JSONObject addValuesObj = new JSONObject();
    addValuesObj.put("name", "AddValues");
    addValuesObj.put("value", rowData.toString());
    addValuesObj.put("type", "other");
    JSONArray addValues = new JSONArray();
    addValues.put(addValuesObj);

    System.out.println(JSONUtil.prettyPrintJson(addValues.toString()));

   
    try {
      AddValuesCommandFactory factory = new AddValuesCommandFactory();
      cmd = (AddValuesCommand) factory.createCommand(addValues, workspace, hNodeId, worksheetId,
          ht.getId(), HNodeType.Transformation, selection.getName());
     
      HNode hnode = repFactory.getHNode(hNodeId);
      cmd.setColumnName(hnode.getColumnName()+" Extractions");
      cmd.doIt(workspace);

View Full Code Here

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory factory = workspace.getFactory();
    SuperSelection superSel = getSuperSelection(worksheet);
    HTable hTable = factory.getHTable(factory.getHNode(hNodeId).getHTableId());
    Selection currentSel = superSel.getSelection(hTable.getId());
    if (currentSel != null) {
      currentSel.updateSelection();
    }
    CommandHistory history = workspace.getCommandHistory();
    List<Command> tmp = gatherAllOperateSelectionCommands(history.getCommandsFromWorksheetId(worksheetId), workspace);
    if (tmp.size() > 0) {
      JSONArray inputJSON = new JSONArray();
      inputJSON.put(CommandInputJSONUtil.createJsonObject("worksheetId", worksheetId, ParameterType.worksheetId));
      inputJSON.put(CommandInputJSONUtil.createJsonObject("hNodeId", hNodeId, ParameterType.hNodeId));
      inputJSON.put(CommandInputJSONUtil.createJsonObject("operation", Operation.Intersect.name(), ParameterType.other));
      inputJSON.put(CommandInputJSONUtil.createJsonObject("pythonCode", SelectionManager.defaultCode, ParameterType.other));
      inputJSON.put(CommandInputJSONUtil.createJsonObject("onError", "false", ParameterType.other));
      inputJSON.put(CommandInputJSONUtil.createJsonObject("selectionName", superSel.getName(), ParameterType.other));
      Command t = null;
      try {
        t = new OperateSelectionCommandFactory().createCommand(inputJSON, workspace);
      }catch(Exception e) {
       
View Full Code Here

    return CommandType.notInHistory;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    SuperSelection selection = getSuperSelection(workspace);
    return new UpdateContainer(new AdditionalRowsUpdate(worksheetId, tableId, selection));
   
  }
View Full Code Here

      labelName = hn.getColumnName();
    }catch(Exception e) {
     
    }
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    OntologyManager ontMgr = workspace.getOntologyManager();
    String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
    Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
    if (alignment == null) {
      alignment = new Alignment(ontMgr);
View Full Code Here

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet wk = workspace.getWorksheet(worksheetId);
    UpdateContainer c = new UpdateContainer();
    SuperSelection selection = getSuperSelection(wk);
    // Get the HNode
    HNode hNode = workspace.getFactory().getHNode(hNodeId);
    columnName = hNode.getColumnName();
    // The column should not have a nested table but check to make sure!
    if (hNode.hasNestedTable()) {
View Full Code Here

  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    Worksheet wk = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(wk);
    if (splitCommaCommand != null)
      return splitCommaCommand.undoIt(workspace);
    RepFactory factory = workspace.getFactory();
    HNode hNode = factory.getHNode(newHNodeId);
    HTable hTable = factory.getHTable(hNode.getHTableId());
View Full Code Here

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet wk = workspace.getWorksheet(worksheetId);
    UpdateContainer c = new UpdateContainer();
    SuperSelection selection = getSuperSelection(wk);
    // Get the HNode
    hNode = workspace.getFactory().getHNode(hNodeId);
    // The column should not have a nested table but check to make sure!
    if (hNode.hasNestedTable()) {
      c.add(new ErrorUpdate("Cannot split column with nested table!"));
View Full Code Here

TOP

Related Classes of edu.isi.karma.controller.command.selection.SuperSelection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.