Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.HTable


    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());
    Selection currentSel = superSel.getSelection(hTable.getId());
    Selection anotherSel = null;
    if (!operation.equalsIgnoreCase(Operation.Invert.name())) {
      anotherSel = new MiniSelection(workspace, worksheetId, hTable.getId(), factory.getNewId("SEL"), superSel.getName(), pythonCode, onError);
      worksheet.getSelectionManager().addSelection(anotherSel);
    }
    if (currentSel == null && operation.equalsIgnoreCase(Operation.Invert.name()) ) {
      return getErrorUpdate("No defined Selection");
    }
    if (currentSel == null) {
      currentSel = new MiniSelection(workspace, worksheetId, hTable.getId(), factory.getNewId("SEL"), superSel.getName(), SelectionManager.defaultCode, onError);
      worksheet.getSelectionManager().addSelection(currentSel);
    }
    try {
      Operation operation = Operation.valueOf(Operation.class, this.operation);
      Selection t = new LargeSelection(workspace, worksheetId, hTable.getId(), factory.getNewId("SEL"), superSel.getName(), currentSel, anotherSel, operation);
      worksheet.getSelectionManager().addSelection(t);
      outputColumns.addAll(t.getInputColumns());
      previousSelection = superSel.getSelection(t.getHTableId());
      if (previousSelection != null)
        superSel.removeSelection(previousSelection);
View Full Code Here


    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);
View Full Code Here

    private Worksheet generateWorksheet(AbstractJDBCUtil dbUtil, ArrayList<ArrayList<String>> data)
    {
      /**
       * Add the headers *
       */
      HTable headers = getWorksheet().getHeaders();
      List<String> headersList = new ArrayList<String>();
      for (int i = 0; i < data.get(0).size(); i++)
      {
        HNode hNode = null;
        hNode = headers.addHNode(data.get(0).get(i), HNodeType.Regular, getWorksheet(), getFactory());
        headersList.add(hNode.getId());
      }

      /**
       * Add the data *
 
View Full Code Here

    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 undoIt(Workspace workspace) {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory repFactory = workspace.getFactory();
    HTable ht = repFactory.getHTable(repFactory.getHNode(hNodeId).getHTableId());
    //remove the new column
    ht.removeHNode(newHNodeId, worksheet);

    return WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet));
   
  }
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);
View Full Code Here

    HNode newhNode = null;
    if(newHNodeId != null && newHNodeId.length() > 0)
      newhNode = workspace.getFactory().getHNode(newHNodeId);
    boolean isUpdate = false;
    if(newhNode == null) {
      HTable hTable = workspace.getFactory().getHTable(hNode.getHTableId());
      newhNode = hTable.getHNodeFromColumnName(newColName);
      if(newhNode == null)
      {
        newhNode = hTable.addHNode(newColName, HNodeType.Transformation, wk, workspace.getFactory());
      }
      if(newhNode.getNestedTable() == null)
      {
        HTable newTable = newhNode.addNestedTable("Comma Split Values", wk, workspace.getFactory());
        newTable.addHNode("Values", HNodeType.Transformation, wk, workspace.getFactory());
      }
      newHNodeId = newhNode.getId();
      hNode.addAppliedCommand("SplitValuesCommand", newhNode);
    } else {
      logger.info("Column names are same, re-compute the split values");
View Full Code Here

    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());
    hTable.removeHNode(newHNodeId, factory.getWorksheet(worksheetId));
    hNode.removeNestedTable();
    return WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, selection);
  }
View Full Code Here

    //pedro: 2012-10-09
    // Now that we cleared the values it is safe to add the nested table.
    //
    // Add the nested new HTable to the hNode
    HTable newTable = hNode.addNestedTable("Comma Split Values", worksheet,
        factory);
    splitValueHNodeId = newTable.addHNode("Values", HNodeType.Transformation, worksheet, factory)
        .getId();

    for (Node node : nodes) {
      //String originalVal = node.getValue().asString();
      String originalVal = oldNodeValueMap.get(node).asString();
View Full Code Here

    columnPaths.set(oldPathIndex, selectedPath);
  }

  public void empty() {
    RepFactory factory = workspace.getFactory();
    HTable ht = factory.getHTable(factory.getHNode(hNodeId).getHTableId());
    List<Table> tables = new ArrayList<Table>();
   
    CloneTableUtils.getDatatable(worksheet.getDataTable(), ht, tables, selection);
    for (Table t : tables) {
      for (Row r : t.getRows(0, t.getNumRows(), selection)) {
View Full Code Here

TOP

Related Classes of edu.isi.karma.rep.HTable

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.