Exemple #1
0
def PrepareSipCollection(adornedRuleset):
    """
    Takes adorned ruleset and returns an RDF dataset
    formed from the sips associated with each adorned
    rule as named graphs.  Also returns a mapping from
    the head predicates of each rule to the rules that match
    it - for efficient retrieval later
    """
    headToRule = {}
    graphs = []
    secondOrderRules = set()
    for rule in adornedRuleset:
        ruleHead = GetOp(rule.formula.head)
        if isinstance(ruleHead,Variable):
            #We store second order rules (i.e., rules whose head is a
            #predicate occurrence whose predicate symbol is a variable) aside
            secondOrderRules.add(rule)
        headToRule.setdefault(ruleHead,set()).add(rule)
        if hasattr(rule,'sip'):
            graphs.append(rule.sip)
    #Second order rules are mapped from a None key (in order to indicate they are wildcards)
    headToRule[None]=secondOrderRules
    if not graphs:
        return
    graph = ReadOnlyGraphAggregate(graphs)
    graph.headToRule = headToRule
    return graph
Exemple #2
0
def PrepareSipCollection(adornedRuleset):
    """
    Takes adorned ruleset and returns an RDF dataset
    formed from the sips associated with each adorned
    rule as named graphs.  Also returns a mapping from
    the head predicates of each rule to the rules that match
    it - for efficient retrieval later
    """
    headToRule = {}
    graphs = []
    secondOrderRules = set()

    for rule in adornedRuleset:
        ruleHead = GetOp(rule.formula.head)

        if isinstance(ruleHead, Variable):
            #We store second order rules (i.e., rules whose head is a
            #predicate occurrence whose predicate symbol is a variable) aside
            secondOrderRules.add(rule)

        headToRule.setdefault(ruleHead, set()).add(rule)

        if hasattr(rule, 'sip'):
            graphs.append(rule.sip)

    # Second order rules are mapped from a None key (in order
    # to indicate they are wildcards)

    headToRule[None] = secondOrderRules

    if not graphs:
        return

    graph = ReadOnlyGraphAggregate(graphs)
    graph.headToRule = headToRule

    return graph