Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.Worksheet


      topA.endArray();

      JsonImport ji = new JsonImport(x.toString(),
          "Nested Table 2", workspace, "UTF-8", -1);
      Worksheet w = ji.generateWorksheet();
      return w;
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }
View Full Code Here


  }

  public JSONArray getTableLayout(VWorkspace vWorkspace) {
    VWorksheet vWorksheet = vWorkspace.getViewFactory()
        .getVWorksheetByWorksheetId(worksheetId);
    Worksheet wk = vWorksheet.getWorksheet();
    ColumnMetadata colMeta = wk.getMetadataContainer().getColumnMetadata();
    List<VHNode> viewHeaders = vWorksheet.getHeaderViewNodes();
     
    return getColumnsJsonArray(viewHeaders, colMeta);
  }
View Full Code Here

    return CommandType.undoable;
  }

  @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!
View Full Code Here

  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
   
    Worksheet wk = workspace.getFactory().getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(wk);
    List<HNodePath> columnPaths = wk.getHeaders().getAllPaths();

    // Get the path which has the split value hNodeId
    HNodePath selectedPath = null;
    for (HNodePath path : columnPaths) {
      if (path.getLeaf().getId().equals(splitValueHNodeId)) {
        selectedPath = path;
      }
    }
    // Clear the nested table for the HNode
    hNode.removeNestedTable();
   
    // Replace the path
    int oldPathIndex = columnPaths.indexOf(selectedPath);
    for (HNodePath path : wk.getHeaders().getAllPaths()) {
      if (path.getLeaf().getId().equals(hNodeId)) {
        hNode = path.getLeaf();
        selectedPath = path;
      }
    }
    columnPaths.set(oldPathIndex, selectedPath);

    // Populate the column with old values
    Collection<Node> nodes = new ArrayList<Node>();
    wk.getDataTable().collectNodes(selectedPath, nodes, selection);

    for (Node node : nodes) {
      //pedro 2012-09-15 this does not look correct.
      node.setNestedTable(null, workspace.getFactory());
      node.setValue(oldNodeValueMap.get(node), oldNodeStatusMap.get(node), workspace.getFactory());
View Full Code Here

  }

  public Command createCommand(JSONArray inputJson, Workspace workspace)
      throws JSONException, KarmaException {
    String worksheetId = HistoryJsonUtil.getStringValue(Arguments.worksheetId.name(), inputJson);
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    this.normalizeSelectionId(worksheetId, inputJson, workspace);
    String selectionName = CommandInputJSONUtil.getStringValue(Arguments.selectionName.name(), inputJson);
    SuggestModelCommand comm = new SuggestModelCommand(getNewId(workspace), worksheet.getId(), false,
        selectionName);
    OntologyManager ontMgr = workspace.getOntologyManager();
    // Add the semantic types that have saved into the history
    for (int i=2; i<inputJson.length(); i++) {
      JSONObject hnodeObj = (JSONObject) inputJson.get(i);
      String hNodeId = (String) hnodeObj.get(ClientJsonKeys.value.name());
     
      JSONObject typeObj = (JSONObject) inputJson.get(++i);
      JSONObject value = (JSONObject) typeObj.get(ClientJsonKeys.value.name());
     
      SemanticType type = null;
      String domain = (String) value.get(SemanticType.ClientJsonKeys.DomainUri.name());
      String fullType = (String) value.get(SemanticType.ClientJsonKeys.FullType.name());
     
      Label typeName = ontMgr.getUriLabel(fullType);
      Label domainName = null;
      if (domain != null && !domain.trim().equals(""))
        domainName = ontMgr.getUriLabel(domain);
     
      if(typeName != null) {
        type = new SemanticType(hNodeId, typeName, domainName, Origin.User, 1.00);
        worksheet.getSemanticTypes().addType(type);
      }
    }
    return comm;
  }
View Full Code Here

    return CommandType.notUndoable;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection currentSel = getSuperSelection(worksheet);
    List<SelectionWithPriority> selections = new ArrayList<SelectionWithPriority>();
    for (Selection sel : currentSel.getAllSelection()) {
      HTable ht = workspace.getFactory().getHTable(sel.getHTableId());
      selections.add(new SelectionWithPriority(sel, hTableDepth(ht, workspace.getFactory())));
View Full Code Here

    return CommandType.notInHistory;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
//    if (worksheet.getSemanticTypes().getListOfTypes().size() == 0) {
//      SemanticTypeUtil.populateSemanticTypesUsingCRF(worksheet, workspace
//          .getTagsContainer().getTag(TagName.Outlier), workspace
//          .getSemanticTypeModelHandler(), workspace.getOntologyManager());
View Full Code Here

    return CommandType.notInHistory;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);

    OntologyManager om= workspace.getOntologyManager();
    WorksheetToFeatureCollection geo = new WorksheetToFeatureCollection(worksheet, om, selection);//ying
   
View Full Code Here

    UpdateContainer uc = new UpdateContainer();
    //save the preferences
    savePreferences(workspace);
    boolean storeOldHistory = ModelingConfiguration.isStoreOldHistoryEnabled();
    System.out.println("storeOldHistory: " + storeOldHistory);
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    CommandHistory history = workspace.getCommandHistory();
    List<Command> oldCommands = history.getCommandsFromWorksheetId(worksheetId);
    if (storeOldHistory) {     
      JSONArray oldCommandsArray = new JSONArray();
      for (Command refined : oldCommands)
        oldCommandsArray.put(workspace.getCommandHistory().getCommandJSON(workspace, refined));
      worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
          Property.oldCommandHistory, oldCommandsArray.toString());
    }
    CommandHistoryUtil historyUtil = new CommandHistoryUtil(history.getCommandsFromWorksheetId(worksheetId), workspace, worksheetId);
    historyUtil.consolidateHistory()
    if (!oldCommands.equals(historyUtil.getCommands())) {
      uc.append(historyUtil.replayHistory());
      uc.removeUpdateByClass(HistoryAddCommandUpdate.class);
      uc.removeUpdateByClass(InfoUpdate.class);
      uc.removeUpdateByClass(ErrorUpdate.class);
      historyUtil.consolidateHistory();
      uc.add(new HistoryUpdate(workspace.getCommandHistory()));

    }
    Set<String> inputColumns = historyUtil.generateInputColumns();
    Set<String> outputColumns = historyUtil.generateOutputColumns();
    JSONArray inputColumnsArray = new JSONArray();
    JSONArray outputColumnsArray = new JSONArray();
    for (String hNodeId : inputColumns) {
      HNode hnode = workspace.getFactory().getHNode(hNodeId);
      JSONArray hNodeRepresentation = hnode.getJSONArrayRepresentation(workspace.getFactory());
      inputColumnsArray.put(hNodeRepresentation);
    }

    for (String hNodeId : outputColumns) {
      HNode hnode = workspace.getFactory().getHNode(hNodeId);
      JSONArray hNodeRepresentation = hnode.getJSONArrayRepresentation(workspace.getFactory());
      outputColumnsArray.put(hNodeRepresentation);
    }
    worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
        Property.inputColumns, inputColumnsArray.toString());
    worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
        Property.outputColumns, outputColumnsArray.toString());   
    this.worksheetName = worksheet.getTitle();
    String graphLabel = worksheet.getMetadataContainer().getWorksheetProperties().
        getPropertyValue(Property.graphLabel);

    if (graphLabel == null || graphLabel.isEmpty()) {
      worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
          Property.graphLabel, worksheet.getTitle());
      graphLabel = worksheet.getTitle();
      worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
          Property.graphName, WorksheetProperties.createDefaultGraphName(graphLabel))
    }
    // Prepare the model file path and names
    final String modelFileName = graphLabel + "-model.ttl";
    final String modelFileLocalPath = ServletContextParameterMap.getParameterValue(
        ContextParameter.R2RML_PUBLISH_DIR) +  modelFileName;

    // Get the alignment for this Worksheet
    Alignment alignment = AlignmentManager.Instance().getAlignment(AlignmentManager.
        Instance().constructAlignmentId(workspace.getId(), worksheetId));

    if (alignment == null) {
      logger.info("Alignment is NULL for " + worksheetId);
      return new UpdateContainer(new ErrorUpdate(
          "Please align the worksheet before generating R2RML Model!"));
    }
    Set<LabeledLink> links = new HashSet<LabeledLink>();
    if (alignment.getSteinerTree() != null) {
      for (LabeledLink link : alignment.getSteinerTree().edgeSet()) {
        if ((link.getStatus() == LinkStatus.Normal || link.getStatus() == LinkStatus.PreferredByUI) && (link.getType() == LinkType.ObjectPropertyLink)) {
          links.add(link);
        }
      }
    }
    JSONArray newEdges = new JSONArray();
    JSONArray initialEdges = new JSONArray();
    ChangeInternalNodeLinksCommandFactory cinlcf = new ChangeInternalNodeLinksCommandFactory();
    for (LabeledLink link : links) {
      JSONObject newEdge = new JSONObject();
      JSONObject initialEdge = new JSONObject();
      newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeSourceId.name(), link.getSource().getId());
      newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeTargetId.name(), link.getTarget().getId());
      newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeId.name(), link.getUri());
      initialEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeSourceId.name(), link.getSource().getId());
      initialEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeTargetId.name(), link.getTarget().getId());
      initialEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeId.name(), link.getUri());
      newEdges.put(newEdge);
      initialEdges.put(initialEdge);
    }
    JSONArray inputJSON = new JSONArray();
    JSONObject t = new JSONObject();
    t.put("name", "worksheetId");
    t.put("type", HistoryJsonUtil.ParameterType.worksheetId.name());
    t.put("value", worksheetId);
    inputJSON.put(t);
    t = new JSONObject();
    t.put("name", "initialEdges");
    t.put("type", HistoryJsonUtil.ParameterType.other.name());
    t.put("value", initialEdges);
    inputJSON.put(t);
    t = new JSONObject();
    t.put("name", "newEdges");
    t.put("type", HistoryJsonUtil.ParameterType.other.name());
    t.put("value", newEdges);
    inputJSON.put(t);
    if (newEdges.length() > 0 || initialEdges.length() > 0) {
      try {
        Command changeInternalNodeLinksCommand = cinlcf.createCommand(inputJSON, workspace);
        workspace.getCommandHistory().doCommand(changeInternalNodeLinksCommand, workspace);
        uc.add(new HistoryUpdate(workspace.getCommandHistory()));
        uc.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
        uc.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
      }catch(Exception e)
      {
        e.printStackTrace();
      }
    }

    // mohsen: my code to enable Karma to leran semantic models
    // *****************************************************************************************
    // *****************************************************************************************

    SemanticModel semanticModel = new SemanticModel(workspace, worksheet, worksheetName, alignment.getSteinerTree(), selection);
    semanticModel.setName(worksheetName);
    try {
      semanticModel.writeJson(ServletContextParameterMap.getParameterValue(ContextParameter.JSON_MODELS_DIR) +
          semanticModel.getName() +
          ".model.json");
    } catch (Exception e) {
      logger.error("error in exporting the model to JSON!");
      //      e.printStackTrace();
    }
    try {
      semanticModel.writeGraphviz(ServletContextParameterMap.getParameterValue(ContextParameter.GRAPHVIZ_MODELS_DIR) +
          semanticModel.getName() +
          ".model.dot", false, false);
    } catch (Exception e) {
      logger.error("error in exporting the model to GRAPHVIZ!");
      //      e.printStackTrace();
    }

    if (ModelingConfiguration.isLearnerEnabled())
      ModelLearningGraph.getInstance(workspace.getOntologyManager(), ModelLearningGraphType.Compact).
      addModelAndUpdateAndExport(semanticModel);

    // *****************************************************************************************
    // *****************************************************************************************

    try {
      R2RMLAlignmentFileSaver fileSaver = new R2RMLAlignmentFileSaver(workspace);

      fileSaver.saveAlignment(alignment, modelFileLocalPath);

      // Write the model to the triple store

      // Get the graph name from properties
      String graphName = worksheet.getMetadataContainer().getWorksheetProperties()
          .getPropertyValue(Property.graphName);
      if (graphName == null || graphName.isEmpty()) {
        // Set to default
        worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
            Property.graphName, WorksheetProperties.createDefaultGraphName(worksheet.getTitle()));
        worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
            Property.graphLabel, worksheet.getTitle());
        graphName = WorksheetProperties.createDefaultGraphName(worksheet.getTitle());
      }

      boolean result = true;//utilObj.saveToStore(modelFileLocalPath, tripleStoreUrl, graphName, true, null);
      if (tripleStoreUrl != null && tripleStoreUrl.trim().compareTo("") != 0) {
        UriBuilder builder = UriBuilder.fromPath(modelFileName);
View Full Code Here

    return CommandType.undoable;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(
        worksheetId);
    inputColumns.clear();
    outputColumns.clear();
    Object para = JSONUtil.createJson(this.getInputParameterJson());
    String addValues = null
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.