hraban / cl-graph

Common Lisp library for manipulating graphs and running graph algorithms
http://common-lisp.net/project/cl-graph/
Other
73 stars 13 forks source link

trying to understand why graph->dot is failing #12

Open arademaker opened 6 years ago

arademaker commented 6 years ago

I am trying to use cl-graph with https://github.com/own-pt/cl-conllu library. This library read conllu files (http://universaldependencies.org/format.html -- with a sentence tokenized). The library implements a class for a sentence that contains tokens (another class).

The first part works:

(let* ((sent (car (read-conllu #P"CF107.conllu")))
        (tks  (sentence-tokens sent))
        (g (cl-graph:make-graph 'cl-graph:graph-container)))
       (dolist (tk tks g)
         (if (equal "0" (token-head tk))
         (add-vertex g tk)
         (add-edge-between-vertexes g tk (nth (token-head tk) tks) :edge-type :directed))))

But it seems the problem is with the edges when I try:

(cl-graph:graph->dot
      *
      nil
      :vertex-labeler 
      (lambda (vertex stream)
        (format stream "~(~A~)" (token-form (element vertex))))
      :edge-formatter
      (lambda (edge stream)
        (format stream "~a" (element edge))))

I got

There is no applicable method for the generic function
  #<STANDARD-GENERIC-FUNCTION CL-GRAPH:DOT-ATTRIBUTE-VALUE (1)>
when called with arguments
  (:LABEL
   #<GRAPH-CONTAINER-DIRECTED-EDGE <#<#<TOKEN {100301C313}>> #<#<TOKEN {100301B153}>> NIL>>).
   [Condition of type SIMPLE-ERROR]

What did I miss?

arademaker commented 6 years ago

ok, maybe related to #8

arademaker commented 6 years ago

But what is the best alternative to customize the edges label? How can I setup the edge's label during the graph construction?

gwkkwg commented 6 years ago

I'll try to look at this this weekend.

gwkkwg commented 6 years ago

So it's been a long time and I'm not sure about the best fix but the problem is that the graph you use for graph->dot must be a subclass of a dot-graph:


(defclass* dot-graph (dot-graph-mixin graph-container)
  ()
  (:export-p t))```

So _I_ think if you use this graph type, you'll be all set. 
arademaker commented 6 years ago

@gwkkwg thank you. But I am still trying to figure out what is the best way to use the lib. I imagine that I should make my classes (sentence and token) subclasses of graph and vertex, right ?

gwkkwg commented 6 years ago

Yes, making subclasses is the thing to do. (Sorry for the delay)

aakropotkin commented 2 years ago

I just ran into this same issue. Y'all should update the guide, it's super misleading since it's the only example.