Package de.fuberlin.wiwiss.d2rq.algebra

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


      }
      joiners = nextJoiners;
    }
    List<NodeRelation> results = new ArrayList<NodeRelation>(joiners.size());
    for (TripleRelationJoiner joiner: joiners) {
      NodeRelation nodeRelation = joiner.toNodeRelation();
      if (!nodeRelation.baseRelation().equals(Relation.EMPTY) || !useAllOptimizations)
        results.add(nodeRelation);
    }
    return results;
  }
View Full Code Here


    newRelations.add(relation);

    VariableConstraints nodeSets = new VariableConstraints();
    for (int i = 0; i < newPatterns.size(); i++) {
      Triple t = (Triple) newPatterns.get(i);
      NodeRelation r = newRelations.get(i);

      if (useAllOptimizations) {
        /*
         * Before adding a NodeMaker, try to adopt aliases from existing NodeMakers
         * in order to prevent unnecessary self-joins (#2798308)
         */
        // This failed when originalName had more than 1 alias r.baseRelation (fixed, GM)
        List<String> names = new ArrayList<String>();
 
        if (t.getSubject().isVariable())
          names.add(t.getSubject().getName());
        if (t.getPredicate().isVariable())
          names.add(t.getPredicate().getName());
        if (t.getObject().isVariable())
          names.add(t.getObject().getName());
 
        for (String name: names) {
          Var nameVar = Var.alloc(name);
          NodeMaker n = (NodeMaker) nodeSets.toMap().get(nameVar);
          if (n != null/* && n instanceof TypedNodeMaker*/) {

            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

    }
    return new TripleRelationJoiner(nodeSets, newPatterns, newRelations, useAllOptimizations);
  }
 
  public NodeRelation toNodeRelation() {
    return new NodeRelation(
        joinedBaseRelation().select(
            nodeSets.constraint()).project(nodeSets.allProjections()),
        nodeSets.toMap());
  }
View Full Code Here

  private final static Var type = Var.alloc("type");
  private final static Var x = Var.alloc("x");
 

  public void testEmptyGraphAndBGP() {
    NodeRelation nodeRel = translate1(Collections.<Triple>emptyList(), Collections.<TripleRelation>emptyList());
    assertEquals(Relation.TRUE, nodeRel.baseRelation());
    assertEquals(Collections.EMPTY_SET, nodeRel.variables());
  }
View Full Code Here

  public void testEmptyGraph() {
    assertNull(translate1("?subject ?predicate ?object", Collections.<TripleRelation>emptyList()));
  }
 
  public void testEmptyBGP() {
    NodeRelation nodeRel = translate1(Collections.<Triple>emptyList(), "engine/type-bridge.n3");
    assertEquals(Relation.TRUE, nodeRel.baseRelation());
    assertEquals(Collections.EMPTY_SET, nodeRel.variables());
  }
View Full Code Here

  public void testAskNoMatch() {
    assertNull(translate1("ex:res1 rdf:type foaf:Project", "engine/type-bridge.n3"));
  }

  public void testAskMatch() {
    NodeRelation nodeRel = translate1("ex:res1 rdf:type ex:Class1", "engine/type-bridge.n3");
    Relation r = nodeRel.baseRelation();
    assertEquals(Collections.singleton(table1), r.tables());
    assertEquals(Collections.EMPTY_SET, r.projections());
    assertEquals(Equality.createAttributeValue(table1id, "1"), r.condition());
    assertEquals(AliasMap.NO_ALIASES, r.aliases());
    assertEquals(Collections.EMPTY_SET, nodeRel.variables());
  }
View Full Code Here

  public void testFindNoMatch() {
    assertNull(translate1("ex:res1 ex:foo ?foo", "engine/type-bridge.n3"));
  }
 
  public void testFindFixedMatch() {
    NodeRelation nodeRel = translate1("ex:res1 rdf:type ?type", "engine/type-bridge.n3");
    Relation r = nodeRel.baseRelation();
    assertEquals(Collections.singleton(table1), r.tables());
    assertEquals(Collections.EMPTY_SET, r.projections());
    assertEquals(Equality.createAttributeValue(table1id, "1"), r.condition());
    assertEquals(AliasMap.NO_ALIASES, r.aliases());
    assertEquals(Collections.singleton(type), nodeRel.variables());
    assertEquals("Fixed(<http://example.org/Class1>)",
        nodeRel.nodeMaker(type).toString());
  }
View Full Code Here


  NodeRelation search(String tableName, String attributeName, NodeRelation[] relation)
  {
    for (int i = 0; i < relation.length; i++) {
      NodeRelation rel = relation[i];
      for (ProjectionSpec p: rel.baseRelation().projections()) {
        Attribute attribute = (Attribute) p;
        if (attribute.tableName().equals(tableName) && attribute.attributeName().equals(attributeName))
          return rel;
      }
    }
View Full Code Here

    assertEquals("Fixed(<http://example.org/Class1>)",
        nodeRel.nodeMaker(type).toString());
  }
 
  public void testFindMatch() {
    NodeRelation nodeRel = translate1("?x rdf:type ex:Class1", "engine/type-bridge.n3");
    Relation r = nodeRel.baseRelation();
    assertEquals(Collections.singleton(table1), r.tables());
    assertEquals(Collections.singleton(table1id), r.projections());
    assertEquals(Expression.TRUE, r.condition());
    assertEquals(AliasMap.NO_ALIASES, r.aliases());
    assertEquals(Collections.singleton(x), nodeRel.variables());
    assertEquals("URI(Pattern(http://example.org/res@@table1.id@@))",
        nodeRel.nodeMaker(x).toString());
  }
View Full Code Here

  {
    List<Triple> pattern = new ArrayList<Triple>();
    pattern.add(Triple.create(Node.createVariable("s"), RDFS.label.asNode(), Node.createVariable("o")));
    NodeRelation[] rels = translate(pattern, "optimizer/filtertests.n3");
   
    NodeRelation label_fr_be  = search("table1", "label_fr_be", rels);
    NodeRelation label_en     = search("table1", "label_en", rels);
    NodeRelation label_noLang = search("table1", "label", rels);
   
    Expr filterFR    = new E_Equals(new E_Lang(new ExprVar("o")), NodeValue.makeString("fr"));
    Expr filterEN_TAG_EN = new E_Equals(new E_Lang(new ExprVar("o")), NodeValue.makeNode("en", "en", (String) null));
    Expr filterFR_BE = new E_Equals(new E_Lang(new ExprVar("o")), NodeValue.makeString("fr-BE"));
    Expr filter      = new E_Equals(new E_Lang(new ExprVar("o")), NodeValue.makeString(""));
View Full Code Here

TOP

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

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.