Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.Node


        hash.put(hashValue, ids);
     
     
      for (String key : hash.keySet()) {
        ArrayList<String> r = hash.get(key);
        Node node = parentRow.getNeighbor(newNode.getId());
        Row lastRow = CloneTableUtils.cloneDataTable(factory.getRow(r.get(0)), node.getNestedTable(), ht, newht, keyhnodes, factory, selection);
        for (String rowid : r) {
          Row cur = factory.getRow(rowid);
          Table dataTable = lastRow.getNeighborByColumnName("Values", factory).getNestedTable();
          CloneTableUtils.cloneDataTable(cur, dataTable, ht, newValueTable, valuehnodes, factory, selection);
        }
View Full Code Here


            for (int i = 0; i < sampleSize; i++) {
              int r = gen.nextInt(nodes.size());
              while (randomNums.contains(r))
                r = gen.nextInt(nodes.size());
              randomNums.add(r);
              Node node = nodes.get(r);
              JSONObject jsonRecord = new JSONObject();
              jsonRecord.put(JsonKeys.id.name(), node.getId());
              String originalVal = node.getValue().asString();
              originalVal = originalVal == null ? "" : originalVal;
              jsonRecord.put(JsonKeys.value.name(), originalVal);
              requestJsonArray.put(jsonRecord);
            }
          }
View Full Code Here

      }
      Map<String, String> keyMapping = new HashMap<String, String>();
      Map<String, String> HNodeidMapping = new HashMap<String, String>();
      ArrayList<Row> rows = t.getRows(0, t.getNumRows(), selection);
      for (Row row : rows) {
        Node n = row.getNode(key.getId());
        keyMapping.put(HashValueManager.getHashValue(oldws, n.getId(), factory), n.getValue().asString());
      }
      for (String mapkey : keyMapping.keySet()) {
        HNode hn = newHT.getHNodeFromColumnName(keyMapping.get(mapkey).toLowerCase().replace('/', '_'));
        if (hn == null) {
          HNode n = newHT.addHNode(keyMapping.get(mapkey).toLowerCase().replace('/', '_'), HNodeType.Transformation, oldws, factory);
          outputColumns.add(n.getId());
          HTable htt = n.addNestedTable("values", oldws, factory);
          outputColumns.add(htt.addHNode("Values", HNodeType.Transformation, oldws, factory).getId());
          HNodeidMapping.put(keyMapping.get(mapkey), n.getId());
        }
        else
          HNodeidMapping.put(keyMapping.get(mapkey), hn.getId());
      }
      Map<String, ArrayList<String>> hash = new HashMap<String, ArrayList<String>>();
      for (Row row : rows) {
        String hashValue = HashValueManager.getHashValue(row, hnodeIds);
        ArrayList<String> ids = hash.get(hashValue);
        if (ids == null)
          ids = new ArrayList<String>();
        ids.add(row.getId());
        hash.put(hashValue, ids);
        //System.out.println("Hash: " + HashValueManager.getHashValue(row, hnodeIDs));
      }

      for (String hashKey : hash.keySet()) {
        ArrayList<String> r = hash.get(hashKey);
        Node node = parentRow.getNeighbor(newNode.getId());
        Row lastRow = CloneTableUtils.cloneDataTable(factory.getRow(r.get(0)), node.getNestedTable(),
            parentHT, newHT, hnodes, factory, selection);
        for (String rowid : r) {
          Row cur = factory.getRow(rowid);
          String newId = HNodeidMapping.get(cur.getNode(key.getId()).getValue().asString());
          Node newnode = lastRow.getNode(newId);
          Node oldnode = cur.getNode(value.getId());
          Row tmprow = newnode.getNestedTable().addRow(factory);
          tmprow.getNeighborByColumnName("Values", factory).setValue(oldnode.getValue().asString(), oldnode.getStatus(), factory);
          //newnode.setValue(oldnode.getValue().asString(), oldnode.getStatus(), factory);
        }
        resultRows.add(lastRow);
      }
    }
View Full Code Here

    }
    CloneTableUtils.cloneHTable(oldws.getHeaders(), newws.getHeaders(), newws, factory, hnodes, selection);
    Map<String, String> keyMapping = new HashMap<String, String>();
    Map<String, String> HNodeidMapping = new HashMap<String, String>();
    for (Row row : rows) {
      Node n = row.getNode(key.getId());
      keyMapping.put(HashValueManager.getHashValue(oldws, n.getId(), factory), n.getValue().asString());
    }
    for (String mapkey : keyMapping.keySet()) {
      HNode n = newws.getHeaders().addHNode(keyMapping.get(mapkey), HNodeType.Transformation, newws, factory);
      HTable ht = n.addNestedTable("values", newws, factory);
      ht.addHNode("Values", HNodeType.Transformation, newws, factory);
      HNodeidMapping.put(keyMapping.get(mapkey), n.getId());
    }

    Map<String, ArrayList<String>> hash = new TreeMap<String, ArrayList<String>>();
    for (Row row : rows) {
      String hashValue = HashValueManager.getHashValue(row, hnodeIds);
      ArrayList<String> ids = hash.get(hashValue);
      if (ids == null)
        ids = new ArrayList<String>();
      ids.add(row.getId());
      hash.put(hashValue, ids);
    }
    List<Row> resultRows = new ArrayList<Row>();
    for (String hashKey : hash.keySet()) {
      ArrayList<String> r = hash.get(hashKey);
      Row lastRow = CloneTableUtils.cloneDataTable(factory.getRow(r.get(0)), newws.getDataTable(),
          oldws.getHeaders(), newws.getHeaders(), hnodes, factory, selection);
      for (String rowid : r) {
        Row cur = factory.getRow(rowid);
        String newId = HNodeidMapping.get(cur.getNode(key.getId()).getValue().asString());
        Node newnode = lastRow.getNode(newId);
        Node oldnode = cur.getNode(value.getId());
        Row tmprow = newnode.getNestedTable().addRow(factory);
        tmprow.getNeighborByColumnName("Values", factory).setValue(oldnode.getValue().asString(), oldnode.getStatus(), factory);
        //newnode.setValue(oldnode.getValue().asString(), oldnode.getStatus(), factory);
      }
      resultRows.add(lastRow);
    }
    for (Row tmpRow : resultRows) {
View Full Code Here

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

    Collection<Node> nodes = new ArrayList<Node>();
    wk.getDataTable().collectNodes(selectedPath, nodes, selection);
    HashSet<Integer> indSet = this.obtainIndexs(nodes.size());
    int index = 0;
    for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext();) {
      Node node = iterator.next();
      if (indSet.contains(index)) {
        String id = node.getId();
        String originalVal = node.getValue().asString();
        HashMap<String, String> x = new HashMap<String, String>();
        x.put("Org", originalVal);
        x.put("Tar", originalVal);
        x.put("Orgdis", originalVal);
        x.put("Tardis", originalVal);
View Full Code Here

    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(" ", "");;
          builder = new StringBuilder();
          String baseURI = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.baseURI);
          try {
            URI uri = new URI(value);
            if (!uri.isAbsolute() && baseURI != null) {
View Full Code Here

      boolean atLeastOneTermSatisified = false;
      for(TemplateTerm term : terms)
      {
        if(term instanceof ColumnTemplateTerm)
        {
          Node n = partial.getValue((ColumnTemplateTerm)term);
          if(n == null)
          {
            allTermsSatisifed = false;
            continue;
          }
          if(n.getValue() == null || n.getValue().asString() == null || n.getValue().isEmptyValue() || n.getValue().asString().trim().isEmpty())
          {
            allTermsSatisifed = false;
          }
          else
          {
            atLeastOneTermSatisified = true;
          }
          references.put((ColumnTemplateTerm) term, n);
          if(useNodeValue)
          {
            uri.append(n.getValue().asString());
          }
          else
          {
            uri.append("_");
            uri.append(n.getId());
          }
        }
        else
        {
          uri.append(term.getTemplateTermValue());
View Full Code Here

    for (HNode hnode : hnodes) {
      HNode newHNode = newHTable.getHNodeFromColumnName(hnode.getColumnName());
      if (newHNode == null)
        continue;
     
      Node oldNode = oldRow.getNode(hnode.getId());
      Node newNode = newrow.getNode(newHNode.getId());
      if (oldNode == null)
        continue;
      if (!oldNode.hasNestedTable()) {
        newNode.setValue(oldNode.getValue(), oldNode.getStatus(), factory);
      }
      else {         
        cloneDataTable(oldNode.getNestedTable(), newNode.getNestedTable(), hnode.getNestedTable(), newHNode.getNestedTable(), hnode.getNestedTable().getSortedHNodes(), factory, sel);
      }
    }
    return newrow;
  }
View Full Code Here

  }
 
  public static void cloneDataTableExistingRow(Row oldRow, Row newRow, Table newDataTable, HTable oldHTable, HTable newHTable, List<HNode> hnodes, RepFactory factory, Map<String, String> mapping, SuperSelection sel) {
    for (HNode hnode : hnodes) {
      HNode newHNode = factory.getHNode(mapping.get(hnode.getId()));
      Node oldNode = oldRow.getNode(hnode.getId());
      Node newNode = newRow.getNode(newHNode.getId());
      if (oldNode == null)
        continue;
      if (!oldNode.hasNestedTable()) {
        newNode.setValue(oldNode.getValue(), oldNode.getStatus(), factory);
      }
      else {         
        cloneDataTable(oldNode.getNestedTable(), newNode.getNestedTable(), hnode.getNestedTable(), newHNode.getNestedTable(), hnode.getNestedTable().getSortedHNodes(), factory, sel);
      }
    }
  }
View Full Code Here

TOP

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

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.