Note that there are some explanatory texts on larger screens.

plurals
  1. POcomparing strings and calculating occurance
    primarykey
    data
    text
    <p>I don't know how to attack this problem!!!</p> <p>I have 3 lists with a word, a tag and a number it appears on a document:</p> <pre><code>v1 = [['be', 'VSIS3S0', 1], ['scott', 'NP00000', 2], ['north', 'NCMS000', 1], ['revolution', 'NP00000', 1], ['name', 'VMP00SM', 1]] v2 = [['mechanic', 'NCMS000', 1], ['be', 'VSIS3S0', 1], ['tool', 'AQ0CS0', 1], ['sam', 'NP00000', 1], ['frida', 'NP00000', 1]] v3 = [['be', 'VSIP3S0', 1], ['scott', 'NP00000', 1], ['who', 'NP00000', 1]] </code></pre> <p>How can I build a function that receiving these lists compare each word so that, for example, the word <code>be</code> in <code>v1</code> appears in the three lists once, in that case append onto a result list <code>(1 * log(3/3))</code>, where 1 -> maximum value of occurrance(which is the 3rd element of the sublist), log numerator 3 -> constant, log denominator 3 -> because the word appears on <code>v1</code>, <code>v2</code> and <code>v3</code>.</p> <p>Next we have <code>scott</code> -> In this case append onto the result list <code>(2 * log(3/2))</code>, 2 -> maximum word´s value of occurrance, log numerator 3 -> constant, log denominator 2 -> because the word 'scott' appears on <code>v1</code> and <code>v2</code>.</p> <p>Next we have <code>north</code> -> In this case append onto the result list <code>(1 * log(3/1))</code>, 1 -> maximum word´s value of occurrance, log numerator 3 -> constant, log denominator 1 -> because the word 'north' appears only <code>v1</code>.</p> <p>Next we have <code>revolution</code> -> In this case append onto the result list <code>(1 * log(3/1))</code>, 1 -> maximum word´s value of occurrance, log numerator 3 -> constant, log denominator 1 -> because the word 'north' appears only <code>v1</code>.</p> <p>Next we have <code>name</code> -> In this case append onto the result list <code>(1 * log(3/1))</code>, 1 -> maximum word´s value of occurrance, log numerator 3 -> constant, log denominator 1 -> because the word 'name' appears only <code>v1</code>.</p> <p>Furthermore we have to do the same with <code>v2</code> by comparing <code>mechanic</code>, <code>be</code>, <code>tool</code>, etc. with the other words, calculate the max value of occurance and multuplying it <code>w/ log(3/?)</code> depending if the word appears or not in <code>v1</code> and <code>v3</code>.</p> <p>This is my attempt for <code>v1</code>:</p> <pre><code>def f1(v1, v2, v3): res =[] for e in v1: if e != 0: if e in v2 and e in v3: res.append(0) elif e in v2: res.append(e * math.log(3/2)) else: res.append(e * math.log(3)) return res </code></pre> <p>returning: <code>[0, 2.1972245773362196, 0, 0, 0, 0]</code></p> <p>and this is obviously not the result</p> <p>it sholud return something like:</p> <pre><code>[['be', 0.47], ['scott', 0.35 ], ['north', 0.47], ['revolution', 0.47], ['north', 0.47]] </code></pre> <p>Hope u can help me w/ this, I have a week trying to solve it!</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload