Examples of UpdateContainer


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

      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();
      return new UpdateContainer(new ErrorUpdate("Error in Generating Values!"));
    }
  }
View Full Code Here

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

 
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {

        KarmaMetadataManager userMetadataManager = new KarmaMetadataManager();
        UpdateContainer uc = new UpdateContainer();
        userMetadataManager.register(new UserPreferencesMetadata(), uc);
        userMetadataManager.register(new UserConfigMetadata(), uc);
        userMetadataManager.register(new PythonTransformationMetadata(), uc);
        PythonRepository.disableReloadingLibrary();
  }
View Full Code Here

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

   
    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)));
      c.add(new SemanticTypesUpdate(wk, worksheetId, alignment));
      c.add(new AlignmentSVGVisualizationUpdate(worksheetId, alignment));
    } catch (Exception e) {
      logger.error("Error occured while populating the worksheet with service data!", e);
      return new UpdateContainer(new ErrorUpdate(
          "Error occured while populating the worksheet with service data!"));
    }

    return c;
   
View Full Code Here

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

  @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>();
//    for (HNode node : worksheetBeforeInvocation.getHeaders().getSortedHNodes()) {
//      HNodePath path = new HNodePath(node);
//      columnPaths.add(path);
//    }
   
    String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
    Alignment alignment = initialAlignment;
    alignment.setGraph(initialGraph);
    if(!this.isExecutedInBatch())
      alignment.align();
    AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
    try {
      // Add the visualization update
      workspace.getFactory().replaceWorksheet(worksheetId, worksheetBeforeInvocation);
      c.add(new ReplaceWorksheetUpdate(worksheetId, worksheetBeforeInvocation));
      c.add(new AlignmentSVGVisualizationUpdate(worksheetId, alignment));
      c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(workspace)));
      c.add(new SemanticTypesUpdate(wk, worksheetId, alignment));
    } catch (Exception e) {
      logger.error("Error occured while populating the worksheet with service data!", e);
      return new UpdateContainer(new ErrorUpdate(
          "Error occured while populating the worksheet with service data!"));
    }
   
//    workspace.getFactory().replaceWorksheet(worksheetId, worksheetBeforeInvocation);
//    c.add(new ReplaceWorksheetUpdate(worksheetId, worksheetBeforeInvocation));
View Full Code Here

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

    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;
            }
          } catch (URISyntaxException e) {
          }
          builder = new StringBuilder();
          value = builder.append("<").append(value).append(">").toString(); //String builder
          uriSet.add(value);
          uris.add(new Key(value.getBytes(UTF8_CHARSET)));
        }
      }
    }
    Set<String> maps = new HashSet<String>();
    Map<String, String> bloomfilterMapping = new HashMap<String, String>();
    try{
      for (String concatenatedPredicateObjectMaps : concatenatedPredicateObjectMapsList) {
        List<String> predicateObjectMaps = new ArrayList<String>(Arrays.asList(concatenatedPredicateObjectMaps.split(",")));
        maps.addAll(predicateObjectMaps);
        if (maps.size() > limit) {
          bloomfilterMapping.putAll(util.getBloomFiltersForMaps(tripleStoreUrl, null, maps));
          maps = new HashSet<String>();
        }
      }
      if (maps.size() > 0)
        bloomfilterMapping.putAll(util.getBloomFiltersForMaps(tripleStoreUrl, null, maps));
    } catch (KarmaException e1) {
      e1.printStackTrace();
    }
    while(concatenatedPredicateObjectMapsListItr.hasNext() && predicatesItr.hasNext() && otherClassesItr.hasNext())
    {

      String concatenatedPredicateObjectMaps = concatenatedPredicateObjectMapsListItr.next();
      List<String> predicateObjectMaps = new ArrayList<String>(Arrays.asList(concatenatedPredicateObjectMaps.split(",")));
      String predicate =  predicatesItr.next();
      String otherClass = otherClassesItr.next();
      try {
        KR2RMLBloomFilter intersectionBF = new KR2RMLBloomFilter(KR2RMLBloomFilter.defaultVectorSize, KR2RMLBloomFilter.defaultnbHash, Hash.JENKINS_HASH);
        for (String triplemap : predicateObjectMaps) {
          String serializedBloomFilter = bloomfilterMapping.get(triplemap);
          if (serializedBloomFilter != null) {
            KR2RMLBloomFilter bf = new KR2RMLBloomFilter();
            bf.populateFromCompressedAndBase64EncodedString(serializedBloomFilter);
            intersectionBF.or(bf);
          }
        }
        System.out.println(predicate + " " + intersectionBF.estimateNumberOfHashedValues());
        intersectionBF.and(uris);
        int estimate = intersectionBF.estimateNumberOfHashedValues();
        JSONObject obj = new JSONObject();
        obj.put("predicate", predicate);
        obj.put("otherClass", otherClass);
        obj.put("estimate", estimate);
        obj.put("incoming", "false");
        //          array.put(obj);
        objects.add(obj);

      } catch (Exception e) {
        LOG.error("Unable to process bloom filter: " + e.getMessage());
      }
    }

    Collections.sort(objects, new Comparator<JSONObject>() {

      @Override
      public int compare(JSONObject a, JSONObject b) {
        return b.getInt("estimate") - a.getInt("estimate");
      }
    });
    for (JSONObject obj : objects) {
      array.put(obj);
    }
    return new UpdateContainer(new AbstractUpdate() {

      @Override
      public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) {
        System.out.println(array.toString());
        pw.print(array.toString());
View Full Code Here

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

    return CommandType.notInHistory;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    UpdateContainer container = new UpdateContainer();
    Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
    container.add(new AlignmentSVGVisualizationUpdate(worksheetId, alignment));
    return container;
  }
View Full Code Here

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

      WorksheetCommandHistoryExecutor histExecutor = new WorksheetCommandHistoryExecutor(worksheetId, workspace);
      histExecutor.executeAllCommands(historyJSON);
    } catch (Exception e) {
      String msg = "Error occured while applying history!";
      logger.error(msg, e);
      return new UpdateContainer(new ErrorUpdate(msg));
    }
   
    // Add worksheet updates that could have resulted out of the transformation commands
    UpdateContainer c = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, SuperSelectionManager.DEFAULT_SELECTION);
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    c.add(new InfoUpdate("History successfully applied!"));
    return c;
  }
View Full Code Here

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

      }
    }
   
   
    // Prepare the output to be sent
    UpdateContainer c = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, SuperSelectionManager.DEFAULT_SELECTION);
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    return c;
  }
View Full Code Here

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

    // Change the column name
    columnNode.setColumnName(oldColumnName);
   
    // Prepare the output to be sent
 
    UpdateContainer c = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, SuperSelectionManager.DEFAULT_SELECTION);
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    return c;
  }
View Full Code Here

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

  }

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

    } catch (Exception e) {
      logger.error("Error occured while generating the model Reason:.", e);
      return new UpdateContainer(new ErrorUpdate(
          "Error occured while generating the model for the source."));
    }
    c.add(new TagsUpdate());
   
    return c;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.