Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

python - How to match use Fuzz with array input

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?

question from:https://stackoverflow.com/questions/65839889/how-to-match-use-fuzz-with-array-input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...