Package de.fuberlin.wiwiss.d2rq.algebra

Examples of de.fuberlin.wiwiss.d2rq.algebra.AliasMap


    RelationName foreignTable = schema.getCorrectCapitalization(foreignKey.table2());
    this.out.println(propertyBridgeIRITurtle(primaryColumns, "ref") + " a d2rq:PropertyBridge;");
    this.out.println("\td2rq:belongsToClassMap " + classMapIRITurtle(primaryTable) + ";");
    this.out.println("\td2rq:property " + vocabularyIRITurtle(primaryColumns) + ";");
    this.out.println("\td2rq:refersToClassMap " + classMapIRITurtle(foreignTable) + ";");
    AliasMap alias = AliasMap.NO_ALIASES;
    // Same-table join? Then we need to set up an alias for the table and join to that
    if (foreignKey.isSameTable()) {
      String aliasName = foreignTable.qualifiedName().replace('.', '_') + "__alias";
      this.out.println("\td2rq:alias \"" + foreignTable.qualifiedName() + " AS " + aliasName + "\";");
      alias = AliasMap.create1(foreignTable, new RelationName(null, aliasName));
    }
    for (Attribute column: primaryColumns) {
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[foreignKey.joinDirection()] + " " +
          alias.applyTo(foreignKey.equalAttribute(column)).qualifiedName() + "\";");
    }
    createObjectProperty(foreignKey);
    this.out.println("\t.");
  }
View Full Code Here


    this.out.println("\td2rq:refersToClassMap " + classMapIRITurtle(table2) + ";");
    for (Attribute column: join1.attributes1()) {
      Attribute otherColumn = join1.equalAttribute(column);
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join1.joinDirection()] + " " + otherColumn.qualifiedName() + "\";");
    }
    AliasMap alias = AliasMap.NO_ALIASES;
    if (isSelfJoin) {
      RelationName aliasName = new RelationName(
          null, table2.tableName() + "_" + linkTableName.tableName() + "__alias");
      alias = AliasMap.create1(table2, aliasName);
      this.out.println("\td2rq:alias \"" + table2.qualifiedName() +
          " AS " + aliasName.qualifiedName() + "\";");
    }
    for (Attribute column: join2.attributes1()) {
      Attribute otherColumn = join2.equalAttribute(column);
      this.out.println("\td2rq:join \"" + column.qualifiedName() + " " + Join.joinOperators[join2.joinDirection()] + " " + alias.applyTo(otherColumn).qualifiedName() + "\";");
    }
    this.out.println("\t.");
    this.out.println();
    createLinkProperty(linkTableName, table1, table2);
    this.out.flush();
View Full Code Here

                D2RQException.DATATYPE_DOES_NOT_SUPPORT_DISTINCT);
          }
        }
      }
    }
    AliasMap aliases = aliases();
   
    // The contract is that all projections are required (must not be NULL).
    // So let's add them all as soft conditions. The soft condition for
    // a non-nullable column is TRUE.
    Collection<Expression> softConditions = new HashSet<Expression>(projections.size());
View Full Code Here

        this.limit,
        this.limitInverse);
  }
 
  public AliasMap aliases() {
    return new AliasMap(this.aliases);
  }
View Full Code Here

    Mapping mapping = MappingHelper.readFromTestFile("parser/alias.ttl");
    MappingHelper.connectToDummyDBs(mapping);
    assertEquals(1, mapping.compiledPropertyBridges().size());
    TripleRelation bridge = (TripleRelation) mapping.compiledPropertyBridges().iterator().next();
    assertTrue(bridge.baseRelation().condition().isTrue());
    AliasMap aliases = bridge.baseRelation().aliases();
    AliasMap expected = new AliasMap(Collections.singleton(SQL.parseAlias("People AS Bosses")));
    assertEquals(expected, aliases);
  }
View Full Code Here

          !this.containsDuplicates);
    }
    if (this.refersToClassMap == null) {
      return buildNodeMaker(wrapValueSource(buildValueSourceBase()), !this.containsDuplicates);
    }
    return this.refersToClassMap.buildAliasedNodeMaker(new AliasMap(aliases()), !this.containsDuplicates);
  }
View Full Code Here

            AttributeSet attributes = AttributeSet.createFrom(n);
            /*
             * If we would set an alias to this table...
             */
            if (attributes != null) {
              AliasMap amap = (AliasMap)(nodeSets.relationAliases().get(nameVar));
              RelationName originalName = amap.originalOf(attributes.relationName);
              if (r.baseRelation().aliases().hasAlias(originalName)) {

                /*
                 * ... and indexes are in place to guarantee uniqueness of the attribute combination...
                 */
                if (isUnique(r.baseRelation().database(), originalName, attributes.attributeNames)) {
                 
                  if (t.getSubject().isVariable() && t.getSubject().getName().equals(name)) {
                    // ... then first find the right relation name...
                    AttributeSet existing = AttributeSet.createFrom(r.nodeMaker(TripleRelation.SUBJECT));
                    if (existing != null && existing.attributeNames.equals(attributes.attributeNames)) {
                      // ... then apply it
                      r = r.renameSingleRelation(existing.relationName, attributes.relationName);
                      newRelations.set(i, r);
                    }
                  }
                 
                  if (t.getPredicate().isVariable() && t.getPredicate().getName().equals(name)) {
                    // ... then first find the right relation name...
                    AttributeSet existing = AttributeSet.createFrom(r.nodeMaker(TripleRelation.PREDICATE));
                    if (existing != null && existing.attributeNames.equals(attributes.attributeNames)) {
                      // ... then apply it
                      r = r.renameSingleRelation(existing.relationName, attributes.relationName);
                      newRelations.set(i, r);
                    }
                  }
                 
                  if (t.getObject().isVariable() && t.getObject().getName().equals(name)) {
                    // ... then first find the right relation name...
                    AttributeSet existing = AttributeSet.createFrom(r.nodeMaker(TripleRelation.OBJECT));
                    if (existing != null && existing.attributeNames.equals(attributes.attributeNames)) {
                      // ... then apply it
                      r = r.renameSingleRelation(existing.relationName, attributes.relationName);
                      newRelations.set(i, r);
                    }
                  }
                }             
              }
            }
          }
        }
      }
     
      if (t.getObject().isVariable()) {
        List<RelationName> relationNames = getRelationNames(
            r.nodeMaker(TripleRelation.OBJECT));
        Set<Alias> aliases = new HashSet<Alias>();
               
        for (RelationName rname: relationNames) {
          if (r.baseRelation().aliases().isAlias(rname))
            aliases.add(new AliasMap.Alias(r.baseRelation().aliases().originalOf(rname), rname));
        }
        nodeSets.add(Var.alloc(t.getObject()), r.nodeMaker(TripleRelation.OBJECT), new AliasMap(aliases));
      }
     
      if (t.getPredicate().isVariable()) {
        List<RelationName> relationNames = getRelationNames(
            r.nodeMaker(TripleRelation.PREDICATE));
        Set<Alias> aliases = new HashSet<Alias>();
               
        for (RelationName rname: relationNames) {
          if (r.baseRelation().aliases().isAlias(rname))
            aliases.add(new AliasMap.Alias(r.baseRelation().aliases().originalOf(rname), rname));
        }
        nodeSets.add(Var.alloc(t.getPredicate()), r.nodeMaker(TripleRelation.PREDICATE), new AliasMap(aliases));
      }
     
      if (t.getSubject().isVariable()) {
        List<RelationName> relationNames = getRelationNames(
            r.nodeMaker(TripleRelation.SUBJECT));
        Set<Alias> aliases = new HashSet<Alias>();
               
        for (RelationName rname: relationNames) {
          if (r.baseRelation().aliases().isAlias(rname))
            aliases.add(new AliasMap.Alias(r.baseRelation().aliases().originalOf(rname), rname));
        }
        nodeSets.add(Var.alloc(t.getSubject()), r.nodeMaker(TripleRelation.SUBJECT), new AliasMap(aliases));
      }

    }
    if (!nodeSets.satisfiable()) {
      return null;
View Full Code Here

  private Relation joinRelations(Collection<Relation> relations, Expression additionalCondition) {
    if (relations.isEmpty()) {
      return Relation.TRUE;
    }
    ConnectedDB connectedDB = ((Relation) relations.iterator().next()).database();
    AliasMap joinedAliases = AliasMap.NO_ALIASES;
    Collection<Expression> expressions = new HashSet<Expression>();
    expressions.add(additionalCondition);
    Collection<Expression> softConditions = new HashSet<Expression>();
    Set<Join> joins = new HashSet<Join>();
    Set<ProjectionSpec> projections = new HashSet<ProjectionSpec>();
    int limit = Relation.NO_LIMIT;
    int limitInverse = Relation.NO_LIMIT;
    List<OrderSpec> orderSpecs = null;
   
    for (Relation relation: relations) {
      joinedAliases = joinedAliases.applyTo(relation.aliases());
      expressions.add(relation.condition());
      softConditions.add(relation.softCondition());
      joins.addAll(relation.joinConditions());
      projections.addAll(relation.projections());
      orderSpecs = orderSpecs == null ? relation.orderSpecs() : orderSpecs;
View Full Code Here

 
  public void testRenameColumnsWithAliasMap() {
    Alias a = new Alias(new RelationName(null, "foo"), new RelationName(null, "bar"));
    assertEquals(SQLExpression.create("bar.col1 = baz.col1"),
        SQLExpression.create("foo.col1 = baz.col1").renameAttributes(
            new AliasMap(Collections.singleton(a))));
  }
View Full Code Here

        SQL.findColumnsInExpression("FUNC('mustnot.match', foo.col1, 'must.not.match')"));
  }
 
  public void testReplaceColumnsInExpressionWithAliasMap() {
    Alias alias = new Alias(new RelationName(null, "foo"), new RelationName(null, "bar"));
    AliasMap fooAsBar = new AliasMap(Collections.singleton(alias));
    assertEquals("bar.col1",
        SQL.replaceColumnsInExpression("foo.col1", fooAsBar));
    assertEquals("LEN(bar.col1) > 0",
        SQL.replaceColumnsInExpression("LEN(foo.col1) > 0", fooAsBar));
    assertEquals("baz.col1",
View Full Code Here

TOP

Related Classes of de.fuberlin.wiwiss.d2rq.algebra.AliasMap

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.