Package de.fuberlin.wiwiss.d2rq.nodes

Examples of de.fuberlin.wiwiss.d2rq.nodes.NodeMaker


  public Collection<TripleRelation> toTripleRelations() {
    this.validate();
    Collection<TripleRelation> results = new ArrayList<TripleRelation>();
    for (Resource property: properties) {
      NodeMaker s = this.belongsToClassMap.nodeMaker();
      NodeMaker p = new FixedNodeMaker(property.asNode(), false);
      NodeMaker o = nodeMaker();
      results.add(new TripleRelation(buildRelation(), s, p, o));
    }
    for (String pattern: dynamicPropertyPatterns) {
      NodeMaker s = this.belongsToClassMap.nodeMaker();
      NodeMaker p = new PropertyMap(pattern, belongsToClassMap.database()).nodeMaker();
      NodeMaker o = nodeMaker();
      results.add(new TripleRelation(buildRelation(), s, p, o));
    }
    return results;
  }
View Full Code Here


    return fromNodeRelation(super.limit(limit));
  }

  public TripleRelation selectTriple(Triple t) {
    MutableRelation newBase = new MutableRelation(baseRelation());
    NodeMaker s = nodeMaker(SUBJECT).selectNode(t.getSubject(), newBase);
    if (s.equals(NodeMaker.EMPTY)) return null;
    NodeMaker p = nodeMaker(PREDICATE).selectNode(t.getPredicate(), newBase);
    if (p.equals(NodeMaker.EMPTY)) return null;
    NodeMaker o = nodeMaker(OBJECT).selectNode(t.getObject(), newBase);
    if (o.equals(NodeMaker.EMPTY)) return null;
    Set<ProjectionSpec> projections = new HashSet<ProjectionSpec>();
    projections.addAll(s.projectionSpecs());
    projections.addAll(p.projectionSpecs());
    projections.addAll(o.projectionSpecs());
    newBase.project(projections);
    if (!s.projectionSpecs().isEmpty() && o.projectionSpecs().isEmpty()) {
        newBase.swapLimits();
    }
    return new TripleRelation(newBase.immutableSnapshot(), s, p, o);
  }
View Full Code Here

    }
    if (replacedColumns.isEmpty()) {
      return this.relation;
    }
    ColumnRenamer renamer = new ColumnRenamerMap(replacedColumns);
    NodeMaker s = this.relation.nodeMaker(TripleRelation.SUBJECT);
    NodeMaker p = this.relation.nodeMaker(TripleRelation.PREDICATE);
    NodeMaker o = this.relation.nodeMaker(TripleRelation.OBJECT);
    Set<ProjectionSpec> projections = new HashSet<ProjectionSpec>();
    projections.addAll(s.projectionSpecs());
    projections.addAll(p.projectionSpecs());
    projections.addAll(o.projectionSpecs());
    return new TripleRelation(
        new RelationImpl(this.relation.baseRelation().database(),
          this.relation.baseRelation().aliases(),
          this.relation.baseRelation().condition(),
          this.relation.baseRelation().softCondition(),
          requiredJoins, projections,
          this.relation.baseRelation().isUnique(),
          this.relation.baseRelation().orderSpecs(),
          this.relation.baseRelation().limit(),
          this.relation.baseRelation().limitInverse()).renameColumns(renamer),
        s.renameAttributes(renamer),
        p.renameAttributes(renamer),
        o.renameAttributes(renamer));
  }
View Full Code Here

  }

  private void groupTripleRelationsByClassMap() {
    if (!classMapInventoryBridges.isEmpty() || !classMapNodeMakers.isEmpty()) return;
    for (Resource classMapResource: mapping.classMapResources()) {
      NodeMaker resourceMaker = this.mapping.classMap(classMapResource).nodeMaker();
      Node classMap = classMapResource.asNode();
      this.classMapNodeMakers.put(toClassMapName(classMap), resourceMaker);
      List<TripleRelation> inventoryBridges = new ArrayList<TripleRelation>();
      for (TripleRelation bridge: mapping.classMap(classMapResource).compiledPropertyBridges()) {
        bridge = bridge.orderBy(TripleRelation.SUBJECT, true);
        if (bridge.selectTriple(new Triple(Node.ANY, RDF.Nodes.type, Node.ANY)) != null) {
          inventoryBridges.add(bridge);
        }
        // TODO The list of label properties is redundantly specified in PageServlet
        if (bridge.selectTriple(new Triple(Node.ANY, RDFS.label.asNode(), Node.ANY)) != null) {
          inventoryBridges.add(bridge);
        } else if (bridge.selectTriple(new Triple(Node.ANY, SKOS.prefLabel.asNode(), Node.ANY)) != null) {
          inventoryBridges.add(bridge);
        } else if (bridge.selectTriple(new Triple(Node.ANY, DC.title.asNode(), Node.ANY)) != null) {
          inventoryBridges.add(bridge);         
        } else if (bridge.selectTriple(new Triple(Node.ANY, DCTerms.title.asNode(), Node.ANY)) != null) {
          inventoryBridges.add(bridge);         
        } else if (bridge.selectTriple(new Triple(Node.ANY, FOAF.name.asNode(), Node.ANY)) != null) {
          inventoryBridges.add(bridge);         
        }
      }
      if (inventoryBridges.isEmpty()) {
        Relation relation = (Relation) this.mapping.classMap(classMapResource).relation();
        NodeMaker typeNodeMaker = new FixedNodeMaker(
            RDF.type.asNode(), false);
        NodeMaker resourceNodeMaker = new FixedNodeMaker(RDFS.Resource.asNode(), false);
        inventoryBridges.add(new TripleRelation(relation,
            resourceMaker, typeNodeMaker, resourceNodeMaker));
      }
      this.classMapInventoryBridges.put(toClassMapName(classMap), inventoryBridges);
    }
View Full Code Here

      return Collections.<String>emptyList();
    }
    List<String> results = new ArrayList<String>();
    for (Entry<String,NodeMaker> entry: classMapNodeMakers.entrySet()) {
      String classMapName = entry.getKey();
      NodeMaker nodeMaker = entry.getValue();
      if (!nodeMaker.selectNode(resource, RelationalOperators.DUMMY).equals(NodeMaker.EMPTY)) {
        results.add(classMapName);
      }
    }
    return results;
  }
View Full Code Here

    ArrayList<Expression> result = new ArrayList<Expression>();
   
    if (this.nodeRelation != null && exprVar != null)
    {
      // get the nodemaker for the expr-var
      NodeMaker nodeMaker = nodeRelation.nodeMaker(exprVar.asVar());
      if (nodeMaker instanceof TypedNodeMaker) {
        TypedNodeMaker typedNodeMaker = (TypedNodeMaker) nodeMaker;
        Iterator<ProjectionSpec> it = typedNodeMaker.projectionSpecs().iterator();
        if (!it.hasNext()) {
          logger.debug("no projection spec for " + exprVar + ", assuming constant");
View Full Code Here

        constant = (ConstantEx) e1;
      }
     
      logger.debug("isEqual(" + variable + ", " + constant + ")");
     
      NodeMaker nm = variable.getNodeMaker();
     
      if (nm instanceof TypedNodeMaker) {
        ValueMaker vm = ((TypedNodeMaker) nm).valueMaker();
        Node node = constant.getNode();
        logger.debug("checking " + node + " with " + nm);
       
        if (XSD.isNumeric(node)) {
          DetermineNodeType filter = new DetermineNodeType();
          nm.describeSelf(filter);
          RDFDatatype datatype = filter.getDatatype();
          if (datatype != null && XSD.isNumeric(datatype)) {
            RDFDatatype numericType = XSD.getNumericType(datatype, node.getLiteralDatatype());
            nm = cast(nm, numericType);
            node = XSD.cast(node, numericType);
          }
        }
       
        boolean empty = nm.selectNode(node, RelationalOperators.DUMMY).equals(NodeMaker.EMPTY);
        logger.debug("result " + new Boolean(empty));
        if (!empty) {
          if (node.isURI())
            expression.push(vm.valueExpression(node.getURI()));
          else if (node.isLiteral()) {
            if (XSD.isSupported(node.getLiteralDatatype()))
              expression.push(vm.valueExpression(constant.value()));
            else
              conversionFailed("cannot compare values of type " + node.getLiteralDatatypeURI(), expr);
          } else
            conversionFailed(expr); // TODO blank nodes?
          return;
        } else {
          expression.push(Expression.FALSE);
          return;
        }
      } else {
        logger.warn("nm is not a TypedNodemaker");
      }
    } else if (e1 instanceof ConstantEx && e2 instanceof ConstantEx) {
      logger.debug("isEqual(" + e1 + ", " + e2 + ")");
      Node c1 = ((ConstantEx) e1).getNode();
      Node c2 = ((ConstantEx) e2).getNode();
      boolean equals;
      if (XSD.isNumeric(c1) && XSD.isNumeric(c2)) {
        RDFDatatype datatype = XSD.getNumericType(c1.getLiteralDatatype(), c2.getLiteralDatatype());
        equals = XSD.cast(c1, datatype).equals(XSD.cast(c2, datatype));
      } else if (isSimpleLiteral(c1) && isSimpleLiteral(c2)) {
        equals = c1.getLiteralValue().equals(c2.getLiteralValue());
      } else if (XSD.isString(c1) && XSD.isString(c2)) {
        equals = c1.getLiteralValue().equals(c2.getLiteralValue());
      } else {
        try {
          equals = NodeFunctions.rdfTermEquals(c1, c2);
        } catch (ExprEvalException e) {
          equals = false;
        }
      }
      logger.debug("constants equal? " + new Boolean(equals));
      expression.push(equals ? Expression.TRUE : Expression.FALSE);
      return;
    } else if (e1 instanceof AttributeExprEx && e2 instanceof AttributeExprEx) {
      logger.debug("isEqual(" + e1 + ", " + e2 + ")");
      AttributeExprEx variable1 = (AttributeExprEx) e1;
      AttributeExprEx variable2 = (AttributeExprEx) e2;
     
      NodeMaker nm1 = variable1.getNodeMaker();
      NodeMaker nm2 = variable2.getNodeMaker();
     
      DetermineNodeType filter1 = new DetermineNodeType();
      nm1.describeSelf(filter1);
      RDFDatatype datatype1 = filter1.getDatatype();
     
      DetermineNodeType filter2 = new DetermineNodeType();
      nm2.describeSelf(filter2);
      RDFDatatype datatype2 = filter2.getDatatype();
     
      if (datatype1 != null && XSD.isNumeric(datatype1) && datatype2 != null && XSD.isNumeric(datatype2)) {
        RDFDatatype numericType = XSD.getNumericType(filter1.getDatatype(), filter2.getDatatype());
        nm1 = cast(nm1, numericType);
        nm2 = cast(nm2, numericType);
      }
      NodeSetConstraintBuilder nodeSet = new NodeSetConstraintBuilder();
      nm1.describeSelf(nodeSet);
      nm2.describeSelf(nodeSet);
     
      if (nodeSet.isEmpty()) {
        logger.debug("nodes " + nm1 + " " + nm2 + " incompatible");
        expression.push(Expression.FALSE);
        return;
View Full Code Here

        constant = (ConstantEx) e1;
      }
     
      logger.debug("isNotEqual(" + variable + ", " + constant + ")");
     
      NodeMaker nm = variable.getNodeMaker();
     
      if (nm instanceof TypedNodeMaker) {
        ValueMaker vm = ((TypedNodeMaker) nm).valueMaker();
        Node node = constant.getNode();
        logger.debug("checking " + node + " with " + nm);
        if (XSD.isNumeric(node)) {
          DetermineNodeType filter = new DetermineNodeType();
          nm.describeSelf(filter);
          RDFDatatype datatype = filter.getDatatype();
          if (datatype != null && XSD.isNumeric(datatype)) {
            RDFDatatype numericType = XSD.getNumericType(datatype, node.getLiteralDatatype());
            nm = cast(nm, numericType);
            node = XSD.cast(node, numericType);
          }
        }
        boolean empty = nm.selectNode(node, RelationalOperators.DUMMY).equals(NodeMaker.EMPTY);
        logger.debug("result " + new Boolean(empty));
        if (!empty) {
          if (node.isURI())
            expression.push(new Negation(vm.valueExpression(node.getURI())));
          else if (node.isLiteral()) {
            if (XSD.isSupported(node.getLiteralDatatype()))
              expression.push(new Negation(vm.valueExpression(constant.value())));
            else // type = boolean or an unknown type
              conversionFailed("cannot compare values of type " + node.getLiteralDatatypeURI(), expr);
          } else
            conversionFailed(expr); // TODO blank nodes?
          return;
        } else {
          expression.push(Expression.TRUE);
          return;
        }
      }
    } else if (e1 instanceof ConstantEx && e2 instanceof ConstantEx) {
      logger.debug("isNotEqual(" + e1 + ", " + e2 + ")");
      Node c1 = ((ConstantEx) e1).getNode();
      Node c2 = ((ConstantEx) e2).getNode();
      boolean equals;
      if (XSD.isNumeric(c1) && XSD.isNumeric(c2)) {
        RDFDatatype datatype = XSD.getNumericType(c1.getLiteralDatatype(), c2.getLiteralDatatype());
        equals = XSD.cast(c1, datatype).equals(XSD.cast(c2, datatype));
      } else if (isSimpleLiteral(c1) && isSimpleLiteral(c2)) {
        equals = c1.getLiteralValue().equals(c2.getLiteralValue());
      } else if (XSD.isString(c1) && XSD.isString(c2)) {
        equals = c1.getLiteralValue().equals(c2.getLiteralValue());
      } else {
        try {
          equals = NodeFunctions.rdfTermEquals(c1, c2);
        } catch (ExprEvalException e) {
          equals = false;
        }
      }
      logger.debug("constants equal? " + new Boolean(equals));
      expression.push(equals ? Expression.FALSE : Expression.TRUE);
      return;
    } else if (e1 instanceof AttributeExprEx && e2 instanceof AttributeExprEx) {
      logger.debug("isNotEqual(" + e1 + ", " + e2 + ")");
      AttributeExprEx variable1 = (AttributeExprEx) e1;
      AttributeExprEx variable2 = (AttributeExprEx) e2;
     
      NodeMaker nm1 = variable1.getNodeMaker();
      NodeMaker nm2 = variable2.getNodeMaker();
     
      DetermineNodeType filter1 = new DetermineNodeType();
      nm1.describeSelf(filter1);
      RDFDatatype datatype1 = filter1.getDatatype();
     
      DetermineNodeType filter2 = new DetermineNodeType();
      nm2.describeSelf(filter2);
      RDFDatatype datatype2 = filter2.getDatatype();
     
      if (datatype1 != null && XSD.isNumeric(datatype1) && datatype2 != null && XSD.isNumeric(datatype2)) {
        RDFDatatype numericType = XSD.getNumericType(filter1.getDatatype(), filter2.getDatatype());
        nm1 = cast(nm1, numericType);
        nm2 = cast(nm2, numericType);
      }
     
      NodeSetConstraintBuilder nodeSet = new NodeSetConstraintBuilder();
      nm1.describeSelf(nodeSet);
      nm2.describeSelf(nodeSet);
     
      if (nodeSet.isEmpty()) {
        logger.debug("nodes " + nm1 + " " + nm2 + " incompatible");
        expression.push(Expression.TRUE);
        return;
View Full Code Here

   
    Expression arg = expression.pop();
   
    if (arg instanceof AttributeExprEx) {
      AttributeExprEx variable = (AttributeExprEx) arg;
      NodeMaker nm = variable.getNodeMaker();
      DetermineNodeType filter = new DetermineNodeType();
      nm.describeSelf(filter);
      expression.push(filter.isLimittedToURIs() ? Expression.TRUE : Expression.FALSE);
    } else if (arg instanceof ConstantEx) {
      ConstantEx constant = (ConstantEx) arg;
      Node node = constant.getNode();
      expression.push(node.isURI() ? Expression.TRUE : Expression.FALSE);
View Full Code Here

   
    Expression arg = expression.pop();
   
    if (arg instanceof AttributeExprEx) {
      AttributeExprEx variable = (AttributeExprEx) arg;
      NodeMaker nm = variable.getNodeMaker();
      DetermineNodeType filter = new DetermineNodeType();
      nm.describeSelf(filter);
      expression.push(filter.isLimittedToBlankNodes() ? Expression.TRUE : Expression.FALSE);
    } else if (arg instanceof ConstantEx) {
      ConstantEx constant = (ConstantEx) arg;
      Node node = constant.getNode();
      expression.push(node.isBlank() ? Expression.TRUE : Expression.FALSE);
View Full Code Here

TOP

Related Classes of de.fuberlin.wiwiss.d2rq.nodes.NodeMaker

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.