Skip to content

Commit

Permalink
Do some line adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
yxhong-tw committed May 10, 2023
1 parent 7642f62 commit d7fc4c3
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ def multi_label_accuracy(outputs, label, config, result=None):
result[i]['FP'] += int(((1 - labels1) * outputs1).sum())
result[i]['TN'] += int(((1 - labels1) * (1 - outputs1)).sum())

return result
return result
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/dataset/JsonFromFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def __len__(self):
if self.reduce:
return int(self.reduce_ratio * len(self.data))

return len(self.data)
return len(self.data)
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def eval_one(model, dataset, epoch, writer, config, gpu_list, output_function, t

if task == 'valid':
writer.add_scalar(config.get('output', 'model_name') + '_eval_epoch', float(total_loss) / (step + 1), epoch)
model.train()
model.train()
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/fact_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ def check_odd_chars(string):
process('test')
logger.info('test data processing is complete.')

logger.info('Task completed.')
logger.info('Task completed.')
3 changes: 1 addition & 2 deletions legal_judgment_prediction/tools/formatter/Basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ def __init__(self, config, mode, *args, **params):
self.mode = mode

def process(self, data, config, mode, *args, **params):
return data

return data
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/formatter/Bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ def process(self, data, config, mode, *args, **kwargs):
article_source = torch.LongTensor(article_source)
article = torch.LongTensor(article)

return {'text': input, 'accuse': charge, 'article_source': article_source, 'article': article}
return {'text': input, 'accuse': charge, 'article_source': article_source, 'article': article}
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/model/Bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def forward(self, data, config, gpu_list, acc_result, mode):
for name in ['accuse', 'article_source', 'article']:
acc_result[name] = self.accuracy_function[name](result[name], data[name], config, acc_result[name])

return {'loss': loss, 'acc_result': acc_result, 'output': result}
return {'loss': loss, 'acc_result': acc_result, 'output': result}
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/model/BertEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def __init__(self, config, gpu_list, *args, **params):
def forward(self, x):
_, y = self.bert(x, output_all_encoded_layers=False)

return y
return y
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/model/Predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def forward(self, h):
article_source = article_source.view(batch, -1, 2)
article = article.view(batch, -1, 2)

return {'accuse': charge, 'article': article, 'article_source': article_source}
return {'accuse': charge, 'article': article, 'article_source': article_source}
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/output/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def ljp_output_function(data, config, *args, **params):
for name_ in ['mip', 'mir', 'mif', 'map', 'mar', 'maf']:
result[name].append(temp[name][name_])

return json.dumps(result, sort_keys=True)
return json.dumps(result, sort_keys=True)
2 changes: 1 addition & 1 deletion legal_judgment_prediction/tools/output/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def init_output_function(config, *args, **params):
else:
information = 'There is no model called %s.' % function_name
logger.error(information)
raise AttributeError
raise AttributeError
4 changes: 1 addition & 3 deletions line_bot/Function.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#這個檔案的作用是:建立功能列表

#===============這些是LINE提供的功能套組,先用import叫出來=============
from linebot import (LineBotApi, WebhookHandler)
from linebot.exceptions import (InvalidSignatureError)
from linebot.models import *
#===============LINEAPI=============================================

#以下是本檔案的內容本文

#1.建立旋轉木馬訊息,名為function_list(未來可以叫出此函數來使用)
#function_list的括號內是設定此函數呼叫時需要給函數的參數有哪些

Expand Down Expand Up @@ -169,4 +166,5 @@ def function_list():
]
)
)

return message
13 changes: 9 additions & 4 deletions line_bot/message.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#這些是LINE官方開放的套件組合透過import來套用這個檔案上
from linebot import (LineBotApi, WebhookHandler)
from linebot.exceptions import (InvalidSignatureError)
from linebot.models import *


#ImagemapSendMessage(組圖訊息)
def imagemap_message():
message = ImagemapSendMessage(
Expand Down Expand Up @@ -47,6 +47,7 @@ def imagemap_message():
)
]
)

return message

#TemplateSendMessage - ButtonsTemplate (按鈕介面訊息)
Expand Down Expand Up @@ -77,8 +78,10 @@ def buttons_message():
]
)
)

return message


#TemplateSendMessage - ConfirmTemplate(確認介面訊息)
def Confirm_Template():

Expand All @@ -99,10 +102,11 @@ def Confirm_Template():
]
)
)

return message

#旋轉木馬按鈕訊息介面

#旋轉木馬按鈕訊息介面
def Carousel_Template():
message = TemplateSendMessage(
alt_text='一則旋轉木馬按鈕訊息',
Expand Down Expand Up @@ -168,8 +172,10 @@ def Carousel_Template():
]
)
)

return message


#TemplateSendMessage - ImageCarouselTemplate(圖片旋轉木馬)
def image_carousel_message1():
message = TemplateSendMessage(
Expand Down Expand Up @@ -207,6 +213,5 @@ def image_carousel_message1():
]
)
)
return message

#關於LINEBOT聊天內容範例
return message
3 changes: 2 additions & 1 deletion line_bot/new.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#這些是LINE官方開放的套件組合透過import來套用這個檔案上
from linebot import (LineBotApi, WebhookHandler)
from linebot.exceptions import (InvalidSignatureError)
from linebot.models import *


def test():
message = TemplateSendMessage(
alt_text='圖片旋轉木馬',
Expand Down Expand Up @@ -39,4 +39,5 @@ def test():
]
)
)

return message
7 changes: 4 additions & 3 deletions line_bot/rich_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
headers = {"Authorization":"Bearer UmN0XsFJwcHP8lL7cPrvu30LXwqhMfni5+cTHdjrHKfOGW3DdgNh04ZmflN74CzwyhcRqiDCSzbnGDXhKxRwzXeYmO/1ELsnZFZnKJneME5cWq+hmbUjCongPvcsaSVOI1Ml6KfKoHybjIGM67pFXQdB04t89/1O/w1cDnyilFU=" , "Content-Type":"application/json"}

# ====================================================

# '''
# Step 1 : 設定一次就可以註解掉了
# '''
Expand Down Expand Up @@ -55,12 +56,13 @@
# print(req.text)
# 在這裡要記起 rich_menu_id


# ====================================================

'''
Step 2 : import 要的東西
這段也不能刪掉
'''

from linebot import (
LineBotApi, WebhookHandler
)
Expand All @@ -80,15 +82,14 @@

# ====================================================


req = requests.request('POST', 'https://api.line.me/v2/bot/user/all/richmenu/'+rich_menu_id,
headers=headers)
print(req.text)

rich_menu_list = line_bot_api.get_rich_menu_list()


# ====================================================

"""
上面要重新設定的話要把 ID 刪掉重來
"""
Expand Down
7 changes: 5 additions & 2 deletions line_bot/scraper/law_scraper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# coding=utf-8
# coding=UTF-8

from bs4 import BeautifulSoup
import requests
import re


def get_law_detail(article_of_fact):
laws = ['刑法', '毒品危害防制條例', '商標法', '槍砲彈藥刀械管制條例', '藥事法', '家庭暴力防治法',
'性騷擾防治法', '廢棄物清理法', '妨害兵役治罪條例', '性侵害犯罪防治法', '公職人員選舉罷免法',
Expand All @@ -16,6 +18,7 @@ def get_law_detail(article_of_fact):
# Convert fact to url
re_string = '^([\u4e00-\u9fa5]*)第(\d+)條(之(\d)+)?$'
match = re.findall(re_string, article_of_fact)[0]

try:
pcode = pcodes[laws.index(match[0])]
except:
Expand Down Expand Up @@ -53,8 +56,8 @@ def get_law_detail(article_of_fact):
law_detail += '\n' if idx != len(content) - 1 else ''
true_idx += 1

# print(law_detail)
return law_detail


if __name__ == '__main__':
get_law_detail('刑法第339條之1')
7 changes: 4 additions & 3 deletions line_bot/scraper/today_news_scraper.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Google search news '刑法'
# coding=utf-8
# coding=UTF-8

from bs4 import BeautifulSoup
import requests
import json


def get_today_news(news_count):
url = 'https://news.google.com/topics/CAAqJQgKIh9DQkFTRVFvSUwyMHZNREZ1TlhjU0JYcG9MVlJYS0FBUAE?hl=zh-TW&gl=TW&ceid=TW%3Azh-Hant'

# get html page and parse to soup
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
Expand All @@ -30,9 +32,8 @@ def get_today_news(news_count):
urls.append(short_url)
titles.append(content[i].text)

# print(urls)
# print(titles)
return urls, titles


if __name__ == '__main__':
get_today_news(3)
13 changes: 9 additions & 4 deletions line_bot/scraper/yahoo_scraping.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Yahoo news
# coding=utf-8
# coding=UTF-8

# 1. pick raw text excluding link and figure
# 2. exclude first <p> with ".*報導$"
# 3.
# remove "【《〈()""
# 3. remove "【《〈()""

from bs4 import BeautifulSoup
import requests
import re


def get_news_content(url):
# get html page and parse to soup
response = requests.get(url)
Expand All @@ -17,15 +19,18 @@ def get_news_content(url):
content = soup.find('div', class_='caas-body')
with open('page2.html', 'w') as f:
f.write(content.prettify())

print(content.text)

# get all <p>
# all_paragraph = content.select("p[")
# law_detail = ''

# for idx, a in enumerate(content):
# if idx == 0: continue
# law_detail += f'{idx}. {a.text}'
# law_detail += '\n' if idx != len(content) - 1 else ''
# # print(law_detail)

# return law_detail

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
do_test = args.do_test
train(parameters, config, gpu_list, do_test)
else: # mode == 'eval'
eval(parameters, config, gpu_list)
eval(parameters, config, gpu_list)

0 comments on commit d7fc4c3

Please sign in to comment.