Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.RepFactory


  @Override
  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());
    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


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

    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);

      newHNodeId = cmd.getNewHNodeId();
     
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

    return CommandType.undoable;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    RepFactory factory = workspace.getFactory();
    for (String rowID: newRowValueMap.keySet()) {
      Row row = factory.getRow(rowID);
      Node existingNode = row.getNode(hNodeID);
      if (existingNode.hasNestedTable()) {
        logger.error("Existing node has a nested table. Cannot overwrite such node with new value. NodeID: " + existingNode.getId());
        continue;
      }
View Full Code Here

    return WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(this.worksheetId, SuperSelectionManager.DEFAULT_SELECTION);
  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    RepFactory factory = workspace.getFactory();
    for (String rowID: oldRowValueMap.keySet()) {
      Row row = factory.getRow(rowID);
     
      Node existingNode = row.getNode(hNodeID);
      if (existingNode.hasNestedTable()) {
        logger.error("Existing node has a nested table. Cannot overwrite such node with new value. NodeID: " + existingNode.getId());
        continue;
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();
View Full Code Here

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

    return splitValueHNodeId;
  }

  public void split(HashMap<Node, CellValue> oldNodeValueMap,
      HashMap<Node, NodeStatus> oldNodeStatusMap) {
    RepFactory factory = workspace.getFactory();
    HNode hNode = factory.getHNode(hNodeId);

    // The column should not have a nested table but check to make sure!
    if (hNode.hasNestedTable()) {
      logger.error("Column has nested table. Cannot perform split operation.");
      return;
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.RepFactory

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.