Hi Peter,<div><br></div><div>just as an aside: did you try the Python wrapper at</div><div><a href="http://bitbucket.org/yannick/cwb-python/overview">http://bitbucket.org/yannick/cwb-python/overview</a></div><div><a href="http://bitbucket.org/yannick/cwb-python/overview"></a>this talks directly to the low-level CWB code, without any pipe in-between,</div>
<div>and would allow you to directly retrieve tokens.</div><div>This means that you have to do some work yourself (i.e., getting</div><div>the offset information from the CQP search subprocess and deciding</div><div>what amount of context to display) but it&#39;s more flexible overall.</div>
<div><br></div><div>Best,</div><div>Yannick<br><br><div class="gmail_quote">On Thu, Aug 19, 2010 at 11:41 AM, Peter Ljunglöf <span dir="ltr">&lt;<a href="mailto:peter.ljunglof@gu.se">peter.ljunglof@gu.se</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Andrew (and others),<br>
<br>
15 aug 2010 kl. 12.36 skrev Hardie, Andrew:<br>
<div class="im"><br>
&gt; Thanks for the patch. You&#39;re right, the current situation looks very messy and needs to change; I didn&#39;t touch the print modules at all in the recent updates to CQP other than to check for Windows incompatibilities. I know that Stefan wanted to do a major overhaul of ALL the print-output modes (if I recall correctly, the plan is cutting them back to two - &quot;plain text&quot; and SGML)<br>

<br>
</div>Sounds like a good idea to me. And make SGML output XML-compatible.<br>
<br>
Also, if you make ALL commands output SGML/XML (if that is the current print-mode), you can get rid of the PrettyPrint flag. It will be much easier to write a new front-end to CWB then.<br>
<div class="im"><br>
&gt; and there is certainly lots of ugliness in the current SGML setup - not just the use of / as a separator, but also the use of HTML-style tags for tables, and the fact that the SGML is not XML-compatible though it easily could be by adding a few end-tags and quotes around att-vals. But the attribute-divider change can be done on its own prior to major fiddling. I&#39;ll add it to the todo list!<br>

<br>
</div>I&#39;d be happy if you could do this, since my Python wrapper depends on these (or similar) fixes.<br>
<font color="#888888"><br>
/Peter<br>
</font><div><div></div><div class="h5"><br>
<br>
&gt;&gt; -----Original Message-----<br>
&gt;&gt; From: <a href="mailto:cwb-bounces@sslmit.unibo.it">cwb-bounces@sslmit.unibo.it</a><br>
&gt;&gt; [mailto:<a href="mailto:cwb-bounces@sslmit.unibo.it">cwb-bounces@sslmit.unibo.it</a>] On Behalf Of Peter Ljunglöf<br>
&gt;&gt; Sent: 14 August 2010 07:15<br>
&gt;&gt; To: <a href="mailto:cwb@sslmit.unibo.it">cwb@sslmit.unibo.it</a><br>
&gt;&gt; Subject: [CWB] CQP output with PrintMode SGML<br>
&gt;&gt;<br>
&gt;&gt; Hi developers,<br>
&gt;&gt;<br>
&gt;&gt; I have started to write a Python wrapper to CQP, and it seems<br>
&gt;&gt; to me that the best KWIC output format is SGML. Then I can<br>
&gt;&gt; extract the KWIC information into a Python object.<br>
&gt;&gt;<br>
&gt;&gt; However, there are two (or three) problems with SGML output<br>
&gt;&gt; which makes it difficult:<br>
&gt;&gt;<br>
&gt;&gt; 1. The attribute separator is &quot;/&quot;, which is a problem when<br>
&gt;&gt; the word or an attribute contains &quot;/&quot;, e.g.:<br>
&gt;&gt;<br>
&gt;&gt; CORPUS&gt; show +lemma;<br>
&gt;&gt; CORPUS&gt; &quot;1/2&quot;;<br>
&gt;&gt; &lt;CONCORDANCE&gt;<br>
&gt;&gt; &lt;attribute type=positional name=&quot;word&quot; anr=0&gt; &lt;attribute<br>
&gt;&gt; type=positional name=&quot;lemma&quot; anr=1&gt;<br>
&gt;&gt; &lt;LINE&gt;(...)&lt;CONTENT&gt;(...)<br>
&gt;&gt; &lt;MATCH&gt;&lt;TOKEN&gt;1/2/1/2&lt;/TOKEN&gt;&lt;/MATCH&gt; (...)&lt;/CONTENT&gt;&lt;/LINE&gt;<br>
&gt;&gt; (...)<br>
&gt;&gt; &lt;/CONCORDANCE&gt;<br>
&gt;&gt;<br>
&gt;&gt; As you can see, it&#39;s impossible to extract the attributes<br>
&gt;&gt; from the SGML. My suggestion is to use &quot;&lt;ATTR&gt;&quot; as the<br>
&gt;&gt; attribute separator instead, which will work since &quot;&lt;&quot; and<br>
&gt;&gt; &quot;&gt;&quot; are SGML escaped.<br>
&gt;&gt;<br>
&gt;&gt; 2. When using an aligned corpus, the SGML in the aligned text<br>
&gt;&gt; is escaped:<br>
&gt;&gt;<br>
&gt;&gt; CORPUS_SWE&gt; show +corpus_nld -lemma;<br>
&gt;&gt; CORPUS_SWE&gt; &quot;veranda&quot;;<br>
&gt;&gt; &lt;CONCORDANCE&gt;<br>
&gt;&gt; &lt;attribute type=positional name=&quot;word&quot; anr=0&gt;<br>
&gt;&gt; &lt;LINE&gt;(...)&lt;CONTENT&gt; (...)<br>
&gt;&gt; &lt;MATCH&gt;&lt;TOKEN&gt;veranda&lt;/TOKEN&gt;&lt;/MATCH&gt; (...)&lt;/CONTENT&gt;&lt;/LINE&gt;<br>
&gt;&gt; &lt;align name=&quot;saltnld_nld&quot;&gt;&amp;lt;CONTENT&amp;gt; (...)<br>
&gt;&gt; &amp;lt;TOKEN&amp;gt;veranda&amp;lt;/TOKEN&amp;gt; (...)<br>
&gt;&gt; &amp;lt;TOKEN&amp;gt;.&amp;lt;/TOKEN&amp;gt; &amp;lt;/CONTENT&amp;gt;<br>
&gt;&gt; (...)<br>
&gt;&gt; &lt;/CONCORDANCE&gt;<br>
&gt;&gt;<br>
&gt;&gt; My suggestion is of course that the aligned text should not<br>
&gt;&gt; be escaped. ALso, that an &quot;&lt;/align&gt;&quot; be printed in the end.<br>
&gt;&gt;<br>
&gt;&gt; 3. A smaller problem (and not a bug at all), is that the rows<br>
&gt;&gt; in the group output are contextual:<br>
&gt;&gt;<br>
&gt;&gt; CORPUS&gt; X = &quot;de&quot; [];<br>
&gt;&gt; CORPUS&gt; group X matchend lemma by match pos cut 50;<br>
&gt;&gt; &lt;TABLE&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;DT&lt;TD&gt;__UNDEF__&lt;TD&gt;152&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;PN&lt;TD&gt;vara&lt;TD&gt;146&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;TD&gt;ha&lt;TD&gt;117&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;TD&gt;skola&lt;TD&gt;100&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;TD&gt;inte&lt;TD&gt;89&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;TD&gt;komma&lt;TD&gt;80&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;DT&lt;TD&gt;mången&lt;TD&gt;71&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;TD&gt;där&lt;TD&gt;61&lt;/TR&gt;<br>
&gt;&gt; &lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;TD&gt;andra,annan,två&lt;TD&gt;52&lt;/TR&gt;<br>
&gt;&gt; &lt;/TABLE&gt;<br>
&gt;&gt;<br>
&gt;&gt; The 3rd row 1st column contains &quot;&amp;nbsp;&quot;, which is a way of<br>
&gt;&gt; saying &quot;the same as above&quot;. This is okay for ascii output and<br>
&gt;&gt; HTML output, but SGML is designed for computer readability,<br>
&gt;&gt; so personally I think that it shouldn&#39;t refer to earlier<br>
&gt;&gt; rows. Similar to &quot;PrettyPrint off&quot;, which only works for<br>
&gt;&gt; &quot;PrintMode ascii&quot;...<br>
&gt;&gt;<br>
&gt;&gt; My suggestion is that the group printer only prints &amp;nbsp; if<br>
&gt;&gt; PrettyPrint is on.<br>
&gt;&gt;<br>
&gt;&gt; 4. I did some digging in the source code, and it was pretty<br>
&gt;&gt; easy to do the necessary changes. (Kudos to the programmers<br>
&gt;&gt; for making the code readable). Only 4 lines are affected,<br>
&gt;&gt; here&#39;s a diff:<br>
&gt;&gt;<br>
&gt;&gt; Index: sgml-print.c<br>
&gt;&gt; ===================================================================<br>
&gt;&gt; --- sgml-print.c     (revision 182)<br>
&gt;&gt; +++ sgml-print.c     (working copy)<br>
&gt;&gt; @@ -77,7 +77,7 @@<br>
&gt;&gt;<br>
&gt;&gt;   &quot;&lt;TOKEN&gt;&quot;,                    /* BeforeToken */<br>
&gt;&gt;   &quot; &quot;,                          /* TokenSeparator */<br>
&gt;&gt; -  &quot;/&quot;,                          /* AttributeSeparator */<br>
&gt;&gt; +  &quot;&lt;ATTR&gt;&quot;,                     /* AttributeSeparator */<br>
&gt;&gt;   &quot;&lt;/TOKEN&gt;&quot;,                   /* AfterToken */<br>
&gt;&gt;<br>
&gt;&gt;   &quot;&lt;CONTENT&gt;&quot;,                  /* BeforeField */<br>
&gt;&gt; @@ -213,7 +213,8 @@<br>
&gt;&gt;   sgml_puts(stream, &quot;&lt;align name=\&quot;&quot;, 0);<br>
&gt;&gt;   sgml_puts(stream, attribute_name, 0);<br>
&gt;&gt;   sgml_puts(stream, &quot;\&quot;&gt;&quot;, 0);<br>
&gt;&gt; -  sgml_puts(stream, line, SUBST_ALL);<br>
&gt;&gt; +  sgml_puts(stream, line, 0);<br>
&gt;&gt; +  sgml_puts(stream, &quot;&lt;/align&gt;&quot;, 0);<br>
&gt;&gt;<br>
&gt;&gt;   fputc(&#39;\n&#39;, stream);<br>
&gt;&gt; }<br>
&gt;&gt; @@ -431,7 +432,7 @@<br>
&gt;&gt;<br>
&gt;&gt;     source_id = group-&gt;count_cells[cell].s;<br>
&gt;&gt;<br>
&gt;&gt; -    if (source_id != last_source_id) {<br>
&gt;&gt; +    if (!pretty_print || (source_id != last_source_id)) {<br>
&gt;&gt;       last_source_id = source_id;<br>
&gt;&gt;       sgml_puts(fd, Group_id2str(group, source_id, 0), SUBST_ALL);<br>
&gt;&gt;       nr_targets = 0;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; best,<br>
&gt;&gt; /Peter Ljunglöf<br>
&gt;&gt;<br>
&gt;&gt; ______________________________________________________________<br>
&gt;&gt; __________________<br>
&gt;&gt; peter ljunglöf, språkbanken, göteborgs universitet<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; CWB mailing list<br>
&gt;&gt; <a href="mailto:CWB@sslmit.unibo.it">CWB@sslmit.unibo.it</a><br>
&gt;&gt; <a href="http://devel.sslmit.unibo.it/mailman/listinfo/cwb" target="_blank">http://devel.sslmit.unibo.it/mailman/listinfo/cwb</a><br>
&gt;&gt;<br>
&gt; _______________________________________________<br>
&gt; CWB mailing list<br>
&gt; <a href="mailto:CWB@sslmit.unibo.it">CWB@sslmit.unibo.it</a><br>
&gt; <a href="http://devel.sslmit.unibo.it/mailman/listinfo/cwb" target="_blank">http://devel.sslmit.unibo.it/mailman/listinfo/cwb</a><br>
<br>
</div></div>________________________________________________________________________________<br>
<div><div></div><div class="h5">peter ljunglöf, språkbanken, göteborgs universitet<br>
<br>
<br>
_______________________________________________<br>
CWB mailing list<br>
<a href="mailto:CWB@sslmit.unibo.it">CWB@sslmit.unibo.it</a><br>
<a href="http://devel.sslmit.unibo.it/mailman/listinfo/cwb" target="_blank">http://devel.sslmit.unibo.it/mailman/listinfo/cwb</a><br>
</div></div></blockquote></div><br></div>