Пример #1
0
void Database::processRule(Rule* rule) {
    //Find the relation in the list of schemes matching the head of the predicate
    Relation* headRelation = getHeadRelation(rule);
    
    //Get the list of predicates
    std::vector<Predicate*> predicateList = rule->j;
    
    //Create new relations from each predicate
    std::vector<Relation*> relationList = getRelationList(predicateList);
    
    //Natural join the relations from the predicates
    Relation* newRelation = join(relationList);
    
    //Project on the final relation; only keep columns matching variables in the rule head
    std::vector<std::string> headVariables = getHeadVariables(rule->hpl);
    newRelation = newRelation->project(headVariables);
    
    //Find the relation in the database that matches the head of the rule
        //Already done (it's headRelation)
    
    //Rename attributes in the new relation so it matches the rule head's schema
    newRelation = renameToMatch(headRelation, newRelation, headVariables);
    
    //Union the new relation with the matching relation
    headRelation = unionWith(headRelation, newRelation);
    std::sort(headRelation->facts.begin(), headRelation->facts.end(), Relation::tupleCompare);
}
Пример #2
0
void PlatformTimeRanges::intersectWith(const PlatformTimeRanges& other)
{
    PlatformTimeRanges invertedOther(other);

    invertedOther.invert();
    invert();
    unionWith(invertedOther);
    invert();
}