Package edu.isi.karma.controller.update

Examples of edu.isi.karma.controller.update.UpdateContainer


    {
      recmd = "";
    }
    msg = String.format("Gen rule end, Time,%d, Worksheet,%s,Examples:%s,Recmd:%s",System.currentTimeMillis(),worksheetId,expstr,recmd);
    logger.info(msg);
    return new UpdateContainer(new CleaningResultUpdate(hNodeId, resdata,
        vars, keys));
  }
View Full Code Here


      }catch(Exception e) {
        e.printStackTrace();
      }
    }
    try{
      UpdateContainer c =  new UpdateContainer();
      c.add(new WorksheetListUpdate());
      if (newws == null)
        c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(oldws.getId(), getSuperSelection(oldws)));
      if (newws != null) {
        c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(newws.getId(), SuperSelectionManager.DEFAULT_SELECTION));
        Alignment alignment = AlignmentManager.Instance().getAlignmentOrCreateIt(workspace.getId(), newws.getId(), workspace.getOntologyManager());
        c.append(WorksheetUpdateFactory.createSemanticTypesAndSVGAlignmentUpdates(newws.getId(), workspace, alignment));
      }
      c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
      return c;
    } catch (Exception e) {
      WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this);
      logger.error("Error in UnfoldCommand" + e.toString());
      Util.logException(logger, e);
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }
  }
View Full Code Here

  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
   
    UpdateContainer c = new UpdateContainer();
    Worksheet wk = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(wk);
    // Clone the worksheet just before the invocation
    Cloner cloner = new Cloner();
    this.worksheetBeforeInvocation = cloner.deepClone(wk);

    AlignmentManager mgr = AlignmentManager.Instance();
    String alignmentId = mgr.constructAlignmentId(workspace.getId(), worksheetId);
    Alignment al = mgr.getAlignment(alignmentId);
   
//    /**
//     *
//     */
//    // FIXME
//    String exportDir = "/Users/mohsen/Dropbox/Service Modeling/iswc2013-exp2/jgraph/";
//    try {
//      GraphUtil.serialize(al.getSteinerTree(), exportDir + wk.getTitle() + ".karma.final.jgraph");
//    } catch (Exception e1) {
//      // TODO Auto-generated catch block
//      e1.printStackTrace();
//    }
//    if (true) return null;
   
    if (al == null) {
      logger.error("The alignment model is null.");
      return new UpdateContainer(new ErrorUpdate(
        "Error occured while populating the source. The alignment model is null."));
    }
   
    DirectedWeightedMultigraph<Node, LabeledLink> tree = al.getSteinerTree();
     
    if (tree == null) {
      logger.error("The alignment tree is null.");
      return new UpdateContainer(new ErrorUpdate(
        "Error occured while populating the source. The alignment model is null."));
    }

    DataSource source = new DataSource(wk.getTitle(), tree);
   
    Map<WebService, Map<String, String>> servicesAndMappings =
      WebServiceLoader.getInstance().getServicesWithInputContainedInModel(source.getModel(), null);
   
    if (servicesAndMappings == null) {
      logger.error("Cannot find any services to be invoked according to this source model.");
      return new UpdateContainer(new ErrorUpdate(
        "Error occured while populating the source. Cannot find any services to be invoked according to this source model."));
    }
   
    // For now, we just use the first service,
    // later we can suggest the user a list of available services and user select among them
    WebService service = null;
    Iterator<WebService> itr = servicesAndMappings.keySet().iterator();
    if (itr != null && itr.hasNext()) {
      service = itr.next();
    }
   
    if (service == null) {
      logger.error("Cannot find any services to be invoked according to this source model.");
      return new UpdateContainer(new ErrorUpdate(
        "Error occured while populating the source. Cannot find any services to be invoked according to this source model."));
    }
   
    List<String> requestIds = new ArrayList<String>();
    Map<String, String> serviceToSourceAttMapping =  servicesAndMappings.get(service);
    List<String> requestURLStrings = getUrlStrings(service, source, wk, serviceToSourceAttMapping, requestIds);
    if (requestURLStrings == null || requestURLStrings.size() == 0) {
      logger.error("Data table does not have any row.");
      return new UpdateContainer(new ErrorUpdate("Data table does not have any row."))
    }
   
   
    InvocationManager invocatioManager;
    try {
      String encoding = wk.getEncoding();
      invocatioManager = new InvocationManager(getUrlColumnName(wk), requestIds, requestURLStrings, encoding);
      logger.info("Requesting data with includeURL=" + true + ",includeInput=" + true + ",includeOutput=" + true);
      Table serviceTable = invocatioManager.getServiceData(false, false, true);
//      logger.debug(serviceTable.getPrintInfo());
      ServiceTableUtil.populateWorksheet(serviceTable, wk, workspace.getFactory(), selection);
      logger.info("The service " + service.getUri() + " has been invoked successfully.");


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

  }
 
  @Override
  public UpdateContainer undoIt(Workspace workspace) {

    UpdateContainer c = new UpdateContainer();
   
    // Create new vWorksheet using the new header order
    List<HNodePath> columnPaths = new ArrayList<HNodePath>();
    for (HNode node : worksheetBeforeInvocation.getHeaders().getSortedHNodes()) {
      HNodePath path = new HNodePath(node);
      columnPaths.add(path);
    }
    workspace.getFactory().replaceWorksheet(this.worksheetId, this.worksheetBeforeInvocation);
   
    c.add(new ReplaceWorksheetUpdate(worksheetId, this.worksheetBeforeInvocation));
    c.append(WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(worksheetId, getSuperSelection(workspace)));
   
    return c; 
   
  }
View Full Code Here

    }
  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    UpdateContainer c = new UpdateContainer();
    if (this.newWorksheetId != null) {
      workspace.removeWorksheet(newWorksheetId);
      workspace.getFactory().removeWorksheet(newWorksheetId, workspace.getCommandHistory());
      c.add(new WorksheetListUpdate());
      c.add(new WorksheetDeleteUpdate(newWorksheetId));
    }
    if (this.newHNodeId != null) {
      Worksheet worksheet = workspace.getWorksheet(worksheetId);
      HNode ndid = workspace.getFactory().getHNode(newHNodeId);
      HTable currentTable = workspace.getFactory().getHTable(ndid.getHTableId());
      ndid.removeNestedTable();
      //remove the new column
      currentTable.removeHNode(newHNodeId, worksheet);
      c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
      c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    }
    return c;
  }
View Full Code Here

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    appliedCommands.clear();
    inputColumns.clear();
    outputColumns.clear();
    UpdateContainer c =  new UpdateContainer();
    alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
    Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
    RepFactory factory = workspace.getFactory();
    Worksheet worksheet = factory.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    if (alignment.GetTreeRoot() != null)
      hNodeId = FetchHNodeIdFromAlignmentCommand.gethNodeId(alignmentId, columnUri);
    if (hNodeId == null) {
      c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
      c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
      return c;
    }
    HNode hnode = factory.getHNode(hNodeId);
    List<String> hNodeIds = new LinkedList<String>();
    hNodeIds.add(hNodeId);
    inputColumns.addAll(hNodeIds);
    List<Table> dataTables = new ArrayList<Table>();
    CloneTableUtils.getDatatable(worksheet.getDataTable(), factory.getHTable(hnode.getHTableId()), dataTables, selection);
    Map<String, String> rowHashToSubjectURI = new HashMap<String, String>();
    Map<String, List<String>> SubjectURIToRowId = new HashMap<String, List<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 uri = n.getValue().asString().trim().replace(" ", "");
          String baseURI = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.baseURI);
          try {
            URI t1 = new URI(uri);
            if (!t1.isAbsolute() && baseURI != null) {
              uri = baseURI + uri;
            }
          } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
          }
//          n.setValue(uri, n.getStatus(), factory);
          rowHashToSubjectURI.put(HashValueManager.getHashValue(r, hNodeIds), uri);

          if (SubjectURIToRowId.get(uri) == null)
            SubjectURIToRowId.put(uri, new ArrayList<String>());
          List<String> rowIds = SubjectURIToRowId.get(uri)
          rowIds.add(r.getId());
        }
      }
    }
    TripleStoreUtil util = new TripleStoreUtil();

    //String modelContext = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.modelContext);
    List<String> subjects = new LinkedList<String>();
    subjects.addAll(rowHashToSubjectURI.values());
    List<String> predicates = new LinkedList<String>();
    List<String> otherClasses = new LinkedList<String>();
    Map<String, List<String>> results = new HashMap<String, List<String>>();

    URIFormatter uriFormatter = new URIFormatter(workspace.getOntologyManager(), new ErrorReport());
    if(sameAsPredicate!= null && !sameAsPredicate.trim().isEmpty())
    {
      sameAsPredicate = uriFormatter.getExpandedAndNormalizedUri(sameAsPredicate);
    }

    JSONArray predicatesarray = new JSONArray(predicate);
    JSONArray otherClassarray = new JSONArray(otherClass);

    for(int i = 0; i < predicatesarray.length(); i++) {
      predicates.add(predicatesarray.getJSONObject(i).getString("predicate"));
      otherClasses.add(otherClassarray.getJSONObject(i).getString("otherClass"));
    }

    while (subjects.size() > 0) {
      ListIterator<String> subjectsIterator = subjects.listIterator();
      LinkedList<String> tempSubjects = new LinkedList<String>();
      while(tempSubjects.size() < limit && subjects.size() > 0)
      {
        tempSubjects.add(subjectsIterator.next());
        subjectsIterator.remove();
      }
      try {
        Map<String, List<String>> temp = null;
        if (!incoming)
          temp = util.getObjectsForSubjectsAndPredicates(dataRepoUrl, null, tempSubjects , predicates, otherClasses, sameAsPredicate);
        else
          temp = util.getSubjectsForPredicatesAndObjects(dataRepoUrl, null, tempSubjects , predicates, otherClasses, sameAsPredicate);
        addMappingToResults(results, temp);
        //        predicates.clear();
        //        otherClasses.clear();
      } catch (KarmaException e) {
        LOG.error("Unable to load data to augment: ", e);
        return new UpdateContainer(new ErrorUpdate(e.getMessage()));
      }
    }


    List<String> resultSubjects = results.get("resultSubjects");
    List<String> resultPredicates = results.get("resultPredicates");
    List<String> resultObjects = results.get("resultObjects");
    List<String> resultClass = results.get("resultClasses");
    AddValuesCommandFactory addFactory = new AddValuesCommandFactory();

    for (int i = 0; i < resultPredicates.size(); i++) {
      String subject = incoming ? resultObjects.get(i) : resultSubjects.get(i);
      List<String> rowIds = SubjectURIToRowId.get(subject);
      boolean isNewNode = false;
      for (String RowId : rowIds) {
        String predicate = resultPredicates.get(i);
        String otherClass = resultClass.get(i);
        JSONArray array = new JSONArray();
        JSONObject obj = new JSONObject();
        JSONObject obj2 = new JSONObject();
        if (otherClass != null && !otherClass.trim().isEmpty())
          obj.put("URIs", incoming ? resultSubjects.get(i) : resultObjects.get(i));
        else
          obj.put("values", incoming ? resultSubjects.get(i) : resultObjects.get(i));
        obj2.put("rowId", RowId);
        obj2.put("rowIdHash", "");
        obj2.put("values", obj);
        array.put(obj2);
        JSONArray input = new JSONArray();
        JSONObject obj3 = new JSONObject();
        obj3.put("name", "AddValues");
        obj3.put("value", array.toString());
        obj3.put("type", "other");
        input.put(obj3);
        try {
          OntologyManager ontMgr = workspace.getOntologyManager();
          Label label = ontMgr.getUriLabel(incoming ? otherClass : predicate);
          AddValuesCommand command = (AddValuesCommand) addFactory.createCommand(input, workspace, hNodeId, worksheetId, hnode.getHTableId(), label.getDisplayName(), HNodeType.AugmentData, selection.getName());
          command.doIt(workspace);
          outputColumns.addAll(command.getOutputColumns());
          isNewNode |= command.isNewNode();
          if (command.isNewNode())
            appliedCommands.push(command);
          newhNodeId = command.getNewHNodeId();


        } catch(Exception e) {
          e.printStackTrace();
          return new UpdateContainer(new ErrorUpdate(e.getMessage()));
        }
      }
      if (isNewNode && alignment.GetTreeRoot() != null) {
        HNode tableHNode =workspace.getFactory().getHNode(newhNodeId);
        String nestedHNodeId = tableHNode.getNestedTable().getHNodeIdFromColumnName("values");
        if (nestedHNodeId == null)
          nestedHNodeId = tableHNode.getNestedTable().getHNodeIdFromColumnName("URIs");
        SetSemanticTypeCommandFactory sstFactory = new SetSemanticTypeCommandFactory();
        JSONArray semanticTypesArray = new JSONArray();
        JSONObject semanticType = new JSONObject();
        edu.isi.karma.rep.alignment.Node n = alignment.getNodeById(columnUri);

        semanticType.put(ClientJsonKeys.isPrimary.name(), "true");
        Set<edu.isi.karma.rep.alignment.Node> oldNodes = new HashSet<edu.isi.karma.rep.alignment.Node>();
        if(resultClass.get(i).trim().isEmpty())
        {
          semanticType.put(ClientJsonKeys.DomainId.name(), n.getId());
          semanticType.put(ClientJsonKeys.FullType.name(), resultPredicates.get(i));
          semanticType.put(ClientJsonKeys.DomainUri.name(), n.getUri());
        }
        else
        {
          if (alignment.getNodesByUri(resultClass.get(i)) != null)
            oldNodes.addAll( alignment.getNodesByUri(resultClass.get(i)));
          semanticType.put(ClientJsonKeys.DomainId.name(), resultClass.get(i));
          semanticType.put(ClientJsonKeys.FullType.name(), Uris.CLASS_INSTANCE_LINK_URI);
        }


        semanticTypesArray.put(semanticType);
        Command sstCommand = sstFactory.createCommand(workspace, worksheetId, nestedHNodeId, false, semanticTypesArray, false, "", selection.getName());
        appliedCommands.push(sstCommand);
        sstCommand.doIt(workspace);
        if(!resultClass.get(i).trim().isEmpty())
        {
          ChangeInternalNodeLinksCommandFactory cinlcf = new ChangeInternalNodeLinksCommandFactory();
          SetMetaPropertyCommandFactory smpcf = new SetMetaPropertyCommandFactory();
          JSONArray newEdges = new JSONArray();
          JSONObject newEdge = new JSONObject();
          String sourceId = n.getId();
          Set<edu.isi.karma.rep.alignment.Node> tempnodes = new HashSet<edu.isi.karma.rep.alignment.Node>();
          tempnodes.addAll(alignment.getNodesByUri(resultClass.get(i)));
          tempnodes.removeAll(oldNodes);

          edu.isi.karma.rep.alignment.Node target = tempnodes.iterator().next();
          String targetId = target.getId();
          String targetUri = target.getLabel().getUri();
          String edgeUri = resultPredicates.get(i);
          if (!incoming) {
            newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeSourceId.name(), sourceId);
            newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeTargetId.name(), targetId);
            newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeId.name(), edgeUri);
          }
          else {
            newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeSourceId.name(), targetId);
            newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeTargetId.name(), sourceId);
            newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeId.name(), edgeUri);
          }
          newEdges.put(newEdge);
          Command changeInternalNodeLinksCommand = cinlcf.createCommand(worksheetId, alignmentId, new JSONArray(), newEdges, workspace);
          changeInternalNodeLinksCommand.doIt(workspace);
          appliedCommands.push(changeInternalNodeLinksCommand);
          Command setMetaDataCommand = smpcf.createCommand(workspace, nestedHNodeId, worksheetId, "isUriOfClass",
              targetUri, targetId, "", selection.getName());
          setMetaDataCommand.doIt(workspace);
          appliedCommands.push(setMetaDataCommand);
        }
      }

    }

    WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this);
    c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    return c;
  }
View Full Code Here

    return c;
  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    UpdateContainer c =  new UpdateContainer();
    while (!appliedCommands.isEmpty()) {
      Command command = appliedCommands.pop();
      command.undoIt(workspace);
    }
    c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(workspace)));
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    return c;
  }
View Full Code Here

    HNode hNode = f.getHNode(hNodeId);
    final JSONArray transformedRows = new JSONArray();
    final JSONArray errorValues = new JSONArray();
    try {
      this.generateTransformedValues(workspace, worksheet, f, hNode, transformedRows, errorValues, 5);
      return new UpdateContainer(new PythonPreviewResultsUpdate(transformedRows, errorValues));
    } catch (Exception e) {
      logger.error("Error while creating python results preview", e);
      String message = e.toString();
      return new UpdateContainer(new ErrorUpdate("Error executing python script: " + message));
    }
  }
View Full Code Here

      Collection<Node> mainNodes = new ArrayList<Node>();
      workspace.getFactory().getWorksheet(mainWorksheetId).getDataTable().collectNodes(mainSelectedPath, mainNodes, selection);
      int i = 0;
      Map<String, String> rowValueMap = new TreeMap<String, String>();
     
      UpdateContainer c = new UpdateContainer();
        for (Node node : mainNodes) {

          Row row = node.getBelongsToRow();
          rowValueMap.put(row.getId(), requestJsonArray.get(i).toString());
          //oldValueMap.put(row.getId(),node.getValue().asString());
          i = i+1;
         
        }
        edit = new MultipleValueEditColumnCommand(mainId, mainWorksheetId, mainHNodeId, rowValueMap);
        c.append(edit.doIt(workspace));
       
       
        return c;
      //return null;
    } catch (Exception e) {
      e.printStackTrace();
      return new UpdateContainer(new ErrorUpdate("Error!"));
    }
  }
View Full Code Here

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    // TODO Auto-generated method stub
   
    UpdateContainer c = new UpdateContainer();
    c.append(edit.undoIt(workspace));
   
    return c;
  }
View Full Code Here

TOP

Related Classes of edu.isi.karma.controller.update.UpdateContainer

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.