cl-graph icon indicating copy to clipboard operation
cl-graph copied to clipboard

trying to understand why graph->dot is failing

Open arademaker opened this issue 8 years ago • 7 comments

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 avatar Jul 27 '17 22:07 arademaker

ok, maybe related to #8

arademaker avatar Jul 27 '17 22:07 arademaker

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

arademaker avatar Jul 27 '17 22:07 arademaker

I'll try to look at this this weekend.

gwkkwg avatar Jul 28 '17 13:07 gwkkwg

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. 

gwkkwg avatar Jul 29 '17 20:07 gwkkwg

@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 ?

arademaker avatar Jul 30 '17 23:07 arademaker

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

gwkkwg avatar Aug 03 '17 17:08 gwkkwg

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

alex-ameen avatar Sep 04 '21 00:09 alex-ameen