def contraposition(self, ygivenx, ygivennotx, ax): Px_given_y = ax * ygivenx.p / (ax * ygivenx.p + (1 - ax) * ygivennotx.p) if ( ax * ygivenx.p + (1 - ax) * ygivennotx.p > 0 ) else +(ax * ygivenx.p != 0) Px_given_noy = ax * (1 - ygivenx.p) / ( ax * (1 - ygivenx.p) + (1 - ax) * (1 - ygivennotx.p)) if ( ax * (1 - ygivenx.p) + (1 - ax) * (1 - ygivennotx.p) > 0) else +(ax * (1 - ygivenx.p) != 0) u_maxi_xy = Px_given_y / ax if ( Px_given_y < ax or ax == 1) else (1 - Px_given_y) / (1 - ax) u_maxi_xnoy = Px_given_noy / ax if ( Px_given_noy < ax or ax == 1) else (1 - Px_given_noy) / (1 - ax) uSyX = ygivenx.u + ygivennotx.u wuyx = ygivenx.u / uSyX if (uSyX > 0) else +(ygivenx.u != 0) wuynox = ygivennotx.u / uSyX if (uSyX > 0) else +(ygivennotx.u != 0) u_maxiyx = ygivenx.p / ygivenx.a if ( ygivenx.p < ygivenx.a or ygivenx.a == 1) else (1 - ygivenx.p) / (1 - ygivenx.a) u_maxiynox = ygivennotx.p / ygivenx.a if ( ygivennotx.p < ygivenx.a or ygivenx.a == 1) else (1 - ygivennotx.p) / (1 - ygivenx.a) uwyx = wuyx * ygivenx.u / u_maxiyx if (u_maxiyx != 0) else 0 uwynox = wuynox * ygivennotx.u / u_maxiynox if (u_maxiynox != 0) else 0 uwyX = uwyx + uwynox vacuous_uxy = uwyX + (1 - abs(ygivenx.p - ygivennotx.p)) * (1 - uwyX) u_x_cp_y = u_maxi_xy * vacuous_uxy u_x_cp_noy = u_maxi_xnoy * vacuous_uxy b_x_cp_y = Px_given_y - ax * u_x_cp_y b_x_cp_noy = Px_given_noy - ax * u_x_cp_noy dr1 = 1 - u_x_cp_y - b_x_cp_y dr2 = 1 - u_x_cp_noy - b_x_cp_noy if (dr1 < 0): b_x_cp_y += dr1 dr1 = 0 elif (b_x_cp_y < 0): dr1 += b_x_cp_y b_x_cp_y = 0 if (dr1 + b_x_cp_y + u_x_cp_y > 1): u_x_cp_y = 1 - dr1 - b_x_cp_y if (dr2 < 0): b_x_cp_noy += dr2 dr2 = 0 elif (b_x_cp_noy < 0): dr2 += b_x_cp_noy b_x_cp_noy = 0 if (dr2 + b_x_cp_noy + u_x_cp_noy > 1): u_x_cp_noy = 1 - dr2 - b_x_cp_noy o1 = Opinion(b_x_cp_y, dr1, u_x_cp_y, ax) o2 = Opinion(b_x_cp_noy, dr2, u_x_cp_noy, ax) return o1, o2
def constraintfusion(self, x, y): har = x.b * y.u + y.b * x.u + x.b * y.b con = x.b * y.d + y.b * x.d if (con == 1): return Opinion(0.5, 0.5, 0.5, 0.5) u = x.u * y.u / (1 - con) b = har / (1 - con) a = (x.a * (1 - x.u) + y.a * (1 - y.u)) / (2 - x.u - y.u) if ( x.u + y.u < 2) else (x.a + y.a) / 2 return Opinion(b, 1 - u - b, u, a)
def codivision(self, x, y): if not x.a > y.a: print("Base Rate Constraint not satisfied") return None if not x.b >= y.b: print("Belief Constraint not satisfied") return None d_constraint = (((1 - x.a) * y.a * (1 - y.b) * y.d) / (x.a * (1 - y.a) * (1 - y.b))) u_constraint = ((y.a * (1 - x.b) * y.u) / (x.a * (1 - y.b))) if not x.d >= d_constraint: print("Disbelief Constraint not satisfied") return None if not x.u >= u_constraint: print("Uncertainty constraint not satisfied") return None b = ((x.b - y.b) / (1 - y.b)) d = ((((1 - y.a) * (x.d + ((1 - x.a) * x.u))) / ((x.a - y.a) * (y.d + ((1 - y.a) * y.u)))) - (((1 - x.a) * (1 - x.b)) / ((x.a - y.a) * (1 - y.b)))) u = (((1 - y.a) * (1 - x.b)) / ((x.a - y.a) * (1 - y.b))) - (((1 - y.a) * (x.d + (1 - x.a) * x.u)) / ((x.a - y.a) * (y.d + (1 - y.a) * y.u))) a = (x.a - y.a) / (1 - y.a) return Opinion(belief=b, disbelief=d, uncertainty=u, baserate=a)
def subtraction(self, xuy, y): b = xuy.b - y.b d = ((xuy.a * (xuy.d + y.b)) - (y.a * (1 - y.b - xuy.b - y.u)) / (xuy.a - y.a)) u = (((xuy.a * xuy.u) - (y.a * y.u)) / xuy.a - y.a) a = xuy.a - y.a return Opinion(belief=b, disbelief=d, uncertainty=u, baserate=a)
def deduction(self, y_x, y_notx, x): bIy = x.b * y_x.b + x.d * y_notx.b + x.u * (y_x.b * x.a + y_notx.b * (1 - x.a)) dIy = x.b * y_x.d + x.d * y_notx.d + x.u * (y_x.d * x.a + y_notx.d * (1 - x.a)) uIy = x.b * y_x.u + x.d * y_notx.u + x.u * (y_x.u * x.a + y_notx.u * (1 - x.a)) Pyvacuousx = y_x.b * x.a + y_notx.b * (1 - x.a) + y_x.a * ( y_x.u * x.a + y_notx.u * (1 - x.a)) if (((y_x.b > y_notx.b) and (y_x.d > y_notx.d)) or ((y_x.b <= y_notx.b) and (y_x.d <= y_notx.d))): k = 0 elif ((y_x.b > y_notx.b) and (y_x.d <= y_notx.d)): if (Pyvacuousx <= (y_notx.b + y_x.a * (1 - y_notx.b - y_x.d))): if (x.p <= x.a): k = x.a * x.u * (bIy - y_notx.b) / (y_x.a * x.p) else: k = x.a * x.u * (dIy - y_x.d) * (y_x.b - y_notx.b) / ( (x.d + (1 - x.a) * x.u) * y_x.a * (y_notx.d - y_x.d)) else: if (x.p <= x.a): k = (1 - x.a) * x.u * (bIy - y_notx.b) * ( y_notx.d - y_x.d) / (x.p * (1 - y_x.a) * (y_x.b - y_notx.b)) else: k = (1 - x.a) * x.u * (dIy - y_x.d) / ((1 - y_x.a) * (x.d + (1 - x.a) * x.u)) else: if (Pyvacuousx <= (y_notx.b + y_x.a * (1 - y_notx.b - y_x.d))): if (x.p <= x.a): k = (1 - x.a) * x.u * (dIy - y_notx.d) * ( y_notx.b - y_x.b) / (x.p * y_x.a * (y_x.d - y_notx.d)) else: k = (1 - x.a) * x.u * (bIy - y_x.b) / (y_x.a * (x.d + (1 - x.a) * x.u)) else: if (x.p <= x.a): k = x.a * x.u * (dIy - y_notx.d) / (x.p * (1 - y_x.a)) else: k = x.a * x.u * (bIy - y_x.b) * (y_x.d - y_notx.d) / ( (1 - y_x.a) * (y_notx.b - y_x.b) * (x.d + (1 - x.a) * x.u)) if (math.isnan(k)): k = 0 by = bIy - y_x.a * k dy = dIy - (1 - y_x.a) * k uy = uIy + k return (Opinion(belief=by, disbelief=dy, uncertainty=uy, baserate=y_x.a))
def comultiplication(self, x, y): temp1 = ((((1 - y.a) * x.a * x.d * y.u) + ((1 - x.a) * y.a * y.d * x.u)) / (x.a + y.a - (x.a * y.a))) temp2 = ((y.a * x.d * y.u) + (x.a * x.u * y.d)) / (x.a + y.a - (x.a * y.a)) b = x.b + y.b - (x.b * y.b) d = (x.d * y.d) + temp1 u = (x.u * y.u) + temp2 a = x.a + y.a - (x.a * y.a) return Opinion(belief=b, disbelief=d, uncertainty=u, baserate=a)
def multiplication(self, x, y): temp = ((((1 - x.a) * y.a * x.b * y.u) + ((1 - y.a) * x.a * y.b * x.u)) / (1 - x.a * y.a)) b = (x.b * y.b) + temp d = x.d + y.d - (x.d * y.d) temp2 = ((((1 - y.a) * x.b * y.u) + ((1 - x.a) * y.b * x.u)) / (1 - x.a * y.a)) u = (x.u * y.u) + temp2 a = (x.a * y.a) return Opinion(belief=b, disbelief=d, uncertainty=u, baserate=a)
def cumulativefusion(self, x, y): if (x.u != 0 or y.u != 0): b = (x.b * y.u + y.b * x.u) / (x.u + y.u - x.u * y.u) u = x.u * y.u / (x.u + y.u - x.u * y.u) a = (x.a * y.u + y.a * x.u - (x.a + y.a) * x.u * y.u) / (x.u + y.u - 2 * x.u * y.u) if ( x.u != 1 or y.u != 1) else (x.a + y.a) / 2 else: b = 0.5 * (x.b + y.b) u = 0 a = 0.5 * (x.a + y.a) return Opinion(b, 1 - u - b, u, a)
def handle(self, id, app, div_comment, driver): self.driver = driver autor = div_comment.find_element_by_class_name("X43Kjb").text data = div_comment.find_element_by_class_name("p2TkOb").text likes = div_comment.find_element_by_class_name("jUL89d").text if likes.strip() == '': likes = 0 else: likes = int(likes) estrelas = len(div_comment.find_elements_by_class_name("vQHuPe")) texto = self.extract_text(div_comment) if texto.strip() == '': return (False, None) #link_comment = self.extract_link(div_comment) opiniao = Opinion(id, autor, app, data, estrelas, texto, likes, 0) return (True, opiniao)
def post_opinion(): keywords = request.json['keywords'] opinion = request.json['opinion'] try: op = Opinion(keywords, opinion).get() except: abort(404) result = { "result": True, "data": { "posOpinions": op.positives, "negOpinions": op.negatives } } return make_response(jsonify(result))
def handle_comment(self, review): self.driver.implicitly_wait(0) html_doc = review.get_attribute('innerHTML') soup = BeautifulSoup(html_doc, 'html.parser') link_perfil_user = soup.select_one(".user-name")['href'] autor = link_perfil_user.split('/')[2] link_review = soup.select_one(".age")['href'] id = link_review.split('/')[2] data_review = soup.select_one(".age").text.strip() now = datetime.now() collect_date = now.strftime("%d-%m-%Y %H:%M") # remoção de tags spoiler desnecessárias msg_spoiler = soup.select_one(".comment-text").select(".message") for msg_tag in msg_spoiler: msg_tag.decompose() # fim remoção review_text = soup.select_one(".comment-text").text star_tag = soup.select_one(".star-rating") star_rating = re.search('\d(\.\d)?', star_tag['title']).group(0) if star_tag else 0 tag_see = soup.select_one('.icon-ok-sign') see = 1 if tag_see else 0 tag_wsee = soup.select_one('.icon-plus-sign') wsee = 1 if tag_wsee else 0 tag_fav = soup.select_one('.favorite') favorito = 1 if tag_fav else 0 likes = int(soup.select_one('.count').text) tag_replies = soup.select_one('.comment-show-replies') replies = int( tag_replies.text.strip().split(' ')[0] if tag_replies else 0) opinion = Opinion(id, autor, self.key_movie, data_review, star_rating, review_text, likes, 0, '', link_review, link_perfil_user, collect_date, see, wsee, favorito, replies) self.driver.implicitly_wait(5) return opinion
def division(self, x, y): if not x.a < y.a: print("Base Rate Constraint not satisfied") return None if not x.d >= y.d: print("Disbelief Constraint not satisfied") return None b_constraint = (x.a * (1 - y.a) * (1 - x.d) * y.b) / ((1 - x.a) * y.a * (1 - x.d)) u_constraint = (((1 - y.a) * (1 - x.d) * y.u) / ((1 - x.a) * (1 - y.d))) if not x.b >= b_constraint: print("Belief Constraint not satisfied") return None if not x.u >= u_constraint: print("Uncertainty Constraint not satisfied") return None b = (((y.a * (x.b + x.a * x.u)) / ((y.a - x.a) * (y.b + y.a * y.u))) - ((x.a * (1 - x.d)) / ((y.a - x.a) * (1 - y.d)))) d = (x.d - y.d) / (1 - y.d) u = (((y.a * (1 - x.d)) / ((y.a - x.a) * (1 - y.d))) - ((y.a * (x.b + x.a * x.u)) / ((y.a - x.a) * (y.b + y.a * y.u)))) a = x.a / y.a return Opinion(belief=b, disbelief=d, uncertainty=u, baserate=a)
if row['PrimaryProbDescription'] not in given_notgiven: given_notgiven[row['PrimaryProbDescription']] = [0, 0] if row['PrimaryProbDescription'] == row['DspProbCodeDescription']: given_notgiven[row['PrimaryProbDescription']][0] += 1 else: given_notgiven[row['PrimaryProbDescription']][1] += 1 given_notgiven_df = pd.DataFrame.from_dict(given_notgiven, orient='index', columns=['correctdsptch', 'wrongdsptch']) given_notgiven_df.to_csv('primary_given.csv') primaryopinions = [] W = 2 a = 0.5 for index, row in given_notgiven_df.iterrows(): r = int(row['correctdsptch']) s = int(row['wrongdsptch']) t = s + r b = r / (W + t) d = s / (W + t) u = 2 / (W + t) primaryopinions.append(Opinion(b, d, u, a)) # y_x = Opinion(belief=0.55, disbelief=0.15, uncertainty=0.3, baserate=0.39) # y_notx = Opinion(belief=0.15, disbelief=0.7, uncertainty=0.15, baserate=0.39) # x = Opinion(belief=0.48, disbelief=0.22, uncertainty=0.3, baserate=0.4) # db = DedAbd() # print("y given x: ", y_x) # print("y given notx: ", y_notx) # print("x: ", x) # print("Deduction: ", db.deduction(y_x, y_notx, x))
def complement(self, x): b = 1 - x.d d = 1 - x.b u = x.u a = 1 - x.a return Opinion(belief=b, disbelief=d, uncertainty=u, baserate=a)
def addition(self, x, y): b = x.b + y.b a = x.a + y.a d = (((x.a * (x.d - y.b)) + (y.a * (y.d - x.b))) / a) u = (((x.a * x.u) + (y.a * y.u)) / a) return Opinion(belief=b, disbelief=d, uncertainty=u, baserate=a)