Package edu.isi.karma.rep.alignment

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


      return;
   
    List<Node> nodes = new ArrayList<Node>(nodeSet);
    logger.debug("number of internal nodes: " + nodes.size());
   
    Node source;
    Node target;
    String sourceUri;
    String targetUri;

    String id = null;
   
    for (int i = 0; i < nodes.size(); i++) {
     
      Node n1 = nodes.get(i);
      for (int j = i+1; j < nodes.size(); j++) {

        Node n2 = nodes.get(j);

        if (n1.equals(n2))
          continue;

        if (this.visitedSourceTargetPairs.contains(n1.getId() + n2.getId()))
          continue;
        if (this.visitedSourceTargetPairs.contains(n2.getId() + n1.getId()))
          continue;
       
        source = n1;
        target = n2;

        sourceUri = source.getUri();
        targetUri = target.getUri();

        id = LinkIdFactory.getLinkId(Uris.DEFAULT_LINK_URI, source.getId(), target.getId());
        CompactLink link = null;

        boolean connected = false;
       
        // order of adding the links is based on the ascending sort of their weight value
       
        if (ModelingConfiguration.getPropertiesDirect()) {
          if (this.ontologyManager.isConnectedByDirectProperty(sourceUri, targetUri) ||
              this.ontologyManager.isConnectedByDirectProperty(targetUri, sourceUri)) {
            logger.debug( sourceUri + " and " + targetUri + " are connected by a direct object property.");
            link = new CompactObjectPropertyLink(id, ObjectPropertyType.Direct);
            addLink(source, target, link);
            connected = true;
          }
        }
       
        if (ModelingConfiguration.getPropertiesIndirect() && !connected) {
          if (this.ontologyManager.isConnectedByIndirectProperty(sourceUri, targetUri) ||
              this.ontologyManager.isConnectedByIndirectProperty(targetUri, sourceUri)) {
            logger.debug( sourceUri + " and " + targetUri + " are connected by an indirect object property.");
            link = new CompactObjectPropertyLink(id, ObjectPropertyType.Indirect);
            addLink(source, target, link);
            connected = true;
          }
        }
       
        if (ModelingConfiguration.getPropertiesWithOnlyRange() && !connected) {
          if (this.ontologyManager.isConnectedByDomainlessProperty(sourceUri, targetUri) ||
              this.ontologyManager.isConnectedByDomainlessProperty(targetUri, sourceUri)) {
            logger.debug( sourceUri + " and " + targetUri + " are connected by an object property whose range is " + sourceUri + " or " + targetUri);
            link = new CompactObjectPropertyLink(id, ObjectPropertyType.WithOnlyRange);
            addLink(source, target, link);
            connected = true;
          }
        }
       
        if (ModelingConfiguration.getPropertiesWithOnlyDomain() && !connected) {
          if (this.ontologyManager.isConnectedByRangelessProperty(sourceUri, targetUri) ||
              this.ontologyManager.isConnectedByRangelessProperty(targetUri, sourceUri)) {
            logger.debug( sourceUri + " and " + targetUri + " are connected by an object property whose domain is " + sourceUri + " or " + targetUri);
            link = new CompactObjectPropertyLink(id, ObjectPropertyType.WithOnlyDomain);
            addLink(source, target, link)
            connected = true;
          }
        }
       
        if (ModelingConfiguration.getPropertiesSubClass() && !connected) {
          if (this.ontologyManager.isSubClass(sourceUri, targetUri, false) ||
              this.ontologyManager.isSubClass(targetUri, sourceUri, false)) {
            logger.debug( sourceUri + " and " + targetUri + " are connected by a subClassOf relation.");
            link = new CompactSubClassLink(id);
            addLink(source, target, link);
            connected = true;
          }
        }
       
        if (ModelingConfiguration.getPropertiesWithoutDomainRange() && !connected) {
          if (this.ontologyManager.isConnectedByDomainlessAndRangelessProperty(sourceUri, targetUri)) {// ||
  //            this.ontologyManager.isConnectedByDomainlessAndRangelessProperty(targetUri, sourceUri)) {
            link = new CompactObjectPropertyLink(id, ObjectPropertyType.WithoutDomainAndRange);
            addLink(source, target, link);
            connected = true;
          }
        }

        if (!connected) {
          this.visitedSourceTargetPairs.add(n1.getId() + n2.getId());
          logger.debug("did not put a link between (" + n1.getId() + ", " + n2.getId() + ")");
        }
      }
    }

    logger.debug("exit>");
View Full Code Here


      Set<Node> matchedNodes = this.graphBuilder.getUriToNodesMap().get(uri);
      int graphNodeCount = matchedNodes == null ? 0 : matchedNodes.size();
     
      for (int i = 0; i < modelNodeCount - graphNodeCount; i++) {
        String id = this.nodeIdFactory.getNodeId(uri);
        Node n = new InternalNode(id, new Label(uri));
        if (this.graphBuilder.addNode(n))
          addedNodes.add((InternalNode)n);
      }
    }
   
    for (Node n : model.getGraph().vertexSet()) {
      if (n instanceof InternalNode) {
        Set<Node> matchedNodes = this.graphBuilder.getUriToNodesMap().get(n.getUri());
        internalNodeMatches.put(n, matchedNodes);
      }
    }

    return internalNodeMatches;
View Full Code Here

 
    Alignment alignment = AlignmentManager.Instance().getAlignment(
        alignmentId);

    final UpdateContainer uc = new UpdateContainer();
    Node node = alignment.getNodeById(nodeId);
    if(node instanceof LiteralNode) {
      final LiteralNode lNode = (LiteralNode)node;
      uc.add(new AbstractUpdate() {

        @Override
View Full Code Here

        Set<LabeledLink> incomingLinks = model.getGraph().incomingEdgesOf(n);
        if (incomingLinks == null || incomingLinks.isEmpty())
          continue;
        if (incomingLinks != null && incomingLinks.size() == 1) {
          LabeledLink[] incomingLinksArray = incomingLinks.toArray(new LabeledLink[0]);
          Node domain = incomingLinksArray[0].getSource();
          String linkUri =  incomingLinksArray[0].getUri();
          String key =  domain.getId() + linkUri;
          Integer count = dataPropertyCount.get(key);
          if (count == null) dataPropertyCount.put(key, 1);
          else dataPropertyCount.put(key, count.intValue() + 1);
          modelNodeDomains.put(n, domain);
          nodeToDataProperty.put(n, incomingLinksArray[0]);
        } else {
          logger.debug("The column node " + ((ColumnNode)n).getColumnName() + " does not have any domain or it has more than one domain.");
          continue;
        }
      }
    }
   
    for (Node n : model.getGraph().vertexSet()) {
      Set<Node> matches = new HashSet<Node>();
      if (n instanceof ColumnNode) {
        Node domain = modelNodeDomains.get(n);
        LabeledLink incomingLink = nodeToDataProperty.get(n);
        Set<Node> matchedNodes = this.graphBuilder.getUriToNodesMap().get(domain.getUri());
        if (matchedNodes == null || matchedNodes.isEmpty()) {
          logger.error("no match found for the node " + domain.getUri() + "in the graph");
          return null;
        }
        for (Node m : matchedNodes) {
          String graphKey = m.getId() + incomingLink.getUri();
          Set<Node> dataPropertyColumnNodes = this.graphBuilder.getNodeDataProperties().get(graphKey);
          Integer graphDataPropertyCount = this.graphBuilder.getNodeDataPropertyCount().get(graphKey);
          if (graphDataPropertyCount == null) graphDataPropertyCount = 0;
          if (dataPropertyColumnNodes != null) {
            for (Node cn : dataPropertyColumnNodes) {
              matches.add(cn);
            }
          }
          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)) {
              matches.add(newNode);
              String linkId = LinkIdFactory.getLinkId(incomingLink.getUri(), m.getId(), newNode.getId());
              DataPropertyLink link = new DataPropertyLink(linkId, new Label(incomingLink.getLabel()));
              this.graphBuilder.addLink(m, newNode, link);
            }
          }
          columnNodeMatches.put(n, matches);
View Full Code Here

  public List<LabeledLink> getPossibleLinks(String sourceId, String targetId, LinkType linkType,
      ObjectPropertyType objectProertyType) {
   
    List<LabeledLink> sortedLinks = new ArrayList<LabeledLink>();

    Node source = this.idToNodeMap.get(sourceId);
    Node target = this.idToNodeMap.get(targetId);
   
    if (source == null || target == null) {
      logger.debug("Cannot find source or target in the graph.");
      return sortedLinks;
    }

    if (source instanceof ColumnNode || target instanceof ColumnNode) {
      logger.debug("Source or target is a column node.");
      return sortedLinks;
    }

    String sourceUri, targetUri;
    sourceUri = source.getUri();
    targetUri = target.getUri();

    HashSet<String> links =
        this.ontologyManager.getPossibleUris(sourceUri, targetUri);

    String id;
View Full Code Here

    } else {
      for (int i = 0; i < mappings.size(); i++) {
        HashMap<Node,Node> nodeMap = mappings.get(i);
        for (Node n : matchedNodes) {
          if (n instanceof ColumnNode) {
            Node modelDomain = modelNodeDomains.get(node);
            Node correspondingMatch = nodeMap.get(modelDomain);
            if ( ((ColumnNode)n).getDomainNode() != correspondingMatch)
              continue;
           
          }
          HashMap<Node,Node> newMapping = new HashMap<Node,Node>(nodeMap);
View Full Code Here

      return null;
    }
   
    logger.debug(model.getId() + " --> number of mappings: " + mappings.size());
   
    Node source, target;
    Node n1, n2;

    int index = 1;
//    int i = 0;
    for (HashMap<Node,Node> mapping : mappings) {
      String indexedModelId = generateLinkModelId(modelId, index++); // modelId
      for (LabeledLink e : model.getGraph().edgeSet()) {
       
        source = e.getSource();
        target = e.getTarget();
       
        n1 = mapping.get(source);
        if (n1 == null) {
//          logger.warn("the mappings does not include the source node " + source.getId());
          continue;
        }
       
        n2 = mapping.get(target);
        if (n2 == null) {
//          logger.warn("the mappings does not include the target node " + target.getId());
          continue;
        }
        String id = LinkIdFactory.getLinkId(e.getUri(), n1.getId(), n2.getId());
        LabeledLink l = this.graphBuilder.getIdToLinkMap().get(id);
        if (l != null) {
          int numOfPatterns = l.getModelIds().size();
//          this.graphBuilder.changeLinkWeight(l, ModelingParams.PATTERN_LINK_WEIGHT);
//          this.graphBuilder.changeLinkWeight(l, ModelingParams.PATTERN_LINK_WEIGHT / (double) (numOfPatterns + 1) );
          if (n2 instanceof InternalNode)
            this.graphBuilder.changeLinkWeight(l, ModelingParams.PATTERN_LINK_WEIGHT - (0.00001 * numOfPatterns) );
          else
            this.graphBuilder.changeLinkWeight(l, ModelingParams.PATTERN_LINK_WEIGHT);
          l.getModelIds().add(indexedModelId);
          n1.getModelIds().add(indexedModelId);
          n2.getModelIds().add(indexedModelId);
        } else {
//          System.out.println("added links: " + i);
//          i++;
          LabeledLink link;
          if (e instanceof DataPropertyLink)
            link = new DataPropertyLink(id, e.getLabel());
          else if (e instanceof ObjectPropertyLink)
            link = new ObjectPropertyLink(id, e.getLabel(), ((ObjectPropertyLink)e).getObjectPropertyType());
          else if (e instanceof SubClassLink)
            link = new SubClassLink(id);
          else if (e instanceof ClassInstanceLink)
            link = new ClassInstanceLink(id, e.getKeyType());
          else if (e instanceof ColumnSubClassLink)
            link = new ColumnSubClassLink(id);
          else if (e instanceof DataPropertyOfColumnLink)
            link = new DataPropertyOfColumnLink(id,
                ((DataPropertyOfColumnLink)e).getSpecializedColumnHNodeId(),
                ((DataPropertyOfColumnLink)e).getSpecializedLinkId()
                );
          else if (e instanceof ObjectPropertySpecializationLink)
            link = new ObjectPropertySpecializationLink(id, ((ObjectPropertySpecializationLink)e).getSpecializedLinkId());
          else {
              logger.error("cannot instanciate a link from the type: " + e.getType().toString());
              continue;
          }
          link.getModelIds().add(indexedModelId);
          if (!this.graphBuilder.addLink(n1, n2, link, ModelingParams.PATTERN_LINK_WEIGHT)) continue;

          n1.getModelIds().add(indexedModelId);
          n2.getModelIds().add(indexedModelId);
         
        }
      }
    }
View Full Code Here

  @Override
  public Set<InternalNode> addModel(SemanticModel model) {

    HashMap<Node, Node> visitedNodes;
    Node source, target;
    Node n1, n2;

    // adding the patterns to the graph

    if (model == null)
      return null;

    String modelId = model.getId();
    if (this.graphBuilder.getModelIds().contains(modelId)) {
      // FIXME
      // we need to somehow update the graph, but I don't know how to do that yet.
      // so, we rebuild the whole graph from scratch.
      logger.info("the graph already includes the model and needs to be updated, we re-initialize the graph from the repository!");
      initializeFromJsonRepository();
      return null;
    }

    visitedNodes = new HashMap<Node, Node>();

    for (LabeledLink e : model.getGraph().edgeSet()) {

      source = e.getSource();
      target = e.getTarget();

      n1 = visitedNodes.get(source);
      n2 = visitedNodes.get(target);

      if (n1 == null) {

        if (source instanceof InternalNode) {
          String id = this.nodeIdFactory.getNodeId(source.getLabel().getUri());
          InternalNode node = new InternalNode(id, new Label(source.getLabel()));
          if (this.graphBuilder.addNode(node)) {
            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;
        }

        visitedNodes.put(target, n2);
      }

      LabeledLink link;
      String id = LinkIdFactory.getLinkId(e.getLabel().getUri(), n1.getId(), n2.getId())
      if (e instanceof DataPropertyLink)
        link = new DataPropertyLink(id, e.getLabel());
      else if (e instanceof ObjectPropertyLink)
        link = new ObjectPropertyLink(id, e.getLabel(), ((ObjectPropertyLink)e).getObjectPropertyType());
      else if (e instanceof SubClassLink)
        link = new SubClassLink(id);
      else if (e instanceof ClassInstanceLink)
        link = new ClassInstanceLink(id, e.getKeyType());
      else if (e instanceof ColumnSubClassLink)
        link = new ColumnSubClassLink(id);
      else if (e instanceof DataPropertyOfColumnLink)
        link = new DataPropertyOfColumnLink(id,
            ((DataPropertyOfColumnLink)e).getSpecializedColumnHNodeId(),
            ((DataPropertyOfColumnLink)e).getSpecializedLinkId()
            );
      else if (e instanceof ObjectPropertySpecializationLink)
        link = new ObjectPropertySpecializationLink(id, ((ObjectPropertySpecializationLink)e).getSpecializedLinkId());
      else {
        logger.error("cannot instanciate a link from the type: " + e.getType().toString());
        continue;
      }


      link.getModelIds().add(modelId);

      if (this.graphBuilder.addLink(n1, n2, link)) {
        this.graphBuilder.changeLinkWeight(link, ModelingParams.PATTERN_LINK_WEIGHT);
      }

      if (!n1.getModelIds().contains(modelId))
        n1.getModelIds().add(modelId);

      if (!n2.getModelIds().contains(modelId))
        n2.getModelIds().add(modelId);

    }
View Full Code Here

    String predicateUri = "";
    String objectUri = "";
    int linkFrequency;
    String id;
    Set<Node> nodes;
    Node node, n1, n2;
    LabeledLink link;

    int countOfObjectProperties = 0;

    if (objectPropertiesTriples != null) {
View Full Code Here

    String subjectUri = "";
    String predicateUri = "";
    int linkFrequency;
    String id;
    Set<Node> nodes;
    Node node, n1, n2;
    LabeledLink link;

    int countOfDataProperties = 0;

    if (dataPropertiesTriples != null) {
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.