def _resolve_ctx(rules):
    """
    Resolve the context of the rules (the type of this element), and building the ieml element.
    :param rules:
    :return:
    """
    if not rules:
        raise ResolveError("Missing node definition.")

    # if rules == [(None, e)] --> e
    if len(rules) == 1 and rules[0][0] is None:
        return rules[0][1]

    if any(r[0] is None for r in rules):
        raise ResolveError("Multiple definition, multiple ieml object provided for the same node.")

    if any(not isinstance(r[0], Path) for r in rules):
        raise ResolveError("Must have only path instance.")

    # resolve all the possible types for this element
    r0 = rules[0]
    types = _inferred_types(*r0)
    for r in rules[1:]:
        types = types.intersection(_inferred_types(*r))

    if not types:
        raise ResolveError("No definition, no type inferred on rules list.")

    if len(types) > 1:
        raise ResolveError("Multiple definition, multiple type inferred on rules list.")

    type = next(types.__iter__())

    if type == Topic:
        error, deps = _build_deps_topic(rules)
        if error:
            return

        flexing = None
        if deps['f']:
            flexing = deps['f']
        if not deps['r']:
            raise ResolveError("No root for the topic node.")

        return topic(deps['r'], flexing)

    if type == Text:
        error, deps = _build_deps_text(rules)
        if error:
            return

        return text(deps)

    if type in (Theory, Fact):
        error, deps = _build_deps_tree_graph(rules)
        if error:
            return

        if type == Fact:
            clauses = []
            for s, a, m in deps:
                clauses.append((s, a, m))
            return fact(clauses)
        else:
            clauses = []
            for s, a, m in deps:
                clauses.append((s, a, m))
            return theory(clauses)

    raise ResolveError("Invalid type inferred %s"%type.__name__)
def _resolve_ctx(rules):
    """
    Resolve the context of the rules (the type of this element), and building the ieml element.
    :param rules:
    :return:
    """
    if not rules:
        raise ResolveError("Missing node definition.")

    # if rules == [(None, e)] --> e
    if len(rules) == 1 and rules[0][0] is None:
        return rules[0][1]

    if any(r[0] is None for r in rules):
        raise ResolveError("Multiple definition, multiple ieml object provided for the same node.")

    if any(not isinstance(r[0], Path) for r in rules):
        raise ResolveError("Must have only path instance.")

    # resolve all the possible types for this element
    r0 = rules[0]
    types = _inferred_types(*r0)
    for r in rules[1:]:
        types = types.intersection(_inferred_types(*r))

    if not types:
        raise ResolveError("No definition, no type inferred on rules list.")

    if len(types) > 1:
        raise ResolveError("Multiple definition, multiple type inferred on rules list.")

    type = next(types.__iter__())

    if type == Topic:
        error, deps = _build_deps_topic(rules)
        if error:
            return

        flexing = None
        if deps['f']:
            flexing = deps['f']
        if not deps['r']:
            raise ResolveError("No root for the topic node.")

        return topic(deps['r'], flexing)

    if type == Text:
        error, deps = _build_deps_text(rules)
        if error:
            return

        return text(deps)

    if type in (Theory, Fact):
        error, deps = _build_deps_tree_graph(rules)
        if error:
            return

        if type == Fact:
            clauses = []
            for s, a, m in deps:
                clauses.append((s, a, m))
            return fact(clauses)
        else:
            clauses = []
            for s, a, m in deps:
                clauses.append((s, a, m))
            return theory(clauses)

    raise ResolveError("Invalid type inferred %s"%type.__name__)
def _resolve_ctx ( rules ) : if not rules : raise ResolveError ( "Missing node definition." ) # if rules == [(None, e)] --> e if len ( rules ) == 1 and rules [ 0 ] [ 0 ] is None : return rules [ 0 ] [ 1 ] if any ( r [ 0 ] is None for r in rules ) : raise ResolveError ( "Multiple definition, multiple ieml object provided for the same node." ) if any ( not isinstance ( r [ 0 ] , Path ) for r in rules ) : raise ResolveError ( "Must have only path instance." ) # resolve all the possible types for this element r0 = rules [ 0 ] types = _inferred_types ( * r0 ) for r in rules [ 1 : ] : types = types . intersection ( _inferred_types ( * r ) ) if not types : raise ResolveError ( "No definition, no type inferred on rules list." ) if len ( types ) > 1 : raise ResolveError ( "Multiple definition, multiple type inferred on rules list." ) type = next ( types . __iter__ ( ) ) if type == Topic : error , deps = _build_deps_topic ( rules ) if error : return flexing = None if deps [ 'f' ] : flexing = deps [ 'f' ] if not deps [ 'r' ] : raise ResolveError ( "No root for the topic node." ) return topic ( deps [ 'r' ] , flexing ) if type == Text : error , deps = _build_deps_text ( rules ) if error : return return text ( deps ) if type in ( Theory , Fact ) : error , deps = _build_deps_tree_graph ( rules ) if error : return if type == Fact : clauses = [ ] for s , a , m in deps : clauses . append ( ( s , a , m ) ) return fact ( clauses ) else : clauses = [ ] for s , a , m in deps : clauses . append ( ( s , a , m ) ) return theory ( clauses ) raise ResolveError ( "Invalid type inferred %s" % type . __name__ )
Resolve the context of the rules (the type of this element), and building the ieml element.
    :param rules:
    :return:
Resolve the context of the rules ( the type of this element ) and building the ieml element . : param rules : : return :