Package edu.isi.karma.kr2rml.template

Examples of edu.isi.karma.kr2rml.template.StringTemplateTerm


       
        if (node.getId().equals(steinerTreeRoot.getId()))
          subj.setAsSteinerTreeRootNode(true);
       
        // Add the user provided namespace as the first template term
        subj.getTemplate().addTemplateTermToSet(new StringTemplateTerm(sourceNamespace));
        StringTemplateTerm typeTerm = new StringTemplateTerm(node.getLabel().getUri(), true);
        TemplateTermSet typeTermSet = new TemplateTermSet();
        typeTermSet.addTemplateTermToSet(typeTerm);
        subj.addRdfsType(typeTermSet);
        r2rmlMapping.getSubjectMapIndex().put(node.getId(), subj);
       

        Set<LabeledLink> outgoingLinks = alignmentGraph.outgoingEdgesOf(node);
        for (LabeledLink link:outgoingLinks) {
         
          if (link instanceof ClassInstanceLink || link instanceof ColumnSubClassLink) {
            Node tNode = link.getTarget();
            if (tNode instanceof ColumnNode) {
              ColumnNode cnode = (ColumnNode) tNode;
              String hNodeId = cnode.getHNodeId();
              String columnName = translator.getColumnNameForHNodeId(hNodeId);
              ColumnTemplateTerm cnTerm = new ColumnTemplateTerm(columnName);
             
              // Identify classInstance links to set the template
              if (link instanceof ClassInstanceLink) {
               
                TemplateTermSet tts = expandColumnTemplateTermForPyTransforms(
                   hNodeId, cnTerm);
                subj.setTemplate(tts);
              }
             
              // Identify the isSubclassOfClass links to set the correct type
              else if (link instanceof ColumnSubClassLink) {
                TemplateTermSet typeTermSet2 = new TemplateTermSet();
                typeTermSet2.addTemplateTermToSet(cnTerm);
                subj.addRdfsType(typeTermSet2);
              }
             
              List<String> columnsCovered = new LinkedList<String>();
              for(TemplateTerm term : subj.getTemplate().getAllColumnNameTermElements())
              {
                columnsCovered.add(term.getTemplateTermValue());
              }
              r2rmlMapping.getAuxInfo().getSubjectMapIdToTemplateAnchor().put(subj.getId(), KR2RMLMappingAuxillaryInformation.findSubjectMapTemplateAnchor(columnsCovered));
            } else {
              logger.error("Target node of Class Instance link should always be a " +
                  "column node.");
            }
          }
        }
      } else if(node instanceof LiteralNode) {
        LiteralNode literalNode = (LiteralNode)node;
       
        SubjectMap subj = new SubjectMap(literalNode.getId());
       
        if (literalNode.getId().equals(steinerTreeRoot.getId()))
          subj.setAsSteinerTreeRootNode(true);
       
        StringTemplateTerm typeTerm = new StringTemplateTerm(literalNode.getLabel().getUri(), true);
        TemplateTermSet typeTermSet = new TemplateTermSet();
        typeTermSet.addTemplateTermToSet(typeTerm);
        subj.addRdfsType(typeTermSet);
       
        TemplateTermSet templateTermSet = new TemplateTermSet();
        StringTemplateTerm tempTerm = new StringTemplateTerm(literalNode.getValue(), literalNode.isUri());
        templateTermSet.addTemplateTermToSet(tempTerm);
        subj.setTemplate(templateTermSet);
       
        r2rmlMapping.getSubjectMapIndex().put(node.getId(), subj);
      }
View Full Code Here


                    new ColumnTemplateTerm(columnName);
                pred.getTemplate().addTemplateTermToSet(cnTerm);
              }
            } else {
              pred.getTemplate().addTemplateTermToSet(
                  new StringTemplateTerm(olink.getLabel().getUri(), true));
            }
            poMap.setPredicate(pred);
            if (generateInverse)
              addInversePropertyIfExists(subjMap, poMap, olink, subjTrMap);
           
            // Add the links in the graph links data structure
            TriplesMapLink link = new TriplesMapLink(subjTrMap, objTrMap, poMap)
            r2rmlMapping.getAuxInfo().getTriplesMapGraph().addLink(link);
          }
         
          else if(target instanceof LiteralNode) {
            LiteralNode lnode = (LiteralNode) target;
           
            //Create the object
            TemplateTermSet termSet = new TemplateTermSet();
            StringTemplateTerm literalTerm = new StringTemplateTerm(lnode.getValue(), lnode.isUri());
            termSet.addTemplateTermToSet(literalTerm);
           
            StringTemplateTerm rdfLiteralTypeTerm = new StringTemplateTerm(lnode.getLabel().getUri(), true);
            TemplateTermSet rdfLiteralTypeTermSet = new TemplateTermSet();
            rdfLiteralTypeTermSet.addTemplateTermToSet(rdfLiteralTypeTerm);
           
            ObjectMap objMap = new ObjectMap(target.getId(), termSet, rdfLiteralTypeTermSet);
            poMap.setObject(objMap);
           
            // Create the predicate
            Predicate pred = new Predicate(olink.getId());
            pred.getTemplate().addTemplateTermToSet(
                  new StringTemplateTerm(olink.getLabel().getUri(), true));
           
            poMap.setPredicate(pred);
            if (generateInverse)
              addInversePropertyIfExists(subjMap, poMap, olink, subjTrMap);
           
          }
         
          // Create a data property map
          else if(target instanceof ColumnNode) {
            // Create the object map
            ColumnNode cnode = (ColumnNode) target;
            String hNodeId = cnode.getHNodeId();
            String columnName = translator.getColumnNameForHNodeId(hNodeId);
            ColumnTemplateTerm cnTerm = new ColumnTemplateTerm(columnName);
            TemplateTermSet termSet = expandColumnTemplateTermForPyTransforms(
                hNodeId, cnTerm);
           
            String rdfLiteralUri =   cnode.getRdfLiteralType() == null? "" : cnode.getRdfLiteralType().getUri();
            StringTemplateTerm rdfLiteralTypeTerm = new StringTemplateTerm(rdfLiteralUri, true);
            TemplateTermSet rdfLiteralTypeTermSet = new TemplateTermSet();
            rdfLiteralTypeTermSet.addTemplateTermToSet(rdfLiteralTypeTerm);

            ObjectMap objMap = new ObjectMap(hNodeId, termSet, rdfLiteralTypeTermSet);
            poMap.setObject(objMap);
           
            // Create the predicate
            Predicate pred = new Predicate(olink.getId());
           
            // Check if a specialization link exists
            LabeledLink specializedEdge = getSpecializationLinkIfExists(olink, node);
            if (specializedEdge != null) {
              Node specializedEdgeTarget = specializedEdge.getTarget();
              if (specializedEdgeTarget instanceof ColumnNode) {
                String targetColumnName = translator.getColumnNameForHNodeId(((ColumnNode) specializedEdgeTarget).getHNodeId());
                ColumnTemplateTerm cnsplTerm =
                    new ColumnTemplateTerm(targetColumnName);
                pred.getTemplate().addTemplateTermToSet(cnsplTerm);
              }
            } else {
              pred.getTemplate().addTemplateTermToSet(
                  new StringTemplateTerm(olink.getLabel().getUri(), true));
            }
            poMap.setPredicate(pred);
           
            // Save link from the columnName to the its PredicateObjectMap in the auxiliary information
            saveLinkFromColumnNameToPredicateObjectMap(columnName, poMap);
View Full Code Here

       
        // Create the predicate
        Predicate pred = new Predicate(synType.getType().getUri() + "-synonym" +
            getNewSynonymIdCount());
        pred.getTemplate().addTemplateTermToSet(
            new StringTemplateTerm(synType.getType().getUri(), true));
        poMap.setPredicate(pred);
       
        // Add the predicate object map to the triples map
        subjTrMap.addPredicateObjectMap(poMap);
       
View Full Code Here

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

     
      PredicateObjectMap pom = new PredicateObjectMap(Prefixes.KARMA_DEV + PredicateObjectMap.getNewId(),triplesMap);
      pom.setObject(new ObjectMap(factory.getNewId("objectmap"), typeTerm, null));
      Predicate typePredicate = new Predicate(factory.getNewId("predicate"));
      TemplateTermSet typeTemplate = new TemplateTermSet();
      typeTemplate.addTemplateTermToSet(new StringTemplateTerm(Uris.RDF_TYPE_URI));
      typePredicate.setTemplate(typeTemplate);
      pom.setPredicate(typePredicate);
      PredicateObjectMappingPlan pomPlan = new ColumnPredicateObjectMappingPlan(subjectMapPlan.getTemplate(), pom, subjectMapPlan.getSubjectTermsToPaths(), kr2rmlMapping,uriFormatter, factory, translator, hNodeToContextUriMap, generateContext, selection);
      columnLinksPlans.add(pomPlan);
    }
View Full Code Here

        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);
           
            // Add the link between triple maps in the auxInfo
            TriplesMapLink link = new TriplesMapLink(trMap, parentTM, pom)
            kr2rmlMapping.getAuxInfo().getTriplesMapGraph().addLink(link);
          }
        } else {
          NodeIterator objMapColStmts = model.listObjectsOfProperty(objNode, columnProp);
          // RDF Literal Type
          Statement objMapRdfLiteralTypeStmt = model.getProperty(objNode, rdfLiteralTypeProp);
          TemplateTermSet rdfLiteralTypeTermSet = null;
          if (objMapRdfLiteralTypeStmt != null && objMapRdfLiteralTypeStmt.getObject().isLiteral()) {
            StringTemplateTerm rdfLiteralTypeTerm =
                new StringTemplateTerm(objMapRdfLiteralTypeStmt.getObject().toString(), true);
            rdfLiteralTypeTermSet = new TemplateTermSet();
            rdfLiteralTypeTermSet.addTemplateTermToSet(rdfLiteralTypeTerm);
          }
          while (objMapColStmts.hasNext()) {
            RDFNode colNode = objMapColStmts.next();
            objMap = new ObjectMap(getNewObjectMapId(objectMapCounter++),
                TemplateTermSetBuilder.constructTemplateTermSetFromR2rmlColumnString(
                    colNode.toString(), formatter), rdfLiteralTypeTermSet);
          }
          if(objMap == null)
          {
            NodeIterator templateItr = model.listObjectsOfProperty(objNode, templateProp);
            //try a literal/constant node
            if(templateItr == null ||  !templateItr.hasNext()){
              templateItr = model.listObjectsOfProperty(objNode, constantProp);
            }
            TemplateTermSet objTemplTermSet = null;
            while (templateItr.hasNext()) {
              RDFNode templNode = templateItr.next();
              String template = templNode.toString();
              boolean isUri = !templNode.isLiteral();
              objTemplTermSet = TemplateTermSetBuilder.constructTemplateTermSetFromR2rmlTemplateString(
                template, isUri, kr2rmlMapping.getColumnNameFormatter());
           
            }
            objMap = new ObjectMap(getNewObjectMapId(objectMapCounter++),
                objTemplTermSet, rdfLiteralTypeTermSet);
          }
          // Check if anything needs to be added to the columnNameToPredicateObjectMap Map
          if(objMap != null)
            addColumnNameToPredObjectMapLink(objMap, pom, kr2rmlMapping);
        }
      }
      pom.setObject(objMap);
      trMap.addPredicateObjectMap(pom);
    }
   
 
    // Try to add template to pom
      TemplateTermSet subjTemplTermSet = trMap.getSubject().getTemplate();
      if(subjTemplTermSet != null)
      {
        List<TemplateTerm> terms = subjTemplTermSet.getAllTerms();
        if(isValidTemplate(terms))
        {
          PredicateObjectMap pom = new PredicateObjectMap(PredicateObjectMap.getNewId(),trMap);
          Predicate pred = new Predicate(Uris.CLASS_INSTANCE_LINK_URI + "-" + predicateIdCounter++);
          pred.getTemplate().addTemplateTermToSet(
              new StringTemplateTerm(Uris.CLASS_INSTANCE_LINK_URI, true));
          pom.setPredicate(pred);
          StringTemplateTerm rdfLiteralTypeTerm = new StringTemplateTerm("", true);
          TemplateTermSet rdfLiteralTypeTermSet = new TemplateTermSet();
          rdfLiteralTypeTermSet.addTemplateTermToSet(rdfLiteralTypeTerm);
          ObjectMap objMap = new ObjectMap(getNewObjectMapId(objectMapCounter++),
              subjTemplTermSet, rdfLiteralTypeTermSet);
          pom.setObject(objMap);
View Full Code Here

        if (typeNode instanceof Resource) {
          // Skip the steiner tree root type
          if(((Resource) typeNode).getURI().equals(Uris.KM_STEINER_TREE_ROOT_NODE))
            continue;
         
          StringTemplateTerm uriTerm = new StringTemplateTerm(
              ((Resource) typeNode).getURI(), true);
          TemplateTermSet typeTermSet = new TemplateTermSet();
          typeTermSet.addTemplateTermToSet(uriTerm);
          subjMap.addRdfsType(typeTermSet);
        } else {
View Full Code Here

    }
  }
  protected TemplateTermSet generateSubjectMapTemplateForBlankNode(SubjectMap subjectMap,
      List<String> columnsCovered) {
    TemplateTermSet subjectTerms = new TemplateTermSet();
    subjectTerms.addTemplateTermToSet(new StringTemplateTerm(Uris.BLANK_NODE_PREFIX));
    subjectTerms.addTemplateTermToSet(new StringTemplateTerm(kr2rmlMapping.getAuxInfo().getBlankNodesUriPrefixMap().get(subjectMap.getId()).replaceAll(":", "_")));
    for(String columnCovered : columnsCovered)
    {
      ColumnTemplateTerm term = new ColumnTemplateTerm(columnCovered);
      subjectTerms.addTemplateTermToSet(term);
    }
View Full Code Here

TOP

Related Classes of edu.isi.karma.kr2rml.template.StringTemplateTerm

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.