Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.Worksheet


  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    UpdateContainer c = new UpdateContainer();
    Worksheet worksheet = workspace.getWorksheet(worksheetId);

    HTable currentTable = workspace.getFactory().getHTable(hTableId);
    HNode ndid = workspace.getFactory().getHNode(newHNodeId);
    ndid.removeNestedTable();
    //remove the new column
View Full Code Here


      nestedTable.removeRow(r);
    return flag;
  }

  private boolean addValues(Node node, String value, RepFactory factory, Table table) {
    Worksheet worksheet = factory.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    boolean flag = true;
    if (table != null) {
      for (Row r : table.getRows(0, table.getNumRows(), selection)) {
        Node n = r.getNeighbor(node.getHNodeId());
View Full Code Here

      // obtain transformed results
      HashMap<String, String> rows = new HashMap<String, String>();
      colnameString = obtainTransformedResultsAndFindNewColumnName(
          workspace, rows);
      createAndExecuteNewAddColumnCommand(workspace, colnameString);
      Worksheet wk = workspace.getWorksheet(worksheetId);
      selectedPath = findPathForNewColumn(workspace, colnameString);
      DataPreProcessor dpp = (DataPreProcessor) wk.getDpp();
      if(dpp == null)
      {
        dpp = new DataPreProcessor(rows.values());
      }
      Messager msg = (Messager) wk.getMsg();
      if(msg == null)
      {
        msg = new Messager();
      }
      RamblerTransformationOutput rtf = applyRamblerTransformation(rows,dpp,msg);
View Full Code Here

    return CommandType.notInHistory;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    HNodePath selectedPath = null;
    List<HNodePath> columnPaths = worksheet.getHeaders().getAllPaths();
    for (HNodePath path : columnPaths) {
      if (path.getLeaf().getId().equals(hNodeId)) {
        selectedPath = path;
      }
    }
    Collection<Node> nodes = new ArrayList<Node>();
    workspace.getFactory().getWorksheet(worksheetId).getDataTable()
        .collectNodes(selectedPath, nodes, selection);

   
    try {
      JSONArray requestJsonArray = new JSONArray()
      for (Node node : nodes) {

        String originalVal = node.getValue().asString();
        originalVal = originalVal == null ? "" : originalVal;
         requestJsonArray.put(originalVal);
      }
      String jsonString = null;
      jsonString = requestJsonArray.toString();

      String url = ServletContextParameterMap.getParameterValue(
          ContextParameter.CLUSTER_SERVICE_URL);
     
      logger.info("Execute Cluster Service:" + url);
     
      StringEntity se = new StringEntity(jsonString);
      String reqResponse = HTTPUtil.executeHTTPPostRequest(url, "application/json",
          null, se);
     
      JSONObject jsonAnnotation = new JSONObject();
      jsonAnnotation.put("worksheetId", worksheetId);
      jsonAnnotation.put("hNodeId", hNodeId);
      jsonAnnotation.put("id", id);
      jsonAnnotation.put("cluster", new JSONObject(reqResponse));
           
     
      JsonImport obj  = new JsonImport(reqResponse, "cluster", workspace, "UTF-8", -1 );
 
      UpdateContainer c = new UpdateContainer();
     
      Worksheet ws = obj.generateWorksheet();
      ws.setJsonAnnotation(jsonAnnotation);
     
      if(worksheet.getJsonAnnotation() != null )
      {
        JSONObject jsonAnnotationCluster = new JSONObject (worksheet.getJsonAnnotation().toString());
        String clusterWorksheetId = jsonAnnotationCluster.get("ClusterId").toString();
        if(workspace.getWorksheet(clusterWorksheetId) != null) {
          DeleteWorksheetCommand deleteWorkseet = new DeleteWorksheetCommand(id, clusterWorksheetId );
          deleteWorkseet.doIt(workspace);
          c.add(new WorksheetDeleteUpdate(clusterWorksheetId));
        }
        jsonAnnotationCluster.remove("cluster");
      }
     
      JSONObject ClusterAnnotation = new JSONObject();
     
      ClusterAnnotation.put("ClusterId",ws.getId());
     
      worksheet.setJsonAnnotation(ClusterAnnotation);
      c.add(new WorksheetListUpdate());
      c.append(WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(ws.getId(), getSuperSelection(ws)));
     
      return c;
      //return null;
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

  }

  // remove the added column
  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);

    HTable currentTable = workspace.getFactory().getHTable(hTableId);
    // remove the new column
    currentTable.removeHNode(newHNodeId, worksheet);
View Full Code Here

  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {

    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    RepFactory factory = workspace.getFactory();
    TripleStoreUtil util = new TripleStoreUtil();
    HashMap<String, List<String>> result = null;
    nodeUri = nodeUri.trim();
    Map<String, Label> parents = workspace.getOntologyManager().getSuperClasses(nodeUri, true);
    Set<String> classes = new HashSet<String>(parents.keySet());
    classes.add(nodeUri);
    StringBuilder builder = new StringBuilder();
    nodeUri = builder.append("<").append(nodeUri).append(">").toString();
    try {
      result = util.getPredicatesForTriplesMapsWithSameClass(tripleStoreUrl, context, classes);
    } catch (KarmaException e) {
      LOG.error("Unable to find predicates for triples maps with same class as: " + nodeUri, e);
    }
    final JSONArray array = new JSONArray();
    List<JSONObject> objects = new ArrayList<JSONObject>();
    List<String> concatenatedPredicateObjectMapsList = result.get("predicateObjectMaps");
    List<String> predicates = result.get("predicates");
    List<String> otherClasses = result.get("otherClasses");
    Iterator<String> concatenatedPredicateObjectMapsListItr = concatenatedPredicateObjectMapsList.iterator();
    Iterator<String> predicatesItr = predicates.iterator();
    Iterator<String> otherClassesItr = otherClasses.iterator();
    String hNodeId = FetchHNodeIdFromAlignmentCommand.gethNodeId(AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId), columnUri);
    if (hNodeId == null) {
      return new UpdateContainer(new AbstractUpdate() {

        @Override
        public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) {
          pw.print(array.toString());
        }
      });
    }
    HNode hnode = factory.getHNode(hNodeId);
    List<Table> dataTables = new ArrayList<Table>();
    CloneTableUtils.getDatatable(worksheet.getDataTable(), factory.getHTable(hnode.getHTableId()), dataTables, selection);
    KR2RMLBloomFilter uris = new KR2RMLBloomFilter(KR2RMLBloomFilter.defaultVectorSize, KR2RMLBloomFilter.defaultnbHash, Hash.JENKINS_HASH);
    Set<String> uriSet = new HashSet<String>();
    for(Table t : dataTables) {
      for(Row r : t.getRows(0, t.getNumRows(), selection)) {
        Node n = r.getNode(hNodeId);
        if(n != null && n.getValue() != null && !n.getValue().isEmptyValue() && n.getValue().asString() != null && !n.getValue().asString().trim().isEmpty() ) {
          String value = n.getValue().asString().trim().replace(" ", "");
          String baseURI = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.baseURI);
          try {
            URI uri = new URI(value);
            if (!uri.isAbsolute() && baseURI != null) {
              value = baseURI + value;
            }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet wk = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(wk);
    String encoding = wk.getEncoding();
    // Clone the worksheet just before the invocation
    Cloner cloner = new Cloner();
    this.worksheetBeforeInvocation = cloner.deepClone(wk);
   
    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);
      AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
    }
   
    if (initialAlignment == null) {
      initialAlignment = alignment.getAlignmentClone();
      initialGraph = (DirectedWeightedMultigraph<Node, DefaultLink>)alignment.getGraph().clone();
    }
   
    List<String> requestURLStrings = new ArrayList<String>();
    List<Row> rows = wk.getDataTable().getRows(0, wk.getDataTable().getNumRows(), selection);
    if (rows == null || rows.size() == 0) {
      logger.error("Data table does not have any row.");
      return new UpdateContainer(new ErrorUpdate("Data table does not have any row."))
    }
   
    List<String> requestIds = new ArrayList<String>();
    for (int i = 0; i < rows.size(); i++) {
      requestIds.add(rows.get(i).getId());
      requestURLStrings.add(rows.get(i).getNode(hNodeId).getValue().asString());
    }

    InvocationManager invocatioManager;
    try {
      invocatioManager = new InvocationManager(getUrlColumnName(wk), requestIds, requestURLStrings, encoding);
      logger.info("Requesting data with includeURL=" + false + ",includeInput=" + true + ",includeOutput=" + true);
     
      // This generate a flat table of the json results
      Table serviceTable = invocatioManager.getServiceData(false, true, true);
      ServiceTableUtil.populateWorksheet(serviceTable, wk, workspace.getFactory(), selection);
     
      // FIXME
//      String json = invocatioManager.getServiceJson(true);
      invocatioManager.getServiceJson(true);
//      new JsonImport(json, wk, ws.getFactory());
//      logger.debug(json);


     
      WebService service = invocatioManager.getInitialServiceModel(null);
      MetadataContainer metaData = wk.getMetadataContainer();
      if (metaData == null) {
        metaData = new MetadataContainer();
        wk.setMetadataContainer(metaData);
      }
      metaData.setService(service);
      logger.info("Service added to the Worksheet.");

    } catch (MalformedURLException e) {
      logger.error("Malformed service request URL.");
      return new UpdateContainer(new ErrorUpdate("Malformed service request URL."));
    } catch (KarmaException e) {
      logger.error(e.getMessage());
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }
   
    // Create new vWorksheet using the new header order
    List<HNodePath> columnPaths = new ArrayList<HNodePath>();
    for (HNode node : wk.getHeaders().getSortedHNodes()) {
      HNodePath path = new HNodePath(node);
      columnPaths.add(path);
    }

   
    alignment = AlignmentManager.Instance().getAlignmentOrCreateIt(workspace.getId(), wk.getId(), ontMgr);
    AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
    UpdateContainer c = new UpdateContainer();
    try {
      // Add the visualization update
      c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(workspace)));
View Full Code Here

  public Worksheet generateWorksheet(Workspace workspace, String title, String encoding) throws KarmaException, IOException {

    if (workspace == null)
      throw new KarmaException("Workspace is null.");
   
    Worksheet worksheet = workspace.getFactory().createWorksheet(title, workspace, encoding);
   
    return worksheet;
  }
View Full Code Here

  }
 
  @Override
  public UpdateContainer undoIt(Workspace workspace) {

    Worksheet wk = workspace.getWorksheet(worksheetId);

    UpdateContainer c = new UpdateContainer();
   
    // Create new vWorksheet using the new header order
//    List<HNodePath> columnPaths = new ArrayList<HNodePath>();
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    UpdateContainer c = new UpdateContainer();
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    OntologyManager ontologyManager = workspace.getOntologyManager();
    if(ontologyManager.isEmpty())
      return new UpdateContainer(new ErrorUpdate("No ontology loaded."));
   
    worksheetName = worksheet.getTitle();
   
    String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
    Alignment alignment = AlignmentManager.Instance().getAlignmentOrCreateIt(workspace.getId(), worksheetId, ontologyManager);
    if (alignment == null) {
      logger.info("Alignment is NULL for " + worksheetId);
      return new UpdateContainer(new ErrorUpdate(
          "Alignment is NULL for " + worksheetId));
    }

    if (initialAlignment == null)
    {
      initialAlignment = alignment.getAlignmentClone();

      initialGraph = (DirectedWeightedMultigraph<Node, DefaultLink>)alignment.getGraph().clone();
     
      List<HNode> orderedNodeIds = new ArrayList<HNode>();
      worksheet.getHeaders().getSortedLeafHNodes(orderedNodeIds);
      if (orderedNodeIds != null) {
        for (int i = 0; i < orderedNodeIds.size(); i++)
        {
          String hNodeId = orderedNodeIds.get(i).getId();
          ColumnNode cn = alignment.getColumnNodeByHNodeId(hNodeId);
         
          if (!cn.hasUserType())
          {
            worksheet.getSemanticTypes().unassignColumnSemanticType(hNodeId);
            List<SemanticType> suggestedSemanticTypes =
                new SemanticTypeUtil().getColumnSemanticSuggestions(workspace, worksheet, cn, 4, selection);
            cn.setSuggestedSemanticTypes(suggestedSemanticTypes);
          }
        }
      }
    } else {
    // Replace the current alignment with the old alignment
      alignment = initialAlignment;
      alignment.setGraph(initialGraph);
      if(!this.isExecutedInBatch())
        alignment.align();
      AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
    }

    steinerNodes = alignment.computeSteinerNodes();
    ModelLearner modelLearner = null;
    if (ModelingConfiguration.isLearnAlignmentEnabled())
      modelLearner = new ModelLearner(alignment.getGraphBuilder(), steinerNodes);
    else
      modelLearner = new ModelLearner(ontologyManager, alignment.getLinksByStatus(LinkStatus.ForcedByUser), steinerNodes);

//    logger.info(GraphUtil.defaultGraphToString(ModelLearningGraph.getInstance(ontologyManager, ModelLearningGraphType.Compact).getGraphBuilder().getGraph()));

    SemanticModel model = modelLearner.getModel();
    if (model == null) {
      logger.error("could not learn any model for this source!");
      return new UpdateContainer(new ErrorUpdate(
          "Error occured while generating a semantic model for the source."));
    }
   
//    logger.info(GraphUtil.labeledGraphToString(model.getGraph()));
   
    List<SemanticType> semanticTypes = new LinkedList<SemanticType>();
    alignment.updateAlignment(model, semanticTypes);
//    Set<ColumnNode> alignmentColumnNodes = alignment.getSourceColumnNodes();
//    if (alignmentColumnNodes != null) {
//      for (ColumnNode cn : alignmentColumnNodes) {
//        worksheet.getSemanticTypes().unassignColumnSemanticType(cn.getHNodeId());
//      }
//    }
//    if (semanticTypes != null) {
//      for (SemanticType st : semanticTypes)
//        worksheet.getSemanticTypes().addType(st);
//    }
   
    try {
      // Save the semantic types in the input parameter JSON
      saveSemanticTypesInformation(worksheet, workspace, worksheet.getSemanticTypes().getListOfTypes());
     
      // Add the visualization update
      c.add(new SemanticTypesUpdate(worksheet, worksheetId, alignment));
      c.add(new AlignmentSVGVisualizationUpdate(
          worksheetId, alignment));
View Full Code Here

TOP

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

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.