Package edu.isi.karma.rep.alignment

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


   
    /*** Add the appropriate nodes and links in alignment graph ***/
    List<SemanticType> typesList = new ArrayList<SemanticType>();
    for (int i = 0; i < typesArr.length(); i++) {
      try {
        LabeledLink newLink = null;
        JSONObject type = typesArr.getJSONObject(i);
       
        String domainValue;
        // For property semantic types, domain uri goes to "domainValue" and link uri goes to "fullTypeValue".
        // For class semantic type, class uri goes "fullTypeValue" and "domainValue" is empty.
        if(type.has(ClientJsonKeys.DomainId.name()))
          domainValue = type.getString(ClientJsonKeys.DomainId.name());
        else
          domainValue = type.getString("Domain"); //For backward compatibility to older models
        String fullTypeValue = type.getString(ClientJsonKeys.FullType.name());
//        logger.trace("FULL TYPE:" + type.getString(ClientJsonKeys.FullType.name()));
//        logger.trace("Domain: " + type.getString(ClientJsonKeys.Domain.name()));
       
        // Look if the domain value exists. If it exists, then it is a domain of a data property. If not
        // then the value in FullType has the the value which indicates if a new class instance is needed
        // or an existing class instance should be used (this is the case when just the class is chosen as a sem type).
//        Label domainName = null;
       
        boolean isClassSemanticType = false;
        boolean semanticTypeAlreadyExists = false;
        Node domain = null;
        String domainUriOrId;
        Label linkLabel;
       
        // if domain value is empty, semantic type is a class semantic type
        if (domainValue.equals("")) {
          isClassSemanticType = true;
          domainUriOrId = fullTypeValue;
          linkLabel = ClassInstanceLink.getFixedLabel();
        } else {
          isClassSemanticType = false;
          domainUriOrId = domainValue;
          linkLabel = ontMgr.getUriLabel(fullTypeValue);
          if (linkLabel == null) {
            logger.error("URI/ID does not exist in the ontology or model: " + fullTypeValue);
            continue;
          }
        }
       
        if(domainUriOrId.endsWith(" (add)"))
          domainUriOrId = domainUriOrId.substring(0, domainUriOrId.length()-5).trim();
       
        domain = alignment.getNodeById(domainUriOrId);
        logger.info("Got domain for domainUriOrId:" + domainUriOrId + " ::" + domain);
        if (domain == null) {
          Label label = ontMgr.getUriLabel(domainUriOrId);
//          if (label == null) {
//            logger.error("URI/ID does not exist in the ontology or model: " + domainUriOrId);
//            continue;
//          }
          if (label == null) {
            if(type.has(ClientJsonKeys.DomainUri.name())) {
              label = new Label(type.getString(ClientJsonKeys.DomainUri.name()));
            } else {
              //This part of the code is for backward compatibility. Newer models should have domainUri
              int len = domainValue.length();
              if ((len > 1) && Character.isDigit(domainValue.charAt(len-1))) {
                String newDomainValue = domainValue.substring(0, len-1);
                label = ontMgr.getUriLabel(newDomainValue);
              }
              if (label == null) {
                logger.error("No graph node found for the node: " + domainValue);
                return new UpdateContainer(new ErrorUpdate("" +
                "Error occured while setting semantic type!"));
              }
            }
          }
          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);
            }           
View Full Code Here


        continue;
     
      id = LinkIdFactory.getLinkId(uri, sourceId, targetId);
      label = new Label(ontologyManager.getUriLabel(uri));
     
      LabeledLink newLink;
      if (uri.equalsIgnoreCase(Uris.RDFS_SUBCLASS_URI))
        newLink = new SubClassLink(id);
      else
        newLink = new ObjectPropertyLink(id, label, linkObjectPropertyType);
     
View Full Code Here

   
    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

        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

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

        SemanticTypeMapping mp = new SemanticTypeMapping(sourceColumn, semanticType, (InternalNode)source, link, target);
View Full Code Here

    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);
      link = new DataPropertyLink(linkId, label);
View Full Code Here

        targetNode = alignment.addInternalNode(new Label(targetUri));
      }

      Label linkLabel = ontMgr.getUriLabel(edgeUri);

      LabeledLink newLink = alignment.addObjectPropertyLink(sourceNode,
          targetNode, linkLabel);
      alignment.changeLinkStatus(newLink.getId(),
          LinkStatus.ForcedByUser);


      // Add info to description string
      if (j == newEdges.length() - 1) {
        descStr.append(newLink.getLabel().getDisplayName());
      } else {
        descStr.append(newLink.getLabel().getDisplayName() + ",");
      }
    }
  }
View Full Code Here

        }

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

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

    int countOfObjectProperties = 0;

    if (objectPropertiesTriples != null) {
      for (Triple t : objectPropertiesTriples) {
View Full Code Here

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

    int countOfDataProperties = 0;

    if (dataPropertiesTriples != null) {
      for (Triple t : dataPropertiesTriples) {
View Full Code Here

TOP

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

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.