예제 #1
0
def HandleNonDisjunctiveClauses(ruleset, network, constructNetwork, negativeStratus, ignoreNegativeStratus, clause):
    from FuXi.DLP import NormalizeClause, ExtendN3Rules, makeRule
    for hc in ExtendN3Rules(network, NormalizeClause(clause), constructNetwork):
        rule = makeRule(hc, network.nsMap)
        if rule.negativeStratus:
            negativeStratus.append(rule)
        if not rule.negativeStratus or not ignoreNegativeStratus:
            ruleset.add(rule)
예제 #2
0
def HandleNonDisjunctiveClauses(ruleset, network, constructNetwork, negativeStratus, ignoreNegativeStratus, clause):
    from FuXi.DLP import NormalizeClause, ExtendN3Rules, makeRule
    for hc in ExtendN3Rules(network, NormalizeClause(clause), constructNetwork):
        rule = makeRule(hc, network.nsMap)
        if rule.negativeStratus:
            negativeStratus.append(rule)
        if not rule.negativeStratus or not ignoreNegativeStratus:
            ruleset.add(rule)
예제 #3
0
def SetupMetaInterpreter(tBoxGraph, goal, useThingRule=True):
    from pprint import pprint
    from FuXi.LP.BackwardFixpointProcedure import BackwardFixpointProcedure
    from FuXi.Rete.Magic import SetupDDLAndAdornProgram  # , PrettyPrintRule
    from FuXi.Horn.PositiveConditions import BuildUnitermFromTuple  # , Exists
    from FuXi.Rete.TopDown import PrepareSipCollection
    from FuXi.DLP import LloydToporTransformation, makeRule
    from FuXi.Rete.SidewaysInformationPassing import GetOp

    owlThingAppears = False
    if useThingRule and OWL.Thing in tBoxGraph.all_nodes():
        owlThingAppears = True
    completionRules = HornFromN3(StringIO(RULES))
    if owlThingAppears:
        completionRules.formulae.extend(
            HornFromN3(StringIO(CONDITIONAL_THING_RULE)))
    reducedCompletionRules = set()
    for rule in completionRules:
        for clause in LloydToporTransformation(rule.formula):
            rule = makeRule(clause, {})
            # _debug(rule)
            # PrettyPrintRule(rule)
            reducedCompletionRules.add(rule)

    network = SetupRuleStore(makeNetwork=True)[-1]
    SetupDDLAndAdornProgram(
        tBoxGraph,
        reducedCompletionRules,
        [goal],
        derivedPreds=derivedPredicates,
        ignoreUnboundDPreds=True,
        hybridPreds2Replace=hybridPredicates)

    lit = BuildUnitermFromTuple(goal)
    op = GetOp(lit)
    lit.setOperator(URIRef(op + '_derived'))
    goal = lit.toRDFTuple()

    sipCollection = PrepareSipCollection(reducedCompletionRules)
    tBoxGraph.templateMap = {}
    bfp = BackwardFixpointProcedure(
        tBoxGraph,
        network,
        derivedPredicates,
        goal,
        sipCollection,
        hybridPredicates=hybridPredicates,
        debug=True)
    bfp.createTopDownReteNetwork(True)
    _debug(pformat(reducedCompletionRules))
    rt = bfp.answers(debug=True)
    _debug(pformat(rt))
    _debug(bfp.metaInterpNetwork)
    bfp.metaInterpNetwork.reportConflictSet(True, sys.stderr)
    for query in bfp.edbQueries:
        _debug("Dispatched query against dataset: %s" % query.asSPARQL())
    _debug(pformat(list(bfp.goalSolutions)))
예제 #4
0
def SetupMetaInterpreter(tBoxGraph, goal, useThingRule=True):
    from FuXi.LP.BackwardFixpointProcedure import BackwardFixpointProcedure
    from FuXi.Rete.Magic import SetupDDLAndAdornProgram
    from FuXi.Horn.PositiveConditions import BuildUnitermFromTuple
    from FuXi.Rete.TopDown import PrepareSipCollection
    from FuXi.DLP import LloydToporTransformation, makeRule
    from FuXi.Rete.SidewaysInformationPassing import GetOp

    owlThingAppears = False
    if useThingRule and OWL.Thing in tBoxGraph.all_nodes():
        owlThingAppears = True
    completionRules = HornFromN3(StringIO(RULES))
    if owlThingAppears:
        completionRules.formulae.extend(
            HornFromN3(StringIO(CONDITIONAL_THING_RULE)))
    reducedCompletionRules = set()
    for rule in completionRules:
        for clause in LloydToporTransformation(rule.formula):
            rule = makeRule(clause, {})
            # log.debug(rule)
            # PrettyPrintRule(rule)
            reducedCompletionRules.add(rule)

    network = SetupRuleStore(makeNetwork=True)[-1]
    SetupDDLAndAdornProgram(
        tBoxGraph,
        reducedCompletionRules,
        [goal],
        derivedPreds=derivedPredicates,
        ignoreUnboundDPreds=True,
        hybridPreds2Replace=hybridPredicates)

    lit = BuildUnitermFromTuple(goal)
    op = GetOp(lit)
    lit.setOperator(URIRef(op + u'_derived'))
    goal = lit.toRDFTuple()

    sipCollection = PrepareSipCollection(reducedCompletionRules)
    tBoxGraph.templateMap = {}
    bfp = BackwardFixpointProcedure(
        tBoxGraph,
        network,
        derivedPredicates,
        goal,
        sipCollection,
        hybridPredicates=hybridPredicates,
        debug=True)
    bfp.createTopDownReteNetwork(True)
    log.debug(reducedCompletionRules)
    rt = bfp.answers(debug=True)
    log.debug(rt)
    log.debug(bfp.metaInterpNetwork)
    bfp.metaInterpNetwork.reportConflictSet(True, sys.stderr)
    for query in bfp.edbQueries:
        log.debug("Dispatched query against dataset: ", query.asSPARQL())
    log.debug(list(bfp.goalSolutions))
예제 #5
0
def GetELHConsequenceProcedureRules(tBoxGraph, useThingRule=True):
    owlThingAppears = False
    if useThingRule and OWL.Thing in tBoxGraph.all_nodes():
        owlThingAppears = True
    completionRules = HornFromN3(StringIO(RULES))
    if owlThingAppears:
        completionRules.formulae.extend(
            HornFromN3(StringIO(CONDITIONAL_THING_RULE)))
    reducedCompletionRules = set()
    for rule in completionRules:
        for clause in LloydToporTransformation(rule.formula):
            rule = makeRule(clause, {})
            # _debug(rule)
            # PrettyPrintRule(rule)
            reducedCompletionRules.add(rule)
    return reducedCompletionRules
예제 #6
0
def GetELHConsequenceProcedureRules(tBoxGraph, useThingRule=True):
    owlThingAppears = False
    if useThingRule and OWL.Thing in tBoxGraph.all_nodes():
        owlThingAppears = True
    completionRules = HornFromN3(StringIO(RULES))
    if owlThingAppears:
        completionRules.formulae.extend(
            HornFromN3(StringIO(CONDITIONAL_THING_RULE)))
    reducedCompletionRules = set()
    for rule in completionRules:
        for clause in LloydToporTransformation(rule.formula):
            rule = makeRule(clause, {})
            # print rule
            #            PrettyPrintRule(rule)
            reducedCompletionRules.add(rule)
    return reducedCompletionRules