Package edu.isi.karma.rep.alignment

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


      ColumnNode cn = (ColumnNode)n;
           
      Set<LabeledLink> incomingLinks = this.graph.incomingEdgesOf(n);
      if (incomingLinks != null && incomingLinks.size() == 1) {
        LabeledLink link = incomingLinks.toArray(new LabeledLink[0])[0];
        Node domain = link.getSource();
        SemanticType st = new SemanticType(cn.getHNodeId(), link.getLabel(), domain.getLabel(), Origin.User, 1.0);
        cn.setUserSelectedSemanticType(st);
      } else
        logger.debug("The column node " + ((ColumnNode)n).getColumnName() + " does not have any domain or it has more than one domain.");
    }
  }
View Full Code Here


      }
     
      for (String s : index.keySet()) {
        Collection<Node> nodeGroup = index.get(s);
        if (nodeGroup != null && nodeGroup.size() == 1) {
          Node n = nodeGroup.iterator().next();
          nodeIds.put(n, nodeIdFactory.getNodeId(n.getLabel().getUri()));
        }
      }
 
      nodeIdSets.add(nodeIds);
    }
   
//    List<Node> nodes = new ArrayList<Node>();
//    List<Set<String>> idList = new ArrayList<Set<String>>();
//    Set<List<String>> idProductSets = null;
//    NodeIdFactory nodeIdFactory = new NodeIdFactory();
//    for (String s : index.keySet()) {
//      Collection<Node> nodeGroup = index.get(s);
//      if (nodeGroup == null)
//        continue;
//      nodes.addAll(nodeGroup);
//      Set<String> ids = new TreeSet<String>();
//      for (Node n : nodeGroup) {
//        ids.add(nodeIdFactory.getNodeId(n.getLabel().getUri()));
//      }
//      idList.add(ids);
//     
//    }
//    if (idList != null)
//      idProductSets = Sets.cartesianProduct(idList);
//   
//    int i = 0;
//    for (List<String> ids : idProductSets) {
//      for (Node n : nodes) System.out.println("node: " + n.getLabel().getUri());
//      for (String id : ids) System.out.println("id: " + id);
//
//      for (int j = 0; j < ids.size() && j < nodes.size(); j++)
//        nodeIdSets.get(i).put(nodes.get(j), ids.get(j));
//      i++;
//    }
   
    int interval = numberOfPossibleSets;
    NodeIdFactory nodeIdFactory = new NodeIdFactory();
    for (String s : index.keySet()) {
      Collection<Node> nodeGroup = index.get(s);
      if (nodeGroup != null && nodeGroup.size() > 1) {
        Set<String> ids = new HashSet<String>();
        List<Node> nodes = new ArrayList<Node>();
        nodes.addAll(nodeGroup);
        for (Node n : nodes)
          ids.add(nodeIdFactory.getNodeId(n.getLabel().getUri()));

        Collection<List<String>> permutations = Collections2.permutations(ids);
        List<List<String>> permList = new ArrayList<List<String>>();
        permList.addAll(permutations);
       
View Full Code Here

    String str = "";
    String separator = "|";
   
    if (gp == null || gp.getLength() == 0)
      return null;
    Node target;
   
    if (gp.getStartNode() == null || gp.getStartNode().getLabel() == null)
      return null;
   
    str += gp.getStartNode().getLabel().getUri();
    str += separator;
   
    for (DefaultLink l : gp.getLinks()) {
     
      target = l.getTarget();
      if (target == null)
        return null;
     
      str += l.getUri();
      str += separator;
         
      if (target instanceof InternalNode) {
        if (target.getLabel() == null)
          return null;
        str += l.getUri();
        str += separator;
      }
     
View Full Code Here

      if (count == null) targetNodes.put(key, 1);
      else targetNodes.put(key, ++count);
    }
   
    // Adding the links to the maps
    Node source, target;
    for (LabeledLink l : mainModel.graph.edgeSet()) {     
      source = l.getSource();
      target = l.getTarget();
     
      if (!(source instanceof InternalNode)) continue;
     
      sourceStr = source.getLabel().getUri();
      linkStr = l.getLabel().getUri();
      if (target instanceof InternalNode) targetStr = target.getLabel().getUri();
      else if (target instanceof ColumnNode) {
        ColumnNode cn = mainModel.mappingToSourceColumns.get(target);
        if (cn == null) continue; else targetStr = cn.getId();
      }
      else continue;
     
      key = sourceStr + linkStr + targetStr;
      count = mainLinks.get(key);
      if (count == null) mainLinks.put(key, 1);
      else mainLinks.put(key, ++count);
     
      Set<String> links = mainNodePairToLinks.get(sourceStr + targetStr);
      if (links == null) { links = new HashSet<String>(); mainNodePairToLinks.put(sourceStr + targetStr, links); }
      links.add(linkStr);
    }
    for (LabeledLink l : targetModel.graph.edgeSet()) {
      source = l.getSource();
      target = l.getTarget();
     
      if (!(source instanceof InternalNode)) continue;
     
      sourceStr = source.getLabel().getUri();
      linkStr = l.getLabel().getUri();
      if (target instanceof InternalNode) targetStr = target.getLabel().getUri();
      else if (target instanceof ColumnNode) {
        ColumnNode cn = targetModel.mappingToSourceColumns.get(target);
        if (cn == null) continue; else targetStr = cn.getId();
View Full Code Here

      }
    }
    if (forcedLinks != null) {
      for (LabeledLink l : forcedLinks) {
        if (l.getStatus() == LinkStatus.ForcedByUser) {
          Node source = l.getSource();
          Node target = l.getTarget();
          if (!this.graphBuilder.addLink(source, target, l)) {
            LabeledLink existingLink = this.graphBuilder.getIdToLinkMap().get(l.getId());
            if (existingLink != null) { // the link already exist, but it may not be forced by user
              this.graphBuilder.changeLinkStatus(existingLink, LinkStatus.ForcedByUser);
            }
View Full Code Here

                  domainURI.getUri() + i,
                  typeURI.getDisplayName(), label.split("\\|")[1], probability);
              if (i == graphLastIndex)
                hasLastNodeFromSteinerTree = true;
            } else {
              Node graphNode = alignment.getNodeById(domainURI.getUri() + i);
              if (graphNode != null)
                insertSemanticTypeSuggestion(arr, clazzLocalNameWithPrefix + i + " (add)",
                  graphNode.getUri(),
                  graphNode.getId(),
                  typeURI.getDisplayName(), label.split("\\|")[1], probability);
            }
          }
          // Add an option to add one more node for the domain
          if (hasLastNodeFromSteinerTree)
            insertSemanticTypeSuggestion(arr, clazzLocalNameWithPrefix + (graphLastIndex+1) + " (add)",
                domainURI.getUri(), domainURI.getUri() + (graphLastIndex+1),
              typeURI.getDisplayName(), label.split("\\|")[1], probability);
        }
      } else {
        Label typeURI = ontMgr.getUriLabel(label);
        if(typeURI == null)
          continue;
       
        String clazzLocalNameWithPrefix = typeURI.getDisplayName();
       
        int graphLastIndex = alignment.getLastIndexOfNodeUri(typeURI.getUri());
        if (graphLastIndex == -1) { // No instance present in the graph
          insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + "1 (add)", typeURI.getUri(), typeURI.getUri() + "1", probability);
        } else {
          boolean hasLastNodeFromSteinerTree = false;
          for (int i=1; i<= graphLastIndex; i++) {
            if (steinerTreeNodeIds.contains(typeURI.getUri() + (graphLastIndex))) {
              insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + i, typeURI.getUri(), typeURI.getUri() + i, probability);
            } else {
              Node graphNode = alignment.getNodeById(typeURI.getUri() + i);
              if (graphNode != null)
                insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + i + " (add)", graphNode.getUri(), graphNode.getId(), probability);
            }
          }
          // Add an option to add one more node for the domain
          if (hasLastNodeFromSteinerTree)
            insertSemanticTypeSuggestion(arr, "", "", clazzLocalNameWithPrefix + (graphLastIndex+1) + " (add)", typeURI.getUri(), typeURI.getUri() + (graphLastIndex+1), probability);
View Full Code Here

 
//    List<HNodePath> paths = new ArrayList<>();
    for (HNodePath path : worksheet.getHeaders().getAllPaths()) {
      HNode node = path.getLeaf();
      String hNodeId = node.getId();
      Node n = alignment.getNodeById(hNodeId);
      if (n == null) {
//        paths.add(path);
        alignment.addColumnNode(hNodeId, node.getColumnName(), null);
//      } else if (n instanceof ColumnNode) {
//        ColumnNode c =  ((ColumnNode)n);
View Full Code Here

      new WeightedMultigraph<Node, DefaultLink>(DefaultLink.class);
   
    Set<DefaultLink> edges = g2.edgeSet();
    DijkstraShortestPath<Node, DefaultLink> path;
   
    Node source, target;
   
    for (DefaultLink edge : edges) {
      source = edge.getSource();
      target = edge.getTarget();
     
View Full Code Here

      if (g5.degreeOf(vertex) == 1 && steinerNodes.indexOf(vertex) == -1) {
        nonSteinerLeaves.add(vertex);
      }
    }
   
    Node source, target;
    for (int i = 0; i < nonSteinerLeaves.size(); i++) {
      source = nonSteinerLeaves.get(i);
      do {
        DefaultLink e = g5.edgesOf(source).toArray(new DefaultLink[0])[0];
        target = this.graph.getEdgeTarget(e);
View Full Code Here

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

    if(metaPropertyId.endsWith(" (add)"))
      metaPropertyId = metaPropertyId.substring(0, metaPropertyId.length()-5).trim();
   
  if (metaPropertyName.equals(METAPROPERTY_NAME.isUriOfClass)) {
      Node classNode = alignment.getNodeById(metaPropertyId);
      if (semanticTypeAlreadyExists) {
        clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
            oldDomainNode, alignment, classNode);
      }

      if (classNode == null) {
        Label classNodeLabel = ontMgr.getUriLabel(metaPropertyUri);
        if (classNodeLabel == null) {
          String errorMessage = "Error while setting a classLink. MetaPropertyUri '"
              + metaPropertyUri
              + "' should be in the Ontology Manager, but it is not.";
          logger.error(errorMessage);
          return new UpdateContainer(new ErrorUpdate(errorMessage));
        }
        classNode = alignment.addInternalNode(classNodeLabel);
      }

      LabeledLink newLink = alignment.addClassInstanceLink(classNode, columnNode,
          LinkKeyInfo.UriOfInstance);
      alignment.changeLinkStatus(newLink.getId(),
          LinkStatus.ForcedByUser);
     
      // Create the semantic type object
      newType = new SemanticType(hNodeId,
          ClassInstanceLink.getFixedLabel(), classNode.getLabel(),
          SemanticType.Origin.User, 1.0);
    } else if (metaPropertyName
        .equals(METAPROPERTY_NAME.isSpecializationForEdge)) {
      LabeledLink propertyLink = alignment.getLinkById(metaPropertyId);
      if (propertyLink == null) {
        String errorMessage = "Error while specializing a link. The DefaultLink '"
            + metaPropertyId
            + "' should already be in the alignment, but it is not.";
        logger.error(errorMessage);
        return new UpdateContainer(new ErrorUpdate(errorMessage));
      }

      Node classInstanceNode = alignment.getNodeById(LinkIdFactory
          .getLinkSourceId(metaPropertyId));
      if (semanticTypeAlreadyExists) {
        clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
            oldDomainNode, alignment, classInstanceNode);
      }

      if (propertyLink instanceof DataPropertyLink) {
        String targetHNodeId = ((ColumnNode) propertyLink.getTarget())
            .getHNodeId();
        LabeledLink newLink = alignment.addDataPropertyOfColumnLink(classInstanceNode,
            columnNode, targetHNodeId, propertyLink.getId());
        alignment.changeLinkStatus(newLink.getId(),
            LinkStatus.ForcedByUser);
       
        // Create the semantic type object
        newType = new SemanticType(hNodeId,
            DataPropertyOfColumnLink.getFixedLabel(),
            classInstanceNode.getLabel(), SemanticType.Origin.User,
            1.0);
      } else if (propertyLink instanceof ObjectPropertyLink) {
        LabeledLink newLink = alignment.addObjectPropertySpecializationLink(
            classInstanceNode, columnNode, propertyLink.getId());
        alignment.changeLinkStatus(newLink.getId(),
            LinkStatus.ForcedByUser);

        // Create the semantic type object
        newType = new SemanticType(hNodeId,
            ObjectPropertySpecializationLink.getFixedLabel(),
            classInstanceNode.getLabel(), SemanticType.Origin.User,
            1.0);
      }

    } else if (metaPropertyName.equals(METAPROPERTY_NAME.isSubclassOfClass)) {
      Node classNode = alignment.getNodeById(metaPropertyId);
      if (semanticTypeAlreadyExists) {
        clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
            oldDomainNode, alignment, classNode);
      }

      if (classNode == null) {
        Label classNodeLabel = ontMgr.getUriLabel(metaPropertyUri);
        if (classNodeLabel == null) {
          String errorMessage = "Error while setting an advances subclass. MetaPropertyValue '"
              + metaPropertyUri
              + "' should be in the Ontology Manager, but it is not.";
          logger.error(errorMessage);
          return new UpdateContainer(new ErrorUpdate(errorMessage));
        }
        classNode = alignment.addInternalNode(classNodeLabel);
      }
      LabeledLink newLink = alignment.addColumnSubClassOfLink(classNode, columnNode);
      alignment.changeLinkStatus(newLink.getId(),
          LinkStatus.ForcedByUser);
     
      // Create the semantic type object
      newType = new SemanticType(hNodeId,
          ColumnSubClassLink.getFixedLabel(), classNode.getLabel(),
          SemanticType.Origin.User, 1.0);
    }

    columnNode.setUserSelectedSemanticType(newType);

View Full Code Here

TOP

Related Classes of edu.isi.karma.rep.alignment.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.