Package edu.isi.karma.kr2rml.planning

Examples of edu.isi.karma.kr2rml.planning.TriplesMap


    Set<Node> nodes = alignmentGraph.vertexSet();
    for (Node node:nodes) {
      if (node instanceof InternalNode) {
        // Create a TriplesMap corresponding to the Internal node
        SubjectMap subjMap = r2rmlMapping.getSubjectMapIndex().get(node.getId());
        TriplesMap trMap = new TriplesMap(TriplesMap.getNewId(), subjMap);
        r2rmlMapping.getTriplesMapIndex().put(node.getId(), trMap);
        this.r2rmlMapping.addTriplesMap(trMap);
        r2rmlMapping.getAuxInfo().getTriplesMapGraph().addTriplesMap(trMap);
      }
    }
View Full Code Here


    Set<Node> nodes = alignmentGraph.vertexSet();
    for (Node node:nodes) {
      if (node instanceof InternalNode) {
        // Create a TriplesMap corresponding to the Internal node
        SubjectMap subjMap = r2rmlMapping.getSubjectMapIndex().get(node.getId());
        TriplesMap subjTrMap = r2rmlMapping.getTriplesMapIndex().get(node.getId());
       
        // Create the predicate object map for each outgoing link
        Set<LabeledLink> outgoingEdges = alignmentGraph.outgoingEdgesOf(node);
        for (LabeledLink olink:outgoingEdges) {
          if (olink instanceof ObjectPropertySpecializationLink
              || olink instanceof DataPropertyOfColumnLink 
              || olink instanceof ColumnSubClassLink)
            continue;
         
          PredicateObjectMap poMap = new PredicateObjectMap(PredicateObjectMap.getNewId(), subjTrMap);
          Node target = olink.getTarget();
         
          // Create an object property map
          if (target instanceof InternalNode) {
            // Get the RefObjMap object for the objectmap
            TriplesMap objTrMap = r2rmlMapping.getTriplesMapIndex().get(target.getId());
            RefObjectMap refObjMap = new RefObjectMap(RefObjectMap.getNewRefObjectMapId(), objTrMap);
            ObjectMap objMap = new ObjectMap(target.getId(), refObjMap);
            poMap.setObject(objMap);
           
            // Create the predicate
View Full Code Here

   
    Label inversePropLabel = ontMgr.getInverseProperty(propUri);
    Label inverseOfPropLabel = ontMgr.getInverseOfProperty(propUri);
   
    if (inversePropLabel != null) {
      TriplesMap inverseTrMap = r2rmlMapping.getTriplesMapIndex().get(poMap.getObject().getId());
      // Create the predicate object map
      PredicateObjectMap invPoMap = new PredicateObjectMap(PredicateObjectMap.getNewId(),inverseTrMap);
      // Create the predicate
      Predicate pred = new Predicate(olink.getId()+"+inverse");
      pred.getTemplate().addTemplateTermToSet(
          new StringTemplateTerm(inversePropLabel.getUri(), true));
      invPoMap.setPredicate(pred);
      // Create the object using RefObjMap
      RefObjectMap refObjMap = new RefObjectMap(RefObjectMap.getNewRefObjectMapId(), subjTrMap);
      ObjectMap invObjMap = new ObjectMap(subjMap.getId(), refObjMap);
      invPoMap.setObject(invObjMap);
     
      boolean alreadyExists = doesPredicateAlreadyExist(inverseTrMap,
          invPoMap, refObjMap);
      if(alreadyExists)
      {
        return;
      }
     
      inverseTrMap.addPredicateObjectMap(invPoMap);
      // Add the link to the link set
      r2rmlMapping.getAuxInfo().getTriplesMapGraph().addLink(new TriplesMapLink(inverseTrMap, subjTrMap, invPoMap));
    }
    if (inverseOfPropLabel != null) {
      // Create the triples map
      // Get the object's triples map
      TriplesMap inverseOfTrMap = r2rmlMapping.getTriplesMapIndex().get(poMap.getObject().getId());
     
      PredicateObjectMap invOfPoMap = new PredicateObjectMap(PredicateObjectMap.getNewId(),inverseOfTrMap);
      // Create the predicate
      Predicate pred = new Predicate(olink.getId()+"+inverseOf");
      pred.getTemplate().addTemplateTermToSet(
          new StringTemplateTerm(inverseOfPropLabel.getUri(), true));
      invOfPoMap.setPredicate(pred);
      // Create the object using RefObjMap
      RefObjectMap refObjMap = new RefObjectMap(RefObjectMap.getNewRefObjectMapId(), subjTrMap);
      ObjectMap invOfObjMap = new ObjectMap(subjMap.getId(), refObjMap);
      invOfPoMap.setObject(invOfObjMap);
     
      boolean alreadyExists = doesPredicateAlreadyExist(inverseOfTrMap,
          invOfPoMap, refObjMap);
      if(alreadyExists)
      {
        return;
      }
      inverseOfTrMap.addPredicateObjectMap(invOfPoMap);
      // Add the link to the link set
      r2rmlMapping.getAuxInfo().getTriplesMapGraph().addLink(new TriplesMapLink(inverseOfTrMap, subjTrMap, invOfPoMap));
    }
  }
View Full Code Here

    while (trMapsResItr.hasNext()) {
      Resource trMapRes = trMapsResItr.next().asResource();
      SubjectMap subjMap = addSubjectMapForTripleMap(trMapRes, kr2rmlMapping, subjectMapResources);
     
      // Add the Triples map
      TriplesMap trMap = new TriplesMap(trMapRes.getURI(), subjMap);
      kr2rmlMapping.getTriplesMapIndex().put(trMapRes.getURI(), trMap);
      kr2rmlMapping.addTriplesMap(trMap);
      kr2rmlMapping.getAuxInfo().getTriplesMapGraph().addTriplesMap(trMap);
    }
    return subjectMapResources;
View Full Code Here

    Property parentTriplesMapProp = model.getProperty(Uris.RR_PARENT_TRIPLE_MAP_URI);
    Property rdfTypeProp = model.getProperty(Uris.RDF_TYPE_URI);
    Property templateProp = model.getProperty(Uris.RR_TEMPLATE_URI);
    Property constantProp = model.getProperty(Uris.RR_CONSTANT);
    KR2RMLColumnNameFormatter formatter = kr2rmlMapping.getColumnNameFormatter();
    TriplesMap trMap = kr2rmlMapping.getTriplesMapIndex().get(trMapRes.getURI());
    if (trMap == null) {
      logger.error("No Triples Map found for resource: " + trMapRes.getURI());
      return;
    }
    NodeIterator predObjItr = model.listObjectsOfProperty(trMapRes, predObjMapProp);
    while (predObjItr.hasNext()) {
      Resource pomBlankNode = predObjItr.next().asResource();
      // Create the PredicateObjectMap object for current POM
      PredicateObjectMap pom = new PredicateObjectMap(pomBlankNode.getURI(), trMap);
     
      // Get the predicate for the POM
      Predicate pred = null;
      NodeIterator pomPredItr = model.listObjectsOfProperty(pomBlankNode, predProp);
      while (pomPredItr.hasNext()) {
        RDFNode pomPredNode = pomPredItr.next();
        pred = new Predicate(pomPredNode.toString() + "-" + predicateIdCounter++);
       
        // Check if the predicate value is a URI or a literal (such as column name)
        if (pomPredNode instanceof Resource) {
          pred.getTemplate().addTemplateTermToSet(
              new StringTemplateTerm(((Resource) pomPredNode).getURI(), true));
        } else {
          pred.setTemplate(TemplateTermSetBuilder.
              constructTemplateTermSetFromR2rmlTemplateString(
                  pomPredNode.toString(), formatter));
        }
      }
      pom.setPredicate(pred);
     
      // Get the object for the POM
      ObjectMap objMap = null;
      NodeIterator pomObjItr = model.listObjectsOfProperty(pomBlankNode, objectMapProp);
     
      while (pomObjItr.hasNext()) {
        Resource objNode = pomObjItr.next().asResource();
       
        /** Check if objBlankNode is a RefObjectMap or a normal object map with column **/
        if (model.contains(objNode, rdfTypeProp, rfObjClassUri)) {
          NodeIterator parentTripleMapItr = model.listObjectsOfProperty(objNode,
              parentTriplesMapProp);
          while (parentTripleMapItr.hasNext()) {
            Resource parentTripleRes = parentTripleMapItr.next().asResource();
            TriplesMap parentTM = kr2rmlMapping.getTriplesMapIndex().get(parentTripleRes.getURI());
           
            // Create a RefObjectMap
            RefObjectMap rfMap = new RefObjectMap(objNode.getURI(), parentTM);
            objMap = new ObjectMap(getNewObjectMapId(objectMapCounter++), rfMap);
           
View Full Code Here

        while (bnodePrefixItr.hasNext()) {
          kr2rmlMapping.getAuxInfo().getBlankNodesUriPrefixMap().put(subjMap.getId(),
              bnodePrefixItr.next().toString());
        }
       
        TriplesMap mytm = null;
        for(TriplesMap tm : kr2rmlMapping.getTriplesMapList())
        {
          if(tm.getSubject().getId().equalsIgnoreCase(subjMap.getId()))
          {
            mytm = tm;
           
            List<PredicateObjectMap> poms = mytm.getPredicateObjectMaps();
            for(PredicateObjectMap pom : poms )
            {
              ObjectMap objMap = pom.getObject();
              if(objMap == null)
              {
View Full Code Here

   
  }

  protected Schema getSchemaForTriplesMap(TriplesMapGraph graph, String triplesMapId)
  {
    TriplesMap map = graph.getTriplesMap(triplesMapId);
    RecordBuilder<Schema> rb = SchemaBuilder.record("subjr"+(id++));
   
    Set<String> currentPredicates = new HashSet<String>();
    FieldAssembler<Schema> fieldAssembler = rb.fields();
    for(PredicateObjectMap pom : map.getPredicateObjectMaps())
    {
   
   
        boolean isMap = false;
        Schema targetSchema = null;
View Full Code Here

     
      // if this is a tripleMap, then add all its RefObjects to the queue
      // for the predicates, add only the ones that satisfy the criteria of being <...hasValue>
      if (currentObj instanceof TriplesMap) {
        String var = "x"+var_count;
        TriplesMap triple = (TriplesMap)currentObj;
        boolean foundHasValue = false;
        List<PredicateObjectMap> predicates = triple.getPredicateObjectMaps();
       
        for (PredicateObjectMap p_map : predicates) {
         
          // if there are tripleMaps linked to the current tripleMap, then
          // we need to save their relation/linkage between them
          if(p_map.getObject().hasRefObjectMap()) {
            RefObjectMap objMap = p_map.getObject().getRefObjectMap();
            queue.add(objMap.getParentTriplesMap());
           
            logger.info(triple.getSubject().getId() + "  ---> " + objMap.getParentTriplesMap().getSubject().getId());
           
            // maintain a list of mapping properties between triples
            ParentMapingInfoList.put(objMap.getParentTriplesMap().getSubject().getId(),
                new ParentMapingInfo(triple, p_map.getPredicate()));
           
          } else if(!foundHasValue) {
            if(p_map.getPredicate().getTemplate().toString().equalsIgnoreCase("<http://www.opengis.net/gml/hasValue>")) {
              queue.add(p_map.getPredicate());
              predicateList.put(p_map.getPredicate(), var);
              foundHasValue = true;
            }
          }
        }
        // if this triple is marked to be included in the query,
        // we add it to the markedTriples list and add to the query string
        // for its class type Eg.
        // Prefix pref1: <.../.../Input>
        // x2 a pref1:
        if (foundHasValue) {
          markedTriples.put(triple, var);
          String rdfsTypes = triple.getSubject().getRdfsType().get(0).toString();
          this.prefix_list.put(rdfsTypes, "pref"+var_count);
          query.append(" ?"+var + " a pref"+var_count+": .");
         
          // if the parent of this triple is also marked for the query
          // then we add the relation to between triples to the query. Eg.
         
//          TriplesMap parentTriple = parent.get(triple.getSubject().getId());
          ParentMapingInfo parentTriple = ParentMapingInfoList.get(triple.getSubject().getId());
         
          if( parentTriple != null && markedTriples.containsKey(parentTriple.parent)) {
            String predicate = parentTriple.predicate.getTemplate().toString();
//            PredicateObjectMap parentPredicate = getPredicateBetweenTriples(triple, parentTriple);
            if(predicate != null) {
              query.append(" ?" + markedTriples.get(parentTriple.parent) + " " +
                predicate + " ?"+var + " . ");
            } else {
              logger.error("predicate is null from parent : " + triple.getSubject().getRdfsType().toString());
            }
          }
         
        }
        var_count++;
      }
      // if it is a predicate Object, create a variable in in the query string
      else if (currentObj instanceof Predicate) {
        Predicate predicate = (Predicate)currentObj;
        query.append(" ?" + predicateList.get(predicate)
            + " " + predicate.getTemplate() + " ?z"+ var_count + " . ");
        select_params.append(" ?z" + var_count);
        var_count++;
       
      }
      // if this is a RefObject add the Child Triple to the queue
      else if (currentObj instanceof RefObjectMap) {
        RefObjectMap refObj = (RefObjectMap)currentObj;
        TriplesMap t = refObj.getParentTriplesMap();
        queue.add(t);
       
      }
    }
   
View Full Code Here

  }
 
  public String get_query(R2RMLMapping r2rmlMap, String graph) {
   
    List<TriplesMap> triples = r2rmlMap.getTriplesMapList();
    TriplesMap root_node = null;

    // get the root node first
    for (TriplesMap row : triples) {
      if (row.getSubject().isSteinerTreeRootNode() ) {
        root_node = row;
View Full Code Here

     
      // if this is a tripleMap, then add all its RefObjects to the queue
      // for the predicates, add only the ones that satisfy the criteria of being <...hasValue>
      if (currentObj instanceof TriplesMap) {
        String var = "x"+var_count;
        TriplesMap triple = (TriplesMap)currentObj;
        boolean foundHasValue = false;
        List<PredicateObjectMap> predicates = triple.getPredicateObjectMaps();
       
        for (PredicateObjectMap p_map : predicates) {
         
          if(p_map.getObject().hasRefObjectMap()) {
            RefObjectMap objMap = p_map.getObject().getRefObjectMap();
            queue.add(objMap.getParentTriplesMap());
           
            logger.info(triple.getSubject().getId() + "  ---> " + objMap.getParentTriplesMap().getSubject().getId());
           
            // maintain a list of mapping properties between triples
            ParentMapingInfoList.put(objMap.getParentTriplesMap().getSubject().getId(),
                new ParentMapingInfo(triple, p_map.getPredicate()));
           
          } else {
              queue.add(p_map.getPredicate());
              predicateList.put(p_map.getPredicate(), var);
              foundHasValue = true;
          }
        }
        // if this triple is marked to be included in the query,
        // we add it to the markedTriples list and add to the query string
        // for its class type Eg.
        // Prefix pref1: <.../.../Input>
        // x2 a pref1:
        if (foundHasValue) {
          markedTriples.put(triple, var);
          String rdfsTypes = triple.getSubject().getRdfsType().get(0).toString();
          this.prefix_list.put("pref"+var_count, rdfsTypes);
          query.append(" ?"+var + " a pref"+var_count+": .");
         
          // if the parent of this triple is also marked for the query
          // then we add the relation to between triples to the query. Eg.
         
//          TriplesMap parentTriple = parent.get(triple.getSubject().getId());
          ParentMapingInfo parentTriple = ParentMapingInfoList.get(triple.getSubject().getId());
         
          // from the current node, keep poping out till we reach the last node in the
          // parent map to see if any of the parents are connected
          if(parentTriple != null) {
            String sq = checkParentMarked(triple, markedTriples, var);
            if (sq.length() > 1) {
              query.append(sq);
            }
           
          }
//          if( parentTriple != null && markedTriples.containsKey(parentTriple.parent)) {
//            String predicate = parentTriple.predicate.getTemplate().toString();
////            PredicateObjectMap parentPredicate = getPredicateBetweenTriples(triple, parentTriple);
//            if(predicate != null) {
//              query.append(" ?" + markedTriples.get(parentTriple.parent) + " " +
//                predicate + " ?"+var + " . ");
//            } else {
//              System.out.println("predicate is null from parent : " + triple.getSubject().getRdfsType().toString());
//            }
//          }
         
        }
        var_count++;
      }
      // if it is a predicate Object, create a variable in in the query string
      else if (currentObj instanceof Predicate) {
        Predicate predicate = (Predicate)currentObj;
        String k = predicate.getTemplate().toString();
        k = k.replace('<', ' ').replace('>', ' ').trim();
        if(columns != null && columns.size() > 0) {
//          if(columnList.containsKey(k)) {
          if(columnList.containsValue(k)) {
            Iterator<String> itr = columnList.keySet().iterator();
            while(itr.hasNext()) {
              String cName = itr.next();
              if(columnList.get(cName).equals(k) && !visited_columns.contains(cName)) {
                // get the column name from the end of this url - either the last '/' or the '#'
                query.append(" ?" + predicateList.get(predicate))
                .append(" ")
                .append(predicate.getTemplate())
                .append(" ?")
                .append(cName + " . ");
                //columnList.remove(cName);
                visited_columns.add(cName);
                var_count++;
                break;
              }
            } 
            // get the column name from the end of this url - either the last '/' or the '#'
//            query.append(" ?" + predicateList.get(predicate))
//              .append(" ")
//              .append(predicate.getTemplate())
//              .append(" ?")
//              .append(columnList.get(k) + " . ");
//            var_count++;
          } else {
            logger.info("ColumnList does not contain : " + k + " " + currentObj);
          }
        } else {
          int index = 0;
          if(k.indexOf("#") > 0) {
            index = k.lastIndexOf('#')+1;
          } else if(k.indexOf("/") > 0) {
            index = k.lastIndexOf('/')+1;
          }
          query.append(" ?" + predicateList.get(predicate))
            .append(" ")
            .append(predicate.getTemplate())
            .append(" ?").append(k.substring(index, k.length()))
            .append(" .");
          var_count++;
        }
       
      }
      // if this is a RefObject add the Child Triple to the queue
      else if (currentObj instanceof RefObjectMap) {
        RefObjectMap refObj = (RefObjectMap)currentObj;
        TriplesMap t = refObj.getParentTriplesMap();
        queue.add(t);
       
      }
    }
   
View Full Code Here

TOP

Related Classes of edu.isi.karma.kr2rml.planning.TriplesMap

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.