Package edu.isi.karma.rep.alignment

Examples of edu.isi.karma.rep.alignment.ColumnNode


          }
          domain = alignment.addInternalNode(label);
        }
         
        // Check if a semantic type already exists for the column
        ColumnNode columnNode = alignment.getColumnNodeByHNodeId(hNodeId);
        columnNode.setRdfLiteralType(rdfLiteralType);
        List<LabeledLink> columnNodeIncomingLinks = alignment.getIncomingLinks(columnNode.getId());
        LabeledLink oldIncomingLinkToColumnNode = null;
        Node oldDomainNode = null;
        if (columnNodeIncomingLinks != null && !columnNodeIncomingLinks.isEmpty()) { // SemanticType already assigned
          semanticTypeAlreadyExists = true;
          oldIncomingLinkToColumnNode = columnNodeIncomingLinks.get(0);
          oldDomainNode = oldIncomingLinkToColumnNode.getSource();
        }

        if (type.getBoolean(ClientJsonKeys.isPrimary.name())) {
         
          if (isClassSemanticType) {
            if (semanticTypeAlreadyExists && oldDomainNode == domain) {
              newLink = oldIncomingLinkToColumnNode;
              // do nothing;
            } else if (semanticTypeAlreadyExists) {
              alignment.removeLink(oldIncomingLinkToColumnNode.getId());
//              alignment.removeNode(oldDomainNode.getId());
              newLink = alignment.addClassInstanceLink(domain, columnNode, LinkKeyInfo.None);
            } else {
              newLink = alignment.addClassInstanceLink(domain, columnNode, LinkKeyInfo.None);
            }
          }
          // Property semantic type
          else {

            // When only the link changes between the class node and the internal node (domain)
            if (semanticTypeAlreadyExists && oldDomainNode == domain) {
              alignment.removeLink(oldIncomingLinkToColumnNode.getId());
              newLink = alignment.addDataPropertyLink(domain, columnNode, linkLabel);
            }
            // When there was an existing semantic type and the new domain is a new node in the graph and semantic type already existed
            else if (semanticTypeAlreadyExists) {
              alignment.removeLink(oldIncomingLinkToColumnNode.getId());
//              alignment.removeNode(oldDomainNode.getId());
              newLink = alignment.addDataPropertyLink(domain, columnNode, linkLabel);
            } else {
              newLink = alignment.addDataPropertyLink(domain, columnNode, linkLabel);
            }           
          }
        } else { // Synonym semantic type
          SemanticType synType = new SemanticType(hNodeId, linkLabel, domain.getLabel(), SemanticType.Origin.User, 1.0);
          typesList.add(synType);
        }
       
        // Create the semantic type object
        newType = new SemanticType(hNodeId, linkLabel, domain.getLabel(), SemanticType.Origin.User, 1.0);
//        newType = new SemanticType(hNodeId, classNode.getLabel(), null, SemanticType.Origin.User, 1.0,isPartOfKey);
        columnNode.setUserSelectedSemanticType(newType);
       
        if(newLink != null) {
          alignment.changeLinkStatus(newLink.getId(),
              LinkStatus.ForcedByUser);
        }
View Full Code Here


        }
      }
      HTable headers = vWorksheet.getWorksheet().getHeaders();
      for (int columnNum = 0; columnNum < hNodeIdList.size(); columnNum++) {
        String hNodeId = hNodeIdList.get(columnNum);
        ColumnNode node = columnNodes.get(hNodeId);
        JSONObject anchorObj;
        HNode hNode = headers.getHNode(hNodeId, true);
        if (node != null) {
          anchorObj = getForceLayoutColumnJsonObject(columnNum,
              hNode.getColumnName(), node.getId(), node.getType()
                  .name(), node.isForced(), hNodeId,
              node.getUri(), columnNum);
        } else {
         
          anchorObj = getForceLayoutColumnJsonObject(columnNum,
              hNode.getColumnName(), hNode.getId(), "ColumnNode",
              false, hNodeId, "", columnNum);
        }
        anchorsArr.put(anchorObj);
        verticesIndex.put(node, columnNum);
      }

      int nodesIndexcounter = hNodeIdList.size();

      if (alignmentGraph != null
          && alignmentGraph.vertexSet().size() != 0) {
        /** Add the nodes **/
        Set<Node> nodes = alignmentGraph.vertexSet();
        for (Node node : nodes) {
          /** Add the semantic type information **/
          if (node instanceof ColumnNode) {
            // Already handled
          } else {
            boolean isUri = false;
            if(node instanceof LiteralNode && ((LiteralNode)node).isUri())
              isUri = true;
            JSONObject nodeObj = getForceLayoutNodeJsonObject(
                nodesIndexcounter, node.getLocalId(),
                node.getId(), node.getType().name(),
                node.isForced(), node.getUri(), isUri);
            nodesArr.put(nodeObj);
            verticesIndex.put(node, nodesIndexcounter++);
          }
        }

View Full Code Here

          int height = nodeHeightsMap.get(node);
          /** Add the hnode ids of the columns that this vertex covers **/
          JSONArray hNodeIdsCoveredByVertex = new JSONArray();
          for (Node v : nodeCoverage.get(node)) {
            if (v instanceof ColumnNode) {
              ColumnNode cNode = (ColumnNode) v;
              hNodeIdsCoveredByVertex.put(cNode.getHNodeId());
            }
          }
          String hNodeId = "";
          /** Add the semantic type information **/
          if (node instanceof ColumnNode) {
            ColumnNode cNode = (ColumnNode) node;
            hNodeId = cNode.getHNodeId();
            hNodeIdsAdded.add(cNode.getHNodeId());
          }

          boolean isUri = false;
          if(node instanceof LiteralNode)
            isUri = ((LiteralNode)node).isUri();

          JSONObject nodeObj = getNormalLayoutNodeJsonObject(node.getLocalId(),
              node.getId(), node.getType().name(), height,
              node.isForced(), hNodeIdsCoveredByVertex,
              hNodeId, node.getUri(), isUri);

          nodesArr.put(nodeObj);
          verticesIndex.put(node, nodesIndexcounter++);
        }
        /*** Add the links ***/
        Set<LabeledLink> links = alignmentGraph.edgeSet();
        for (LabeledLink link : links) {
          Node source = link.getSource();
          Integer sourceIndex = verticesIndex.get(source);
          Node target = link.getTarget();
          Integer targetIndex = verticesIndex.get(target);
          Set<LabeledLink> outEdges = alignmentGraph
              .outgoingEdgesOf(target);
          if (sourceIndex == null || targetIndex == null) {
            logger.error("Edge vertex index not found!");
            continue;
          }
          JSONObject linkObj = new JSONObject();
          linkObj.put(JsonKeys.source.name(), sourceIndex);
          linkObj.put(JsonKeys.target.name(), targetIndex);
          linkObj.put(JsonKeys.sourceNodeId.name(), source.getId());
          linkObj.put(JsonKeys.targetNodeId.name(), target.getId());
          linkObj.put(JsonKeys.label.name(), link.getLabel()
              .getLocalName());
          linkObj.put(JsonKeys.id.name(), link.getId() + "");
          linkObj.put(JsonKeys.linkStatus.name(), link.getStatus()
              .name());
          linkObj.put(JsonKeys.linkUri.name(), link.getLabel()
              .getUri());
          if (target.getType() == NodeType.ColumnNode
              && outEdges.isEmpty()) {
            linkObj.put(JsonKeys.linkType.name(),
                JsonValues.holderLink.name());
          }
          linksArr.put(linkObj);
          if (link.getType() == LinkType.ClassInstanceLink
              && target instanceof ColumnNode) {
            ColumnNode cNode = (ColumnNode) target;
            // Add the holder vertex object and the link that
            // attaches nodes to the columns
            JSONArray hNodeIdsCoveredByVertex_holder = new JSONArray();
            hNodeIdsCoveredByVertex_holder.put(cNode.getHNodeId());

            JSONObject vertObj_holder = getNormalLayoutNodeJsonObject(
                JsonValues.key.name(), source.getId()
                    + "_holder",
                NodeType.ColumnNode.name(), 0, false,
                hNodeIdsCoveredByVertex_holder,
                cNode.getHNodeId(), cNode.getLabel().getUri(), false);

            nodesArr.put(vertObj_holder);
            nodesIndexcounter++;
            // Add the holder link
            JSONObject linkObj_holder = getNormalLayoutLinkJsonObject(
                JsonValues.key.name(), "", nodesIndexcounter,
                nodesIndexcounter - 1, "", "", "", "");
            linksArr.put(linkObj_holder);
          }
          if (link.getType() == LinkType.DataPropertyOfColumnLink) {
            DataPropertyOfColumnLink dpLink = (DataPropertyOfColumnLink) link;
            String startHNodeId = dpLink
                .getSpecializedColumnHNodeId();
            // Get height of the class instance node
            int height = maxTreeHeight
                - nodeHeightsMap.get(link.getSource());
            // Add 2 more holder nodes
            // Start node
            JSONArray hNodeIdsCoveredByVertex_holder = new JSONArray();
            boolean isSUri = false;
            if(source instanceof LiteralNode) {
              isSUri = ((LiteralNode)source).isUri();
            }
             
            hNodeIdsCoveredByVertex_holder.put(startHNodeId);

            JSONObject startNode = getNormalLayoutNodeJsonObject("",
                source.getId() + "_holder",
                JsonValues.DataPropertyOfColumnHolder.name(),
                height - 0.35, false,
                hNodeIdsCoveredByVertex_holder, startHNodeId,
                source.getLabel().getUri(), isSUri);

            nodesArr.put(startNode);
            nodesIndexcounter++;
            // End node
            String endHNodeId = ((ColumnNode) link.getTarget())
                .getHNodeId();
            JSONArray hNodeIdsCoveredByVertex_holder_2 = new JSONArray();
            hNodeIdsCoveredByVertex_holder_2.put(endHNodeId);

            boolean isTUri = false;
            if(target instanceof LiteralNode) {
              isTUri = ((LiteralNode)target).isUri();
            }
           
            JSONObject endNode = getNormalLayoutNodeJsonObject("",
                target.getId() + "_holder",
                JsonValues.DataPropertyOfColumnHolder.name(),
                height - 0.35, false,
                hNodeIdsCoveredByVertex_holder_2, endHNodeId,
                target.getLabel().getUri(), isTUri);

            nodesArr.put(endNode);
            nodesIndexcounter++;
            // Add the horizontal link
            JSONObject linkObj_holder = getNormalLayoutLinkJsonObject("", "",
                nodesIndexcounter - 2, nodesIndexcounter - 1,
                JsonValues.horizontalDataPropertyLink.name(),
                "", "", "");
            linksArr.put(linkObj_holder);
          } else if (link.getType() == LinkType.ObjectPropertySpecializationLink) {
            ObjectPropertySpecializationLink opLink = (ObjectPropertySpecializationLink) link;
            String specializedLinkId = opLink
                .getSpecializedLinkId();
            // Get height of the class instance node
            Node specializedLinkTarget = this.alignment
                .getNodeById(LinkIdFactory
                    .getLinkTargetId(specializedLinkId));
            int height = nodeHeightsMap.get(specializedLinkTarget);
            // Add 2 more holder nodes
            // Start node
            JSONArray hNodeIdsCoveredByVertex_holder = new JSONArray();
            for (Node v : nodeCoverage.get(specializedLinkTarget)) {
              if (v instanceof ColumnNode) {
                ColumnNode cNode = (ColumnNode) v;
                hNodeIdsCoveredByVertex_holder.put(cNode
                    .getHNodeId());
              }
            }

            boolean isSUri = false;
View Full Code Here

          String modelKey = domain.getId() + incomingLink.getUri();
          int modelDataPropertyCount = dataPropertyCount.get(modelKey);
          for (int i = 0; i < modelDataPropertyCount - graphDataPropertyCount; i++) {
            Node newNode = null;
            if (n instanceof ColumnNode) {
              ColumnNode c = (ColumnNode)n;
              newNode = new ColumnNode(new RandomGUID().toString(), c.getHNodeId(), c.getColumnName(), c.getRdfLiteralType());
            }
            if (newNode == null) {
              return null;
            }
            if (this.graphBuilder.addNode(newNode)) {
View Full Code Here

    List<SemanticType> candidateSemanticTypes;
    String domainUri = "", propertyUri = "";

    for (Node n : steinerNodes) {

      ColumnNode cn = null;
      if (n instanceof ColumnNode)
        cn = (ColumnNode)n;
      else
        continue;
       
      candidateSemanticTypes = getCandidateSemanticTypes(cn, useCorrectTypes, numberOfCandidates);
      columnSemanticTypes.put(cn, candidateSemanticTypes);

      for (SemanticType semanticType: candidateSemanticTypes) {

        if (semanticType == null ||
            semanticType.getDomain() == null ||
            semanticType.getType() == null) continue;

        domainUri = semanticType.getDomain().getUri();
        propertyUri = semanticType.getType().getUri();

        Integer count = semanticTypesCount.get(domainUri + propertyUri);
        if (count == null) semanticTypesCount.put(domainUri + propertyUri, 1);
        else semanticTypesCount.put(domainUri + propertyUri, count.intValue() + 1);
      }
    }

    long numOfMappings = 1;
   
    for (Node n : steinerNodes) {

      if (n instanceof InternalNode)
        continue;
     
      ColumnNode cn = null;
      if (n instanceof ColumnNode)
        cn = (ColumnNode)n;
      else
        continue;
     
      candidateSemanticTypes = columnSemanticTypes.get(n);
      if (candidateSemanticTypes == null) continue;

      logger.info("===== Column: " + cn.getColumnName());

      Set<SemanticTypeMapping> semanticTypeMappings = new HashSet<SemanticTypeMapping>();
      for (SemanticType semanticType: candidateSemanticTypes) {

        logger.info("\t" + semanticType.getConfidenceScore() + " :" + semanticType.getModelLabelString());

        if (semanticType == null ||
            semanticType.getDomain() == null ||
            semanticType.getType() == null) continue;

        domainUri = semanticType.getDomain().getUri();
        propertyUri = semanticType.getType().getUri();
        Integer countOfSemanticType = semanticTypesCount.get(domainUri + propertyUri);
        logger.debug("count of semantic type: " +  countOfSemanticType);

        if (cn.getDomainNode() != null) {
          SemanticTypeMapping mp = new SemanticTypeMapping(cn, semanticType, cn.getDomainNode(), cn.getDomainLink(), cn);
          semanticTypeMappings.add(mp);
        } else {

          tempSemanticTypeMappings = findSemanticTypeInGraph(cn, semanticType, semanticTypesCount, addedNodes);
          logger.debug("number of matches for semantic type: "
             + (tempSemanticTypeMappings == null ? 0 : tempSemanticTypeMappings.size()));
 
          if (tempSemanticTypeMappings != null)
            semanticTypeMappings.addAll(tempSemanticTypeMappings);
 
          int countOfMatches = tempSemanticTypeMappings == null ? 0 : tempSemanticTypeMappings.size();
          if (countOfMatches < countOfSemanticType)
//          if (countOfMatches == 0) // No struct in graph is matched with the semantic type, we add a new struct to the graph
          {
            SemanticTypeMapping mp = addSemanticTypeStruct(cn, semanticType, addedNodes);
            if (mp != null)
              semanticTypeMappings.add(mp);
          }
        }
      }
      //      System.out.println("number of matches for column " + n.getColumnName() +
      //          ": " + (semanticTypeMappings == null ? 0 : semanticTypeMappings.size()));
      logger.debug("number of matches for column " + cn.getColumnName() +
          ": " + (semanticTypeMappings == null ? 0 : semanticTypeMappings.size()));
      numOfMappings *= (semanticTypeMappings == null || semanticTypeMappings.isEmpty() ? 1 : semanticTypeMappings.size());

      logger.debug("number of candidate steiner sets before update: " + candidateSteinerSets.getSteinerSets().size());
      candidateSteinerSets.updateSteinerSets(semanticTypeMappings);
View Full Code Here

          }
        }


        String nodeId = new RandomGUID().toString();
        ColumnNode target = new ColumnNode(nodeId, nodeId, sourceColumn.getColumnName(), null);
        if (!this.graphBuilder.addNode(target)) continue;;
        addedNodes.add(target);

        String linkId = LinkIdFactory.getLinkId(propertyUri, source.getId(), target.getId())
        LabeledLink link = new DataPropertyLink(linkId, new Label(propertyUri));
       
        boolean result = weight == null ? this.graphBuilder.addLink(source, target, link) : this.graphBuilder.addLink(source, target, link, weight);
        if (!result) continue;;
View Full Code Here

      source = new InternalNode(nodeId, new Label(domainUri));
      if (!this.graphBuilder.addNodeAndUpdate(source, addedNodes)) return null;
    }

    nodeId = new RandomGUID().toString();
    ColumnNode target = new ColumnNode(nodeId, nodeId, sourceColumn.getColumnName(), null);
    if (!this.graphBuilder.addNode(target)) return null;
    addedNodes.add(target);

    String linkId = LinkIdFactory.getLinkId(propertyUri, source.getId(), target.getId())
    LabeledLink link;
    if (propertyUri.equalsIgnoreCase(ClassInstanceLink.getFixedLabel().getUri()))
      link = new ClassInstanceLink(linkId);
    else {
      Label label = this.ontologyManager.getUriLabel(propertyUri);
View Full Code Here

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

        // alignment.changeLinkStatus(linkId, LinkStatus.Normal);
        alignment.removeLink(linkId);
       
        Node node = alignment.getNodeById(targetId);
        if(node instanceof ColumnNode) {
          ColumnNode cNode = (ColumnNode)node;
          worksheet.getSemanticTypes().unassignColumnSemanticType(cNode.getHNodeId());
        }
//      }
    }
  }
View Full Code Here

            n1 = node;
          } else continue;
        }
        else {
          String id = new RandomGUID().toString();
          ColumnNode node = new ColumnNode(id, id, ((ColumnNode)target).getColumnName(), null);
          if (this.graphBuilder.addNode(node)) {
            n1 = node;
          } else continue;
        }

        visitedNodes.put(source, n1);
      }

      if (n2 == null) {

        if (target instanceof InternalNode) {
          String id = nodeIdFactory.getNodeId(target.getLabel().getUri());
          InternalNode node = new InternalNode(id, new Label(target.getLabel()));
          if (this.graphBuilder.addNode(node)) {
            n2 = node;
          } else continue;
        }
        else if(target instanceof LiteralNode) {
          LiteralNode lTarget = (LiteralNode)target;
          String id = nodeIdFactory.getNodeId(lTarget.getValue());
          LiteralNode node = new LiteralNode(id, lTarget.getValue(), new Label(target.getLabel()), lTarget.isUri());
          if (this.graphBuilder.addNode(node)) {
            n2 = node;
          } else continue;
        }
        else {
          String id = new RandomGUID().toString();
          ColumnNode node = new ColumnNode(id, id, ((ColumnNode)target).getColumnName(), null);
          if (this.graphBuilder.addNode(node)) {
            n2 = node;
          } else continue;
        }
View Full Code Here

TOP

Related Classes of edu.isi.karma.rep.alignment.ColumnNode

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.