I'd better post here instead of the IRC so we get a more public discussion.

Background: I'm counting words in texts and storing them in idx lists where
the word is the key and the count the value. When storing in the database
somehow the value (count) gets lost and I have no idea why.

In the real application the situation is more complex, but I've been able to
isolate what is happening in this code:

(class +Awords +Entity)
(rel idx (+Key +Any))

(pool "tmp.db")

(de countWords (L)
   (let Words NIL
      (for W (split L "," "." ";" ":" ")" "[" "]" "{" "}" "(" "/" "!" "?"
"\"" "\\" "=" "+" "*" " " "|" "^M" "^J" "<" ">")
         (and
            (setq W (lowc (pack W)))
            (not (idx '*Common W))
            (if (idx 'Words W T)
               (inc (car @))
               (set W 1))))
      Words ))

(setq Wrds (chop "hello hello world apple orange strawberry apple hello"))
(setq Widx (countWords Wrds))

(println (val (car (idx 'Widx "hello"))))

(new! '(+Awords) 'idx Widx)
(setq Wdb (; (car (collect 'idx '+Awords)) idx))

(println (val (car (idx 'Wdb "hello"))))

The *Common global is an idx of common words I want to filter out, it can be
disregarded in this example as it is not important to the issue at hand
here. The code will work without it, we simply end up not filtering out any
words at all.

Output:
3
"hello"
-> "hello"

What I'm after in the end is of course the number 3, not "hello". Somehow I
think there is something I haven't really understood here.

Cheers,

/Henrik

------=_Part_31993_13682467.1223103454766
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<div dir="ltr">I&#39;d better post here instead of the IRC so we get a more 
public discussion.<br><br>Background: I&#39;m counting words in texts and 
storing them in idx lists where the word is the key and the count the value. 
When storing in the database somehow the value (count) gets lost and I have no 
idea why.<br>
<br>In the real application the situation is more complex, but I&#39;ve been 
able to isolate what is happening in this code:<br><br>(class +Awords 
+Entity)<br>(rel idx (+Key +Any))<br><br>(pool &quot;tmp.db&quot;)<br><br>
(de countWords (L)<br>&nbsp;&nbsp; (let Words 
NIL<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (for W (split L &quot;,&quot; 
&quot;.&quot; &quot;;&quot; &quot;:&quot; &quot;)&quot; &quot;[&quot; 
&quot;]&quot; &quot;{&quot; &quot;}&quot; &quot;(&quot; &quot;/&quot; 
&quot;!&quot; &quot;?&quot; &quot;\&quot;&quot; &quot;\\&quot; &quot;=&quot; 
&quot;+&quot; &quot;*&quot; &quot; &quot; &quot;|&quot; &quot;^M&quot; 
&quot;^J&quot; &quot;&lt;&quot; &quot;&gt;&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (and 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq W 
(lowc (pack W))) 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (not 
(idx &#39;*Common W)) 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if (idx 
&#39;Words W 
T)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 (inc (car 
@))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 (set W 1))))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Words ))<br>
<br>(setq Wrds (chop &quot;hello hello world apple orange strawberry apple 
hello&quot;))<br>(setq Widx (countWords Wrds))<br><br>(println (val (car (idx 
&#39;Widx &quot;hello&quot;))))<br><br>(new! &#39;(+Awords) &#39;idx Widx)<br>
(setq Wdb (; (car (collect &#39;idx &#39;+Awords)) idx))<br><br>(println (val 
(car (idx &#39;Wdb &quot;hello&quot;))))<br><br>The *Common global is an idx of 
common words I want to filter out, it can be disregarded in this example as it 
is not important to the issue at hand here. The code will work without it, we 
simply end up not filtering out any words at all.<br>
<br>Output:<br>3<br>&quot;hello&quot;<br>-&gt; &quot;hello&quot;<br><br>What 
I&#39;m after in the end is of course the number 3, not &quot;hello&quot;. 
Somehow I think there is something I haven&#39;t really understood here. <br>
<br>Cheers,<br><br>/Henrik<br></div>

------=_Part_31993_13682467.1223103454766--
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]

Reply via email to