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;