Beispiel #1
0
 def draw(self, prob, targetFile):
     # Do the graphing stuff here...
     # Root graph
     g = Dot(graph_type="digraph", nodesep=2, overlap=False)
     #g.set_edge_defaults(weight="0", minlen="10")
     # Organise by adding constraints (adds edges too)
     for constr in prob.constrs:
         # Node for constraint
         constrNode = Node(constr.name, shape="ellipse", style="filled", fillcolor = "#aaaaff")
         constrNode.set_label(constr.name + ": " + constr.getTextFormula())
         g.add_node(constrNode)
         # Associated expressions
         for expr in constr.exprs:
             self.addNodesForChildren(g, expr, constr)
     # Finally, render
     #g.write_png("problem_structure.png", prog="dot")
     g.write_png(targetFile, prog="neato")
Beispiel #2
0
def generateBGLNode(dot, node, namespace_manager, identifier):
    from FuXi.Rete import ReteNetwork, BetaNode, BuiltInAlphaNode, AlphaNode
    from .BetaNode import LEFT_MEMORY, RIGHT_MEMORY

    vertex = Node(identifier)

    shape = "circle"
    root = False
    if isinstance(node, ReteNetwork):
        root = True
        peripheries = "3"
    elif isinstance(node, BetaNode) and not node.consequent:
        peripheries = "1"
        if node.fedByBuiltin:
            label = "Built-in pass-thru\\n"
        elif node.aPassThru:
            label = "Pass-thru Beta node\\n"
        elif node.commonVariables:
            label = "Beta node\\n(%s)" % (",".join(["?%s" % i for i in node.commonVariables]))
        else:
            label = "Beta node"
        if not node.fedByBuiltin:
            leftLen = node.memories[LEFT_MEMORY] and len(node.memories[LEFT_MEMORY]) or 0
            rightLen = len(node.memories[RIGHT_MEMORY])
            label += "\\n %s in left, %s in right memories" % (leftLen, rightLen)

    elif isinstance(node, BetaNode) and node.consequent:
        # rootMap[vertex] = 'true'
        peripheries = "2"
        stmts = []
        for s, p, o in node.consequent:
            stmts.append(
                " ".join(
                    [
                        str(namespace_manager.normalizeUri(s)),
                        str(namespace_manager.normalizeUri(p)),
                        str(namespace_manager.normalizeUri(o)),
                    ]
                )
            )

        rhsVertex = Node(BNode(), label='"' + "\\n".join(stmts) + '"', shape="plaintext")
        edge = Edge(vertex, rhsVertex)
        # edge.color = 'red'
        dot.add_edge(edge)
        dot.add_node(rhsVertex)
        if node.commonVariables:
            inst = node.network.instantiations.get(node, 0)
            label = str(
                "Terminal node\\n(%s)\\n%d instantiations" % (",".join(["?%s" % i for i in node.commonVariables]), inst)
            )
        else:
            label = "Terminal node"
        leftLen = node.memories[LEFT_MEMORY] and len(node.memories[LEFT_MEMORY]) or 0
        rightLen = len(node.memories[RIGHT_MEMORY])
        label += "\\n %s in left, %s in right memories" % (leftLen, rightLen)
        inst = node.network.instantiations[node]
        if inst:
            label += "\\n%s instantiations" % inst

    elif isinstance(node, BuiltInAlphaNode):
        peripheries = "1"
        shape = "plaintext"
        # label = '..Builtin Source..'
        label = repr(node.n3builtin)
        canonicalFunc = namespace_manager.normalizeUri(node.n3builtin.uri)
        canonicalArg1 = namespace_manager.normalizeUri(node.n3builtin.argument)
        canonicalArg2 = namespace_manager.normalizeUri(node.n3builtin.result)
        label = "%s(%s,%s)" % (canonicalFunc, canonicalArg1, canonicalArg2)

    elif isinstance(node, AlphaNode):
        peripheries = "1"
        shape = "plaintext"
        # widthMap[vertex] = '50em'
        label = " ".join(
            [isinstance(i, BNode) and i.n3() or str(namespace_manager.normalizeUri(i)) for i in node.triplePattern]
        )

    vertex.set_shape(shape)
    vertex.set_label('"%s"' % label)
    vertex.set_peripheries(peripheries)
    if root:
        vertex.set_root("true")
    return vertex
Beispiel #3
0
 def to_node(self):
     node = Node(self.uri)
     node.set_label( self.label_for_properties() )
     return node
Beispiel #4
0
def generateBGLNode(dot, node, namespace_manager, identifier):
    from FuXi.Rete import ReteNetwork, BetaNode, BuiltInAlphaNode, AlphaNode
    from .BetaNode import LEFT_MEMORY, RIGHT_MEMORY
    vertex = Node(identifier)

    shape = 'circle'
    root = False
    if isinstance(node, ReteNetwork):
        root = True
        peripheries = '3'
    elif isinstance(node, BetaNode) and not node.consequent:
        peripheries = '1'
        if node.fedByBuiltin:
            label = "Built-in pass-thru\\n"
        elif node.aPassThru:
            label = "Pass-thru Beta node\\n"
        elif node.commonVariables:
            label = "Beta node\\n(%s)" % (','.join(
                ["?%s" % i for i in node.commonVariables]))
        else:
            label = "Beta node"
        if not node.fedByBuiltin:
            leftLen = node.memories[LEFT_MEMORY] and len(
                node.memories[LEFT_MEMORY]) or 0
            rightLen = len(node.memories[RIGHT_MEMORY])
            label += '\\n %s in left, %s in right memories' % (leftLen,
                                                               rightLen)

    elif isinstance(node, BetaNode) and node.consequent:
        # rootMap[vertex] = 'true'
        peripheries = '2'
        stmts = []
        for s, p, o in node.consequent:
            stmts.append(' '.join([
                str(namespace_manager.normalizeUri(s)),
                str(namespace_manager.normalizeUri(p)),
                str(namespace_manager.normalizeUri(o))
            ]))

        rhsVertex = Node(BNode(),
                         label='"' + '\\n'.join(stmts) + '"',
                         shape='plaintext')
        edge = Edge(vertex, rhsVertex)
        # edge.color = 'red'
        dot.add_edge(edge)
        dot.add_node(rhsVertex)
        if node.commonVariables:
            inst = node.network.instantiations.get(node, 0)
            label = str("Terminal node\\n(%s)\\n%d instantiations" %
                        (','.join(["?%s" % i
                                   for i in node.commonVariables]), inst))
        else:
            label = "Terminal node"
        leftLen = node.memories[LEFT_MEMORY] and len(
            node.memories[LEFT_MEMORY]) or 0
        rightLen = len(node.memories[RIGHT_MEMORY])
        label += '\\n %s in left, %s in right memories' % (leftLen, rightLen)
        inst = node.network.instantiations[node]
        if inst:
            label += "\\n%s instantiations" % inst

    elif isinstance(node, BuiltInAlphaNode):
        peripheries = '1'
        shape = 'plaintext'
        # label = '..Builtin Source..'
        label = repr(node.n3builtin)
        canonicalFunc = namespace_manager.normalizeUri(node.n3builtin.uri)
        canonicalArg1 = namespace_manager.normalizeUri(node.n3builtin.argument)
        canonicalArg2 = namespace_manager.normalizeUri(node.n3builtin.result)
        label = '%s(%s,%s)' % (canonicalFunc, canonicalArg1, canonicalArg2)

    elif isinstance(node, AlphaNode):
        peripheries = '1'
        shape = 'plaintext'
        # widthMap[vertex] = '50em'
        label = ' '.join([
            isinstance(i, BNode) and i.n3()
            or str(namespace_manager.normalizeUri(i))
            for i in node.triplePattern
        ])

    vertex.set_shape(shape)
    vertex.set_label('"%s"' % label)
    vertex.set_peripheries(peripheries)
    if root:
        vertex.set_root('true')
    return vertex