1

I want to try to get match values from the two arrays I input. I use Fuzzy for that. but I still can't get that value, maybe because the input form is an array. help me, please :)

Thank you and I'm sorry if my question does not clear. Thank you :)

a = [
      [
        "nyeri",
        "tekan"
      ],
      [
        "nyeri",
        "pada",
        "kulit"
      ],
      [
        "demam"
      ]
   ]

b = [
      [
        "nyeri",
        "tekan"
      ],
      [
        "pembengkakan",
        "pada",
        "kulit"
      ],
      [
        "demam",
        "tinggi"
      ]
   ]

I tried the following code :

c = []
for i in range(0, len(a)):
    for j in range(0, len(b):   
    
        Matching = fuzz.ratio(a,b)
        
        if len(a) == len(b) and Matching == 100:
            c.append([a, 'value:', 1])  
        elif len(a) != len(b) and 90 <= Matching <= 99:
            c.append([a, 'value:', 0.8])
        elif len(a) != len(b) and 80 <= Matching <= 89:
            c.append([a, 'value:', 0.7])
        elif len(a) != len(b) and 70 <= Matching <= 79:
            c.append([a, 'value:', 0.6])
        elif len(a) != len(b) and 0 <= Matching <= 69:
            c.append([a, 'value:', 0])
        return jsonify(c)

expected result :

[
      [
        "nyeri",
        "tekan"
      ], 
      "value:", 1
      [
        "nyeri",
        "pada",
        "kulit"
      ],
      "value:", 0
      [
        "demam"
      ],
      "value:", 0
]
     

Can someone help?

davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

2

You're taking the fuzz ratio on the overall a object. i and j are completely unused. I assume that this is closer to what you're actually attempting.

c = jsonify([
  fuzz.ratio(a_element,b_element)
  for a_element in a
  for b_element in b
])
Ted Brownlow
  • 1,103
  • 9
  • 15